src/game.c

changeset 114
12df1b7c792f
parent 113
5f58df30d422
equal deleted inserted replaced
113:5f58df30d422 114:12df1b7c792f
272 272
273 size_t bufpos = 0; 273 size_t bufpos = 0;
274 char movestr[MOVESTR_BUFLEN]; 274 char movestr[MOVESTR_BUFLEN];
275 bool remis_rejected = false; 275 bool remis_rejected = false;
276 bool remis_suggested = false; 276 bool remis_suggested = false;
277 bool resign_suggested = false;
277 bool use_premove = false; 278 bool use_premove = false;
278 uint8_t code; 279 uint8_t code;
279 280
280 if (*gamestate->premove) { 281 if (*gamestate->premove) {
281 use_premove = true; 282 use_premove = true;
292 return 1; 293 return 1;
293 } 294 }
294 295
295 move(inputy, 0); 296 move(inputy, 0);
296 printw("Use chess notation to enter your move.\n"); 297 printw("Use chess notation to enter your move.\n");
297 if (remis_suggested) { 298 if (resign_suggested) {
298 printw("The opponent offers remis. Also type remis to accept.\n\n"); 299 if (remis_suggested) {
300 printw("The opponent asks you to resign or accept remis. \n\n");
301 } else {
302 printw("The opponent asks you to resign. \n\n");
303 }
304 } else if (remis_suggested) {
305 printw("The opponent offers remis. Type remis to accept. \n\n");
299 } else if (remis_rejected) { 306 } else if (remis_rejected) {
300 printw("Remis offer rejected. \n\n"); 307 printw("Remis offer rejected. \n\n");
301 } else { 308 } else {
302 printw("Or use a command: remis, resign, savepgn \n\n"); 309 printw("Or use a command: remis, resign, savepgn \n\n");
303 } 310 }
304 printw("Type your move: "); 311 printw("Type your move: ");
305 clrtoeol(); 312 clrtoeol();
306 313
307 /* check if the opponent sent us something */ 314 /* check if the opponent sent us something */
308 code = net_recieve_code_async(opponent); 315 code = net_recieve_code_async(opponent);
309 switch (code) { 316 switch (code) {
310 case NETCODE_REMIS: 317 case NETCODE_REMIS:
311 remis_suggested = true; 318 remis_suggested = true;
319 break;
320 case NETCODE_TAUNT:
321 resign_suggested = true;
312 break; 322 break;
313 case NETCODE_RESIGN: 323 case NETCODE_RESIGN:
314 gamestate->resign = 1; 324 gamestate->resign = 1;
315 printw("\rYour opponent resigned!"); 325 printw("\rYour opponent resigned!");
316 clrtoeol(); 326 clrtoeol();
422 int opponent, uint8_t mycolor) { 432 int opponent, uint8_t mycolor) {
423 memset(gamestate->premove, 0, sizeof(gamestate->premove)); 433 memset(gamestate->premove, 0, sizeof(gamestate->premove));
424 434
425 size_t bufpos = 0; 435 size_t bufpos = 0;
426 char movestr[MOVESTR_BUFLEN]; 436 char movestr[MOVESTR_BUFLEN];
427 bool remis_suggested = false; 437 bool remis_suggested = false, resign_suggested = false;
428 while (1) { 438 while (1) {
429 timecontrol(gamestate, gameinfo); 439 timecontrol(gamestate, gameinfo);
430 440
431 move(inputy, 0); 441 move(inputy, 0);
432 printw("Awaiting opponent move. Use chess notation to prepare a move.\n"); 442 printw("Waiting for opponent. Use chess notation to prepare a move.\n");
433 if (*gamestate->premove) { 443 if (*gamestate->premove) {
434 printw("Current pre-move: %s \n\n", 444 printw("Current pre-move: %s \n\n",
435 gamestate->premove); 445 gamestate->premove);
436 } else if (remis_suggested) { 446 } else if (remis_suggested && !resign_suggested) {
437 printw("Suggested remis. \n\n"); 447 printw("Suggested remis. \n\n");
438 } else { 448 } else if (resign_suggested) {
439 printw("Or use a command: remis, resign, savepgn\n\n"); 449 if (remis_suggested) {
450 printw("Suggested to resign or at least to accept remis. \n\n");
451 } else {
452 printw("Suggested to resign. \n\n");
453 }
454 } else {
455 printw("Or use a command: remis, resign, taunt, savepgn \n\n");
440 } 456 }
441 printw("Prepare your next move: "); 457 printw("Prepare your next move: ");
442 clrtoeol(); 458 clrtoeol();
443 refresh(); 459 refresh();
444 460
449 printw("You resigned!"); 465 printw("You resigned!");
450 clrtoeol(); 466 clrtoeol();
451 refresh(); 467 refresh();
452 net_send_code(opponent, NETCODE_RESIGN); 468 net_send_code(opponent, NETCODE_RESIGN);
453 return 1; 469 return 1;
470 } else if (strncmp(movestr, "taunt", MOVESTR_BUFLEN) == 0) {
471 resign_suggested = true;
472 net_send_code(opponent, NETCODE_TAUNT);
454 } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) { 473 } else if (strncmp(movestr, "remis", MOVESTR_BUFLEN) == 0) {
455 remis_suggested = true; 474 remis_suggested = true;
456 net_send_code(opponent, NETCODE_REMIS); 475 net_send_code(opponent, NETCODE_REMIS);
457 } else if (strncmp(movestr, "savepgn", MOVESTR_BUFLEN) == 0) { 476 } else if (strncmp(movestr, "savepgn", MOVESTR_BUFLEN) == 0) {
458 save_pgn(gamestate, gameinfo); 477 save_pgn(gamestate, gameinfo);

mercurial