#include "player.h" #include #include #define BOOL int #define TRUE 1 #define FALSE 0 direction last = RIGHT; direction where_go(); // MASTER CONTROLLER BOOL on_flw(); // Sulla mia strada ci sono fiori? direction flw_dir(); // Segui un fiore vicino BOOL is_wall(direction dir); // Davanti c'e` un muro? direction where_free(); // La prima posizione senza muro // Non utilizzate BOOL is_btf(btf_elm btf, direction dir); BOOL is_there_btf(btf_elm btf); // Guardo se c'e` un particolare simbolo direction where_is_btf(btf_elm btf); // Guardo se intorno a me c'e` un simbolo BOOL is_wall(direction dir) { btf_elm sym = read_battle_field(dir); if(sym == VLN || sym == HLN || sym == TLC || sym == TRC || sym == BLC || sym == BRC || sym == TRC || sym == BRC) return TRUE; return FALSE; } BOOL on_flw() { if(read_battle_field(last) == FUTF) return TRUE; else FALSE; } direction flw_dir() { //FILE * stream = file_stream(); btf_elm r = read_battle_field(RIGHT); btf_elm l = read_battle_field(LEFT); btf_elm d = read_battle_field(DOWN); btf_elm u = read_battle_field(UP); if(r == FUTF) return RIGHT; if(d == FUTF) return DOWN; if(l == FUTF) return LEFT; if(u == FUTF) return UP; return IN; } direction where_free() // anti-loop 75% tested { direction dirs[] = {RIGHT, DOWN, LEFT, UP}; int i = 0; if(last == UP) i = 0; if(last == RIGHT) i = 1; if(last == DOWN) i = 2; if(last == LEFT) i = 3; for(; i<4; (i++)%4 ) if(is_wall(dirs[i]) == FALSE) return dirs[i]; } direction where_go() { BOOL right_flw = on_flw(); direction new_flw_dir; // Inizio a guardare se riesco a seguire i fiori if(right_flw == TRUE) return last; else if((new_flw_dir = flw_dir()) != IN) return new_flw_dir; // Se no cerco di non andare a sbattere contro un muro if(is_wall(last) == TRUE) return where_free(); else return last; } // Generiche (non solo per il fiore) usate per log/debug BOOL is_btf(btf_elm btf, direction dir) { if(read_battle_field(dir) == btf) return TRUE; return FALSE; } BOOL is_there_btf(btf_elm btf) { return is_btf(btf, RIGHT) || is_btf(btf, DOWN) || is_btf(btf, LEFT) || is_btf(btf, UP); } direction where_is_btf(btf_elm btf){ if(is_there_btf(btf) == TRUE){ if(is_btf(btf, RIGHT)) return RIGHT; if(is_btf(btf, DOWN)) return DOWN; if(is_btf(btf, LEFT)) return LEFT; if(is_btf(btf, UP)) return UP; } } //////////////////////////////// // MY MOVE //////////////////////////////// direction tuki_turn(){ direction choose; btf_elm next_r = read_battle_field(RIGHT); btf_elm next_d = read_battle_field(DOWN); choose = where_go(); last = choose; return choose; }