12 * A suitably terrible program which combines C style IO with C++ style IO
17 int main(int argc, char ** argv)
23 //Read in the colour, and choose a layout
25 int width = 14; int height = 14;
27 string colour; string opponent;
28 cin >> colour; cin >> opponent; cin >> width; cin >> height;
31 //fprintf(stderr, "Colour is \"%s\", width and height are (%d, %d), opponent is \"%s\"\n", colour.c_str(), width, height, opponent.c_str());
33 assert(width == 10 && height == 10); //Can't deal with other sized boards
36 fprintf(stdout, "FBnyBmSsBn\n");
37 fprintf(stdout, "BBCMccccnC\n");
38 fprintf(stdout, "LSGmnsnsSm\n");
39 fprintf(stdout, "sLSBLLssss\n");
41 else if (colour == "BLUE")
43 fprintf(stdout, "sLSBLLssss\n");
44 fprintf(stdout, "LSGmnsnsSm\n");
45 fprintf(stdout, "BBCMccccnC\n");
46 fprintf(stdout, "FBnyBmSsBn\n");
55 char board[width][height];
57 vector<pair<int, int> > choices;
59 int myPid = (int)(getpid());
63 //fprintf(stderr, "%s [%d] looping\n", argv[0], myPid);
66 //fprintf(stderr, "%s Waiting for status line...\n", colour.c_str());
67 char c = fgetc(stdin);
70 //fprintf(stderr,"%c",c);
73 //fprintf(stderr, "%s Got status, waiting for board line...\n", colour.c_str());
76 for (int y=0; y < height; ++y)
78 for (int x=0; x < width; ++x)
80 board[x][y] = fgetc(stdin);
81 if (board[x][y] == EOF)
84 if (board[x][y] != '.' && board[x][y] != '*' && board[x][y] != '#' && board[x][y] != '+')
86 choices.push_back(pair<int, int>(x, y));
89 assert(fgetc(stdin) == '\n');
94 int dir = 0; int startDir = 0; int choice = rand() % choices.size(); int startChoice = choice;
95 int x1 = 0; int y1 = 0;
100 pair<int,int> pear = choices[choice];
103 //fprintf(stderr,"Trying unit at %d %d...\n", x1, y1);
105 if (board[x1][y1] == 'B' || board[x1][y1] == 'F')
107 choice = (choice+1) % choices.size();
113 dir = rand() % 4; startDir = dir; int lastDir = dir;
118 //fprintf(stderr," Trying direction %d...\n", dir);
136 okay = !(x2 < 0 || y2 < 0 || x2 >= width || y2 >= height || (board[x2][y2] != '.' && board[x2][y2] != '*' && board[x2][y2] != '#'));
148 choice = (choice+1) % choices.size();
152 while (choice != startChoice);
171 printf("%d %d %s\n", x1, y1, direction.c_str());
172 //fprintf(stderr,"%s Made move, waiting for confirmation line\n", colour.c_str());
173 while (fgetc(stdin) != '\n'); //Read in result line
174 //fprintf(stderr, "%s Done turn\n", colour.c_str());
175 //fprintf(stderr,"%s - %d %d %s\n",colour.c_str(), x1, y1, direction.c_str() );
176 //fprintf(stderr, "%s [%d] computed move\n", argv[0], myPid);