bot-evolution-simulation

This program is a terrarium of little bots who undergo ruthless evolution in a 2D world with it's own rules.
Log | Files | Refs | README | LICENSE

field.pixi (2264B)


      1 fn get_cell_ul_diag($i) {
      2     /*
      3         x * *
      4         * o *
      5         * * *
      6     */
      7     $cell = $i - (COLUMNS + 1)
      8     
      9     // if index exceeds array size
     10     if ($i % COLUMNS == 0) {
     11         $cell = $i - 1
     12     }
     13     
     14     if ($cell < 0) {
     15         $cell = (COLUMNS * ROWS) + $cell
     16     }
     17     
     18     ret($cell)
     19 }
     20 
     21 fn get_cell_above($i) {
     22     /*
     23         * x *
     24         * o *
     25         * * *
     26     */
     27     $cell = $i - COLUMNS
     28     
     29     // if index exceeds array size
     30     if ($cell < 0) {
     31         $cell = (COLUMNS * ROWS) + $cell
     32     }
     33     
     34     ret($cell)
     35 }
     36 
     37 fn get_cell_ur_diag($i) {
     38     /*
     39         * * x
     40         * o *
     41         * * *
     42     */
     43     $cell = $i - (COLUMNS - 1)
     44     
     45     // if index exceeds array size
     46     if (($i + 1) % COLUMNS == 0) {
     47         $cell = $i - (COLUMNS * 2 - 1)
     48     }
     49     
     50     if ($cell < 0) {
     51         $cell = (COLUMNS * ROWS) + $cell
     52     }
     53     
     54     ret($cell)
     55 }
     56 
     57 fn get_cell_left($i) {
     58     /*
     59         * * *
     60         x o *
     61         * * *
     62     */
     63     $cell = $i - 1
     64     
     65     // if index exceeds array size
     66     if ($i % COLUMNS == 0) {
     67         $cell = $i + (COLUMNS - 1)
     68     }
     69     
     70     ret($cell)
     71 }
     72 
     73 
     74 fn get_cell_right($i) {
     75     /*
     76         * * *
     77         * o x
     78         * * *
     79     */
     80     $cell = $i + 1
     81     
     82     // if index exceeds array size
     83     if (($i + 1) % COLUMNS == 0) {
     84         $cell = $i - (COLUMNS - 1)
     85     }
     86     
     87     ret($cell)
     88 }
     89 
     90 fn get_cell_dl_diag($i) {
     91     /*
     92         * * *
     93         * o *
     94         x * *
     95     */
     96     $cell= $i + (COLUMNS - 1)
     97     
     98     // if index exceeds array size
     99     if ($i % COLUMNS == 0) {
    100         $cell = $i + (COLUMNS * 2 - 1)
    101     }
    102     
    103     if ($cell > COLUMNS * ROWS - 1) {
    104         $cell = $cell - (COLUMNS * ROWS)
    105     }
    106     
    107     ret($cell)
    108 }
    109 
    110 fn get_cell_below($i) {
    111     /*
    112         * * *
    113         * o *
    114         * x *
    115     */
    116     $cell = $i + COLUMNS
    117     
    118     // if index exceeds array size
    119     if ($cell >= (COLUMNS * ROWS)) {
    120         $cell = $cell  - (COLUMNS * ROWS)
    121     }
    122     
    123     ret($cell)
    124 }
    125 
    126 fn get_cell_dr_diag($i) {
    127     /*
    128         * * *
    129         * o *
    130         * * x
    131     */
    132     $cell = $i + (COLUMNS + 1)
    133     
    134     // if index exceeds array size
    135     if (($i + 1) % COLUMNS == 0) {
    136         $cell = $i + 1
    137     }
    138     
    139      if ($cell > COLUMNS * ROWS - 1) {
    140         $cell = $cell - (COLUMNS * ROWS)
    141     }
    142     
    143     ret($cell)
    144 }