gene.pixi (3242B)
1 fn execute_gene($bot, $gene) { 2 // go UP-LEFT DIAGONAL 3 if (BOTS[$bot].genome[$gene] == 0) || (BOTS[$bot].genome[$gene] == 8) { 4 // get the next cell 5 $next = get_cell_ul_diag(BOTS[$bot].cell) 6 } 7 8 // go UP 9 if (BOTS[$bot].genome[$gene] == 1) || (BOTS[$bot].genome[$gene] == 9) { 10 // get the next cell 11 $next = get_cell_above(BOTS[$bot].cell) 12 } 13 14 // go UP-RIGHT DIAGONAL 15 if (BOTS[$bot].genome[$gene] == 2) || (BOTS[$bot].genome[$gene] == 10) { 16 // get the next cell 17 $next = get_cell_ur_diag(BOTS[$bot].cell) 18 } 19 20 // go LEFT 21 if (BOTS[$bot].genome[$gene] == 3) || (BOTS[$bot].genome[$gene] == 11) { 22 // get the next cell 23 $next = get_cell_left(BOTS[$bot].cell) 24 } 25 26 // go RIGHT 27 if (BOTS[$bot].genome[$gene] == 4) || (BOTS[$bot].genome[$gene] == 12) { 28 // get the next cell 29 $next = get_cell_right(BOTS[$bot].cell) 30 } 31 32 // go DOWN-LEFT DIAGONAL 33 if (BOTS[$bot].genome[$gene] == 5) || (BOTS[$bot].genome[$gene] == 13) { 34 // get the next cell 35 $next = get_cell_dl_diag(BOTS[$bot].cell) 36 } 37 38 // go DOWN 39 if (BOTS[$bot].genome[$gene] == 6) || (BOTS[$bot].genome[$gene] == 14) { 40 // get the next cell 41 $next = get_cell_below(BOTS[$bot].cell) 42 } 43 44 // go DOWN-RIGHT DIAGONAL 45 if (BOTS[$bot].genome[$gene] == 7) || (BOTS[$bot].genome[$gene] == 15) { 46 // get the next cell 47 $next = get_cell_dr_diag(BOTS[$bot].cell) 48 } 49 50 // move gene 51 if (BOTS[$bot].genome[$gene] >= 0) && (BOTS[$bot].genome[$gene] <= 7) { 52 // if the next cell is empty 53 if (CELLS[$next].type == 0) { 54 // erase bot from it's current position 55 fbox(BOTS[$bot].x_coord, BOTS[$bot].y_coord, CELL_SIZE - 1, CELL_SIZE - 1, COL_FIELD) 56 57 // update previous cell's type to empty (0) 58 CELLS[BOTS[$bot].cell].type = 0 59 60 // update bot's coordinates and cell 61 BOTS[$bot].x_coord = CELLS[$next].x_coord 62 BOTS[$bot].y_coord = CELLS[$next].y_coord 63 BOTS[$bot].cell = $next 64 65 // update next cell's type to bot (1) 66 CELLS[$next].type = 1 67 } 68 } 69 70 // eat/drink gene 71 if (BOTS[$bot].genome[$gene] >= 8) && (BOTS[$bot].genome[$gene] <= 15) { 72 // if the next cell is food 73 if (CELLS[$next].type == 2) { 74 // bot gets quenches it's hunger 75 BOTS[$bot].energy = BOTS[$bot].energy + 8 76 } 77 78 // if the next cell is water 79 if (CELLS[$next].type == 3) { 80 // bot gets quenches it's thirst 81 BOTS[$bot].thirst = BOTS[$bot].thirst + 4 82 } 83 } 84 85 // bot gets hungry 86 BOTS[$bot].energy = BOTS[$bot].energy - 1 87 // bot gets thirsty 88 BOTS[$bot].thirst = BOTS[$bot].thirst - 1 89 90 // update life indicator 91 //$indic = (BOTS[$bot].energy + BOTS[$bot].thirst) / 2 92 93 // redraw the bot 94 fbox(BOTS[$bot].x_coord, BOTS[$bot].y_coord, CELL_SIZE - 1, CELL_SIZE - 1, COL_BOT_ALIVE) 95 //print(n2s($indic), BOTS[$bot].x_coord + (CELL_SIZE / 2), BOTS[$bot].y_coord + (CELL_SIZE / 2), WHITE) 96 }