// // Genetic Algorithm Example #include "raylib.h" #include #define MAX_PATH 1024 enum terrain{TREE=1,GROUND=0,AIPLAYER1=2,AIPLAYER2=3,GOAL=4,GOALREACHED=5}; enum flag{UP,DOWN,LEFT,RIGHT,WAIT}; // // You can set any number of 3 and 2 on the map. more 4's untested. keep the borders(1) intact(memory errors) // //1=border,2=ai unit,3=defensiveunit,4=objective int map1[10][10] = { {1,1,1,1,1,1,1,1,1,1}, {1,0,0,0,0,1,0,0,3,1}, {1,0,0,0,0,1,0,0,0,1}, {1,3,0,0,0,1,0,0,0,1}, {1,0,0,0,0,1,1,0,1,1}, {1,0,0,0,0,1,0,0,0,1}, {1,1,1,0,1,1,0,0,0,1}, {1,0,0,0,0,0,2,0,0,1}, {1,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1} }; int map[10][10] = {0}; int dijkstramap[10][10]={0}; typedef struct pathnode{ int x; int y; }pathnode; void makedijkstramap(); static float distance(float x1,float y1,float x2,float y2); static float edistance(float x1,float y1,float x2,float y2); int topdijkstralen=0; int screenWidth; int screenHeight; int tileWidth,tileHeight,mapWidth,mapHeight; int main(void) { // Initialization //-------------------------------------------------------------------------------------- screenWidth = 800; screenHeight = 600; mapWidth = 10; mapHeight = 10; tileWidth = ceil((float)screenWidth/(float)mapWidth); tileHeight = ceil((float)screenHeight/(float)mapHeight); InitWindow(screenWidth, screenHeight, "raylib example."); SetTargetFPS(200); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- //makedijkstramap(); // The 4 = the goal that gets flooded from... for(int y=0;y0){ // Take the first value from the array. int x1=list[0].x; int y1=list[0].y; // shift all up. for(int i=0;i= mapWidth || ny>= mapHeight)continue; // If we can get there then put the new distance there and add this position // to the list. if(dijkstramap[ny][nx]==0 && map[ny][ny]!=1){ dijkstramap[ny][nx]=dijkstramap[y1][x1]+1; if(dijkstramap[ny][nx]>topdijkstralen)topdijkstralen=dijkstramap[ny][nx]; // add to last // list[listlen].x = nx; list[listlen].y = ny; listlen++; // } } // Error? failed+=1; if(failed>160000)return; } } // Manhattan Distance (less precise) float distance(float x1,float y1,float x2,float y2){ return (float)abs(x2-x1)+abs(y2-y1); } // Euclidean distance (more precise) float edistance(float x1,float y1,float x2,float y2){ return sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) ); }