src/game.c

changeset 37
bcf624518909
parent 35
6c64b7a073af
child 42
21cb830efe91
equal deleted inserted replaced
36:ebe0c961e9a6 37:bcf624518909
170 default: 170 default:
171 printw("Can't interpret move - please use algebraic notation."); 171 printw("Can't interpret move - please use algebraic notation.");
172 } 172 }
173 } 173 }
174 174
175 #define MOVESTR_BUFLEN 8
175 static int domove_singlemachine(GameState *gamestate, GameInfo *gameinfo) { 176 static int domove_singlemachine(GameState *gamestate, GameInfo *gameinfo) {
176 177
177 const size_t buflen = 8; 178
178 size_t bufpos = 0; 179 size_t bufpos = 0;
179 char movestr[buflen]; 180 char movestr[MOVESTR_BUFLEN];
180 181
181 flushinp(); 182 flushinp();
182 while (1) { 183 while (1) {
183 if (timecontrol(gamestate, gameinfo)) { 184 if (timecontrol(gamestate, gameinfo)) {
184 return 1; 185 return 1;
189 "Use chess notation to enter your move.\n" 190 "Use chess notation to enter your move.\n"
190 "Or type 'surr' to surrender or 'remis' to end with remis.\n\n" 191 "Or type 'surr' to surrender or 'remis' to end with remis.\n\n"
191 "Type your move: "); 192 "Type your move: ");
192 clrtoeol(); 193 clrtoeol();
193 194
194 if (asyncgetnstr(movestr, &bufpos, buflen)) { 195 if (asyncgetnstr(movestr, &bufpos, MOVESTR_BUFLEN)) {
195 if (strncmp(movestr, "surr", buflen) == 0) { 196 if (strncmp(movestr, "surr", MOVESTR_BUFLEN) == 0) {
196 printw("%s surrendered!", 197 printw("%s surrendered!",
197 gamestate->mycolor==WHITE?"White":"Black"); 198 gamestate->mycolor==WHITE?"White":"Black");
198 clrtoeol(); 199 clrtoeol();
199 refresh(); 200 refresh();
200 return 1; 201 return 1;
201 } else if (strncmp(movestr, "remis", buflen) == 0) { 202 } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) {
202 printw("Game ends remis."); 203 printw("Game ends remis.");
203 clrtoeol(); 204 clrtoeol();
204 refresh(); 205 refresh();
205 return 1; 206 return 1;
206 } else { 207 } else {
234 } 235 }
235 } 236 }
236 237
237 static int sendmove(GameState *gamestate, GameInfo *gameinfo, int opponent) { 238 static int sendmove(GameState *gamestate, GameInfo *gameinfo, int opponent) {
238 239
239 const size_t buflen = 8;
240 size_t bufpos = 0; 240 size_t bufpos = 0;
241 char movestr[buflen]; 241 char movestr[MOVESTR_BUFLEN];
242 _Bool remisrejected = FALSE; 242 _Bool remisrejected = FALSE;
243 uint8_t code; 243 uint8_t code;
244 244
245 flushinp(); 245 flushinp();
246 while (1) { 246 while (1) {
261 "Or type 'surr' to surrender or 'remis' to offer remis.\n\n" 261 "Or type 'surr' to surrender or 'remis' to offer remis.\n\n"
262 "Type your move: "); 262 "Type your move: ");
263 } 263 }
264 clrtoeol(); 264 clrtoeol();
265 265
266 if (asyncgetnstr(movestr, &bufpos, buflen)) { 266 if (asyncgetnstr(movestr, &bufpos, MOVESTR_BUFLEN)) {
267 if (strncmp(movestr, "surr", buflen) == 0) { 267 if (strncmp(movestr, "surr", MOVESTR_BUFLEN) == 0) {
268 printw("You surrendered!"); 268 printw("You surrendered!");
269 clrtoeol(); 269 clrtoeol();
270 refresh(); 270 refresh();
271 net_send_code(opponent, NETCODE_SURRENDER); 271 net_send_code(opponent, NETCODE_SURRENDER);
272 return 1; 272 return 1;
273 } else if (strncmp(movestr, "remis", buflen) == 0) { 273 } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) {
274 if (!remisrejected) { 274 if (!remisrejected) {
275 net_send_code(opponent, NETCODE_REMIS); 275 net_send_code(opponent, NETCODE_REMIS);
276 printw("Remis offer sent - waiting for acceptance..."); 276 printw("Remis offer sent - waiting for acceptance...");
277 refresh(); 277 refresh();
278 if (net_recieve_code(opponent) == NETCODE_ACCEPT) { 278 if (net_recieve_code(opponent) == NETCODE_ACCEPT) {

mercurial