#include #include #include "../team.h" // Orange Hello World typedef struct{ t_coord pos; int new_born; int try; int brings_food; int last_dir; int last_action; } orange_data; t_coord o_newPos(t_coord coord, int dir){ t_coord new_coord = coord; switch(dir){ case NORTH : new_coord.y++; break; case SOUTH : new_coord.y--; break; case WEST : new_coord.x++; break; case EAST : new_coord.x--; break; } return new_coord; } int o_abs(int val){ return val > 0 ? val : -val; } int o_dist(t_coord coord, int x, int y){ return o_abs(coord.x-x) + o_abs(coord.y-y); } t_action orange_update(){ t_action action; int i, type; int success = getSuccess(); orange_data* data = (orange_data*)getMemory(); if(!data->new_born){ success = 0; data->new_born = 1; } if(data->last_action == MOVE){ if(success) data->pos = o_newPos(data->pos, data->last_dir); } if(data->try && success) data->brings_food = 1; data->try = 0; if(data->brings_food){ int distance = o_dist(data->pos, 0, 0); if(distance == 1){ action.type = WAIT; action.dir = 0; for(i=0; i<4; i++){ type = getNear(i); if(type == SPAWN){ action.dir = i; action.type = PUT; data->brings_food = 0; break; } } }else{ action.type = MOVE; do{ action.dir = rand()%4; }while(o_dist(o_newPos(data->pos, action.dir), 0, 0) > distance && distance != 0); } data->last_dir = action.dir; data->last_action = action.type; return action; } for(i=0; i<4; i++){ type = getNear(i); if(type == BERRIES || type == TREE || type == IRON_ORE || type == ROCK){ action.type = WORK; action.dir = i; data->last_dir = action.dir; data->last_action = action.type; return action; }else if(type == FOOD){ action.type = PICK; action.dir = i; data->try = 1; data->last_dir = action.dir; data->last_action = action.type; return action; } } action.type = MOVE; do{ action.dir = (data->last_dir + rand()%3)%4; type = getNear(action.dir); }while(type == WALL && type == ROCK && type == BEDROCK && type == IRON_ORE && type == TREE && type == LIBRARY); data->last_dir = action.dir; data->last_action = action.type; return action; }