Skip to content

Keep track of move history and allow game navigation#25

Open
Bhoomish-Patel wants to merge 1 commit intoprrockzed:mainfrom
Bhoomish-Patel:move_history
Open

Keep track of move history and allow game navigation#25
Bhoomish-Patel wants to merge 1 commit intoprrockzed:mainfrom
Bhoomish-Patel:move_history

Conversation

@Bhoomish-Patel
Copy link
Contributor

🚀 Pull Request Overview

Description

Please provide a clear and concise description of the changes made in this pull request.

Summary:

To check the [ ] box, write 'x' between the square brackets (leave the box unchecked if it is not applicable to you)

  • Bug Fix 🐛
  • [x ] New Feature ✨
  • Custom 🔧

🐛 Bug Fix:

  • Issue Fixed: [Link to the issue being fixed]
  • Description of Fix: Provide a detailed explanation of how the bug was resolved.
  • Steps to Verify:
    1. Steps to reproduce the bug (as described in the issue).
    2. Actions to confirm the fix works as expected.

✨ New Feature:

  • Feature Added:Keep track of move history and allow game navigation Keep track of move history and allow game navigation #16
  • Reason for Feature: Currently, there is no way to track or review the history of moves made during the game. Keeping
    track of move history and allowing users to navigate between the moves provides a better player experience.
  • Implementation Details:

Move History and Game Navigation Feature

The feature to keep track of move history and allow game navigation was implemented in the Arbiter component of the chess application. Below are the key components and strategies used:


State Management

Board State
The current state of the chessboard is managed using the useState hook, which holds a Board object. This object is cloned from the initial board setup and updated with each move.

Board History
A separate state, boardHistory, is maintained to keep a record of all board states after each move. This allows for easy navigation between different game states.

Move History
Another state, moveHistory, is used to store the algebraic notation of moves for each team. This is updated every time a move is played, capturing the move details and any special notations like check or promotion.


Move Execution

The playMove function is responsible for executing a move.

  • It checks if the move is valid.
  • Updates the board state.
  • Appends the new board state to boardHistory.
  • Updates moveHistory with algebraic notation, including special cases like check or pawn promotion.

Game Navigation

Navigation Functions
Two functions are implemented to facilitate navigation through the game's history:

  • gotToMove: Navigates to a specific move in the game history.

User Interface

  • Navigation Buttons:

    • Previous Move: Goes to the previous move.
    • Next Move: Goes to the next move.
  • Move History Table:
    A table displays the move history for all teams, allowing players to review past moves. The teams are:

    • Red
    • Blue
    • Yellow
    • Green

Summary of Key Features

  • State management using useState for board, board history, and move history.
  • Move execution and game history updates.
  • Navigation functionality for reviewing past moves.
  • User-friendly UI with navigation buttons and a move history table.

Additional Context

Screenshot 2024-12-17 213106
Screenshot 2024-12-17 213030

Open Source Programs

KWoc


✅ Checklist:

  • [x ] My code adheres to the code style of this project.
  • [x ] I have run the appropriate tests for this change.
  • [x ] I have updated the documentation (if needed).
  • [x ] My PR references any relevant issues (if applicable).
  • [x ] Breaking changes?

@ThePhoenix08 ThePhoenix08 mentioned this pull request Dec 19, 2024
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant