Skip to content

tpun27/Refactored-Chess-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Chess Game (Refactored)

Overview

  • 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)

Contents

Commits / Tutorial Outline

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-?

Steps

Step 0

Piece Creation (Diff)

- Created initial Java Project using IntelliJ
- Created Chess Piece classes
- King, Queen, Rook, Bishop, Knight, Pawn extend abstract class Piece

Reset Instructions:

git checkout -f step-0

Keywords: class, abstract, extends

Step 1

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

Reset Instructions:

git checkout -f step-1

Keywords: enum, static, final, void, protected, attribute, method, getter, setter

Step 2

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

Reset Instructions:

git checkout -f step-2

Keywords: constructor, super

Step 3

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

Reset Instructions:

git checkout -f step-3

Step 4

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

Reset Instructions:

git checkout -f step-4

Step 5

Piece Movement & Example Game (Diff)

- Added method to Board to make Chess moves
- Updated PlayChess to show an example game

Reset Instructions:

git checkout -f step-5

Step 6

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()

Reset Instructions:

git checkout -f step-6

Step 7

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()

Reset Instructions:

git checkout -f step-7

Step 8

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

Reset Instructions:

git checkout -f step-8

Step 9

Checking For Valid Vertical/Horizontal Moves (Diff)

- Added isValidStraightPath() to check that two Coordinates form an unobstructed straight path

Reset Instructions:

git checkout -f step-9

Step 10

Checking For Valid King Moves (Diff)

- Made methods in MoveUtility static
- Implemented isValidKingMove()
- Modified PlayChess to demonstrate isValidPath()

Reset Instructions:

git checkout -f step-10

Step 11

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

Reset Instructions:

git checkout -f step-11

Step 12

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

Reset Instructions:

git checkout -f step-12

Step 13

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

Reset Instructions:

git checkout -f step-13

Step 14

Verifying That Moves Are Valid Based On Whether Or Not King Is In Check (Diff)

- Added methods isMovePossibleWithoutCheck() and isInCheck() to CheckUtility
- Implemented isMovePossibleWithoutCheck()

Reset Instructions:

git checkout -f step-14

Step 15

Determining Whether Or Not King Is In Check (Diff)

- Implemented isInCheck() and getKingCoordinate()

Reset Instructions:

git checkout -f step-15

Step 16

Determining Whether Or Not King Is In Checkmate (Diff)

- Implemented is isInCheckMate() which uses helper methods isKingMovable() and isCheckBlockable()
- Implemented isKingMovable()

Reset Instructions:

git checkout -f step-16

Step 17

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

Reset Instructions:

git checkout -f step-17

Step 18

Determining Whether Or Not A Stalemate Has Occured (Diff)

- Implemented isInStaleMate() which calls isMovable()

Reset Instructions:

git checkout -f step-18

Step 19

Determining Whether Or Not Any Pieces Are Moveable For Stalemate (Diff)

- Implemented isMovable() which calls calculateMoves()

Reset Instructions:

git checkout -f step-19

Step 20

Calculating Possible Moves (Diff)

- Implemented calculateMoves()

Reset Instructions:

git checkout -f step-20

Step 21

Adding Check, Checkmate, & Stalemate Verification To Movement Method (Diff)

- Added check/checkmate validation to Board.makeMove()

Reset Instructions:

git checkout -f step-21

Step 22

Castling (Diff)

- Overloaded Board.makeMove() to handle castling

Reset Instructions:

git checkout -f step-22

Step 23

Making The Game Playable (Diff)

- Created Game class to allow some to play the game!

Reset Instructions:

git checkout -f step-23

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages