• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Over-Run;37988196]Okay so for my 3rd year college project I was thinking of doing an AI simulation. I was thinking of having it top down, a single AI at first, just in a house and it interacts with stuff, eventually I was thinking of being able to give the AI a personality the user defines at start up so the AI will do stuff dependant on what mood it's in. Just wondering if anybody here thinks its a good idea for a project and where I should look for some help with this. I'm guessing the hardest part will be collision detection and having the AI move to certain areas freely, but after that I suppose it would be a lot of if statements for the whole mood dependant stuff. I was going to have like a box on the GUI where text will print out what the AI is doing so it could be quite entertaining. So yeah, what would be some good resources for this stuff?[/QUOTE] 90 day virtual simulation of this, where you can control the time. Also, have a document made at the end of the simulation, retelling all of his actions. Also, make random events occur every now an then, such as a stray cat showing up on the doorstep. Depending on his mood, he will either care for it, not care for it, or kick it out. That's just one example, but the premise could be applied to many circumstances. Good luck!
Man that cat idea is good can I steal it?
Credit me as "Guy with cat idea"
Ok, I [i]REALLY[/i] need help with dealing with circular dependencies/references in c++. Could someone please tell me what I'm doing wrong here and how to fix it? A.h: [code]#include <iostream> using namespace std; #include "B.h" class A { public: A() { cout << "A Start" << endl; b = new B(this); } void test1() { cout << "A Test1\n"; b->test1(); } void test2() { cout << "A Test2\n"; } B *b; };[/code] B.h: [code]#include <iostream> using namespace std; #include "C.h" class A; class B { public: B(A *a) { cout << "B Start" << endl; c = new C(a,this); this->a = a; } void test1() { cout << "B Test1\n"; c->test1(); } void test2() { cout << "B Test2\n"; a->test2(); } C *c; A *a; };[/code] C.h [code]#include <iostream> using namespace std; class B; class A; class C { public: C(A *a, B *b) { cout << "C Start" << endl; this->a = a; this->b = b; } void test1() { cout << "C Test1\n"; test2(); } void test2() { cout << "C Test2\n"; b->test2(); } A *a; B *b; };[/code] Main.cpp [code]#include <iostream> using namespace std; #include "A.h" void main() { A *lol = new A(); lol->test1(); system("pause"); }[/code] And incase you need them, here are the errors i'm getting (all linker): [code]Error 1 error C2027: use of undefined type 'B' c:\users\andrey\documents\visual studio 2012\projects\circular dependancy fixer\circular dependancy fixer\c.h 24 Error 2 error C2227: left of '->test2' must point to class/struct/union/generic type c:\users\andrey\documents\visual studio 2012\projects\circular dependancy fixer\circular dependancy fixer\c.h 24 Error 3 error C2027: use of undefined type 'A' c:\users\andrey\documents\visual studio 2012\projects\circular dependancy fixer\circular dependancy fixer\b.h 24 Error 4 error C2227: left of '->test2' must point to class/struct/union/generic type c:\users\andrey\documents\visual studio 2012\projects\circular dependancy fixer\circular dependancy fixer\b.h 24 [/code]
You need to include "A.h" in B.h and both A.h and B.h in C.h
Nope, tried that already: [code]#ifndef ch #define ch #include <iostream> using namespace std; //class B; //class A; #include "A.h" #include "B.h" class C { public: C(A *a, B *b) { cout << "C Start" << endl; this->a = a; this->b = b; } void test1() { cout << "C Test1\n"; test2(); } void test2() { cout << "C Test2\n"; b->test2(); } A *a; B *b; }; #endif[/code] With different variations of the "class a/b" and "#include A/b" stuff in both a.h and b.h (Aka, different positioning, commenting some out, etc).\ There must be a way to do this properly.
Simple answer: only store declarations in header (.h) files. Put definitions into code files (.cpp). [b]a.h[/b] [cpp]// Include b.h because this header references a class in b.h #include "b.h" class A { public: A(B *b); void dothings(); B *b; };[/cpp] [b]a.cpp[/b] [cpp]// a.h already includes b.h so including b.h is not necessary here // but since this file does use content in b.h, I'd do it for clarity // #include "b.h" #include "a.h" A::A(B *b) { this->b = b; } void A::dothings() { return; }[/cpp] The reason is that including in C/C++ has to function equivalently to simply copy/pasting the files where the include directives are, and the language requires that you have declared or defined everything you use, including methods inside classes.
Oh good lord.... I KNEW that it was something stupidly simple like that. In fact, when isn't it something stupidly simple that you just totally space on? Anyway, thanks a lot man, you have cured my headache and made me a happy coder once again!
So nobody has any good place to look for help with AI shit no?
[CODE]private void ReplaceInFile(string filePath, string searchVal1, string newStr) { Encoding encoding = Encoding.Default; byte[] bytes = encoding.GetBytes(searchVal1); Encoding aSCII = Encoding.ASCII; char[] chars = new char[aSCII.GetCharCount(bytes, 0, bytes.Length)]; aSCII.GetChars(bytes, 0, bytes.Length, chars, 0); string str = new string(chars); File.SetAttributes(filePath, FileAttributes.Normal); FileStream stream = new FileStream(filePath, FileMode.Open); StreamReader reader = new StreamReader(stream, Encoding.Default); int index = reader.ReadToEnd().IndexOf(str); reader.Close(); stream.Close(); FileStream stream2 = null; try { using (stream2 = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite)) { byte[] buffer = encoding.GetBytes(newStr); stream2.Seek((long) index, SeekOrigin.Begin); stream2.Write(buffer, 0, buffer.Length); } } catch (Exception) { this.toolStripStatusLabel1.Text = "&#1071;&#1079;&#1099;&#1082; &#1091;&#1082;&#1072;&#1079;&#1072;&#1085; &#1085;&#1077;&#1074;&#1077;&#1088;&#1085;&#1086;!"; } } [/CODE] Can someone tell me what this function basically does? I used .NET Reflector to get the code from Arma 2 OA language changer, and was wondering if i could change the language without the program.
[QUOTE=ollie;37994488][CODE] Can someone tell me what this function basically does? I used .NET Reflector to get the code from Arma 2 OA language changer, and was wondering if i could change the language without the program.[/QUOTE] Basically it searches a file given in the first parameter, looks for the string given in the second paremeter, and replaces by the string in the third. What I'm guessing is that it looks for a localized file that holds the current language, looks for the words and then replaces them, and by such, changes the language. If you were to know what words it's looking for, and what words to replace, you COULD do it manually, but that'll probably take a while.
Do you guys think that making a guitar tuner app would be a good choice for a 3rd year project? Or would that be really advanced and hard?
[QUOTE=eternalflamez;37994685]Basically it searches a file given in the first parameter, looks for the string given in the second paremeter, and replaces by the string in the third. What I'm guessing is that it looks for a localized file that holds the current language, looks for the words and then replaces them, and by such, changes the language. If you were to know what words it's looking for, and what words to replace, you COULD do it manually, but that'll probably take a while.[/QUOTE] Here's some more code i found: [CODE]private void button2_Click(object sender, EventArgs e) { if (this.checkBox1.Checked) { this.toolStripStatusLabel1.Text = "&#1047;&#1072;&#1084;&#1077;&#1085;&#1103;&#1077;&#1084; &#1103;&#1079;&#1099;&#1082; ArmA 2 OA..."; string text = this.textBox1.Text; if (this.comboBox1.SelectedIndex == 0) { this.searchText = "English"; this.replaceText = "Russian"; this.toolStripStatusLabel1.Text = "&#1052;&#1077;&#1085;&#1103;&#1077;&#1084; ENG &#1085;&#1072; RUS..."; } if (this.comboBox1.SelectedIndex == 1) { this.searchText = "Russian"; this.replaceText = "English"; this.toolStripStatusLabel1.Text = "&#1052;&#1077;&#1085;&#1103;&#1077;&#1084; RUS &#1085;&#1072; ENG..."; } this.ReplaceInFile(text, this.searchText, this.replaceText); this.toolStripStatusLabel1.Text = "&#1047;&#1072;&#1084;&#1077;&#1085;&#1072; &#1079;&#1072;&#1074;&#1077;&#1088;&#1096;&#1077;&#1085;&#1072;!"; } if (this.checkBox2.Checked) { this.toolStripStatusLabel1.Text = "&#1047;&#1072;&#1084;&#1077;&#1085;&#1103;&#1077;&#1084; &#1103;&#1079;&#1099;&#1082; ArmA 2 OA Beta..."; string filePath = this.textBox1.Text.Substring(0, this.textBox1.Text.LastIndexOf(@"\")) + @"\expansion\beta\arma2oa.exe"; if (this.comboBox1.SelectedIndex == 0) { this.searchText = "English"; this.replaceText = "Russian"; this.toolStripStatusLabel1.Text = "&#1052;&#1077;&#1085;&#1103;&#1077;&#1084; ENG &#1085;&#1072; RUS..."; } if (this.comboBox1.SelectedIndex == 1) { this.searchText = "Russian"; this.replaceText = "English"; this.toolStripStatusLabel1.Text = "&#1052;&#1077;&#1085;&#1103;&#1077;&#1084; RUS &#1085;&#1072; ENG..."; } this.ReplaceInFile(filePath, this.searchText, this.replaceText); this.toolStripStatusLabel1.Text = "&#1047;&#1072;&#1084;&#1077;&#1085;&#1072; &#1079;&#1072;&#1074;&#1077;&#1088;&#1096;&#1077;&#1085;&#1072;!"; } } [/CODE] How on earth can it replace something in an .exe file?
Someone find a way to create a class in this program or something. I don't know anything about classes, and I'd like to see an example. If anyone can find any other ways I could've done things in the program, please tell me. [cpp] //rotate a set of vertexes (can be used for polyhedrons, aka 3d solids) around an origin //i later found out opengl is capable of performing these operations #include <iostream> #include <cmath> using namespace std; const double PI = 4 * atan(1); //pi const double DEG = PI / 180; //constant to convert radians to degrees const double RAD = 180 / PI; //constant to convert degrees to radians //outputs a vertex rotated around an origin to outPolyH //if preferential, get this function to return its output instead of simply have it in the arguments list void rotate(double inPolyH[][3], int size, double center[3], double angle[3], double outPolyH[][3]) { //copy input vertex array to output vertex array for (int vector = 0; vector < size; ++vector) for (int axis = 0; axis < 3; ++axis) outPolyH[vector][axis] = inPolyH[vector][axis]; //converts rotation angles to radians for usage in functions //angles are on planes where positive x is up and positive y is right //also reverses the sign of angle so that way an angle that turns right is positive //while an angle that turns left is negative for (int axis = 0; axis < 3; ++axis) angle[axis] *= -DEG; //this is where all the math happens //dont make me explain it, i hear this code takes the place of matrix operations maybe? for (int vector = 0; vector < size; ++vector) for (int axis = 0; axis < 3; ++axis) { double pt2CtrX = outPolyH[vector][0] - center[0], pt2CtrY = outPolyH[vector][1] - center[1], pt2CtrZ = outPolyH[vector][2] - center[2]; double distXY = sqrt(pow(pt2CtrX, 2) + pow(pt2CtrY, 2)), distXZ = sqrt(pow(pt2CtrX, 2) + pow(pt2CtrZ, 2)), distYZ = sqrt(pow(pt2CtrY, 2) + pow(pt2CtrZ, 2)); //below output is in radians //when old or new angles are 0 degrees, the angle points to the right double oldAngleXY = atan2(pt2CtrY, pt2CtrX), oldAngleXZ = atan2(pt2CtrZ, pt2CtrX), oldAngleYZ = atan2(pt2CtrZ, pt2CtrY); //below output is also in radians double newAngleXY = oldAngleXY + angle[0], newAngleXZ = oldAngleXZ + angle[1], newAngleYZ = oldAngleYZ + angle[2]; if (axis == 0) { outPolyH[vector][0] = center[0] + (distXY * cos(newAngleXY)); outPolyH[vector][1] = center[0] + (distXY * sin(newAngleXY)); } else if (axis == 1) { outPolyH[vector][0] = center[1] + (distXZ * cos(newAngleXZ)); outPolyH[vector][2] = center[1] + (distXZ * sin(newAngleXZ)); } else { outPolyH[vector][1] = center[2] + (distYZ * cos(newAngleYZ)); outPolyH[vector][2] = center[2] + (distYZ * sin(newAngleYZ)); } } } //auto-create input, fetch output, then output the output int main() { int size = 8; //input amount of vectors that are in polyhedron double polyH[][3] = {{1, 1, 1}, {-1, 1, 1}, {-1, -1, 1}, {1, -1, 1}, /*input vertices: {x, y, z}*/ {1, 1, -1}, {-1, 1, -1}, {-1, -1, -1}, {1, -1, -1}}; double center[] = {0, 0, 0}; //input origin: {x, y, z} double angle[] = {45, 0, 0}; //input rotation: {xy, xz, yz} double rPolyH[size][3]; //create the output vertex array rotate(polyH, size, center, angle, rPolyH); //output vertices: {x, y, z} for (int vector = 0; vector < size; ++vector) //output the output cout << rPolyH[vector][0] << ", " << rPolyH[vector][1] << ", " << rPolyH[vector][2] << endl; return 0; } [/cpp]
[QUOTE=Over-Run;37994957]Do you guys think that making a guitar tuner app would be a good choice for a 3rd year project? Or would that be really advanced and hard?[/QUOTE] Buy a book on ai programming and do that project. I believe in you!
[QUOTE=Meatpuppet;37996561]Buy a book on ai programming and do that project. I believe in you![/QUOTE] Your talking about my other project idea about the AI right? Unless you want me to do a guitar tuner with an AI that tunes to different frequencies depending on if it owns a cat or not?
So I recently started my first game. I don't plan for it to be big or anything, more like a game so I can learn how to use Unity Anyway, I'm trying to make my character jump, and I encounter this problem He does jump, but because I wrote my code so you can just hold down the key and he keeps jumping, that doesn't really work properly. When I change my code so you jump only when you press once, so you no longer can hold down the key, he doesn't jump. I get this little bump from my character, and that's it. I literally just changed my code from GetKey to GetKeyDown, and all this happens. Here's my entire movement script. [code]using UnityEngine; using System.Collections; public class AvatarMovement : MonoBehaviour { // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Input.GetKey(KeyCode.D)) { transform.position += transform.forward * 2.0f * Time.deltaTime; } if (Input.GetKey(KeyCode.A)) { transform.position += transform.forward * -2.0f * Time.deltaTime; } } [B]public float JumpSpeed = 25.0f; void FixedUpdate(){ { if (Input.GetKeyDown(KeyCode.Space)) { rigidbody.AddForce(Vector3.up * JumpSpeed); } }[/B] } }[/code] Focus on the highlighted code.
Doesn't that just execute the jumping code once per time you press on the key? Aka one time of [code] rigidbody.AddForce(Vector3.up * JumpSpeed); [/code]
[QUOTE=eternalflamez;37998692]Doesn't that just execute the jumping code once per time you press on the key? Aka one time of [code] rigidbody.AddForce(Vector3.up * JumpSpeed); [/code][/QUOTE] Not if you run Input.GetKey instead of Input.GetKeyDown. Then it'll execute it once a frame. As you can imagine, you go up pretty high pretty fast. Correction: I just realized it's not once a frame, that seemed like a lot when I wrote it. It's written under a FixedUpdate method, so it's a certain number of times every second as long as the if statement is true. My bad.
Can someone suggest me some simple modern-style C++ game source code to study? I'm learning C++ and I'm interested in how some gamedev related things are usually implemented.
[QUOTE=SupahVee;37998910]Can someone suggest me some simple modern-style C++ game source code to study? I'm learning C++ and I'm interested in how some gamedev related things are usually implemented.[/QUOTE] What ever the latest open source ID engine is
[QUOTE=Richy19;38001526]What ever the latest open source ID engine is[/QUOTE] Go with this. It's pretty cool and optimized, runs even on older netbooks as well as the lastest hardware.
I was wondering something.. What language would be good for programming a game? And set aside things like speed and performance-related things. What would be some of the concepts that would be important for a game? I reckon object orientation would be a good idea, but what else?
[QUOTE=T3hGamerDK;38017326]I was wondering something.. What language would be good for programming a game? And set aside things like speed and performance-related things. What would be some of the concepts that would be important for a game? I reckon object orientation would be a good idea, but what else?[/QUOTE] There's no language that's better for making a game. It depends more on the framework than the language itself; for example, XNA for C# is a full fledged game framework. C++ has SFML, but it's more of a media library and doesn't have specific game logic built in.
Ok so i'm progressing with my understanding of this. It makes sense for the most part. i commented parts that confuse me. [code] segment .data x dw 7 y dw 2 segment .bss ; … segment .text global _start ; global scope _start: ; main function mov cx, 1 mov bx, 0 label1: mov ax, cx div x cmp ah, 0 jne next mov ax, cx div ax, y ; why are they specifying ax in this one but not in the one where they divide x? wtf? cmp ah, 0 jne next add bx, 1 ; what's the point of bx even? Once the program reaches this part it's exiting already. next: add cx, 1 cmp cx, 100 jle label1 ; why does the program not return the value of cx or bx? isn't that its purpose? ; All of these calculations were for nothing if the result isn't printed or returned... ; Unless this is not a standard program in which case, ugh. exit: mov eax, 1 ; Select system call 1 xor ebx, ebx ; Set default exit code - what the fuck int 0x80 ; Invoke selected system call ; End[/code] Also, one of the questions on the assignment is "how would you convert a string like "123" or "1" or "34673" to an actual number? I know how you'd do it for a single digit, Just convert to decimal then subtract 48. It doesn't work if you have more than 1 digit though.
[QUOTE=twoski;38022883]Also, one of the questions on the assignment is "how would you convert a string like "123" or "1" or "34673" to an actual number? I know how you'd do it for a single digit, Just convert to decimal then subtract 48. It doesn't work if you have more than 1 digit though.[/QUOTE] In pseudo-code: [code] number = 0 for i = 0 to digits n = convertToAscii(character) number += n * (10 ** i) end [/code]
My answer was similar to that. Start with a stored final result of 0. Loop through the string starting at the most significant digit. 1. Multiply the stored result by 10. 2. Subtract 0x30 from the current ascii digit and add the result to the final result. 3. Move to the next digit in the string and start the process over. 4. Return with the final result if there are no more ascii digits. The next question after this one is: Considering the fact that each ASCII character is stored on 8 bits, explain how you would do to fit your converted number into a 32-bit word. wouldn't the number fit anyhow?
holy christ i absolutely hate assembly. [code] segment .data BUFFLEN equ 1 ; length of buffer CtrlMsg db "Control Character", 10 ;what does this 10 do SymbolMsg db "Symbol", 10 NumberMsg db "Number", 10 CapitalMsg db "Capital Letter", 10 LowercaseMsg db "Lower Case Letter", 10 segment .bss input resb 1 ; characters are 1 byte segment .text global _start _start: ; main function mov eax, 3 mov ebx, 1 mov ecx, input mov edx, BUFFLEN int 0x80 ; interrupt and get user input cmp byte [ecx],20h jb IsControl cmp byte [ecx],30h jb IsSymbol cmp byte [ecx],3Ah jb IsNumber cmp byte [ecx],41h jb IsSymbol cmp byte [ecx],5Bh jb IsCapital cmp byte [ecx],61h jb IsSymbol cmp byte [ecx],7Bh jb IsLowercase cmp byte [ecx],7Fh je IsControl ; ascii isn't very organized jmp IsSymbol ; for anything else, assume it's a symbol IsLowercase: mov edx, len ; how the shit do you get the length of a string in nasm mov ecx, LowercaseMsg jmp Print IsCapital: mov edx, len mov ecx, CapitalMsg jmp Print IsSymbol: mov edx, len mov ecx, SymbolMsg jmp Print IsNumber: mov edx, len mov ecx, NumberMsg jmp Print IsControl: mov edx, len mov ecx, CtrlMsg jmp Print Print: mov ebx, 1 ; writing to screen mov eax, 4 ; sysout command int 0x80 ; interrupt exit: mov eax, 1 ; Select system call 1 xor ebx, ebx ; Set default exit code int 0x80 ; Invoke selected system call [/code] We're supposed to read in a character then print what kind of character it is. I can't think of any easier way than comparing the character with hex values to determine what category it falls under. Input and output in assembly makes no sense to me (you just pass arbitrary numbers to the registers then interrupt?!) and i just have a massive headache from this stupid assignment. Is there a way to get the length of a string on the fly or do i have to hardcode the length of each of my output strings?
[QUOTE=twoski;38036537] Is there a way to get the length of a string on the fly or do i have to hardcode the length of each of my output strings?[/QUOTE] Can't you call strlen() on the char* with your string? I'm guessing it's null-terminated.
[QUOTE=Eudoxia;38036557]Can't you call strlen() on the char* with your string? I'm guessing it's null-terminated.[/QUOTE] This is a class where we're doing things strictly in NASM. I don't think we're allowed to use anything like strlen().
Sorry, you need to Log In to post a reply to this thread.