-
Notifications
You must be signed in to change notification settings - Fork 0
Iteration 4
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 column from East edge
- AtWestEdge: the pawn is at West edge
- AtWestBorder: the pawn is one column from West edge
- MiddleEW: otherwise
-
NorthSouth: to capture the pawn's behaviors when it is moving in North or South direction. It has substates:
- Finished: the game is finished
2. Action Method (Events):
- startGame() Transits pawn from Setup state to either PlayingNorthSouth or PlayingEastWest state
- moveDown() Performs moving or jumping pawn in South direction
- moveUp() Performs moving or jumping 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 West 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
3. Guard Conditions:
- isLegalStep(MoveDirection dir): checks if it is legal for a pawn to step in direction dir
- isLegalJump(MoveDirection dir): checks if it is legal for a pawn to jump in direction dir
- isLegalDiagonalMove(MoveDirection dir): checks if it is legal for a pawn to jump diagonally in direction dir.
4. Extra Helper Methods:
- getCurrentPawnRow(): gets the row position of this pawn
- getCurrentPawnColumn(): gets the column position of this pawn
- getWallMap(): returns a hash map of every walls' positions on the board for quick position validation.
- isThereWallInDir(MoveDirection dir, int row, int col): checks if there is a wall in direction dir from the position specified by row and col parameters
- isTherePlayerInDir(MoveDirection dir, int row, int col): checks if there is a pawn in direction dir from the position specified by row and col parameters
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:
- 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.
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.
- 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.
- 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.
Feature 1: Move Pawn
Fully implemented and fully pass all step definitions.
Feature 2: Jump Pawn
Fully implemented and fully pass all step definitions.
TOPlayer
- enum Color {White,Black};
- enum Side {Up,Down,Left,Right,UpRight,UpLeft,DownRight,DownLeft);
- Integer row;
- Integer col;
- Color color;
- getPlayers() - Gets the list of player transfer objects.
Group 10 | ECSE 223 Model Based Programming