start AI orange

This commit is contained in:
Lendemor 2015-01-17 10:54:05 +01:00
parent 695f9e79a0
commit 7f196ac60f

150
orange.c
View File

@ -1,19 +1,155 @@
#include "team.h"
#include "stdio.h"
#include "stdlib.h"
// Hello World
// Development in progress
//Structure definition
enum{
JOBLESS, MASTER, GATHERER, WOODCUTTER, MINER, NB_JOBS
};
enum{
AIM_SPAWN, AIM_SPOT,NO_AIM
};
typedef struct{
int plop; // custom info
} t_data;
char type; //the type of ressource that was found
int x; // x where ressource was found
int y; // y where ressource was found
} t_ressource_spot;
typedef struct{
char name; // name of the dude
int x; // x relative to the spawn
int y; // y relative to the spawn
char job;
char aim;
t_ressource_spot res_spot;
char last_action;
char last_dir;
} t_info_data;
typedef union{
t_ressource_spot res_spot;
}t_message;
typedef struct{
char name_sender;
t_message message;
} t_com_data;
void check_action_success(t_info_data*, int);
void search_job(t_action*, t_info_data*, int);
void gather_res(t_action*, t_info_data*, int);
t_action orange_update(void* my_info, void* com_data, int success){
t_data* data = (t_data*)my_info;
t_info_data* data = (t_info_data*)my_info;
t_action action;
action.type = MOVE;
action.dir = rand()%4;
action.data = NULL;
check_action_success(data,success);
//search_job(action, data, success);
switch(data.job){
case JOBLESS:
case MASTER:
case GATHERER:
gather_food(action,data,success);
case WOODCUTTER:
case MINER:
}
return action;
}
void check_action_success(t_info_data* data, int success){
if (!success) return;
switch(data->last_action){
case MOVE:
switch(data->last_dir){
case NORTH:
data->x++;
break;
case SOUTH:
data->x--;
break;
case EAST:
data->y++;
break;
case WEST:
data->y--;
break;
default:
break;
}
break;
case ATTACK:
case PICK:
data->searching=0;
case PUT:
case WORK:
case WAIT:
case COMMUNICATE:
default:
break;
}
}
void search_job(t_action* action, t_info_data* data, int success){
return;
}
void gather_food(t_action* action, t_info_data* data, int success){
int i,t;
if (getInventory() == -1){
for(i=0;i<4;i++){
t = getNear(i);
switch(t){
case BERRIES:
action.type = WORK;
action.dir = i;
action.data = NULL;
break;
case FOOD:
action.type = PICK;
action.dir = i;
action.data = NULL;
break;
default:
action.type = MOVE;
action.dir = rand()%4;
action.data = NULL;
break;
}
}
}else{
i= newDir(data);
}
return;
}
int newDir(t_info_data* data){
switch(data->aim){
case AIM_SPAWN:
return dirToAim(O,O);
case AIM_SPOT:
return dirToAim(data->res_spot->x,data->res_spot->y);
case NO_TARGET:
return rand()%4;
}
}
int distTo(x1,y1,x2,y2){
return abs(x2-x1) + abs(y2-y1);
}
int dirToAim(int x, int y){
do{
}while(distTo(x,y) > distTo(x,y))
}