6 #include "controller.h"
13 #define theBoard Board::theBoard
16 bool CheckForQuitWhilstWaiting(int wait);
23 int main(int argc, char ** argv)
27 for (int y = 5; y < 9; ++y)
29 for (int x = 3; x < 5; ++x)
31 theBoard.AddPiece(x,y,Piece::BOULDER, Piece::NONE);
33 for (int x = 9; x < 11; ++x)
35 theBoard.AddPiece(x,y,Piece::BOULDER, Piece::NONE);
39 red = new Controller(Piece::RED, argv[1]);
40 blue = new Controller(Piece::BLUE, argv[2]);
43 Board::MovementResult redSetup = red->Setup(argv[2]);
44 Board::MovementResult blueSetup = blue->Setup(argv[1]);
45 if (redSetup != Board::OK)
47 fprintf(stderr, "Blue wins by DEFAULT!\n");
48 red->SendMessage("ILLEGAL");
49 blue->SendMessage("DEFAULT");
52 if (blueSetup != Board::OK)
54 fprintf(stderr, "Red wins by DEFAULT!\n");
55 red->SendMessage("DEFAULT");
56 blue->SendMessage("ILLEGAL");
60 Board::MovementResult result = Board::OK;
65 if (!Graphics::Initialised())
66 Graphics::Initialise("Stratego", theBoard.Width()*32, theBoard.Height()*32);
72 red->SendMessage("START");
73 Colour turn = Piece::RED;
74 while (Board::LegalResult(result))
77 fprintf(stderr, "This is move %d...\n", count);
78 fprintf(stderr,"---RED's turn---\n");
80 result = red->MakeMove(buffer);
81 red->SendMessage(buffer);
82 blue->SendMessage(buffer);
84 if (!Board::LegalResult(result))
87 Board::theBoard.Draw();
88 if (CheckForQuitWhilstWaiting(0.2))
90 red->SendMessage("QUIT");
91 blue->SendMessage("QUIT");
95 fprintf(stderr,"---BLUE's turn---\n");
97 result = blue->MakeMove(buffer);
98 blue->SendMessage(buffer);
99 red->SendMessage(buffer);
101 if (!Board::LegalResult(result))
107 Board::theBoard.Draw();
108 if (CheckForQuitWhilstWaiting(0.2))
110 red->SendMessage("QUIT");
111 blue->SendMessage("QUIT");
115 Board::theBoard.Print(stderr);
123 printf("Final board state\n");
125 Board::theBoard.Draw();
126 if (CheckForQuitWhilstWaiting(4))
128 red->SendMessage("QUIT");
129 blue->SendMessage("QUIT");
133 Board::theBoard.Print(stderr);
138 if (turn == Piece::RED)
140 fprintf(stderr,"Game ends on RED's turn - REASON: ");
142 else if (turn == Piece::BLUE)
144 fprintf(stderr,"Game ends on BLUE's turn - REASON: ");
148 fprintf(stderr,"Game ends on ERROR's turn - REASON: ");
153 case Board::NO_BOARD:
154 fprintf(stderr,"Board does not exit?!\n");
156 case Board::INVALID_POSITION:
157 fprintf(stderr,"Coords outside board\n");
159 case Board::NO_SELECTION:
160 fprintf(stderr,"Move does not select a piece\n");
162 case Board::NOT_YOUR_UNIT:
163 fprintf(stderr,"Selected piece belongs to other player\n");
165 case Board::IMMOBILE_UNIT:
166 fprintf(stderr,"Selected piece is not mobile (FLAG or BOMB)\n");
168 case Board::INVALID_DIRECTION:
169 fprintf(stderr,"Selected unit cannot move that way\n");
171 case Board::POSITION_FULL:
172 fprintf(stderr,"Attempted move into square occupied by allied piece\n");
175 fprintf(stderr,"Captured the flag\n");
177 case Board::BAD_RESPONSE:
178 fprintf(stderr,"Unintelligable response\n");
181 fprintf(stderr,"Did not make a move (may have exited)\n");
194 bool CheckForQuitWhilstWaiting(int wait)
198 TimerThread timer(wait*1000000); //Wait in seconds
200 while (!timer.Finished())
203 while (SDL_PollEvent(&event))