/* Langtongs Ant Eine Kooperationsarbeit von Kristof und Alexander Version: 0.1 */ #include #include //Imports the library, which needs to be //Initialized in setup. #define DELAY 10 //Sets the time each generation is shown #define SIZEX 14 //Sets the X axis size #define SIZEY 9 //Sets the Y axis size #define DIRECTIONS 4 //Defines the amount of dircetions possible bool world[SIZEX][SIZEY][2]; //Creates a double buffer world long density = 25; //Sets density % during seeding enum direction { NORTH, EAST, SOUTH, WEST }; struct Ant { int x; int y; direction orientation; } ant; void step(){ switch (ant.orientation) { case NORTH: ant.y=(ant.y+1)%SIZEY; break; case EAST: ant.x=(ant.x+SIZEX-1)%SIZEX; break; case SOUTH: ant.y=(ant.y+SIZEY-1)%SIZEY; break; case WEST: ant.x=(ant.x+1)%SIZEX; break; } } void turn(){ ant.orientation=(direction)((world[ant.x][ant.y][0])? (((int)ant.orientation)+DIRECTIONS-1)%DIRECTIONS : (((int)ant.orientation)+1)%DIRECTIONS); } void toggle(){ world[ant.x][ant.y][0]=!world[ant.x][ant.y][0]; } void cycle(){ step(); turn(); toggle(); } //Re-seeds based off of RESEEDRATE void seedWorld(){ randomSeed(analogRead(5)); for (int i = 0; i < SIZEX; i++) { for (int j = 0; j < SIZEY; j++) { if (random(100) < density) { world[i][j][1] = 1; } } } } void setup() { LedSign::Init(); //Initilizes the LoL Shield ant.x = (SIZEX/2); ant.y = (SIZEY/2); ant.orientation = NORTH; randomSeed(analogRead(5)); //Builds the world with an initial seed. for (int i = 0; i < SIZEX; i++) { for (int j = 0; j < SIZEY; j++) { world[i][j][0] = 0; world[i][j][1] = 0; // world[i][j][0] = 0; } } } void loop() { cycle(); for (int x = 0; x < SIZEX; x++) { for (int y = 0; y < SIZEY; y++) { LedSign::Set(x,y,world[x][y][0]); } } delay(DELAY); }