SE 2811 Lab 1: Checkers Pieces

In this lab, you will explore a maintenance task that does not take advantage of patterns. While we will study design patterns that are useful to this maintenance task later in this course, you should NOT apply design patterns while working this lab. The goals of this lab include refreshing skills with Java and JavaFX and to encounter coding challenges that are addressed by introducing design patterns.

This is an individual lab. Consult with your instructor, not other students while working on the lab. In addition, follow your instructor’s directions on the version of Java and JavaFX to be used in this lab.

If your instructor does not have alternative instructions, follow the directions at tayorial.com to create a new Java project. Follow the steps to add the JavaFX SDK library. Create a subdirectory checkers under src and download and unpack the files in checkers.zip to this folder. Build the project to see a six by six checkers board as shown in this image. This version of the game allows you to move pieces towards the other side of the board and to capture pieces by jumping them. It does not support multi-capture moves. It also does not support pieces being “kinged” - more on this below.

In checkers, pieces move diagonally, staying on the same color squares. Each move is to an empty square. When that square is adjacent, the piece moves just one square. If an adjacent square is occupied by an opponent’s piece and the square past that (in a straight line) is unoccupied, the piece can capture the opponent’s piece by jumping it. At the start of the game, all pieces are regular pieces, meaning they can only move towards the opponent’s side. For full rules of checkers and to get experience playing the game, you might check out cardgames.io/checkers/.

In this lab you will add support for kings. Once a piece reaches the opponent’s side of the board, the piece is “kinged” by placing a second checker on it. Kings can then move in any direction, though each move is still limited to be on the same color squares (so moving diagonally) to adjacent squares or jumping opponent pieces in adjacent squares.

Detailed steps

The following steps add king pieces to the game. All changes in this lab should be to the file Piece.java. If you feel you need to change other files, talk to your instructor to identify an alternative approach.

Note that only the black pieces will be shown as kings such as shown in this image. Further changes would be necessary for red pieces, but do not implement those in this lab.

  1. Identify the place in the code where the type of a piece is defined.
  2. Add a boolean at that place to track whether a piece is a “king”.
  3. Add an optional parameter to the Piece constructor that allows clients to create pieces as kings from the start. By default, pieces are not kings. Remember the DRY principle!
  4. Identify the place in the code where it determines that a black piece has reached the last row of the board.
  5. When a black piece reaches this position, update the piece’s state to indicate it now represents a king.
  6. Identify the place in the code which creates the ellipse and places it on the screen. (See also step 8.)
  7. Modify this code to draw two ellipses instead of one for kings. Place the second ellipse (known as the “crown”) ten pixels above the first ellipse. To implement this, note the createEllipse method can be called twice. Alternatively, you might find it useful to introduce a Pane object to treat the pair of ellipses as a single item. In any case, both elipses must be selectable and both must be highlighted when selected.
  8. Identify the code which places the ellipse at the correct location on the screen.
  9. Modify the code to place the “crown” piece in the correct place on the screen.
  10. Identify the place in the code where it determines if an ordinary move is valid.
  11. Update this code to work for black kings; that is, so that black kings can move diagonally towards either side.
  12. Identify the place in the code where it determines if a capture move is valid.
  13. Update this code to work for black kings. As for regular pieces, a king must jump a piece (on the diagonal) to capture it, but the jump can be towards either side of the board.
  14. Identify the place in the code where a piece is visually removed from the board.
  15. Update this code to work for black kings; both elipses need to be removed when a king is captured.

The intent is that you would leave the general structure of Piece.java in place. However, you can rename methods and variables, introduce new methods and variables, split long methods, and add comments that help you understand the code.

Submission instructions

Your instructor will state how to submit your solution on Canvas or elsewhere.