src/main.c

changeset 163
2a6d83f4677e
parent 157
07cbfc477b22
equal deleted inserted replaced
162:f0fc70b6f8f9 163:2a6d83f4677e
353 addch(' '); 353 addch(' ');
354 } 354 }
355 } 355 }
356 } 356 }
357 357
358 static void eval_move_failed_msg(int code) { 358 static void eval_move_failed_msg(uint32_t code) {
359 switch (code) { 359 switch (code) {
360 case AMBIGUOUS_MOVE: 360 case AMBIGUOUS_MOVE:
361 printw("Ambiguous move - please specify the piece to move."); 361 printw("Ambiguous move - please specify the piece to move.");
362 break; 362 break;
363 case PIECE_NOT_FOUND: 363 case PIECE_NOT_FOUND:
379 printw("Move does not comply chess rules."); 379 printw("Move does not comply chess rules.");
380 break; 380 break;
381 case KING_MOVES_INTO_CHECK: 381 case KING_MOVES_INTO_CHECK:
382 printw("Can't move the king into a check position."); 382 printw("Can't move the king into a check position.");
383 break; 383 break;
384 case MISSING_CHECK:
385 printw("Move does not indicate check.");
386 break;
387 case MISSING_CHECKMATE:
388 printw("Move does not indicate checkmate.");
389 break;
390 case INVALID_CHECK:
391 printw("Move incorrectly indicates check.");
392 break;
393 case INVALID_CHECKMATE:
394 printw("Move incorrectly indicates checkmate.");
395 break;
384 default: 396 default:
385 printw("Unknown move parser error."); 397 printw("Unknown move parser error.");
386 } 398 }
387 } 399 }
388 400
459 save_pgn(gamestate); 471 save_pgn(gamestate);
460 } else if (movestr[0] == 0) { 472 } else if (movestr[0] == 0) {
461 /* ignore empty move strings and ask again */ 473 /* ignore empty move strings and ask again */
462 } else { 474 } else {
463 Move move; 475 Move move;
464 int result = eval_move(gamestate, movestr, &move, curcolor); 476 int result = eval_move_lazy(gamestate,
477 movestr, curcolor, &move);
465 if (result == VALID_MOVE_SYNTAX) { 478 if (result == VALID_MOVE_SYNTAX) {
466 result = validate_move(gamestate, &move); 479 result = validate_move(gamestate, &move);
467 if (result == VALID_MOVE_SEMANTICS) { 480 if (result == VALID_MOVE_SEMANTICS) {
468 apply_move(gamestate, &move); 481 apply_move(gamestate, &move);
469 if (gamestate->checkmate) { 482 if (gamestate->checkmate) {
594 } 607 }
595 } else if (movestr[0] == 0) { 608 } else if (movestr[0] == 0) {
596 /* ignore empty move strings and ask again */ 609 /* ignore empty move strings and ask again */
597 } else { 610 } else {
598 Move move; 611 Move move;
599 int eval_result = eval_move(gamestate, movestr, &move, mycolor); 612 int eval_result = eval_move_lazy(gamestate,
613 movestr, mycolor, &move);
600 switch (eval_result) { 614 switch (eval_result) {
601 case VALID_MOVE_SYNTAX: 615 case VALID_MOVE_SYNTAX:
602 net_send_data(opponent, NETCODE_MOVE, &move, sizeof(Move)); 616 net_send_data(opponent, NETCODE_MOVE, &move, sizeof(Move));
603 code = net_recieve_code(opponent); 617 code = net_recieve_code(opponent);
604 move.check = code == NETCODE_CHECK || 618 /* we could validate the move's check/checkmate flag with
605 code == NETCODE_CHECKMATE; 619 * the network response code, but we choose not to do it */
606 gamestate->checkmate = code == NETCODE_CHECKMATE; 620 gamestate->checkmate = code == NETCODE_CHECKMATE;
607 gamestate->stalemate = code == NETCODE_STALEMATE; 621 gamestate->stalemate = code == NETCODE_STALEMATE;
608 if (code == NETCODE_DECLINE) { 622 if (code == NETCODE_DECLINE) {
609 uint32_t reason; 623 uint32_t reason;
610 net_recieve_data(opponent, &reason, sizeof(uint32_t)); 624 net_recieve_data(opponent, &reason, sizeof(uint32_t));

mercurial