52 lines
1.1 KiB
C
52 lines
1.1 KiB
C
#include <stdlib.h>
|
|
#include "job.h"
|
|
|
|
typedef struct{
|
|
char job;
|
|
t_coord pos;
|
|
char identity;
|
|
int last_dir;
|
|
int last_action;
|
|
|
|
int population;
|
|
int nb_explorers;
|
|
int nb_workers;
|
|
unsigned char town_done;
|
|
unsigned char town[8];
|
|
unsigned char country_done;
|
|
unsigned char country[8];
|
|
} purple_data_king;
|
|
|
|
t_action p_king_ia(){
|
|
t_action action;
|
|
purple_data_king* data = getMemory();
|
|
action.type = WAIT;
|
|
if(data->pos.x != -1 || data->pos.y != -2)
|
|
data->job = P_JOBLESS;
|
|
else{
|
|
t_com* com_data = getComData();
|
|
p_request* request = ((void*)com_data)+sizeof(int);
|
|
p_request answer;
|
|
if(com_data != NULL){
|
|
action.dir = com_data->flag;
|
|
action.type = COMMUNICATE;
|
|
if(request->identity < 1)
|
|
answer.identity = data->population++; // temp way to handle demography
|
|
if(request->job == P_WORKER)
|
|
data->nb_workers--;
|
|
if(request->job == P_EXPLORER)
|
|
data->nb_explorers--;
|
|
if(data->nb_explorers*2 > data->nb_workers){
|
|
answer.job = P_WORKER;
|
|
|
|
}else{
|
|
answer.job = P_EXPLORER;
|
|
|
|
}
|
|
|
|
// send message
|
|
}
|
|
}
|
|
return action;
|
|
}
|