AI Invader

This is a discussion on AI Invader within the Game Programming forums, part of the General Programming Boards category; Ok, I've (seriously) breifly (no really, Breifly) read a few things on artificial intelligence and nueral nets and some of ...

  1. #1
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704

    AI Invader

    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:
    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];
    	};
    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.

    A look at the node structure:
    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;
    	};
    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.
    [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
    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;
    			}
    			*/
    		}
    	}
    };
    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.
    Attached Images Attached Images  
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  2. #2
    Registered User heat511's Avatar
    Join Date
    Dec 2001
    Posts
    169
    hmmmm you could use a binary (or more i guess) tree and have the neural net set up that way. at each node it could randomly pick the next node and continue on. you could also randomly add points in 'personality' categories to decide how aggressive the ship is, etc. then depending on the lvl of aggressiveness the ship could decide to travel down the aggressive branch of the tree, blazing in firing crazily. or the passive path and flee in abject terror when an enemy approachs.

    not sure if any of that helps... looks pretty cool in my head tho... like a lot of things
    "uh uh uh, you didn't say the magic word"
    -Jurassic Park

  3. #3
    Registered User Aalmaron's Avatar
    Join Date
    Jan 2004
    Location
    In front of a monitor
    Posts
    48
    Code:
    )(rand()%1)
    doesn't like to be truly random. you might want to try something else for randomness.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple space combat AI
    By VirtualAce in forum Game Programming
    Replies: 5
    Last Post: 01-05-2009, 11:54 PM
  2. chess ai contest
    By Raven Arkadon in forum Contests Board
    Replies: 7
    Last Post: 07-09-2005, 06:38 AM
  3. AI Contest Proposal
    By MadCow257 in forum Contests Board
    Replies: 4
    Last Post: 03-13-2005, 02:27 PM
  4. Game Design Topic #1 - AI Behavior
    By TechWins in forum Game Programming
    Replies: 13
    Last Post: 10-11-2002, 10:35 AM
  5. Technique of all board-like games?
    By Nutshell in forum Game Programming
    Replies: 28
    Last Post: 04-24-2002, 08:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21