@@ -922,7 +922,7 @@ void take_turn()
922922 move_t wmove = { -1 , -1 , MIN_VALUE };
923923 move_t bmove = { -1 , -1 , MAX_VALUE };
924924
925- // Reset the flags for this turn
925+ // Gather the move statistics for this turn
926926 game.stats .start_move_stats ();
927927 game.stats .move_stats .depth = 0 ;
928928
@@ -936,16 +936,55 @@ void take_turn()
936936 Bool const whites_turn = game.turn ; // same as (White == game.turn) ? True : False;
937937 move_t move = { -1 , -1 , whites_turn ? MIN_VALUE : MAX_VALUE };
938938
939- // See if we have an opening book move
940- check_book ();
939+ // Handle human player input if applicable
940+ Bool is_human_turn = (whites_turn && game.options .white_human ) || (!whites_turn && game.options .black_human );
941+ if (is_human_turn) {
942+ Bool valid_input = False;
943+ while (!valid_input) {
944+ // Prompt the user
945+ show_side (whites_turn ? White : Black);
946+ printf (Debug1, " 's turn. Enter move as 4 digits col1row1col2row2 (0-7, rows 7-0 bottom to top): " );
947+
948+ // Poll for input
949+ while (!check_serial ()) {
950+ delay (100 ); // Non-blocking wait to avoid CPU spin
951+ }
941952
942- if (game.options .shuffle_pieces ) {
943- game.sort_pieces (game.turn );
944- game.shuffle_pieces (SHUFFLE);
945- }
953+ // Proceed to generation to validate the supplied move
954+ // See if we have an opening book move (for AI fallback if needed, but skip for human)
955+ check_book (); // Optional, but keep if book can override invalid human moves; remove if pure human
946956
947- // Choose the best moves for both sides
948- choose_best_moves (wmove, bmove, consider_move);
957+ if (game.options .shuffle_pieces ) {
958+ game.sort_pieces (game.turn );
959+ game.shuffle_pieces (SHUFFLE);
960+ }
961+
962+ // Choose the best moves (this will validate supplied via consider_move)
963+ choose_best_moves (wmove, bmove, consider_move);
964+
965+ // Check if the supplied move was valid (matched a legal generated move)
966+ if (game.supply_valid ) {
967+ valid_input = True;
968+ } else {
969+ printf (Debug1, " Invalid move - try again.\n " );
970+ // Reset supplied flags for next attempt
971+ game.user_supplied = False;
972+ game.supplied = { -1 , -1 , 0L };
973+ }
974+ }
975+ } else {
976+ // Non-human (AI) path - original logic
977+ // See if we have an opening book move
978+ check_book ();
979+
980+ if (game.options .shuffle_pieces ) {
981+ game.sort_pieces (game.turn );
982+ game.shuffle_pieces (SHUFFLE);
983+ }
984+
985+ // Choose the best moves for both sides
986+ choose_best_moves (wmove, bmove, consider_move);
987+ }
949988
950989 // Gather the move statistics for this turn
951990 game.stats .stop_move_stats ();
@@ -1021,7 +1060,7 @@ void take_turn()
10211060 // Delete any soft-deleted pieces for real
10221061 if (piece_count != game.piece_count ) {
10231062 for (index_t i = 0 ; i < game.piece_count ; i++) {
1024- if (- 1 == game.pieces [i].x ) {
1063+ if (game.pieces [i].x == - 1 ) {
10251064 game.pieces [i] = game.pieces [--game.piece_count ];
10261065 break ;
10271066 }
0 commit comments