A simple chess game implementation in Java with both Human vs Human and Human vs Computer game modes.
- Human vs Human gameplay
- Human vs Computer gameplay (computer plays as either White or Black)
- Standard chess rules implementation
- Check detection
- Pawn promotion
- Visual board representation
- Turn management
- Make sure you have Java installed on your system
- Compile all Java files:
javac *.java - Run the game:
java ChessGame
- Click on a piece to select it (it will be highlighted in green)
- Click on a valid destination square to move the piece
- The status bar shows whose turn it is and if a king is in check
- In Human vs Computer mode, the computer will automatically make its move
ChessGame.java- Main class that initializes the game window and handles game mode selectionBoard.java- Manages the chess board, piece movement, and game statePiece.java- Abstract base class for all chess piecesGameModeDialog.java- Dialog for selecting game mode (Human vs Human or Human vs Computer)
Pawn.java- Implements pawn movement rules including first move and captureRook.java- Implements rook movement (horizontal and vertical)Knight.java- Implements knight's L-shaped movementBishop.java- Implements bishop's diagonal movementQueen.java- Implements queen's combined rook and bishop movementKing.java- Implements king's movement and check detection
ComputerPlayer.java- Implements basic AI for computer player with random valid moves
The main entry point of the application. Creates the game window and initializes the game mode selection dialog.
Core game logic class that:
- Manages the 8x8 chess board
- Handles piece movement and validation
- Implements turn management
- Manages check detection
- Handles pawn promotion
- Controls the game's visual representation
Abstract base class that defines:
- Common properties for all pieces (color, position)
- Abstract methods for movement validation
- Helper methods for checking valid positions and piece interactions
Creates a dialog window that allows players to:
- Choose between Human vs Human and Human vs Computer modes
- Select the computer's color (White or Black)
Implements pawn-specific rules:
- Forward movement (one or two squares on first move)
- Diagonal capture
- Pawn promotion when reaching the opposite end
Implements rook movement:
- Horizontal and vertical movement
- No jumping over other pieces
Implements knight movement:
- L-shaped movement (2 squares in one direction, 1 square perpendicular)
- Can jump over other pieces
Implements bishop movement:
- Diagonal movement
- No jumping over other pieces
Implements queen movement:
- Combines rook and bishop movement
- Most powerful piece on the board
Implements king movement:
- One square in any direction
- Check detection
- Cannot move into check
Implements basic AI:
- Generates valid moves for computer's pieces
- Randomly selects from valid moves
- Ensures moves don't leave the king in check
- Add difficulty levels for computer player
- Implement checkmate detection
- Add move history
- Add save/load game functionality
- Improve computer player's strategy
- Add sound effects
- Add a restart button
- Implement castling and en passant moves