Ok, I've (seriously) breifly (no really, Breifly) read a few things on artificial intelligence and nueral nets and some of that other fun stuff. In order to conduct a fun (very uninformed) project I decided to make a program using my comprehension (probably so very wrong).
Here is some of theory behind the game so far:
I have a basic ship class (currently rendered as triangle) that has 6 basic functions, forward, rotate left, rotate right, move forward,move backward , fire, and mutate. These functions are controlled,or rather activated by (my)neural net(of six nodes).
The structure of the class:
The net is basicly 6 nodes that share a randomized connection route(created by mutate function). Each node is associated with one of the six functions. Each node has an energy capacity and when reached calls the ship function.Code:class cInvader { public: cInvader(unsigned long int gen); ~cInvader(); void Fire(); void RotateL(void); void RotateR(void); void MoveF(); void MoveB(); void Mutate(); void Think(int node, float energy); void Think(aiNode *node, float energy); void FunctionCenter(int func); void Render(); void NetRender(); private: float location[3]; // x,y,z float velocity[3]; // xyz; float orientation[3]; // x,y,z int kills; unsigned long int generation; public: aiNode aiNet[6]; };
A look at the node structure:
The way the network works is an energy is introduced to a starting node, and travels through the connections (disapating as it travels) and adds to the capacity of each node.When the node is activated, it fires and resets. This is done repeatedly until the introductory energy is disapated.Code:struct aiNode { aiNode *link; // pointer to 5 links float inLoss; // energy loss from incomming signals float outLoss; // energy loss from outgoing signals float capacitor; // energy storage float energyReq; // int id; bool linked; int linkid; };
[SIde/Related note] currently this makes the network only able to handle one energy input from start to finish. Its not so much real time. Eventually I was thinking of making the network calculations run on seperate threads to the game, as to allow for multiple node immitions and enery imputs in real time.[End side/related note]
The way the net is innitiated is at some point in time an energy is inputed to a starting node (will later be implimented that information about the surrounding will fire different energy to different nodes [ie an enemy ship within a specific range prompts 2 micro joules of energy to node 2--and then disperses through the net] These things will be radar, damage, location, longevity etc) and the energy will travel through the randomized linked nodes firing off nodes appropriatly when enough energy is accumulated.
What I am looking for, is the best way to randomize the linkage between 6 nodes of a net. Every node must be in the net, and every node can only link to one other node. Currently my function seems to work at program start, but when mutate is called later, it seems to go into an infinite loop when trying to re-randomize the net. Any input or ideas on a propper algorythem, or other net structures would be greatly appreciated. Thanks.
btw: heres the current mutate code
PS. The image attached is what the game currently looks like. I've only got one ship active, and its net (with accumalated vs. required energy) shown on the right portion of the screen. Not much to look at, but its the functionality thats interesting.Code:void cInvader::Mutate() { for(int i = 0; i < 6; i++) { this->aiNet[i].linked = false; // unlink net for relinking this->aiNet[i].linkid = -1; } for( i = 0; i < 6; i++ ) { bool unlinked = true; int index = 0; this->aiNet[i].energyReq = (float)(rand()%10)/50; this->aiNet[i].inLoss = (float)(rand()%1)/10000; this->aiNet[i].outLoss = (float)(rand()%1)/10000; this->aiNet[i].capacitor = 0; while( unlinked ) { index = rand()%10; index = wrap(0, 5, index); if(this->aiNet[index].linked != true && this->aiNet[i].linkid != index) { this->aiNet[index].link = &this->aiNet[i]; this->aiNet[index].linked = true; this->aiNet[index].linkid = i; unlinked = false; } else { continue; } /* if(this->aiNet[index].linked != true && this->aiNet[i] ) { this->aiNet[i].link = &this->aiNet[index]; unlinked = false; this->aiNet[index].linked = true; this->aiNet[index].linkid = i; } else { continue; } */ } } };



LinkBack URL
About LinkBacks


