diff --git a/0_6_1.cpp b/0_6_1.cpp deleted file mode 100644 index 5d22656..0000000 --- a/0_6_1.cpp +++ /dev/null @@ -1,535 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -class dot -{ - public: - int x; - int y; -}; -class player -{ - public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - for(i=1;i<=10;i++) - for(j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for(k=2;k<=num;k++) - { - if(road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if(road[k-1]->x==road[k]->x) - { - if(road[k-1]->yy) - { - if(j==road[k]->y&&i>road[k]->x) top=true; - if(j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if(road[k-1]->y>road[k]->y) - { - if(j==road[k-1]->y&&i>road[k]->x) top=true; - if(j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if(road[k-1]->y==road[k]->y) - { - if(road[k-1]->xx) - { - if(i==road[k]->x&&j>road[k]->y) left=true; - if(i==road[k]->x&&j<=road[k]->y) right=true; - } - if(road[k-1]->x>road[k]->x) - { - if(i==road[k-1]->x&&j>road[k]->y) left=true; - if(i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if(top&&bottom&&left&&right) - { - if(-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if(state_die==state) - { - if(ID_0==ID) {player0->die();if(player0->road[1]->x==x&&player0->road[1]->y==y){player0->insert(x,y);player0->paint();player0->clear();}} - if(ID_1==ID) {player1->die();if(player1->road[1]->x==x&&player1->road[1]->y==y){player1->insert(x,y);player1->paint();player1->clear();}} - if(ID_2==ID) {player2->die();if(player2->road[1]->x==x&&player2->road[1]->y==y){player2->insert(x,y);player2->paint();player2->clear();}} - if(ID_3==ID) {player3->die();if(player3->road[1]->x==x&&player3->road[1]->y==y){player3->insert(x,y);player3->paint();player3->clear();}} - } - if(state_up==state) - { - if(ID_0==ID) - { - if(state_down==player0->state) player0->insert(x,y); - player0->paint(); - player0->up(); - player0->clear(); - player0->insert(x,y); - } - if(ID_1==ID) - { - if(state_down==player1->state) player1->insert(x,y); - player1->paint(); - player1->up(); - player1->clear(); - player1->insert(x,y); - } - if(ID_2==ID) - { - if(state_down==player2->state) player2->insert(x,y); - player2->paint(); - player2->up(); - player2->clear(); - player2->insert(x,y); - } - if(ID_3==ID) - { - if(state_down==player3->state) player3->insert(x,y); - player3->paint(); - player3->up(); - player3->clear(); - player3->insert(x,y); - } - } - if(state_down==state) - { - if(ID_0==ID) - { - player0->down(); - player0->insert(x,y); - } - if(ID_1==ID) - { - player1->down(); - player1->insert(x,y); - } - if(ID_2==ID) - { - player2->down(); - player2->insert(x,y); - } - if(ID_3==ID) - { - player3->down(); - player3->insert(x,y); - } - } - if(ID_0==ID) player0->change(x,y); - if(ID_1==ID) player1->change(x,y); - if(ID_2==ID) player2->change(x,y); - if(ID_3==ID) player3->change(x,y); - } - void make() - { - int i,j,k; - for(i=0;i<=3;i++) - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - if(1==minimap[i][j][k]) tot[i]++; - } - - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for(int s=0;s<=3;s++) - if(tot[s]score=player0->score+area[0]*area[0]*10; - player1->score=player1->score+area[1]*area[1]*10; - player2->score=player2->score+area[2]*area[2]*10; - player3->score=player3->score+area[3]*area[3]*10; - for(i=0;i<=3;i++) - if(0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot bind[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if(!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if(!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for(int i=0;i<=10;i++) for(int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -void brain() -{ - update_edge_status(); - update_distance(game->player0->position,0); - update_distance(game->player1->position,1); - update_distance(game->player2->position,2); - update_distance(game->player3->position,3); - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==0&&now_y==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //Output Area - if(mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for(int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if(!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for(int i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3c5a43 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +This repository is cleared because it's no longer support by its owner. diff --git a/enclosure.exe b/enclosure.exe deleted file mode 100644 index d2b576b..0000000 Binary files a/enclosure.exe and /dev/null differ diff --git a/log.tar.gz b/log.tar.gz deleted file mode 100644 index a55aa8d..0000000 Binary files a/log.tar.gz and /dev/null differ diff --git a/log0.in b/log0.in deleted file mode 100644 index 9537c02..0000000 --- a/log0.in +++ /dev/null @@ -1,41 +0,0 @@ -[START] 0 -[STATUS] 10 0 0 0 0 5 5 0 0 0 5 5 0 0 0 5 5 0 0 0 0 -[STATUS] 10 1 1 0 0 5 5 0 4 0 4 5 0 0 -10 5 5 0 4 0 2 5 4 2 5 6 2 -[STATUS] 10 2 1 0 0 5 5 0 3 0 5 5 0 0 -20 5 5 0 3 0 5 5 4 1 5 6 1 4 5 2 4 4 2 4 6 2 -[STATUS] 10 3 1 0 0 5 5 0 4 0 4 5 0 4 -30 5 5 0 4 0 4 5 4 2 5 6 2 4 4 1 4 6 1 -[STATUS] 10 4 1 0 0 5 5 0 3 0 4 5 0 3 -30 5 5 0 3 0 2 5 4 1 5 6 1 -[STATUS] 10 5 1 0 0 5 5 0 2 0 4 5 0 2 -30 5 5 0 2 0 0 -[STATUS] 10 6 1 0 0 5 5 0 1 0 4 5 0 1 -30 5 5 0 1 0 0 -[STATUS] 10 7 1 0 0 5 5 0 0 0 4 5 0 0 -30 5 5 0 0 0 0 -[STATUS] 10 8 1 0 0 6 5 0 0 0 4 4 0 0 -30 5 4 0 0 0 0 -[STATUS] 10 9 1 0 0 5 5 0 0 0 5 4 0 0 -30 6 4 0 0 0 0 -[STATUS] 10 10 1 0 0 5 5 0 0 0 5 4 0 0 -30 6 5 0 0 0 0 -[STATUS] 9 10 1 0 0 5 5 0 0 0 4 4 0 0 -30 6 6 0 0 0 0 -[STATUS] 8 10 1 0 0 5 6 0 0 0 5 4 0 0 -30 6 7 0 0 0 0 -[STATUS] 7 10 1 0 0 5 5 0 0 0 4 4 0 0 -30 6 6 0 0 0 0 -[STATUS] 6 10 1 0 0 5 6 0 0 0 3 4 0 0 -30 6 6 0 0 0 0 -[STATUS] 5 10 1 0 0 5 5 0 0 0 3 4 0 0 -30 6 5 0 0 0 0 -[STATUS] 4 10 1 0 0 6 5 1 0 0 4 4 1 0 -30 7 5 -1 0 0 0 -[STATUS] 3 10 1 0 0 7 5 1 0 0 5 4 1 0 -30 7 5 -1 0 0 0 -[STATUS] 2 10 1 0 0 7 4 1 0 0 5 3 1 0 -30 7 5 -1 0 0 0 -[STATUS] 1 10 1 0 0 7 3 1 0 0 5 2 1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 10 1 0 0 6 3 1 0 0 4 2 1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 9 1 0 0 5 3 1 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 8 1 0 0 5 4 1 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 7 1 0 0 5 5 0 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 6 1 0 0 5 5 0 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 5 1 0 0 4 5 0 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 4 1 0 0 4 6 0 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 3 1 0 0 4 5 0 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 2 1 0 0 3 5 0 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 1 1 0 0 3 4 0 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 0 0 1 0 0 3 4 0 0 0 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 1 0 1 0 0 4 4 0 0 -10 3 2 -1 0 -30 7 5 -1 0 0 3 3 4 2 3 3 2 3 5 2 -[STATUS] 2 0 1 0 0 4 4 0 0 -10 3 2 -1 0 -30 7 5 -1 0 0 3 3 4 1 3 3 1 3 5 1 -[STATUS] 3 0 1 0 0 4 3 0 0 -20 3 2 -1 0 -30 7 5 -1 0 0 3 3 4 2 4 4 2 5 4 2 -[STATUS] 4 0 1 0 0 3 3 0 0 -20 3 2 -1 0 -30 7 5 -1 0 0 3 3 4 1 4 4 1 5 4 1 -[STATUS] 5 0 1 0 0 3 4 0 4 -20 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 6 0 1 0 0 3 4 0 3 -20 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 7 0 1 0 0 3 4 0 2 -20 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 8 0 1 0 0 3 4 0 1 -20 3 2 -1 0 -30 7 5 -1 0 0 0 -[STATUS] 9 0 1 0 0 3 4 0 0 -20 3 2 -1 0 -30 7 5 -1 0 0 0 diff --git a/log0.out b/log0.out deleted file mode 100644 index beb4f94..0000000 --- a/log0.out +++ /dev/null @@ -1,41 +0,0 @@ -[POS] 10 0 -[ACTION] d 1 -[ACTION] d 0 -[ACTION] d 0 -[ACTION] d 0 -[ACTION] d 0 -[ACTION] d 0 -[ACTION] d 0 -[ACTION] d 0 -[ACTION] d 0 -[ACTION] d 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] l 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] u 0 -[ACTION] r 0 -[ACTION] r 0 -[ACTION] r 0 -[ACTION] r 0 -[ACTION] r 0 -[ACTION] r 0 -[ACTION] r 0 -[ACTION] r 0 -[ACTION] r 0 -[ACTION] r 0 diff --git a/log1.in b/log1.in deleted file mode 100644 index 461cad1..0000000 --- a/log1.in +++ /dev/null @@ -1,2 +0,0 @@ -[START] 1 -[STATUS] 10 0 0 0 0 10 0 0 0 0 5 5 0 0 0 5 5 0 0 0 0 diff --git a/log1.out b/log1.out deleted file mode 100644 index 7a08867..0000000 --- a/log1.out +++ /dev/null @@ -1,2 +0,0 @@ -[POS] 10 0 -[ACTION] d 1 diff --git a/log2.in b/log2.in deleted file mode 100644 index 1f184c7..0000000 --- a/log2.in +++ /dev/null @@ -1,2 +0,0 @@ -[START] 2 -[STATUS] 10 0 0 0 0 10 0 0 0 0 10 0 0 0 0 5 5 0 0 0 0 diff --git a/log2.out b/log2.out deleted file mode 100644 index 7a08867..0000000 --- a/log2.out +++ /dev/null @@ -1,2 +0,0 @@ -[POS] 10 0 -[ACTION] d 1 diff --git a/log3.in b/log3.in deleted file mode 100644 index cc43ba8..0000000 --- a/log3.in +++ /dev/null @@ -1,2 +0,0 @@ -[START] 3 -[STATUS] 10 0 0 0 0 10 0 0 0 0 10 0 0 0 0 10 0 0 0 0 0 diff --git a/log3.out b/log3.out deleted file mode 100644 index 7a08867..0000000 --- a/log3.out +++ /dev/null @@ -1,2 +0,0 @@ -[POS] 10 0 -[ACTION] d 1 diff --git a/orz_0_0.cpp b/orz_0_0.cpp deleted file mode 100644 index 83f185f..0000000 --- a/orz_0_0.cpp +++ /dev/null @@ -1,285 +0,0 @@ -#include -#include -#include -//dqb area -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -//Soft Ginger area -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -//dqb area -using namespace std; -int map[20][20]; -class point -{ - public: - int x; - int y; -}; -class player -{ - public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]->x=x; - road[num]->y=y; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - int size=0; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (0==map[i][j]) - { - map[i][j]=ID; - size++; - } - - } - } - score=score+size*size*10; - num=0; - } -}; -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) player0->die(); - if (ID_1==ID) player1->die(); - if (ID_2==ID) player2->die(); - if (ID_3==ID) player3->die(); - } - if (state_up==state) - { - if (ID_0==ID) {if (state_down==player0->state) player0->paint();player0->up();} - if (ID_1==ID) {if (state_down==player1->state) player1->paint();player1->up();} - if (ID_2==ID) {if (state_down==player2->state) player2->paint();player2->up();} - if (ID_3==ID) {if (state_down==player3->state) player3->paint();player3->up();} - } - if (state_down==state) - { - if (ID_0==ID) {player0->down();player0->insert(x,y);} - if (ID_1==ID) {player1->down();player1->insert(x,y);} - if (ID_2==ID) {player2->down();player2->insert(x,y);} - if (ID_3==ID) {player3->down();player3->insert(x,y);} - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } -}; -//dqb area -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -//Soft Ginger area -int mode=mode_start; -void brain() -{ - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==0&&now_y==10) mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //State Processing - if(mode==mode_left&&now_y==0) - { - cout<<"[ACTION] r 1"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - bool started=false; //Update: variable name changed from visited to started - while (true) - { - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - continue; - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - int tot; - cin>>tot; - for (i=1;i<=tot;i++) - { - cin>>bind[i].x>>bind[j].y>>timeleft[i]; - } - //Soft Ginger area - brain(); - //dqb area - } -} diff --git a/orz_0_1.cpp b/orz_0_1.cpp deleted file mode 100644 index 48c93c0..0000000 --- a/orz_0_1.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include -#include -#include -//dqb area -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -//Soft Ginger area -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -//dqb area -using namespace std; -int map[20][20]; -int now[4]; -class point -{ - public: - int x; - int y; -}; -class player -{ - public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]->x=x; - road[num]->y=y; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - int size=0; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (0==map[i][j]) - { - map[i][j]=now[ID]; - now[ID]++; - size++; - } - - } - } - score=score+size*size*10; - num=0; - } -}; -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) player0->die(); - if (ID_1==ID) player1->die(); - if (ID_2==ID) player2->die(); - if (ID_3==ID) player3->die(); - } - if (state_up==state) - { - if (ID_0==ID) {if (state_down==player0->state) player0->paint();player0->up();} - if (ID_1==ID) {if (state_down==player1->state) player1->paint();player1->up();} - if (ID_2==ID) {if (state_down==player2->state) player2->paint();player2->up();} - if (ID_3==ID) {if (state_down==player3->state) player3->paint();player3->up();} - } - if (state_down==state) - { - if (ID_0==ID) {player0->down();player0->insert(x,y);} - if (ID_1==ID) {player1->down();player1->insert(x,y);} - if (ID_2==ID) {player2->down();player2->insert(x,y);} - if (ID_3==ID) {player3->down();player3->insert(x,y);} - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } -}; -//dqb area -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -//Soft Ginger area -int mode=mode_start; -void brain() -{ - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==0&&now_y==10) mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //State Processing - if(mode==mode_left&&now_y==0) - { - cout<<"[ACTION] r 1"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - bool started=false; //Update: variable name changed from visited to started - while (true) - { - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - continue; - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - int tot; - cin>>tot; - for (i=1;i<=tot;i++) - { - cin>>bind[i].x>>bind[j].y>>timeleft[i]; - } - //Soft Ginger area - brain(); - //dqb area - } -} diff --git a/orz_0_2.cpp b/orz_0_2.cpp deleted file mode 100644 index fe08182..0000000 --- a/orz_0_2.cpp +++ /dev/null @@ -1,303 +0,0 @@ -#include -#include -#include -#include -#include -//dqb area -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -//Soft Ginger area -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -//dqb area -using namespace std; -int map[20][20]; -int now[4]; -class point -{ - public: - int x; - int y; -}; -class player -{ - public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position=new point; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new point; - road[num]->x=x; - road[num]->y=y; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - int size=0; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (0==map[i][j]) - { - map[i][j]=now[ID]; - now[ID]++; - size++; - } - - } - } - score=score+size*size*10; - num=0; - } -}; -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) player0->die(); - if (ID_1==ID) player1->die(); - if (ID_2==ID) player2->die(); - if (ID_3==ID) player3->die(); - } - if (state_up==state) - { - if (ID_0==ID) {if (state_down==player0->state) player0->paint();player0->up();} - if (ID_1==ID) {if (state_down==player1->state) player1->paint();player1->up();} - if (ID_2==ID) {if (state_down==player2->state) player2->paint();player2->up();} - if (ID_3==ID) {if (state_down==player3->state) player3->paint();player3->up();} - } - if (state_down==state) - { - if (ID_0==ID) {player0->down();player0->insert(x,y);} - if (ID_1==ID) {player1->down();player1->insert(x,y);} - if (ID_2==ID) {player2->down();player2->insert(x,y);} - if (ID_3==ID) {player3->down();player3->insert(x,y);} - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } -}; -//dqb area -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -//Soft Ginger area -ofstream fout("output.txt"); -int mode=mode_start; -void brain() -{ - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==0&&now_y==10) mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //State Processing - if(mode==mode_left&&now_x==10) - { - cout<<"[ACTION] l 1"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - int tot; - cin>>tot; - for (i=1;i<=tot;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - //Soft Ginger area - brain(); - //dqb area - } -} diff --git a/orz_0_3.cpp b/orz_0_3.cpp deleted file mode 100644 index fe08182..0000000 --- a/orz_0_3.cpp +++ /dev/null @@ -1,303 +0,0 @@ -#include -#include -#include -#include -#include -//dqb area -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -//Soft Ginger area -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -//dqb area -using namespace std; -int map[20][20]; -int now[4]; -class point -{ - public: - int x; - int y; -}; -class player -{ - public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position=new point; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new point; - road[num]->x=x; - road[num]->y=y; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - int size=0; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (0==map[i][j]) - { - map[i][j]=now[ID]; - now[ID]++; - size++; - } - - } - } - score=score+size*size*10; - num=0; - } -}; -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) player0->die(); - if (ID_1==ID) player1->die(); - if (ID_2==ID) player2->die(); - if (ID_3==ID) player3->die(); - } - if (state_up==state) - { - if (ID_0==ID) {if (state_down==player0->state) player0->paint();player0->up();} - if (ID_1==ID) {if (state_down==player1->state) player1->paint();player1->up();} - if (ID_2==ID) {if (state_down==player2->state) player2->paint();player2->up();} - if (ID_3==ID) {if (state_down==player3->state) player3->paint();player3->up();} - } - if (state_down==state) - { - if (ID_0==ID) {player0->down();player0->insert(x,y);} - if (ID_1==ID) {player1->down();player1->insert(x,y);} - if (ID_2==ID) {player2->down();player2->insert(x,y);} - if (ID_3==ID) {player3->down();player3->insert(x,y);} - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } -}; -//dqb area -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -//Soft Ginger area -ofstream fout("output.txt"); -int mode=mode_start; -void brain() -{ - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==0&&now_y==10) mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //State Processing - if(mode==mode_left&&now_x==10) - { - cout<<"[ACTION] l 1"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - int tot; - cin>>tot; - for (i=1;i<=tot;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - //Soft Ginger area - brain(); - //dqb area - } -} diff --git a/orz_0_4.cpp b/orz_0_4.cpp deleted file mode 100644 index f847b52..0000000 --- a/orz_0_4.cpp +++ /dev/null @@ -1,308 +0,0 @@ -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[20][20]; -int now[4]; -int hedge[20][20]; -int vedge[20][20]; -class point -{ - public: - int x; - int y; -}; -class player -{ - public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position=new point; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new point; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - int size=0; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (-1==map[i][j]) - { - map[i][j]=now[ID]; - size++; - } - - } - } - if (0!=size) now[ID]++; - score=score+size*size*10; - num=0; - } -}; -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) player0->die(); - if (ID_1==ID) player1->die(); - if (ID_2==ID) player2->die(); - if (ID_3==ID) player3->die(); - } - if (state_up==state) - { - if (ID_0==ID) {if (state_down==player0->state) player0->insert(x,y);player0->paint();player0->up();player0->clear();player0->insert(x,y);} - if (ID_1==ID) {if (state_down==player1->state) player1->insert(x,y);player1->paint();player1->up();player1->clear();player1->insert(x,y);} - if (ID_2==ID) {if (state_down==player2->state) player2->insert(x,y);player2->paint();player2->up();player2->clear();player2->insert(x,y);} - if (ID_3==ID) {if (state_down==player3->state) player3->insert(x,y);player3->paint();player3->up();player3->clear();player3->insert(x,y);} - } - if (state_down==state) - { - if (ID_0==ID) {player0->down();player0->insert(x,y);} - if (ID_1==ID) {player1->down();player1->insert(x,y);} - if (ID_2==ID) {player2->down();player2->insert(x,y);} - if (ID_3==ID) {player3->down();player3->insert(x,y);} - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } -}; -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -ofstream fout("output.txt"); -int mode=mode_start; -void update_edge_status() -int enclosure_distance(point p1,point p2) -{ - //Todo: - return -1; -} -void brain() -{ - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - if(mode==mode_start) - { - mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==0&&now_y==10) mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - if(mode==mode_left&&now_x==10) - { - cout<<"[ACTION] l 1"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - int tot; - cin>>tot; - for (i=1;i<=tot;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_4_1.cpp b/orz_0_4_1.cpp deleted file mode 100644 index e450b63..0000000 --- a/orz_0_4_1.cpp +++ /dev/null @@ -1,364 +0,0 @@ -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[20][20][5]; -int now[4]; -int edge_color[20][20][20][20]; -class point -{ - public: - int x; - int y; -}; -class player -{ - public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position=new point; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new point; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - int size=0; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (-1==map[i][j]) - { - map[i][j]=now[ID]; - size++; - } - - } - } - if (0!=size) now[ID]++; - score=score+size*size*10; - num=0; - } -}; -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) player0->die(); - if (ID_1==ID) player1->die(); - if (ID_2==ID) player2->die(); - if (ID_3==ID) player3->die(); - } - if (state_up==state) - { - if (ID_0==ID) {if (state_down==player0->state) player0->insert(x,y);player0->paint();player0->up();player0->clear();player0->insert(x,y);} - if (ID_1==ID) {if (state_down==player1->state) player1->insert(x,y);player1->paint();player1->up();player1->clear();player1->insert(x,y);} - if (ID_2==ID) {if (state_down==player2->state) player2->insert(x,y);player2->paint();player2->up();player2->clear();player2->insert(x,y);} - if (ID_3==ID) {if (state_down==player3->state) player3->insert(x,y);player3->paint();player3->up();player3->clear();player3->insert(x,y);} - } - if (state_down==state) - { - if (ID_0==ID) {player0->down();player0->insert(x,y);} - if (ID_1==ID) {player1->down();player1->insert(x,y);} - if (ID_2==ID) {player2->down();player2->insert(x,y);} - if (ID_3==ID) {player3->down();player3->insert(x,y);} - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } -}; -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -int mode=mode_start; -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int enclosure_distance(point p1,point p2,int PID) -{ - //Todo: - return -1; -} -void brain() -{ - update_edge_status(); - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==0&&now_y==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - - if(mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - int tot; - cin>>tot; - for (i=1;i<=tot;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_4_1.exe b/orz_0_4_1.exe deleted file mode 100644 index 496403c..0000000 Binary files a/orz_0_4_1.exe and /dev/null differ diff --git a/orz_0_4_2.cpp b/orz_0_4_2.cpp deleted file mode 100644 index e450b63..0000000 --- a/orz_0_4_2.cpp +++ /dev/null @@ -1,364 +0,0 @@ -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[20][20][5]; -int now[4]; -int edge_color[20][20][20][20]; -class point -{ - public: - int x; - int y; -}; -class player -{ - public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position=new point; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new point; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - int size=0; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (-1==map[i][j]) - { - map[i][j]=now[ID]; - size++; - } - - } - } - if (0!=size) now[ID]++; - score=score+size*size*10; - num=0; - } -}; -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) player0->die(); - if (ID_1==ID) player1->die(); - if (ID_2==ID) player2->die(); - if (ID_3==ID) player3->die(); - } - if (state_up==state) - { - if (ID_0==ID) {if (state_down==player0->state) player0->insert(x,y);player0->paint();player0->up();player0->clear();player0->insert(x,y);} - if (ID_1==ID) {if (state_down==player1->state) player1->insert(x,y);player1->paint();player1->up();player1->clear();player1->insert(x,y);} - if (ID_2==ID) {if (state_down==player2->state) player2->insert(x,y);player2->paint();player2->up();player2->clear();player2->insert(x,y);} - if (ID_3==ID) {if (state_down==player3->state) player3->insert(x,y);player3->paint();player3->up();player3->clear();player3->insert(x,y);} - } - if (state_down==state) - { - if (ID_0==ID) {player0->down();player0->insert(x,y);} - if (ID_1==ID) {player1->down();player1->insert(x,y);} - if (ID_2==ID) {player2->down();player2->insert(x,y);} - if (ID_3==ID) {player3->down();player3->insert(x,y);} - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } -}; -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -int mode=mode_start; -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int enclosure_distance(point p1,point p2,int PID) -{ - //Todo: - return -1; -} -void brain() -{ - update_edge_status(); - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==0&&now_y==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - - if(mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - int tot; - cin>>tot; - for (i=1;i<=tot;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_4_3.cpp b/orz_0_4_3.cpp deleted file mode 100644 index 26b62cd..0000000 --- a/orz_0_4_3.cpp +++ /dev/null @@ -1,443 +0,0 @@ -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[20][20]; -int minimap[4][20][20]; -int now[4]; -int tot[4]; -int area[4]; -int edge_color[20][20][20][20]; -class point -{ -public: - int x; - int y; -}; -class player -{ -public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position=new point; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new point; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ -public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) {player0->die();if (player0->road[1]->x==x&&player0->road[1]->y==y){player0->insert(x,y);player0->paint();player0->clear();}} - if (ID_1==ID) {player1->die();if (player1->road[1]->x==x&&player1->road[1]->y==y){player1->insert(x,y);player1->paint();player1->clear();}} - if (ID_2==ID) {player2->die();if (player2->road[1]->x==x&&player2->road[1]->y==y){player2->insert(x,y);player2->paint();player2->clear();}} - if (ID_3==ID) {player3->die();if (player3->road[1]->x==x&&player3->road[1]->y==y){player3->insert(x,y);player3->paint();player3->clear();}} - } - if (state_up==state) - { - if (ID_0==ID) - { - if (state_down==player0->state) player0->insert(x,y); - player0->paint(); - player0->up(); - player0->clear(); - player0->insert(x,y); - } - if (ID_1==ID) - { - if (state_down==player1->state) player1->insert(x,y); - player1->paint(); - player1->up(); - player1->clear(); - player1->insert(x,y); - } - if (ID_2==ID) - { - if (state_down==player2->state) player2->insert(x,y); - player2->paint(); - player2->up(); - player2->clear(); - player2->insert(x,y); - } - if (ID_3==ID) - { - if (state_down==player3->state) player3->insert(x,y); - player3->paint(); - player3->up(); - player3->clear(); - player3->insert(x,y); - } - } - if (state_down==state) - { - if (ID_0==ID) - { - player0->down(); - player0->insert(x,y); - } - if (ID_1==ID) - { - player1->down(); - player1->insert(x,y); - } - if (ID_2==ID) - { - player2->down(); - player2->insert(x,y); - } - if (ID_3==ID) - { - player3->down(); - player3->insert(x,y); - } - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } - void make() - { - int i,j,k; - for (i=0;i<=3;i++) - for (j=1;j<=10;j++) - for (k=1;k<=10;k++) - { - if (1==minimap[i][j][k]) tot[i]++; - } - - for (j=1;j<=10;j++) - for (k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for (int s=0;s<=3;s++) - if (tot[s]score=player0->score+area[0]*area[0]*10; - player1->score=player1->score+area[1]*area[1]*10; - player2->score=player2->score+area[2]*area[2]*10; - player3->score=player3->score+area[3]*area[3]*10; - for (i=0;i<=3;i++) - if (0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -int mode=mode_start; -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if (diff_x==0&&diff_y==0) cout<<"s "; - else if (diff_x==0&&diff_y==1) cout<<"d "; - else if (diff_x==0&&diff_y==-1) cout<<"u "; - else if (diff_x==1&&diff_y==0) cout<<"r "; - else if (diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if (j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if (i<10) - { - //Downward Road - if (j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if (j>0) - { - //Leftward Road - if (i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if (j<10) - { - //Rightward Road - if (i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int enclosure_distance(point p1,point p2,int ID) -{ - //Todo: - return -1; -} -void brain() -{ - update_edge_status(); - int now_x,now_y; - switch (now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - - if (mode==mode_start) - { - mode=mode_right; - } - else if (mode==mode_right) - { - if (now_x==10&&now_y==10) mode=mode_up; - } - else if (mode==mode_up) - { - if (now_x==0&&now_y==10) mode=mode_left; - } - else if (mode==mode_left) - { - if (now_x==0&&now_y==0) mode=mode_down; - } - else if (mode==mode_down) - { - if (now_x==10&&now_y==0) mode=mode_halt; - } - - if (mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if (mode==mode_right) - { - generate_output(0,1,0); - } - else if (mode==mode_up) - { - generate_output(-1,0,0); - } - else if (mode==mode_left) - { - generate_output(0,-1,0); - } - else if (mode==mode_down) - { - generate_output(1,0,0); - } - else if (mode==mode_halt) - { - generate_output(0,0,0); - } - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int tot; - cin>>tot; - for (i=1;i<=tot;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_5.cpp b/orz_0_5.cpp deleted file mode 100644 index 7959e54..0000000 --- a/orz_0_5.cpp +++ /dev/null @@ -1,451 +0,0 @@ -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[20][20]; -int minimap[4][20][20]; -int now[4]; -int tot[4]; -int area[4]; -int edge_color[20][20][20][20]; -class point -{ -public: - int x; - int y; -}; -class player -{ -public: - point* position; - int ID; - int score; - int state; - int trappedleft; - int num; - point* road[300]; - player(int ID,int x,int y) - { - position=new point; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new point; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ -public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) {player0->die();if (player0->road[1]->x==x&&player0->road[1]->y==y){player0->insert(x,y);player0->paint();player0->clear();}} - if (ID_1==ID) {player1->die();if (player1->road[1]->x==x&&player1->road[1]->y==y){player1->insert(x,y);player1->paint();player1->clear();}} - if (ID_2==ID) {player2->die();if (player2->road[1]->x==x&&player2->road[1]->y==y){player2->insert(x,y);player2->paint();player2->clear();}} - if (ID_3==ID) {player3->die();if (player3->road[1]->x==x&&player3->road[1]->y==y){player3->insert(x,y);player3->paint();player3->clear();}} - } - if (state_up==state) - { - if (ID_0==ID) - { - if (state_down==player0->state) player0->insert(x,y); - player0->paint(); - player0->up(); - player0->clear(); - player0->insert(x,y); - } - if (ID_1==ID) - { - if (state_down==player1->state) player1->insert(x,y); - player1->paint(); - player1->up(); - player1->clear(); - player1->insert(x,y); - } - if (ID_2==ID) - { - if (state_down==player2->state) player2->insert(x,y); - player2->paint(); - player2->up(); - player2->clear(); - player2->insert(x,y); - } - if (ID_3==ID) - { - if (state_down==player3->state) player3->insert(x,y); - player3->paint(); - player3->up(); - player3->clear(); - player3->insert(x,y); - } - } - if (state_down==state) - { - if (ID_0==ID) - { - player0->down(); - player0->insert(x,y); - } - if (ID_1==ID) - { - player1->down(); - player1->insert(x,y); - } - if (ID_2==ID) - { - player2->down(); - player2->insert(x,y); - } - if (ID_3==ID) - { - player3->down(); - player3->insert(x,y); - } - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } - void make() - { - int i,j,k; - for (i=0;i<=3;i++) - for (j=1;j<=10;j++) - for (k=1;k<=10;k++) - { - if (1==minimap[i][j][k]) tot[i]++; - } - - for (j=1;j<=10;j++) - for (k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for (int s=0;s<=3;s++) - if (tot[s]score=player0->score+area[0]*area[0]*10; - player1->score=player1->score+area[1]*area[1]*10; - player2->score=player2->score+area[2]*area[2]*10; - player3->score=player3->score+area[3]*area[3]*10; - for (i=0;i<=3;i++) - if (0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -int m,n,i,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -point bind[200]; -int timeleft[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -int mode=mode_start; -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if (diff_x==0&&diff_y==0) cout<<"s "; - else if (diff_x==0&&diff_y==1) cout<<"d "; - else if (diff_x==0&&diff_y==-1) cout<<"u "; - else if (diff_x==1&&diff_y==0) cout<<"r "; - else if (diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if (j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if (i<10) - { - //Downward Road - if (j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if (j>0) - { - //Leftward Road - if (i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if (j<10) - { - //Rightward Road - if (i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int enclosure_distance(point p1,point p2,int ID) -{ - //Todo: - return -1; -} -void brain() -{ - update_edge_status(); - int now_x,now_y; - switch (now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - - if (mode==mode_start) - { - mode=mode_right; - } - else if (mode==mode_right) - { - if (now_x==10&&now_y==10) mode=mode_up; - } - else if (mode==mode_up) - { - if (now_x==0&&now_y==10) mode=mode_left; - } - else if (mode==mode_left) - { - if (now_x==0&&now_y==0) mode=mode_down; - } - else if (mode==mode_down) - { - if (now_x==10&&now_y==0) mode=mode_halt; - } - - if (mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if (mode==mode_right) - { - generate_output(0,1,0); - } - else if (mode==mode_up) - { - generate_output(-1,0,0); - } - else if (mode==mode_left) - { - generate_output(0,-1,0); - } - else if (mode==mode_down) - { - generate_output(1,0,0); - } - else if (mode==mode_halt) - { - generate_output(0,0,0); - } - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for (i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for (i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_5_1.cpp b/orz_0_5_1.cpp deleted file mode 100644 index 4ea5497..0000000 --- a/orz_0_5_1.cpp +++ /dev/null @@ -1,531 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -class dot -{ - public: - int x; - int y; -}; -class player -{ - public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - for(i=1;i<=10;i++) - for(j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for(k=2;k<=num;k++) - { - if(road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if(road[k-1]->x==road[k]->x) - { - if(road[k-1]->yy) - { - if(j==road[k]->y&&i>road[k]->x) top=true; - if(j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if(road[k-1]->y>road[k]->y) - { - if(j==road[k-1]->y&&i>road[k]->x) top=true; - if(j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if(road[k-1]->y==road[k]->y) - { - if(road[k-1]->xx) - { - if(i==road[k]->x&&j>road[k]->y) left=true; - if(i==road[k]->x&&j<=road[k]->y) right=true; - } - if(road[k-1]->x>road[k]->x) - { - if(i==road[k-1]->x&&j>road[k]->y) left=true; - if(i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if(top&&bottom&&left&&right) - { - if(-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if(state_die==state) - { - if(ID_0==ID) {player0->die();if(player0->road[1]->x==x&&player0->road[1]->y==y){player0->insert(x,y);player0->paint();player0->clear();}} - if(ID_1==ID) {player1->die();if(player1->road[1]->x==x&&player1->road[1]->y==y){player1->insert(x,y);player1->paint();player1->clear();}} - if(ID_2==ID) {player2->die();if(player2->road[1]->x==x&&player2->road[1]->y==y){player2->insert(x,y);player2->paint();player2->clear();}} - if(ID_3==ID) {player3->die();if(player3->road[1]->x==x&&player3->road[1]->y==y){player3->insert(x,y);player3->paint();player3->clear();}} - } - if(state_up==state) - { - if(ID_0==ID) - { - if(state_down==player0->state) player0->insert(x,y); - player0->paint(); - player0->up(); - player0->clear(); - player0->insert(x,y); - } - if(ID_1==ID) - { - if(state_down==player1->state) player1->insert(x,y); - player1->paint(); - player1->up(); - player1->clear(); - player1->insert(x,y); - } - if(ID_2==ID) - { - if(state_down==player2->state) player2->insert(x,y); - player2->paint(); - player2->up(); - player2->clear(); - player2->insert(x,y); - } - if(ID_3==ID) - { - if(state_down==player3->state) player3->insert(x,y); - player3->paint(); - player3->up(); - player3->clear(); - player3->insert(x,y); - } - } - if(state_down==state) - { - if(ID_0==ID) - { - player0->down(); - player0->insert(x,y); - } - if(ID_1==ID) - { - player1->down(); - player1->insert(x,y); - } - if(ID_2==ID) - { - player2->down(); - player2->insert(x,y); - } - if(ID_3==ID) - { - player3->down(); - player3->insert(x,y); - } - } - if(ID_0==ID) player0->change(x,y); - if(ID_1==ID) player1->change(x,y); - if(ID_2==ID) player2->change(x,y); - if(ID_3==ID) player3->change(x,y); - } - void make() - { - int i,j,k; - for(i=0;i<=3;i++) - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - if(1==minimap[i][j][k]) tot[i]++; - } - - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for(int s=0;s<=3;s++) - if(tot[s]score=player0->score+area[0]*area[0]*10; - player1->score=player1->score+area[1]*area[1]*10; - player2->score=player2->score+area[2]*area[2]*10; - player3->score=player3->score+area[3]*area[3]*10; - for(i=0;i<=3;i++) - if(0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot bind[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if(!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if(!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for(int i=0;i<=10;i++) for(int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -void brain() -{ - update_edge_status(); - update_distance(game->player0->position,0); - update_distance(game->player1->position,1); - update_distance(game->player2->position,2); - update_distance(game->player3->position,3); - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==0&&now_y==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //Output Area - if(mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for(int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if(!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for(int i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_5_1.exe b/orz_0_5_1.exe deleted file mode 100644 index 5eafe49..0000000 Binary files a/orz_0_5_1.exe and /dev/null differ diff --git a/orz_0_6.cpp b/orz_0_6.cpp deleted file mode 100644 index 5d22656..0000000 --- a/orz_0_6.cpp +++ /dev/null @@ -1,535 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -class dot -{ - public: - int x; - int y; -}; -class player -{ - public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - for(i=1;i<=10;i++) - for(j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for(k=2;k<=num;k++) - { - if(road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if(road[k-1]->x==road[k]->x) - { - if(road[k-1]->yy) - { - if(j==road[k]->y&&i>road[k]->x) top=true; - if(j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if(road[k-1]->y>road[k]->y) - { - if(j==road[k-1]->y&&i>road[k]->x) top=true; - if(j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if(road[k-1]->y==road[k]->y) - { - if(road[k-1]->xx) - { - if(i==road[k]->x&&j>road[k]->y) left=true; - if(i==road[k]->x&&j<=road[k]->y) right=true; - } - if(road[k-1]->x>road[k]->x) - { - if(i==road[k-1]->x&&j>road[k]->y) left=true; - if(i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if(top&&bottom&&left&&right) - { - if(-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if(state_die==state) - { - if(ID_0==ID) {player0->die();if(player0->road[1]->x==x&&player0->road[1]->y==y){player0->insert(x,y);player0->paint();player0->clear();}} - if(ID_1==ID) {player1->die();if(player1->road[1]->x==x&&player1->road[1]->y==y){player1->insert(x,y);player1->paint();player1->clear();}} - if(ID_2==ID) {player2->die();if(player2->road[1]->x==x&&player2->road[1]->y==y){player2->insert(x,y);player2->paint();player2->clear();}} - if(ID_3==ID) {player3->die();if(player3->road[1]->x==x&&player3->road[1]->y==y){player3->insert(x,y);player3->paint();player3->clear();}} - } - if(state_up==state) - { - if(ID_0==ID) - { - if(state_down==player0->state) player0->insert(x,y); - player0->paint(); - player0->up(); - player0->clear(); - player0->insert(x,y); - } - if(ID_1==ID) - { - if(state_down==player1->state) player1->insert(x,y); - player1->paint(); - player1->up(); - player1->clear(); - player1->insert(x,y); - } - if(ID_2==ID) - { - if(state_down==player2->state) player2->insert(x,y); - player2->paint(); - player2->up(); - player2->clear(); - player2->insert(x,y); - } - if(ID_3==ID) - { - if(state_down==player3->state) player3->insert(x,y); - player3->paint(); - player3->up(); - player3->clear(); - player3->insert(x,y); - } - } - if(state_down==state) - { - if(ID_0==ID) - { - player0->down(); - player0->insert(x,y); - } - if(ID_1==ID) - { - player1->down(); - player1->insert(x,y); - } - if(ID_2==ID) - { - player2->down(); - player2->insert(x,y); - } - if(ID_3==ID) - { - player3->down(); - player3->insert(x,y); - } - } - if(ID_0==ID) player0->change(x,y); - if(ID_1==ID) player1->change(x,y); - if(ID_2==ID) player2->change(x,y); - if(ID_3==ID) player3->change(x,y); - } - void make() - { - int i,j,k; - for(i=0;i<=3;i++) - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - if(1==minimap[i][j][k]) tot[i]++; - } - - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for(int s=0;s<=3;s++) - if(tot[s]score=player0->score+area[0]*area[0]*10; - player1->score=player1->score+area[1]*area[1]*10; - player2->score=player2->score+area[2]*area[2]*10; - player3->score=player3->score+area[3]*area[3]*10; - for(i=0;i<=3;i++) - if(0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot bind[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if(!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if(!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for(int i=0;i<=10;i++) for(int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -void brain() -{ - update_edge_status(); - update_distance(game->player0->position,0); - update_distance(game->player1->position,1); - update_distance(game->player2->position,2); - update_distance(game->player3->position,3); - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==0&&now_y==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //Output Area - if(mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for(int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if(!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for(int i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_6_1.cpp b/orz_0_6_1.cpp deleted file mode 100644 index 5d22656..0000000 --- a/orz_0_6_1.cpp +++ /dev/null @@ -1,535 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -class dot -{ - public: - int x; - int y; -}; -class player -{ - public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - for(i=1;i<=10;i++) - for(j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for(k=2;k<=num;k++) - { - if(road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if(road[k-1]->x==road[k]->x) - { - if(road[k-1]->yy) - { - if(j==road[k]->y&&i>road[k]->x) top=true; - if(j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if(road[k-1]->y>road[k]->y) - { - if(j==road[k-1]->y&&i>road[k]->x) top=true; - if(j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if(road[k-1]->y==road[k]->y) - { - if(road[k-1]->xx) - { - if(i==road[k]->x&&j>road[k]->y) left=true; - if(i==road[k]->x&&j<=road[k]->y) right=true; - } - if(road[k-1]->x>road[k]->x) - { - if(i==road[k-1]->x&&j>road[k]->y) left=true; - if(i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if(top&&bottom&&left&&right) - { - if(-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ - public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if(state_die==state) - { - if(ID_0==ID) {player0->die();if(player0->road[1]->x==x&&player0->road[1]->y==y){player0->insert(x,y);player0->paint();player0->clear();}} - if(ID_1==ID) {player1->die();if(player1->road[1]->x==x&&player1->road[1]->y==y){player1->insert(x,y);player1->paint();player1->clear();}} - if(ID_2==ID) {player2->die();if(player2->road[1]->x==x&&player2->road[1]->y==y){player2->insert(x,y);player2->paint();player2->clear();}} - if(ID_3==ID) {player3->die();if(player3->road[1]->x==x&&player3->road[1]->y==y){player3->insert(x,y);player3->paint();player3->clear();}} - } - if(state_up==state) - { - if(ID_0==ID) - { - if(state_down==player0->state) player0->insert(x,y); - player0->paint(); - player0->up(); - player0->clear(); - player0->insert(x,y); - } - if(ID_1==ID) - { - if(state_down==player1->state) player1->insert(x,y); - player1->paint(); - player1->up(); - player1->clear(); - player1->insert(x,y); - } - if(ID_2==ID) - { - if(state_down==player2->state) player2->insert(x,y); - player2->paint(); - player2->up(); - player2->clear(); - player2->insert(x,y); - } - if(ID_3==ID) - { - if(state_down==player3->state) player3->insert(x,y); - player3->paint(); - player3->up(); - player3->clear(); - player3->insert(x,y); - } - } - if(state_down==state) - { - if(ID_0==ID) - { - player0->down(); - player0->insert(x,y); - } - if(ID_1==ID) - { - player1->down(); - player1->insert(x,y); - } - if(ID_2==ID) - { - player2->down(); - player2->insert(x,y); - } - if(ID_3==ID) - { - player3->down(); - player3->insert(x,y); - } - } - if(ID_0==ID) player0->change(x,y); - if(ID_1==ID) player1->change(x,y); - if(ID_2==ID) player2->change(x,y); - if(ID_3==ID) player3->change(x,y); - } - void make() - { - int i,j,k; - for(i=0;i<=3;i++) - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - if(1==minimap[i][j][k]) tot[i]++; - } - - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for(int s=0;s<=3;s++) - if(tot[s]score=player0->score+area[0]*area[0]*10; - player1->score=player1->score+area[1]*area[1]*10; - player2->score=player2->score+area[2]*area[2]*10; - player3->score=player3->score+area[3]*area[3]*10; - for(i=0;i<=3;i++) - if(0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot bind[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if(!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if(!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for(int i=0;i<=10;i++) for(int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -void brain() -{ - update_edge_status(); - update_distance(game->player0->position,0); - update_distance(game->player1->position,1); - update_distance(game->player2->position,2); - update_distance(game->player3->position,3); - int now_x,now_y; - switch(now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==0&&now_y==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //Output Area - if(mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for(int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if(!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for(int i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_6_2.cpp b/orz_0_6_2.cpp deleted file mode 100644 index 615402c..0000000 --- a/orz_0_6_2.cpp +++ /dev/null @@ -1,621 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -class dot -{ -public: - int x; - int y; -}; -class player -{ -public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void cut() - { - num--; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=num;k++) - { - if (road[k-1]->x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if (road[k-1]->x==road[k]->x) - { - if (road[k-1]->yy) - { - if (j==road[k]->y&&i>road[k]->x) top=true; - if (j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if (road[k-1]->y>road[k]->y) - { - if (j==road[k-1]->y&&i>road[k]->x) top=true; - if (j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if (road[k-1]->y==road[k]->y) - { - if (road[k-1]->xx) - { - if (i==road[k]->x&&j>road[k]->y) left=true; - if (i==road[k]->x&&j<=road[k]->y) right=true; - } - if (road[k-1]->x>road[k]->x) - { - if (i==road[k-1]->x&&j>road[k]->y) left=true; - if (i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if (top&&bottom&&left&&right) - { - if (-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ -public: - player* player0; - player* player1; - player* player2; - player* player3; - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if (state_die==state) - { - if (ID_0==ID) - { - player0->die(); - if (player0->road[1]->x==x&&player0->road[1]->y==y) - { - player0->insert(x,y); - player0->paint(); - player0->clear(); - } - } - if (ID_1==ID) - { - player1->die(); - if (player1->road[1]->x==x&&player1->road[1]->y==y) - { - player1->insert(x,y); - player1->paint(); - player1->clear(); - } - } - if (ID_2==ID) - { - player2->die(); - if (player2->road[1]->x==x&&player2->road[1]->y==y) - { - player2->insert(x,y); - player2->paint(); - player2->clear(); - } - } - if (ID_3==ID) - { - player3->die(); - if (player3->road[1]->x==x&&player3->road[1]->y==y) - { - player3->insert(x,y); - player3->paint(); - player3->clear(); - } - } - } - if (state_up==state) - { - if (ID_0==ID) - { - if (state_down==player0->state) player0->insert(x,y); - player0->paint(); - player0->up(); - player0->clear(); - player0->insert(x,y); - } - if (ID_1==ID) - { - if (state_down==player1->state) player1->insert(x,y); - player1->paint(); - player1->up(); - player1->clear(); - player1->insert(x,y); - } - if (ID_2==ID) - { - if (state_down==player2->state) player2->insert(x,y); - player2->paint(); - player2->up(); - player2->clear(); - player2->insert(x,y); - } - if (ID_3==ID) - { - if (state_down==player3->state) player3->insert(x,y); - player3->paint(); - player3->up(); - player3->clear(); - player3->insert(x,y); - } - } - if (state_down==state) - { - if (ID_0==ID) - { - player0->down(); - player0->insert(x,y); - } - if (ID_1==ID) - { - player1->down(); - player1->insert(x,y); - } - if (ID_2==ID) - { - player2->down(); - player2->insert(x,y); - } - if (ID_3==ID) - { - player3->down(); - player3->insert(x,y); - } - } - if (ID_0==ID) player0->change(x,y); - if (ID_1==ID) player1->change(x,y); - if (ID_2==ID) player2->change(x,y); - if (ID_3==ID) player3->change(x,y); - } - void make() - { - int i,j,k; - for (i=0;i<=3;i++) - for (j=1;j<=10;j++) - for (k=1;k<=10;k++) - { - if (1==minimap[i][j][k]) tot[i]++; - } - - for (j=1;j<=10;j++) - for (k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for (int s=0;s<=3;s++) - if (tot[s]score=player0->score+area[0]*area[0]*10; - player1->score=player1->score+area[1]*area[1]*10; - player2->score=player2->score+area[2]*area[2]*10; - player3->score=player3->score+area[3]*area[3]*10; - for (i=0;i<=3;i++) - if (0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot bind[200]; -enclosure* game; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if (diff_x==0&&diff_y==0) cout<<"s "; - else if (diff_x==0&&diff_y==1) cout<<"d "; - else if (diff_x==0&&diff_y==-1) cout<<"u "; - else if (diff_x==1&&diff_y==0) cout<<"r "; - else if (diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if (j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if (i<10) - { - //Downward Road - if (j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if (j>0) - { - //Leftward Road - if (i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if (j<10) - { - //Rightward Road - if (i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while ((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if ((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if (!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if ((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if (!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if ((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if (!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if ((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if (!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for (int i=0;i<=10;i++) for (int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -int calculate_area(dot** x,int dot_num) -{ - int i,j,k; - int ans=0; - for (i=1;i<=10;i++) - for (j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for (k=2;k<=dot_num;k++) - { - if (x[k-1]->x==x[k]->x&&x[k-1]->y==x[k]->y) continue; - if (x[k-1]->x==x[k]->x) - { - if (x[k-1]->yy) - { - if (j==x[k]->y&&i>x[k]->x) top=true; - if (j==x[k]->y&&i<=x[k]->x) bottom=true; - } - if (x[k-1]->y>x[k]->y) - { - if (j==x[k-1]->y&&i>x[k]->x) top=true; - if (j==x[k-1]->y&&i<=x[k]->x) bottom=true; - } - continue; - } - if (x[k-1]->y==x[k]->y) - { - if (x[k-1]->xx) - { - if (i==x[k]->x&&j>x[k]->y) left=true; - if (i==x[k]->x&&j<=x[k]->y) right=true; - } - if (x[k-1]->x>x[k]->x) - { - if (i==x[k-1]->x&&j>x[k]->y) left=true; - if (i==x[k-1]->x&&j<=x[k]->y) right=true; - } - } - } - if (left&&right&&top&&bottom) ans++; - } - return ans; -} -void brain() -{ - update_edge_status(); - update_distance(game->player0->position,0); - update_distance(game->player1->position,1); - update_distance(game->player2->position,2); - update_distance(game->player3->position,3); - int now_x,now_y; - switch (now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - if (mode==mode_start) - { - mode=mode_right; - } - else if (mode==mode_right) - { - if (now_x==10&&now_y==10) mode=mode_up; - } - else if (mode==mode_up) - { - if (now_x==0&&now_y==10) mode=mode_left; - } - else if (mode==mode_left) - { - if (now_x==0&&now_y==0) mode=mode_down; - } - else if (mode==mode_down) - { - if (now_x==10&&now_y==0) mode=mode_halt; - } - //Output Area - if (mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if (mode==mode_right) - { - generate_output(0,1,0); - } - else if (mode==mode_up) - { - generate_output(-1,0,0); - } - else if (mode==mode_left) - { - generate_output(0,-1,0); - } - else if (mode==mode_down) - { - generate_output(1,0,0); - } - else if (mode==mode_halt) - { - generate_output(0,0,0); - } - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for (int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if (!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for (int i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_6_3.cpp b/orz_0_6_3.cpp deleted file mode 100644 index 96d2de2..0000000 --- a/orz_0_6_3.cpp +++ /dev/null @@ -1,560 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -#define mode_idle 6 -#define mode_draw 7 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -ofstream fout5(".\\output5.txt"); -class dot -{ -public: - int x; - int y; -}; -class player -{ -public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void cut() - { - num--; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k,s=1; - for(i=1;i<=num-1;i++) - if(road[i]->x==road[num]->x&&road[i]->y==road[num]->y) s=i; - fout5<<"---------ROAD----------"<x<<" "<y<x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if(road[k-1]->x==road[k]->x) - { - if(road[k-1]->yy) - { - if(j==road[k]->y&&i>road[k]->x) top=true; - if(j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if(road[k-1]->y>road[k]->y) - { - if(j==road[k-1]->y&&i>road[k]->x) top=true; - if(j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if(road[k-1]->y==road[k]->y) - { - if(road[k-1]->xx) - { - if(i==road[k]->x&&j>road[k]->y) left=true; - if(i==road[k]->x&&j<=road[k]->y) right=true; - } - if(road[k-1]->x>road[k]->x) - { - if(i==road[k-1]->x&&j>road[k]->y) left=true; - if(i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if(top&&bottom&&left&&right) - { - if(-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ -public: - player* players[4]; - enclosure(int* x,int* y) - { - for(int i=0;i<4;i++) players[i]=new player(i,x[i],y[i]); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if(state_die==state) - { - players[ID]->die(); - //Needs revision - if(players[ID]->road[1]->x==x&&players[ID]->road[1]->y==y) - { - players[ID]->insert(x,y); - players[ID]->paint(); - players[ID]->clear(); - } - } - if(state_up==state) - { - if(state_down==players[ID]->state) players[ID]->insert(x,y); - players[ID]->paint(); - players[ID]->up(); - players[ID]->clear(); - players[ID]->insert(x,y); - } - if(state_down==state) - { - players[ID]->down(); - players[ID]->insert(x,y); - } - players[ID]->change(x,y); - } - void make() - { - for(int i=0;i<=3;i++) - for(int j=1;j<=10;j++) - for(int k=1;k<=10;k++) - { - if(1==minimap[i][j][k]) tot[i]++; - } - - for(int j=1;j<=10;j++) - for(int k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for(int s=0;s<=3;s++) - if(tot[s]score+=area[i]*area[i]*10; - for(int i=0;i<=3;i++) if(0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot bind[200]; -enclosure* game; - -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while ((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if(!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if(!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for(int i=0;i<=10;i++) for(int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -int calculate_area(dot** x,int dot_num) -{ - int i,j,k,s=1; - int ans=0; - for(i=1;i<=dot_num-1;i++) - if(x[i]->x==x[dot_num]->x&&x[i]->y==x[dot_num]->y) s=i; - for(i=1;i<=10;i++) - for(j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for(k=s+1;k<=dot_num;k++) - { - if(x[k-1]->x==x[k]->x&&x[k-1]->y==x[k]->y) continue; - if(x[k-1]->x==x[k]->x) - { - if(x[k-1]->yy) - { - if(j==x[k]->y&&i>x[k]->x) top=true; - if(j==x[k]->y&&i<=x[k]->x) bottom=true; - } - if(x[k-1]->y>x[k]->y) - { - if(j==x[k-1]->y&&i>x[k]->x) top=true; - if(j==x[k-1]->y&&i<=x[k]->x) bottom=true; - } - continue; - } - if(x[k-1]->y==x[k]->y) - { - if(x[k-1]->xx) - { - if(i==x[k]->x&&j>x[k]->y) left=true; - if(i==x[k]->x&&j<=x[k]->y) right=true; - } - if(x[k-1]->x>x[k]->x) - { - if(i==x[k-1]->x&&j>x[k]->y) left=true; - if(i==x[k-1]->x&&j<=x[k]->y) right=true; - } - } - } - if(left&&right&&top&&bottom&&-1==map[i][j]) ans++; - } - return ans; -} -int calculate_maximum_safe_enclosure(int now_id) -{ - -} -void brain() -{ - update_edge_status(); - int original_edge_color[15][15][15][15]; - memcpy(original_edge_color,edge_color,sizeof(original_edge_color)); - for(int i=0;i<4;i++) - { - memcpy(edge_color,original_edge_color,sizeof(edge_color)); - if(game->players[i]->state==state_down) - { - for(int j=1;jplayers[i]->num;j++) - { - dot* p1=new dot(); - dot* p2=new dot(); - p1=game->players[i]->road[j]; - p2=game->players[i]->road[j+1]; - edge_color[p1->x][p1->y][p2->x][p2->y]=edge_color[p2->x][p2->y][p1->x][p1->y]=400; - } - } - else if(game->players[i]->state==state_up) - { - //Downward Road - for(int j=0;j<10;j++) for(int k=0;k<=10;k++) if((edge_color[j][k][j+1][k]/100)==i) edge_color[j][k][j+1][k]=-1; - //Upward Road - for(int j=1;j<=10;j++) for(int k=0;k<=10;k++) if((edge_color[j][k][j-1][k]/100)==i) edge_color[j][k][j-1][k]=-1; - //Rightward Road - for(int j=0;j<=10;j++) for(int k=0;k<10;k++) if((edge_color[j][k][j][k+1]/100)==i) edge_color[j][k][j][k+1]=-1; - //Leftward Road - for(int j=0;j<=10;j++) for(int k=1;k<=10;k++) if((edge_color[j][k][j][k-1]/100)==i) edge_color[j][k][j][k-1]=-1; - } - update_distance(game->players[i]->position,i); - } - memcpy(edge_color,original_edge_color,sizeof(edge_color)); - int now_x[4],now_y[4]; - for(int i=0;i<4;i++) - { - now_x[i]=game->players[i]->position->x; - now_y[i]=game->players[i]->position->y; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x[now_id]==10&&now_y[now_id]==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x[now_id]==0&&now_y[now_id]==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x[now_id]==0&&now_y[now_id]==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x[now_id]==10&&now_y[now_id]==0) mode=mode_halt; - } - //Output Area - if(mode==mode_right&&now_y[now_id]==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for(int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if(!started) - { - started=true; - //game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - game=new enclosure(x,y); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for(int i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_6_3.exe b/orz_0_6_3.exe deleted file mode 100644 index 770c75b..0000000 Binary files a/orz_0_6_3.exe and /dev/null differ diff --git a/orz_0_6_4.cpp b/orz_0_6_4.cpp deleted file mode 100644 index c341a71..0000000 --- a/orz_0_6_4.cpp +++ /dev/null @@ -1,657 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -#define mode_idle 6 -#define mode_draw 7 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -ofstream fout5(".\\output5.txt"); -class dot -{ -public: - int x; - int y; -}; -class player -{ -public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void cut() - { - num--; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k,s=1; - for(i=1;i<=num-1;i++) - if(road[i]->x==road[num]->x&&road[i]->y==road[num]->y) s=i; - fout5<<"---------ROAD----------"<x<<" "<y<x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if(road[k-1]->x==road[k]->x) - { - if(road[k-1]->yy) - { - if(j==road[k]->y&&i>road[k]->x) top=true; - if(j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if(road[k-1]->y>road[k]->y) - { - if(j==road[k-1]->y&&i>road[k]->x) top=true; - if(j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if(road[k-1]->y==road[k]->y) - { - if(road[k-1]->xx) - { - if(i==road[k]->x&&j>road[k]->y) left=true; - if(i==road[k]->x&&j<=road[k]->y) right=true; - } - if(road[k-1]->x>road[k]->x) - { - if(i==road[k-1]->x&&j>road[k]->y) left=true; - if(i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if(top&&bottom&&left&&right) - { - if(-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ -public: - /* - player* player0; - player* player1; - player* player2; - player* player3; - player* players[4]; - */ - enclosure(int x0,int y0,int x1,int y1,int x2,int y2,int x3,int y3) - { - player0=new player(ID_0,x0,y0); - player1=new player(ID_1,x1,y1); - player2=new player(ID_2,x2,y2); - player3=new player(ID_3,x3,y3); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if(state_die==state) - { - if(ID_0==ID) - { - player0->die(); - if(player0->road[1]->x==x&&player0->road[1]->y==y) - { - player0->insert(x,y); - player0->paint(); - player0->clear(); - } - } - if(ID_1==ID) - { - player1->die(); - if(player1->road[1]->x==x&&player1->road[1]->y==y) - { - player1->insert(x,y); - player1->paint(); - player1->clear(); - } - } - if(ID_2==ID) - { - player2->die(); - if(player2->road[1]->x==x&&player2->road[1]->y==y) - { - player2->insert(x,y); - player2->paint(); - player2->clear(); - } - } - if(ID_3==ID) - { - player3->die(); - if(player3->road[1]->x==x&&player3->road[1]->y==y) - { - player3->insert(x,y); - player3->paint(); - player3->clear(); - } - } - } - if(state_up==state) - { - if(ID_0==ID) - { - if(state_down==player0->state) player0->insert(x,y); - player0->paint(); - player0->up(); - player0->clear(); - player0->insert(x,y); - } - if(ID_1==ID) - { - if(state_down==player1->state) player1->insert(x,y); - player1->paint(); - player1->up(); - player1->clear(); - player1->insert(x,y); - } - if(ID_2==ID) - { - if(state_down==player2->state) player2->insert(x,y); - player2->paint(); - player2->up(); - player2->clear(); - player2->insert(x,y); - } - if(ID_3==ID) - { - if(state_down==player3->state) player3->insert(x,y); - player3->paint(); - player3->up(); - player3->clear(); - player3->insert(x,y); - } - } - if(state_down==state) - { - if(ID_0==ID) - { - player0->down(); - player0->insert(x,y); - } - if(ID_1==ID) - { - player1->down(); - player1->insert(x,y); - } - if(ID_2==ID) - { - player2->down(); - player2->insert(x,y); - } - if(ID_3==ID) - { - player3->down(); - player3->insert(x,y); - } - } - if(ID_0==ID) player0->change(x,y); - if(ID_1==ID) player1->change(x,y); - if(ID_2==ID) player2->change(x,y); - if(ID_3==ID) player3->change(x,y); - } - void make() - { - int i,j,k; - for(i=0;i<=3;i++) - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - if(1==minimap[i][j][k]) tot[i]++; - } - - for(j=1;j<=10;j++) - for(k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for(int s=0;s<=3;s++) - if(tot[s]score=player0->score+area[0]*area[0]*10; - player1->score=player1->score+area[1]*area[1]*10; - player2->score=player2->score+area[2]*area[2]*10; - player3->score=player3->score+area[3]*area[3]*10; - for(i=0;i<=3;i++) - if(0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot bind[200]; -enclosure* game; - -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while ((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if(!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if(!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for(int i=0;i<=10;i++) for(int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -int calculate_area(dot** x,int dot_num) -{ - int i,j,k,s=1; - int ans=0; - for(i=1;i<=dot_num-1;i++) - if(x[i]->x==x[dot_num]->x&&x[i]->y==x[dot_num]->y) s=i; - for(i=1;i<=10;i++) - for(j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for(k=s+1;k<=dot_num;k++) - { - if(x[k-1]->x==x[k]->x&&x[k-1]->y==x[k]->y) continue; - if(x[k-1]->x==x[k]->x) - { - if(x[k-1]->yy) - { - if(j==x[k]->y&&i>x[k]->x) top=true; - if(j==x[k]->y&&i<=x[k]->x) bottom=true; - } - if(x[k-1]->y>x[k]->y) - { - if(j==x[k-1]->y&&i>x[k]->x) top=true; - if(j==x[k-1]->y&&i<=x[k]->x) bottom=true; - } - continue; - } - if(x[k-1]->y==x[k]->y) - { - if(x[k-1]->xx) - { - if(i==x[k]->x&&j>x[k]->y) left=true; - if(i==x[k]->x&&j<=x[k]->y) right=true; - } - if(x[k-1]->x>x[k]->x) - { - if(i==x[k-1]->x&&j>x[k]->y) left=true; - if(i==x[k-1]->x&&j<=x[k]->y) right=true; - } - } - } - if(left&&right&&top&&bottom&&-1==map[i][j]) ans++; - } - return ans; -} -int calculate_maximum_safe_enclosure(int now_id) -{ - -} -void brain() -{ - update_edge_status(); - int original_edge_color[15][15][15][15]; - memcpy(original_edge_color,edge_color,sizeof(original_edge_color)); - if(game->player0->state=state_down) - { - memcpy(edge_color,original_edge_color,sizeof(edge_color)); - for(int i=1;iplayer0->num;i++) - { - dot* p1=game->player0->road[i]; - dot* p2=game->player0->road[i+1]; - edge_color[p1->x][p1->y][p2->x][p2->y]=edge_color[p2->x][p2->y][p1->x][p1->y]=400; - } - } - - update_distance(game->player1->position,1); - update_distance(game->player2->position,2); - update_distance(game->player3->position,3); - int now_x,now_y; - switch (now_id) - { - case 0: - now_x=game->player0->position->x; - now_y=game->player0->position->y; - break; - case 1: - now_x=game->player1->position->x; - now_y=game->player1->position->y; - break; - case 2: - now_x=game->player2->position->x; - now_y=game->player2->position->y; - break; - case 3: - now_x=game->player3->position->x; - now_y=game->player3->position->y; - break; - default: - break; - } - //Finite State Machine - /*Whole closure - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x==10&&now_y==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x==0&&now_y==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x==0&&now_y==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x==10&&now_y==0) mode=mode_halt; - } - //Output Area - if(mode==mode_right&&now_y==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - */ - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for(int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if(!started) - { - started=true; - game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for(int i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_6_6.cpp b/orz_0_6_6.cpp deleted file mode 100644 index cea99e1..0000000 --- a/orz_0_6_6.cpp +++ /dev/null @@ -1,558 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define ID_0 0 -#define ID_1 1 -#define ID_2 2 -#define ID_3 3 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -#define mode_idle 6 -#define mode_draw 7 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,j,k; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -ofstream fout5(".\\output5.txt"); -class dot -{ -public: - int x; - int y; -}; -class player -{ -public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void cut() - { - num--; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k,s=1; - for(i=1;i<=num-1;i++) - if(road[i]->x==road[num]->x&&road[i]->y==road[num]->y) s=i; - fout5<<"---------ROAD----------"<x<<" "<y<x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if(road[k-1]->x==road[k]->x) - { - if(road[k-1]->yy) - { - if(j==road[k]->y&&i>road[k]->x) top=true; - if(j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if(road[k-1]->y>road[k]->y) - { - if(j==road[k-1]->y&&i>road[k]->x) top=true; - if(j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if(road[k-1]->y==road[k]->y) - { - if(road[k-1]->xx) - { - if(i==road[k]->x&&j>road[k]->y) left=true; - if(i==road[k]->x&&j<=road[k]->y) right=true; - } - if(road[k-1]->x>road[k]->x) - { - if(i==road[k-1]->x&&j>road[k]->y) left=true; - if(i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if(top&&bottom&&left&&right) - { - if(-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ -public: - player* players[4]; - enclosure(int* x,int* y) - { - for(int i=0;i<4;i++) players[i]=new player(i,x[i],y[i]); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if(state_die==state) - { - players[ID]->die(); - //Needs revision - players[ID]->insert(x,y); - players[ID]->paint(); - players[ID]->clear(); - } - if(state_up==state) - { - if(state_down==players[ID]->state) players[ID]->insert(x,y); - players[ID]->paint(); - players[ID]->up(); - players[ID]->clear(); - players[ID]->insert(x,y); - } - if(state_down==state) - { - players[ID]->down(); - players[ID]->insert(x,y); - } - players[ID]->change(x,y); - } - void make() - { - for(int i=0;i<=3;i++) - for(int j=1;j<=10;j++) - for(int k=1;k<=10;k++) - { - if(1==minimap[i][j][k]) tot[i]++; - } - - for(int j=1;j<=10;j++) - for(int k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for(int s=0;s<=3;s++) - if(tot[s]score+=area[i]*area[i]*10; - for(int i=0;i<=3;i++) if(0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot bind[200]; -enclosure* game; - -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - //Upward Road - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - //Downward Road - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - //Leftward Road - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - //Rightward Road - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while ((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if(!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if(!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for(int i=0;i<=10;i++) for(int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -int calculate_area(dot** x,int dot_num) -{ - int i,j,k,s=1; - int ans=0; - for(i=1;i<=dot_num-1;i++) - if(x[i]->x==x[dot_num]->x&&x[i]->y==x[dot_num]->y) s=i; - for(i=1;i<=10;i++) - for(j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for(k=s+1;k<=dot_num;k++) - { - if(x[k-1]->x==x[k]->x&&x[k-1]->y==x[k]->y) continue; - if(x[k-1]->x==x[k]->x) - { - if(x[k-1]->yy) - { - if(j==x[k]->y&&i>x[k]->x) top=true; - if(j==x[k]->y&&i<=x[k]->x) bottom=true; - } - if(x[k-1]->y>x[k]->y) - { - if(j==x[k-1]->y&&i>x[k]->x) top=true; - if(j==x[k-1]->y&&i<=x[k]->x) bottom=true; - } - continue; - } - if(x[k-1]->y==x[k]->y) - { - if(x[k-1]->xx) - { - if(i==x[k]->x&&j>x[k]->y) left=true; - if(i==x[k]->x&&j<=x[k]->y) right=true; - } - if(x[k-1]->x>x[k]->x) - { - if(i==x[k-1]->x&&j>x[k]->y) left=true; - if(i==x[k-1]->x&&j<=x[k]->y) right=true; - } - } - } - if(left&&right&&top&&bottom&&-1==map[i][j]) ans++; - } - return ans; -} -int calculate_maximum_safe_enclosure(int now_id,int road_id) -{ - //Todo: - //1. Fetch the road from road_id to -} -void brain() -{ - update_edge_status(); - int original_edge_color[15][15][15][15]; - memcpy(original_edge_color,edge_color,sizeof(original_edge_color)); - for(int i=0;i<4;i++) - { - memcpy(edge_color,original_edge_color,sizeof(edge_color)); - if(game->players[i]->state==state_down) - { - for(int j=1;jplayers[i]->num;j++) - { - dot* p1=new dot(); - dot* p2=new dot(); - p1=game->players[i]->road[j]; - p2=game->players[i]->road[j+1]; - edge_color[p1->x][p1->y][p2->x][p2->y]=edge_color[p2->x][p2->y][p1->x][p1->y]=400; - } - } - else if(game->players[i]->state==state_up) - { - //Downward Road - for(int j=0;j<10;j++) for(int k=0;k<=10;k++) if((edge_color[j][k][j+1][k]/100)==i) edge_color[j][k][j+1][k]=-1; - //Upward Road - for(int j=1;j<=10;j++) for(int k=0;k<=10;k++) if((edge_color[j][k][j-1][k]/100)==i) edge_color[j][k][j-1][k]=-1; - //Rightward Road - for(int j=0;j<=10;j++) for(int k=0;k<10;k++) if((edge_color[j][k][j][k+1]/100)==i) edge_color[j][k][j][k+1]=-1; - //Leftward Road - for(int j=0;j<=10;j++) for(int k=1;k<=10;k++) if((edge_color[j][k][j][k-1]/100)==i) edge_color[j][k][j][k-1]=-1; - } - update_distance(game->players[i]->position,i); - } - memcpy(edge_color,original_edge_color,sizeof(edge_color)); - int now_x[4],now_y[4]; - for(int i=0;i<4;i++) - { - now_x[i]=game->players[i]->position->x; - now_y[i]=game->players[i]->position->y; - } - //Finite State Machine - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x[now_id]==10&&now_y[now_id]==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x[now_id]==0&&now_y[now_id]==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x[now_id]==0&&now_y[now_id]==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x[now_id]==10&&now_y[now_id]==0) mode=mode_halt; - } - //Output Area - if(mode==mode_right&&now_y[now_id]==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for(int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if(!started) - { - started=true; - //game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - game=new enclosure(x,y); - } - game->pass(ID_0,x[0],y[0],state[0]); - game->pass(ID_1,x[1],y[1],state[1]); - game->pass(ID_2,x[2],y[2],state[2]); - game->pass(ID_3,x[3],y[3],state[3]); - game->make(); - int total; - cin>>total; - for(int i=1;i<=total;i++) - { - cin>>bind[i].x>>bind[i].y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_6_8.cpp b/orz_0_6_8.cpp deleted file mode 100644 index e7724ff..0000000 --- a/orz_0_6_8.cpp +++ /dev/null @@ -1,801 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define state_up 0 -#define state_down 1 -#define state_die -1 -#define mode_start 0 -#define mode_right 1 -#define mode_up 2 -#define mode_left 3 -#define mode_down 4 -#define mode_halt 5 -#define mode_idle 6 -#define mode_draw 7 -using namespace std; -int map[15][15]; -int minimap[4][15][15]; -int now[4],tot[4],area[4]; -int m,n,bind_total; -int x[4],y[4],state[4],trappedleft[4],scoredecline[4]; -int now_id; -int edge_color[15][15][15][15]; -int timeleft[200]; -int mode=mode_start; -unsigned int relative_distance[4][15][15][15][15]; -ofstream fout1(".\\output1.txt"); -ofstream fout2(".\\output2.txt"); -ofstream fout3(".\\output3.txt"); -ofstream fout4(".\\output4.txt"); -ofstream fout5(".\\output5.txt"); -ofstream fout6(".\\output6.txt"); -class dot -{ - public: - int x; - int y; -}; -class exdot -{ - public: - int x; - int y; - int meta[10]; -}; -class player -{ - public: - dot* position; - int ID; - int score; - int state; - int trappedleft; - int num; - dot* road[300]; - player(int ID,int x,int y) - { - position=new dot; - position->x=x; - position->y=y; - this->ID=ID; - score=4-ID; - state=state_up; - trappedleft=0; - num=0; - } - void insert(int x,int y) - { - num++; - road[num]=new dot; - road[num]->x=x; - road[num]->y=y; - } - void cut() - { - num--; - } - void clear() - { - num=0; - } - void change(int x,int y) - { - position->x=x; - position->y=y; - } - void down() - { - this->state=state_down; - } - void up() - { - this->state=state_up; - } - void die() - { - this->state=state_die; - } - void paint() - { - int i,j,k,s=1; - for(i=1;i<=num-1;i++) - if(road[i]->x==road[num]->x&&road[i]->y==road[num]->y) s=i; - fout5<<"---------ROAD----------"<x<<" "<y<x==road[k]->x&&road[k-1]->y==road[k]->y) continue; - if(road[k-1]->x==road[k]->x) - { - if(road[k-1]->yy) - { - if(j==road[k]->y&&i>road[k]->x) top=true; - if(j==road[k]->y&&i<=road[k]->x) bottom=true; - } - if(road[k-1]->y>road[k]->y) - { - if(j==road[k-1]->y&&i>road[k]->x) top=true; - if(j==road[k-1]->y&&i<=road[k]->x) bottom=true; - } - continue; - } - if(road[k-1]->y==road[k]->y) - { - if(road[k-1]->xx) - { - if(i==road[k]->x&&j>road[k]->y) left=true; - if(i==road[k]->x&&j<=road[k]->y) right=true; - } - if(road[k-1]->x>road[k]->x) - { - if(i==road[k-1]->x&&j>road[k]->y) left=true; - if(i==road[k-1]->x&&j<=road[k]->y) right=true; - } - } - } - if(top&&bottom&&left&&right) - { - if(-1==map[i][j]) - { - minimap[ID][i][j]=1; - } - } - } - num=0; - } -}; - -class enclosure -{ - public: - player* players[4]; - enclosure(int* x,int* y) - { - for(int i=0;i<4;i++) players[i]=new player(i,x[i],y[i]); - } - enclosure(){} - void pass(int ID,int x,int y,int state) - { - if(state_die==state) - { - players[ID]->die(); - players[ID]->insert(x,y); - players[ID]->paint(); - players[ID]->clear(); - } - if(state_up==state) - { - if(state_down==players[ID]->state) players[ID]->insert(x,y); - players[ID]->paint(); - players[ID]->up(); - players[ID]->clear(); - players[ID]->insert(x,y); - } - if(state_down==state) - { - players[ID]->down(); - players[ID]->insert(x,y); - } - players[ID]->change(x,y); - } - void make() - { - for(int i=0;i<=3;i++) - for(int j=1;j<=10;j++) - for(int k=1;k<=10;k++) - { - if(1==minimap[i][j][k]) tot[i]++; - } - - for(int j=1;j<=10;j++) - for(int k=1;k<=10;k++) - { - int mini=10000000; - int minID=-1; - for(int s=0;s<=3;s++) - if(tot[s]score+=area[i]*area[i]*10; - for(int i=0;i<=3;i++) if(0!=area[i]) now[i]++; - memset(minimap,0,sizeof(minimap)); - memset(area,0,sizeof(area)); - memset(tot,0,sizeof(tot)); - } -}; -dot* bind[200]; -dot* bestroad[300]; -enclosure* game; - -void generate_output(int diff_x,int diff_y,int other_action) -{ - cout<<"[ACTION] "; - if(diff_x==0&&diff_y==0) cout<<"s "; - else if(diff_x==0&&diff_y==1) cout<<"d "; - else if(diff_x==0&&diff_y==-1) cout<<"u "; - else if(diff_x==1&&diff_y==0) cout<<"r "; - else if(diff_x==-1&&diff_y==0) cout<<"l "; - cout<0) - { - if(j==0||j==10||map[i][j]!=map[i][j+1]||map[i][j]==-1||map[i][j+1]==-1) edge_color[i][j][i-1][j]=-1; - else edge_color[i][j][i-1][j]=map[i][j]; - } - if(i<10) - { - if(j==0||j==10||map[i+1][j]!=map[i+1][j+1]||map[i+1][j]==-1||map[i+1][j+1]==-1) edge_color[i][j][i+1][j]=-1; - else edge_color[i][j][i+1][j]=map[i+1][j+1]; - } - if(j>0) - { - if(i==0||i==10||map[i][j]!=map[i+1][j]||map[i][j]==-1||map[i+1][j]==-1) edge_color[i][j][i][j-1]=-1; - else edge_color[i][j][i][j-1]=map[i+1][j]; - } - if(j<10) - { - if(i==0||i==10||map[i][j+1]!=map[i+1][j+1]||map[i][j+1]==-1||map[i+1][j+1]==-1) edge_color[i][j][i][j+1]=-1; - else edge_color[i][j][i][j+1]=map[i][j+1]; - } - } - } -} -int update_distance(dot* start_point,int ID) -{ - //Todo: - //1. Get unpassable lines - //2. Do a bfs - //Note: - //1. An edge label 400 or 500 means specially defined unpassable lines - //2. This update process is only valid for a certain ID, i.e. the defined player - unsigned int tmp_distance[15][15]; - bool in_queue[15][15]; - memset(tmp_distance,0xff,sizeof(tmp_distance)); - memset(in_queue,0,sizeof(in_queue)); - queue* q=new queue; - q->push(start_point); - tmp_distance[start_point->x][start_point->y]=0; - while ((!q->empty())) - { - dot* tmp=q->front(); - q->pop(); - in_queue[tmp->x][tmp->y]=false; - if((tmp->x>0)&&(edge_color[tmp->x][tmp->y][tmp->x-1][tmp->y]==-1)&&(tmp_distance[tmp->x-1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x-1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x-1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x-1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x-1][tmp->y]=true; - } - } - if((tmp->x<10)&&(edge_color[tmp->x][tmp->y][tmp->x+1][tmp->y]==-1)&&(tmp_distance[tmp->x+1][tmp->y]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x+1][tmp->y]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x+1; - tmp2->y=tmp->y; - if(!in_queue[tmp->x+1][tmp->y]) - { - q->push(tmp2); - in_queue[tmp->x+1][tmp->y]=true; - } - } - if((tmp->y>0)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y-1]==-1)&&(tmp_distance[tmp->x][tmp->y-1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y-1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y-1; - if(!in_queue[tmp->x][tmp->y-1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y-1]=true; - } - } - if((tmp->y<10)&&(edge_color[tmp->x][tmp->y][tmp->x][tmp->y+1]==-1)&&(tmp_distance[tmp->x][tmp->y+1]>tmp_distance[tmp->x][tmp->y]+1)) - { - tmp_distance[tmp->x][tmp->y+1]=tmp_distance[tmp->x][tmp->y]+1; - dot* tmp2=new dot; - tmp2->x=tmp->x; - tmp2->y=tmp->y+1; - if(!in_queue[tmp->x][tmp->y+1]) - { - q->push(tmp2); - in_queue[tmp->x][tmp->y+1]=true; - } - } - } - for(int i=0;i<=10;i++) for(int j=0;j<=10;j++) relative_distance[ID][start_point->x][start_point->y][i][j]=tmp_distance[i][j]; - return -1; -} -int calculate_area(dot** x,int dot_num) -{ - int i,j,k,s=1; - int ans=0; - for(i=1;i<=dot_num-1;i++) - if(x[i]->x==x[dot_num]->x&&x[i]->y==x[dot_num]->y) s=i; - for(i=1;i<=10;i++) - for(j=1;j<=10;j++) - { - bool left=false; - bool right=false; - bool top=false; - bool bottom=false; - for(k=s+1;k<=dot_num;k++) - { - if(x[k-1]->x==x[k]->x&&x[k-1]->y==x[k]->y) continue; - if(x[k-1]->x==x[k]->x) - { - if(x[k-1]->yy) - { - if(j==x[k]->y&&i>x[k]->x) top=true; - if(j==x[k]->y&&i<=x[k]->x) bottom=true; - } - if(x[k-1]->y>x[k]->y) - { - if(j==x[k-1]->y&&i>x[k]->x) top=true; - if(j==x[k-1]->y&&i<=x[k]->x) bottom=true; - } - continue; - } - if(x[k-1]->y==x[k]->y) - { - if(x[k-1]->xx) - { - if(i==x[k]->x&&j>x[k]->y) left=true; - if(i==x[k]->x&&j<=x[k]->y) right=true; - } - if(x[k-1]->x>x[k]->x) - { - if(i==x[k-1]->x&&j>x[k]->y) left=true; - if(i==x[k-1]->x&&j<=x[k]->y) right=true; - } - } - } - if(left&&right&&top&&bottom&&-1==map[i][j]) ans++; - } - return ans; -} -inline int get_distance(int ID,dot* p1,dot* p2,double heuristic) -{ - int tmp_distance=relative_distance[ID][p1->x][p1->y][p2->x][p2->y]; - double h_distance=(double)tmp_distance*heuristic; - //if((*p1)==(*(game->players[ID]->position))&&(*p2)==(*(game->players[ID]->position))) return 0; - if(p1->x==game->players[ID]->position->x&&p1->y==game->players[ID]->position->y&&p2->x==game->players[ID]->position->x&&p2->y==game->players[ID]->position->y) return 0; - else return (floor(h_distance)+game->players[ID]->trappedleft); -} -int calculate_maximum_safe_enclosure(int ID,int road_id,double heuristic) -{ - if((int)(relative_distance[ID][game->players[ID]->position->x][game->players[ID]->position->y][game->players[ID]->road[road_id]->x][game->players[ID]->road[road_id]->y])==-1) return; - int tmp_num=0,max_length=INT_MAX; - dot* tmp_road[300]; - for(int i=0;i<300;i++) tmp_road[i]=new dot; - for(int i=road_id;iplayers[ID]->num;i++) tmp_road[++tmp_num]=game->players[ID]->road[i]; - fout6<<"-----AI LOG------"<players[ID]->position->x<<","<players[ID]->position->y<<")"<players[ID]->num;i++) - { - int tmp_min_length=INT_MAX; - for(int j=0;j<4;j++) - { - if(j==ID) continue; - int real_distance=get_distance(j,game->players[j]->position,game->players[ID]->road[i],heuristic); - if(real_distanceplayers[ID]->position->x][game->players[ID]->position->y][game->players[ID]->road[1]->x][game->players[ID]->road[1]->y];i<=max_length;i++) - { - fout6<<"TESTING LENGTH: "<players[ID]->road[road_id]; - for(int j=0;j<300;j++) s[j]=new exdot; - bool visited[15][15]; - memset(visited,0,sizeof(visited)); - int s_size=0; - exdot* tmp=new exdot; - tmp->x=game->players[ID]->position->x; - tmp->y=game->players[ID]->position->y; - tmp->meta[0]=0; - s[s_size++]=tmp; - visited[tmp->x][tmp->y]=true; - fout6<<"DFS INITIALIZED"<0) - { - exdot* tmp1=new exdot; - tmp1=s[s_size-1]; - if((s_size>i&&!(tmp1->x==target->x&&tmp1->y==target->y))||(s_size!=i+1&&tmp1->x==target->x&&tmp1->y==target->y)) - { - //fout6<<"STACK OVERFLOW AT POINT ("<x<<","<y<<")"<x][tmp1->y]=false; - continue; - } - //fout6<<"APPROACHED POINT ("<x<<","<y<<")"<x==target->x&&tmp1->y==target->y&&s_size==i+1) - { - fout6<<"TARGET APPROACHED"<x=s[j]->x; - tmp2->y=s[j]->y; - sp[tmp_num+j+1]=tmp2; - } - fout6<<"CALCULATING AREA..."<maximum_area) - { - fout6<<"REPLACING MAXIMUM EXPECTED AREA... "<x=s[j-1]->x; - bestroad[j]->y=s[j-1]->y; - } - } - s_size--; - visited[tmp1->x][tmp1->y]=false; - } - else if(tmp1->meta[0]==0) - { - tmp1->meta[0]++; - if(tmp1->y<10&&edge_color[tmp1->x][tmp1->y][tmp1->x][tmp1->y+1]==-1&&!visited[tmp1->x][tmp1->y+1]) - { - bool safe=true; - for(int j=0;j<4;j++) - { - if(j!=now_id) - { - dot* p=new dot; - p->x=tmp1->x; - p->y=tmp1->y+1; - int tmp_distance=get_distance(j,game->players[j]->position,p,heuristic); - if(tmp_distancex=tmp1->x; - tmp2->y=tmp1->y+1; - tmp2->meta[0]=0; - visited[tmp2->x][tmp2->y]=true; - s[s_size++]=tmp2; - } - } - } - else if(tmp1->meta[0]==1) - { - tmp1->meta[0]++; - if(tmp1->y>0&&edge_color[tmp1->x][tmp1->y][tmp1->x][tmp1->y-1]==-1&&!visited[tmp1->x][tmp1->y-1]) - { - bool safe=true; - for(int j=0;j<4;j++) - { - if(j!=now_id) - { - dot* p=new dot; - p->x=tmp1->x; - p->y=tmp1->y-1; - int tmp_distance=get_distance(j,game->players[j]->position,p,heuristic); - if(tmp_distancex=tmp1->x; - tmp2->y=tmp1->y-1; - tmp2->meta[0]=0; - visited[tmp2->x][tmp2->y]=true; - s[s_size++]=tmp2; - } - } - } - else if(tmp1->meta[0]==2) - { - tmp1->meta[0]++; - if(tmp1->x<10&&edge_color[tmp1->x][tmp1->y][tmp1->x+1][tmp1->y]==-1&&!visited[tmp1->x+1][tmp1->y]) - { - bool safe=true; - for(int j=0;j<4;j++) - { - if(j!=now_id) - { - dot* p=new dot; - p->x=tmp1->x+1; - p->y=tmp1->y; - int tmp_distance=get_distance(j,game->players[j]->position,p,heuristic); - if(tmp_distancex=tmp1->x+1; - tmp2->y=tmp1->y; - tmp2->meta[0]=0; - visited[tmp2->x][tmp2->y]=true; - s[s_size++]=tmp2; - } - } - } - else if(tmp1->meta[0]==3) - { - tmp1->meta[0]++; - if(tmp1->x>0&&edge_color[tmp1->x][tmp1->y][tmp1->x-1][tmp1->y]==-1&&!visited[tmp1->x-1][tmp1->y]) - { - bool safe=true; - for(int j=0;j<4;j++) - { - if(j!=now_id) - { - dot* p=new dot; - p->x=tmp1->x-1; - p->y=tmp1->y; - int tmp_distance=get_distance(j,game->players[j]->position,p,heuristic); - if(tmp_distancex=tmp1->x-1; - tmp2->y=tmp1->y; - tmp2->meta[0]=0; - visited[tmp2->x][tmp2->y]=true; - s[s_size++]=tmp2; - } - } - } - else if(tmp1->meta[0]==4) - { - visited[tmp1->x][tmp1->y]=false; - s_size--; - } - } - } - return maximum_area; -} -void isolate_bind() -{ - for(int j=1;j<=bind_total;j++) - { - if(bind[j]->x>0) edge_color[bind[j]->x-1][bind[j]->y][bind[j]->x][bind[j]->y]=edge_color[bind[j]->x][bind[j]->y][bind[j]->x-1][bind[j]->y]=500; - if(bind[j]->x<=10) edge_color[bind[j]->x+1][bind[j]->y][bind[j]->x][bind[j]->y]=edge_color[bind[j]->x][bind[j]->y][bind[j]->x+1][bind[j]->y]=500; - if(bind[j]->y>0) edge_color[bind[j]->x][bind[j]->y+1][bind[j]->x][bind[j]->y]=edge_color[bind[j]->x][bind[j]->y][bind[j]->x][bind[j]->y-1]=500; - if(bind[j]->y<=10) edge_color[bind[j]->x][bind[j]->y-1][bind[j]->x][bind[j]->y]=edge_color[bind[j]->x][bind[j]->y][bind[j]->x][bind[j]->y+1]=500; - } -} -void brain() -{ - dot* tmp_bestroad[300]; - for(int i=0;i<300;i++) tmp_bestroad[i]=new dot; - update_edge_status(); - int original_edge_color[15][15][15][15]; - memcpy(original_edge_color,edge_color,sizeof(original_edge_color)); - for(int i=0;i<4;i++) - { - memcpy(edge_color,original_edge_color,sizeof(edge_color)); - isolate_bind(); - if(game->players[i]->state==state_down) - { - for(int j=1;jplayers[i]->num;j++) - { - dot* p1=new dot; - dot* p2=new dot; - p1=game->players[i]->road[j]; - p2=game->players[i]->road[j+1]; - edge_color[p1->x][p1->y][p2->x][p2->y]=edge_color[p2->x][p2->y][p1->x][p1->y]=400; - } - } - else if(game->players[i]->state==state_up) - { - //Downward Road - for(int j=0;j<10;j++) for(int k=0;k<=10;k++) if((edge_color[j][k][j+1][k]/100)==i) edge_color[j][k][j+1][k]=-1; - //Upward Road - for(int j=1;j<=10;j++) for(int k=0;k<=10;k++) if((edge_color[j][k][j-1][k]/100)==i) edge_color[j][k][j-1][k]=-1; - //Rightward Road - for(int j=0;j<=10;j++) for(int k=0;k<10;k++) if((edge_color[j][k][j][k+1]/100)==i) edge_color[j][k][j][k+1]=-1; - //Leftward Road - for(int j=0;j<=10;j++) for(int k=1;k<=10;k++) if((edge_color[j][k][j][k-1]/100)==i) edge_color[j][k][j][k-1]=-1; - } - update_distance(game->players[i]->position,i); - } - memcpy(edge_color,original_edge_color,sizeof(edge_color)); - if(game->players[now_id]->state==state_down) - { - isolate_bind(); - for(int j=1;jplayers[now_id]->num;j++) - { - dot* p1=new dot; - dot* p2=new dot; - p1=game->players[now_id]->road[j]; - p2=game->players[now_id]->road[j+1]; - edge_color[p1->x][p1->y][p2->x][p2->y]=edge_color[p2->x][p2->y][p1->x][p1->y]=400; - } - for(int j=1;jplayers[now_id]->num;j++) calculate_maximum_safe_enclosure(now_id,j,1); - } - memcpy(edge_color,original_edge_color,sizeof(edge_color)); - int now_x[4],now_y[4]; - for(int i=0;i<4;i++) - { - now_x[i]=game->players[i]->position->x; - now_y[i]=game->players[i]->position->y; - } - //Finite State Machine - /* - if(mode==mode_start) - { - mode=mode_right; - } - else if(mode==mode_right) - { - if(now_x[now_id]==10&&now_y[now_id]==10) mode=mode_up; - } - else if(mode==mode_up) - { - if(now_x[now_id]==0&&now_y[now_id]==10) mode=mode_left; - } - else if(mode==mode_left) - { - if(now_x[now_id]==0&&now_y[now_id]==0) mode=mode_down; - } - else if(mode==mode_down) - { - if(now_x[now_id]==10&&now_y[now_id]==0) mode=mode_halt; - } - //Output Area - if(mode==mode_right&&now_y[now_id]==0) - { - generate_output(0,1,1); - } - else if(mode==mode_right) - { - generate_output(0,1,0); - } - else if(mode==mode_up) - { - generate_output(-1,0,0); - } - else if(mode==mode_left) - { - generate_output(0,-1,0); - } - else if(mode==mode_down) - { - generate_output(1,0,0); - } - else if(mode==mode_halt) - { - generate_output(0,0,0); - } - */ - //Debug Output - fout1<<"---MAP---"<>label; - cin>>now_id; - cout<<"[POS] 10 0"<>label; - for(int i=0;i<=3;i++) - { - cin>>x[i]>>y[i]>>state[i]>>trappedleft[i]>>scoredecline[i]; - } - if(!started) - { - started=true; - //game=new enclosure(x[0],y[0],x[1],y[1],x[2],y[2],x[3],y[3]); - game=new enclosure(x,y); - } - game->pass(0,x[0],y[0],state[0]); - game->pass(1,x[1],y[1],state[1]); - game->pass(2,x[2],y[2],state[2]); - game->pass(3,x[3],y[3],state[3]); - game->make(); - cin>>bind_total; - for(int i=1;i<=bind_total;i++) - { - cin>>bind[i]->x>>bind[i]->y>>timeleft[i]; - } - brain(); - } -} diff --git a/orz_0_6_8.exe b/orz_0_6_8.exe deleted file mode 100644 index 9d9073f..0000000 Binary files a/orz_0_6_8.exe and /dev/null differ