12 * A suitably terrible program which combines C style IO with C++ style IO
17 int main(int argc, char ** argv)
24 //Read in the colour, and choose a layout
26 int width = 14; int height = 14;
28 string colour; string opponent;
29 cin >> colour; cin >> opponent; cin >> width; cin >> height;
32 //fprintf(stderr, "Colour is \"%s\", width and height are (%d, %d), opponent is \"%s\"\n", colour.c_str(), width, height, opponent.c_str());
34 assert(width == 10 && height == 10); //Can't deal with other sized boards
37 fprintf(stdout, "FBnyBmSsBn\n");
38 fprintf(stdout, "BBCMccccnC\n");
39 fprintf(stdout, "LSGmnsnsSm\n");
40 fprintf(stdout, "sLSBLLssss\n");
42 else if (colour == "BLUE")
44 fprintf(stdout, "sLSBLLssss\n");
45 fprintf(stdout, "LSGmnsnsSm\n");
46 fprintf(stdout, "BBCMccccnC\n");
47 fprintf(stdout, "FBnyBmSsBn\n");
56 char board[width][height];
58 vector<pair<int, int> > choices;
60 int myPid = (int)(getpid());
64 //fprintf(stderr, "%s [%d] looping\n", argv[0], myPid);
67 //fprintf(stderr, "%s Waiting for status line...\n", colour.c_str());
68 char c = fgetc(stdin);
71 //fprintf(stderr,"%c",c);
74 //fprintf(stderr, "%s Got status, waiting for board line...\n", colour.c_str());
77 for (int y=0; y < height; ++y)
79 for (int x=0; x < width; ++x)
81 board[x][y] = fgetc(stdin);
82 if (board[x][y] == EOF)
85 if (board[x][y] != '.' && board[x][y] != '*' && board[x][y] != '#' && board[x][y] != '+')
87 choices.push_back(pair<int, int>(x, y));
90 assert(fgetc(stdin) == '\n');
95 int dir = 0; int startDir = 0; int choice = rand() % choices.size(); int startChoice = choice;
96 int x1 = 0; int y1 = 0;
101 pair<int,int> pear = choices[choice];
104 //fprintf(stderr,"Trying unit at %d %d...\n", x1, y1);
106 if (board[x1][y1] == 'B' || board[x1][y1] == 'F')
108 choice = (choice+1) % choices.size();
114 dir = rand() % 4; startDir = dir; int lastDir = dir;
119 //fprintf(stderr," Trying direction %d...\n", dir);
137 okay = !(x2 < 0 || y2 < 0 || x2 >= width || y2 >= height || (board[x2][y2] != '.' && board[x2][y2] != '*' && board[x2][y2] != '#'));
149 choice = (choice+1) % choices.size();
153 while (choice != startChoice);
172 printf("%d %d %s\n", x1, y1, direction.c_str());
173 //fprintf(stderr,"%s Made move, waiting for confirmation line\n", colour.c_str());
174 while (fgetc(stdin) != '\n'); //Read in result line
175 //fprintf(stderr, "%s Done turn\n", colour.c_str());
176 //fprintf(stderr,"%s - %d %d %s\n",colour.c_str(), x1, y1, direction.c_str() );
177 //fprintf(stderr, "%s [%d] computed move\n", argv[0], myPid);