Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/movement through history #76

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
670 changes: 627 additions & 43 deletions src/board.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
}
app.board.unselect_cell();
}
KeyCode::Char('N') => app.board.history_forward(),
KeyCode::Char('P') => app.board.history_backward(),
// Other handlers you could add here.
_ => {}
}
Expand Down
9 changes: 9 additions & 0 deletions src/pieces/king.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,20 +658,29 @@ mod tests {
from_x: 7,
to_y: 4,
to_x: 7,
is_en_passant: false,
piece_captured: None,
promotion_piece: None,
}),
(PieceMove {
piece_type: PieceType::Pawn,
from_y: 6,
from_x: 2,
to_y: 5,
to_x: 2,
is_en_passant: false,
piece_captured: None,
promotion_piece: None,
}),
(PieceMove {
piece_type: PieceType::Rook,
from_y: 4,
from_x: 7,
to_y: 0,
to_x: 7,
is_en_passant: false,
piece_captured: None,
promotion_piece: None,
}),
],
false,
Expand Down
3 changes: 3 additions & 0 deletions src/pieces/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ impl PieceType {
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct PieceMove {
pub piece_type: PieceType,
pub piece_captured: Option<PieceType>,
pub is_en_passant: bool,
pub promotion_piece: Option<PieceType>,
pub from_x: i8,
pub from_y: i8,
pub to_x: i8,
Expand Down
9 changes: 9 additions & 0 deletions src/pieces/pawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ mod tests {
from_x: 2,
to_y: 3,
to_x: 2,
is_en_passant: false,
piece_captured: None,
promotion_piece: None,
})],
false,
);
Expand Down Expand Up @@ -400,6 +403,9 @@ mod tests {
from_x: 3,
to_y: 4,
to_x: 3,
is_en_passant: false,
piece_captured: None,
promotion_piece: None,
})],
false,
);
Expand Down Expand Up @@ -453,6 +459,9 @@ mod tests {
from_x: 3,
to_y: 4,
to_x: 3,
is_en_passant: false,
piece_captured: None,
promotion_piece: None,
})],
false,
);
Expand Down
2 changes: 2 additions & 0 deletions src/popups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ pub fn render_help_popup(frame: &mut Frame) {
Line::from(""),
Line::from("`Esc`: Deselect a piece / hide popups"),
Line::from(""),
Line::from("`P` for previous position, `N` for next"),
Line::from(""),
Line::from("q: Quit the game"),
Line::from(""),
Line::from(""),
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ pub fn get_cell_paragraph(
bounding_rect: Rect,
) -> Paragraph<'_> {
// Get piece and color
let piece_color = get_piece_color(board.board, cell_coordinates);
let piece_type = get_piece_type(board.board, cell_coordinates);
let piece_color = get_piece_color(board.display_board, cell_coordinates);
let piece_type = get_piece_type(board.display_board, cell_coordinates);
let piece_enum = PieceType::piece_type_to_string_enum(piece_type, &board.display_mode);

let paragraph = match board.display_mode {
Expand Down