Skip to content

Commit

Permalink
[120] (fix on better-notation) Better notation for black moves.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomPlanche committed Feb 2, 2025
1 parent 112a3c2 commit 4e27b6e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
52 changes: 29 additions & 23 deletions src/game_logic/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl UI {
}

/// Method to render the right panel history
pub fn history_render(&self, area: Rect, frame: &mut Frame, move_history: &[PieceMove]) {
pub fn history_render(&self, area: Rect, frame: &mut Frame, game: &Game) {
// We write the history board on the side
let history_block = Block::default()
.title("History")
Expand All @@ -182,43 +182,52 @@ impl UI {

let mut lines: Vec<Line> = vec![];

for i in (0..move_history.len()).step_by(2) {
let piece_type_from = move_history[i].piece_type;
for i in (0..game.game_board.move_history.len()).step_by(2) {
let piece_type_from = game.game_board.move_history[i].piece_type;

let utf_icon_white =
PieceType::piece_to_utf_enum(&piece_type_from, Some(PieceColor::White));
let utf_icon_white = PieceType::piece_to_utf_enum(&piece_type_from, Some(PieceColor::White));
let move_white = convert_position_into_notation(&format!(
"{}{}{}{}",
move_history[i].from.row,
move_history[i].from.col,
move_history[i].to.row,
move_history[i].to.col
game.game_board.move_history[i].from.row,
game.game_board.move_history[i].from.col,
game.game_board.move_history[i].to.row,
game.game_board.move_history[i].to.col
));

let mut utf_icon_black = " ";
let mut move_black: String = " ".to_string();

// If there is something for black
if i + 1 < move_history.len() {
let piece_type_to = move_history[i + 1].piece_type;
if i + 1 < game.game_board.move_history.len() {
let piece_type_to = game.game_board.move_history[i + 1].piece_type;
let black_move = &game.game_board.move_history[i + 1];

// Invert black moves if not playing against bot
let (from, to) = if game.bot.is_none() {
(
invert_position(&black_move.from),
invert_position(&black_move.to)
)
} else {
(black_move.from, black_move.to)
};

move_black = convert_position_into_notation(&format!(
"{}{}{}{}",
move_history[i + 1].from.row,
move_history[i + 1].from.col,
move_history[i + 1].to.row,
move_history[i + 1].to.col
from.row,
from.col,
to.row,
to.col
));
utf_icon_black =
PieceType::piece_to_utf_enum(&piece_type_to, Some(PieceColor::Black));
utf_icon_black = PieceType::piece_to_utf_enum(&piece_type_to, Some(PieceColor::Black));
}

lines.push(Line::from(vec![
Span::raw(format!("{}. ", i / 2 + 1)), // line number
Span::styled(format!("{utf_icon_white} "), Style::default().fg(WHITE)), // white symbol
Span::raw(move_white.to_string()), // white move
Span::raw(" "), // separator
Span::styled(format!("{utf_icon_black} "), Style::default().fg(WHITE)), // white symbol
Span::raw(" "), // separator
Span::styled(format!("{utf_icon_black} "), Style::default().fg(WHITE)), // black symbol
Span::raw(move_black.to_string()), // black move
]));
}
Expand All @@ -233,10 +242,7 @@ impl UI {
.split(area);

frame.render_widget(history_block.clone(), right_panel_layout[0]);
frame.render_widget(
history_paragraph,
history_block.inner(right_panel_layout[0]),
);
frame.render_widget(history_paragraph, history_block.inner(right_panel_layout[0]));
}

/// Method to render the white material
Expand Down
8 changes: 3 additions & 5 deletions src/ui/main_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,9 @@ pub fn render_game_ui(frame: &mut Frame<'_>, app: &mut App, main_area: Rect) {
);

// We make the inside of the board
app.game.ui.history_render(
board_block.inner(right_box_layout[1]),
frame,
&app.game.game_board.move_history,
);
app.game
.ui
.history_render(board_block.inner(right_box_layout[1]), frame, &app.game);

//bottom box for black matetrial
app.game.ui.white_material_render(
Expand Down

0 comments on commit 4e27b6e

Please sign in to comment.