- A Bite-Sized Commit Tutorial Project
- This project converts this Java Chess repository into a tutorial with step-by-step commits.
Project SDK: Java 1.8 (1.8.0_144)
- Step 0 - Piece Creation
- Step 1 - Piece Symbols & Colors
- Step 2 - Piece Constructor Implementation & Coordinate Positions
- Step 3 - Chess Board Array & Coordinate Validation
- Step 4 - Initialize Board Pieces
- Step 5 - Piece Movement & Example Game
- Step 6 - Checking Valid Moves Based On Start & End Positions
- Step 7 - Checking For Valid Knight Moves
- Step 8 - Checking For Valid Diagonal Moves
- Step 9 - Checking For Valid Vertical/Horizontal Moves
- Step 10 - Checking For Valid King Moves
- Step 11 - Checking For Valid Pawn Moves (2-Space Forward Moves)
- Step 12 - Checking For Valid Pawn Moves (1-Space Forward & Diagonal Moves)
- Step 13 - Exception Handling For Invalid Moves
- Step 14 - Verifying That Moves Are Valid Based On Whether Or Not King Is In Check
- Step 15 - Determining Whether Or Not King Is In Check
- Step 16 - Determining Whether Or Not King Is In Checkmate
- Step 17 - Determining Whether Or Not Check Is Blockable
- Step 18 - Determining Whether Or Not A Stalemate Has Occured
- Step 19 - Determining Whether Or Not Any Pieces Are Moveable For Stalemate
- Step 20 - Calculating Possible Moves
- Step 21 - Adding Check, Checkmate, & Stalemate Verification To Movement Method
- Step 22 - Castling
- Step 23 - Making The Game Playable
You can check out any point of the tutorial using:
git checkout step-?
To see the changes made between any two lessons use the git diff
command:
git diff step-?..step-?
Piece Creation (Diff)
- Created initial Java Project using IntelliJ
- Created Chess Piece classes
- King, Queen, Rook, Bishop, Knight, Pawn extend abstract class Piece
git checkout -f step-0
Piece Symbols & Colors (Diff)
- Added Unicode constants into each Chess piece symbol
- Created Enum for piece color
- Created attributes for Piece color and symbol
- Added getters/setters for Piece color and symbol, including abstract setPieceSymbol() method
- Implemented setPieceSymbol() in each subclass
git checkout -f step-1
Piece Constructor Implementation & Coordinate Positions (Diff)
- Added Coordinate class for piece positioning
- Coordinate will allow you to interchange string (e.g. 'd4') and integer (e.g. (2, 5)) board positions
- Added Coordinate attribute to Piece class
- Modified piece constructors to use pieceColor and pieceStringPos
git checkout -f step-2
Chess Board Array & Coordinate Validation (Diff)
- Created Board class with boardArray attribute
- Created BoardUtility to provide static helper methods
- Modified Coordinate to dynamically calculate integer board positions (posX and posX) from chessStringPos
git checkout -f step-3
Initialize Board Pieces (Diff)
- Added methods to BoardUtility to populate Board's boardArray
- boardArray is a 2-D array that contains Piece objects
- The mappings from traditional board notation to the boardArray indices are:
- <img src="./images/traditional-board-notation.png" width="50%" height="50%">
- <img src="./images/board-array-mapping.png" width="50%" height="50%">
- Created PlayChess class to run the program and display the chess board on the console
git checkout -f step-4
Piece Movement & Example Game (Diff)
- Added method to Board to make Chess moves
- Updated PlayChess to show an example game
git checkout -f step-5
Checking Valid Moves Based On Start & End Positions (Diff)
- Created MoveUtility class to store methods that validate moves
- Implemented isValidEndpoints() to validate moves solely on piece color
- Started implementing isValidPath() to check for piece specific movement validation
- Modified PlayChess to demonstrate isValidEndpoints()
git checkout -f step-6
Checking For Valid Knight Moves (Diff)
- Added method isValidKnightMove() to MoveUtility to check for legal start and end Coordinates
- Added helper methods subtractXCoordinates() and subtractYCoordinates()
- Continued implementing isValidPath()
git checkout -f step-7
Checking For Valid Diagonal Moves (Diff)
- Added isValidDiagonalPath() to check that two Coordinates form an unobstructed diagonal path
- Added helper methods to the Coordinate class
git checkout -f step-8
Checking For Valid Vertical/Horizontal Moves (Diff)
- Added isValidStraightPath() to check that two Coordinates form an unobstructed straight path
git checkout -f step-9
Checking For Valid King Moves (Diff)
- Made methods in MoveUtility static
- Implemented isValidKingMove()
- Modified PlayChess to demonstrate isValidPath()
git checkout -f step-10
Checking For Valid Pawn Moves (2-Space Forward Moves) (Diff)
- Started implementing isValidPawnMove()
- In isValidPawnMove(), a check was added to validated 2-space forward moves
- Added hasMoved attribute to Piece class
git checkout -f step-11
Checking For Valid Pawn Moves (1-Space Forward & Diagonal Moves) (Diff)
- Continued implementing isValidPawnMove()
- In isValidPawnMove(), checks were added to validate diagonal moves and 1-space forward moves
git checkout -f step-12
Exception Handling For Invalid Moves (Diff)
- Created InvalidMoveException and InvalidBoardPositionException classes
- Created CheckUtility class
- Added move validation to Board.makeMove() method
- Implemented PlayChess.move() method to handle exceptions
git checkout -f step-13
Verifying That Moves Are Valid Based On Whether Or Not King Is In Check (Diff)
- Added methods isMovePossibleWithoutCheck() and isInCheck() to CheckUtility
- Implemented isMovePossibleWithoutCheck()
git checkout -f step-14
Determining Whether Or Not King Is In Check (Diff)
- Implemented isInCheck() and getKingCoordinate()
git checkout -f step-15
Determining Whether Or Not King Is In Checkmate (Diff)
- Implemented is isInCheckMate() which uses helper methods isKingMovable() and isCheckBlockable()
- Implemented isKingMovable()
git checkout -f step-16
Determining Whether Or Not Check Is Blockable (Diff)
- Implemented isCheckBlockable() which determines if a checkmate can be prevented by moving a piece other than the king
git checkout -f step-17
Determining Whether Or Not A Stalemate Has Occured (Diff)
- Implemented isInStaleMate() which calls isMovable()
git checkout -f step-18
Determining Whether Or Not Any Pieces Are Moveable For Stalemate (Diff)
- Implemented isMovable() which calls calculateMoves()
git checkout -f step-19
Calculating Possible Moves (Diff)
- Implemented calculateMoves()
git checkout -f step-20
Adding Check, Checkmate, & Stalemate Verification To Movement Method (Diff)
- Added check/checkmate validation to Board.makeMove()
git checkout -f step-21
Castling (Diff)
- Overloaded Board.makeMove() to handle castling
git checkout -f step-22
Making The Game Playable (Diff)
- Created Game class to allow some to play the game!
git checkout -f step-23