Skip to content

martian58/ChessGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

ChessGame

1. Overview:

  • Code Name: ChessGame
  • Purpose: Implements a two-player command-line chess game in Python.

2. Class and Methods:

  • Class: ChessGame
  • Methods:
    • __init__(self): Initializes the chess game with an 8x8 chessboard and sets initial player and game state.
    • create_board(self): Creates the initial 8x8 chessboard with piece positions.
    • display_board(self): Displays the current state of the chessboard.
    • make_move(self, move): Processes a player's move and updates the board.
    • is_valid_move(self, start_col, start_row, end_col, end_row): Validates if a move adheres to chess rules.
    • Various methods for validating moves of different chess pieces.
    • no_obstacles(self, start_row, start_col, end_row, end_col): Checks if there are obstacles between two positions.
    • get_king_position(self, player): Retrieves the position of the king for the specified player.
    • is_check(self, player): Checks if the player's king is in check.
    • is_checkmate(self, player): Determines if the player is in checkmate.
    • play_game(self): Initiates the game loop, allowing players to make moves until checkmate.

3. Execution:

  • The game is initiated by creating an instance of ChessGame and calling the play_game method.
  • Players take turns entering moves in standard chess notation (e.g., 'e2 e4').
  • The game continues until one player achieves checkmate, and the winner is announced.

4. Check and Checkmate:

  • The code includes methods (is_check and is_checkmate) to determine if a player's king is in check or checkmate.

5. Conclusion:

  • The code successfully implements a basic two-player chess game with command-line interaction.
  • It provides a foundation for further improvements, such as code readability and additional features.

6. Recommendations for Improvement:

  • Add comments for better code readability.
  • Refactor to eliminate code duplication, particularly in the checkmate detection block.
  • Implement input validation to ensure moves are in the correct format.
  • Consider breaking down the code into smaller, more focused methods for improved modularity.

7. Usage:

  • Execute the code to start the chess game.
  • Follow the prompts to enter moves in standard chess notation.

Releases

No releases published

Packages

No packages published

Languages