Repository files navigation
Code Name: ChessGame
Purpose: Implements a two-player command-line chess game in Python.
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.
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.
The code includes methods (is_check and is_checkmate) to determine if a player's king is in check or checkmate.
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.
Execute the code to start the chess game.
Follow the prompts to enter moves in standard chess notation.
About
Chess Game with python.
Topics
Resources
Stars
Watchers
Forks
You can’t perform that action at this time.