71 lines
1.4 KiB
C
71 lines
1.4 KiB
C
#include "team.h"
|
|
#include "stdlib.h"
|
|
|
|
// Hello World
|
|
|
|
typedef struct{
|
|
t_coord pos;
|
|
int try;
|
|
int brings_food;
|
|
} t_data;
|
|
|
|
int get_purple_size(){
|
|
return sizeof(t_data);
|
|
}
|
|
|
|
t_coord getPos(t_coord coord, int dir);
|
|
|
|
t_action purple_update(void* my_info, void* com_data, int my_id, int success){
|
|
t_data* data = (t_data*)my_info;
|
|
t_action action;
|
|
int i, type;
|
|
|
|
if(data->try && success)
|
|
data->brings_food = 1;
|
|
data->try = 0;
|
|
|
|
if(data->brings_food){
|
|
if(data->pos.x == 0)
|
|
action.dir = WEST;
|
|
else{
|
|
if(data->pos.y == 0){
|
|
if(data->pos.x > 0)
|
|
action.dir = EAST;
|
|
else
|
|
action.dir = WEST;
|
|
if(data->pos.x == -1 || data->pos.x == 1){
|
|
data->brings_food = 0;
|
|
action.type = PUT;
|
|
action.data = NULL;
|
|
return action;
|
|
}
|
|
}else
|
|
action.dir = data->pos.y > 0 ? SOUTH : NORTH;
|
|
}
|
|
action.type = MOVE;
|
|
action.data = NULL;
|
|
data->pos = getPos(data->pos, action.dir);
|
|
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;
|
|
action.data = NULL;
|
|
return action;
|
|
}else if(type == FOOD){
|
|
action.type = PICK;
|
|
action.dir = i;
|
|
action.data = NULL;
|
|
data->try = 1;
|
|
}
|
|
}
|
|
|
|
action.type = MOVE;
|
|
action.dir = rand()%4;
|
|
action.data = NULL;
|
|
data->pos = getPos(data->pos, action.dir);
|
|
return action;
|
|
} |