Skip to content

Commit

Permalink
[118] (fix on better-notation) correct move notation when playing as …
Browse files Browse the repository at this point in the history
…black
  • Loading branch information
TomPlanche committed Jan 26, 2025
1 parent 8f049ac commit 077e795
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/game_logic/game.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{bot::Bot, coord::Coord, game_board::GameBoard, opponent::Opponent, ui::UI};
use crate::{
pieces::{PieceColor, PieceMove, PieceType},
utils::get_int_from_char,
utils::{get_int_from_char, invert_position},
};

#[derive(Clone, Debug, PartialEq, Eq, Copy)]
Expand Down Expand Up @@ -382,12 +382,23 @@ impl Game {

self.game_board.board[from] = None;

// We store it in the history
// When recording the move, invert coordinates if playing as black
let (history_from, history_to) = if self.player_turn == PieceColor::Black
&& self.bot.is_none() // Don't invert for bot moves
&& (!self.opponent.as_ref().map_or(false, |opp| opp.color == PieceColor::Black))
// Don't invert for multiplayer
{
(invert_position(from), invert_position(to))
} else {
(*from, *to)
};

// Store the move in history with potentially inverted coordinates
self.game_board.move_history.push(PieceMove {
piece_type: piece_type_from,
piece_color: self.player_turn,
from: *from,
to: *to,
from: history_from,
to: history_to,
});
// We store the current position of the board
self.game_board.board_history.push(self.game_board.board);
Expand Down

0 comments on commit 077e795

Please sign in to comment.