Skip to content

Iteration 4

Andrew Ta edited this page Nov 17, 2019 · 28 revisions

Iteration 4 - State Machines

Pawn State Machine

State Machine Diagram

1. State Machine Specification:

  • Each pawn's behavior is captured in a seperate pawn state machine, namely whiteBehavior and blackBehavior defined inside QuoridorApplicaiton.java file. A pawn state machine has the following states:
  • Playing: to capture the pawn's behaviors when the game is running
    • NorthSouth: to capture the pawn's behaviors when it is moving in North or South direction. It has substates:
      • setup: the game is initialized
      • AtNorthEdge: the pawn is at North edge of the board
      • AtNorthBorder: the pawn is one row from North edge
      • AtSouthEdge: the pawn is at South edge
      • AtSouthBorder: the pawn is one row from South edge
      • MiddleNS: otherwise
    • EastWest: to capture the pawn's behaviors when it is moving in East or West direction. It has substates:
      • setup: the game is initialized
      • AtEastEdge: the pawn is at East edge of the board
      • AtEastBorder: the pawn is one row from East edge
      • AtWestEdge: the pawn is at West edge
      • AtWestBorder: the pawn is one row from West edge
      • MiddleEW: otherwise
  • Finished: the game is finished

##2. Action Method:

  • moveDown() Performs moving or jumping pawn in South direction
  • moveUp() Performs moving or jumping pawn pawn in North direction
  • moveRight() Performs moving or jumping pawn in East direction
  • moveLeft() Performs moving or jumping pawn in West direction
  • moveUpRight() Performs the diagonal jump of the pawn in North East direction
  • moveUpLeft() Performs the diagonal jump of the pawn in North East direction
  • moveDownRight() Performs the diagonal jump of the pawn in South East direction
  • moveDownLeft() Performs the diagonal jump of the pawn in South West direction

Implementation of the Player Movement Features

Implementation of both player movement features took place within the same controller method. This was possible since the state machine would handle the logic of whether or not the pawn should move or jump at a specific instance in the game.

Controller Method

movePawn(TOPlayer.side side) Performs the movement of the player's pawn during the respective player's turn. When the method is called, the feature will first check if there is a wall in hand. If so, the feature cannot be implemented since the keyboard movements will be allocated towards the wall. The following step is to verify with the transfer object which button was clicked by the user in the UI. According to the button clicked, the movement of the pawn will be mapped into the boardgame through the state machine. The last condition is to check whether the movement is legal within the current game state either due to blockages from walls or from edge cases of the board game.

Helper Method:

  1. isRunning() -check if the game is running

Feature 1: Move Pawn

Perform a player step that only moves the pawn a single tile adjacent from the player's current position. This can only be performed if there are no obstacles in the adjacent tile the player wishes to move toward.

Move Pawn Operation

Feature 2: Jump Pawn

Perform a player jump that allows the pawn to jump over tiles in specific conditions. The two conditions are the following: a pawn can jump over another pawn and a pawn can jump diagonally.

  1. A player can jump over another pawn orthogonally in a straight line towards a neighboring square in one move as long as no walls are crossed.

Jump Pawn Operation

  1. If there is a wall behind the opposing player's pawn, a jump is permitted to one of the free squares adjacent to the jumped pawn.

Jump Pawn Operation

Step Definitions (Gherkins Scenario Mappings)

Feature 1: Move Pawn
Fully implemented and fully pass all step definitions.
Feature 2: Jump Pawn
Fully implemented and fully pass all step definitions.

Transfer Objects

TOPlayer

  • enum Color {White,Black};
  • enum Side {Up,Down,Left,Right,UpRight,UpLeft,DownRight,DownLeft);
  • Integer row;
  • Integer col;
  • Color color;

Query Methods

  1. getPlayers() - Gets the list of player transfer objects.
Clone this wiki locally