Skip to content

Deliverable 4 Report && State chart diagram

Tritin Truong edited this page Nov 18, 2019 · 11 revisions

All of the statecharts are available for download in the below link: https://drive.google.com/drive/folders/1zeoqgsVwb5Ytf3tNd1ZhH_UkFIKY9fTt?usp=sharing

Project Report

Using Yakindu, we created a state machine for pawn jump and move. A pawn is able to either jump in one direction by two, jump diagonally by one or move in one direction by one. Additionally, in the user interface of the game, due to the state machine, the player will only be allowed to move if and only if the move is legal. As a result, there will be no notifications for illegal move since it would be impossible to make illegal moves.

Our state machine includes two orthogonal states where one side describes the vertical movement, and the other describes the horizontal movement of the pawn. When the pawn is moving or jumping in one direction, the movement will only depend on one of the orthogonal states. However, when jumping diagonally, since the pawn will be moving horizontally and vertically, it will depend on both orthogonal states. As a result, in the guard condition, we must use active( state ) in order to prevent from the state in transitioning when the other associated orthogonal state is unable to transition. For instance, when your pawn is currently at the right edge of the board and you attempt to jump diagonally to the right. Although, the vertical orthogonal state can transition its state, the horizontal orthogonal state will not be able to transition. Therefore, the state of the pawn will not change.

Each orthogonal state includes 5 different states and a choice node. We would have an entry outside the orthogonal state that connects a synchronous node will be used to connect both choice nodes of the orthogonal states. Once inside the choice node, the choice node will have a transition that will connect each of these states. The guard condition for each transition depends on the position of the pawn.

In order to change state, the pawn will transition back to the choice node with an event that updates the pawn position. Before transitioning, each guard condition will check if the move ( isMoveValid() ) or jump ( isJumpValid() ) is valid as well as if the other associated orthogonal state is conflicted if the pawn is jumping orthogonally. If the guard condition is passed, then the pawn move or jump event ( pawn.movePawn("direction", distance) ) is executed and we would transition back to the choice node to be transferred to another state.

Extra methods

To help check the guard conditions, we implemented a few extra helper methods

isPawnBlocking(Tile tile)

This method simply checks if there a pawn at the target tile, useful to check if there is a pawn is blocking movement and for setting up jumps

isWallBlocking(Tile t1, Tile t2)

This method checks if there is a wall blocking the movement between 2 tiles.

isPathValidJump(Tile source, Tile destination, Tile enemy Tile)

This method checks if there is a valid jump starting from the source tile, jumping over the enemy tile and ending on the destination tile.

Explanation of Active Transitions

In the vertical orthogonal state, the five states are Top, Almost Top, Middle, Almost Bottom, Bottom.

The Top state is only reached when the row of the position is 1. Once the pawn is in this state, it can perform 4 different types of movements. It can either jump down, move down, jump down-left or jump down-right.

The Almost Top state is only reached when the row of the position is 2. Once the pawn is in this state, it can perform 7 different types of movements. It can either move up, jump up-left, jump up-right, jump down, move down, jump down-left or jump down-right.

The Middle state is only reached when the row of the position is between 3 and 7. Once the pawn is in this state, it can perform 8 different types of movements. It can either jump up, move up, jump up-left, jump up-right, jump down, move down, jump down-left or jump down-right.

The Almost Bottom state is only reached when the row of the position is 8. Once the pawn is in this state, it can perform 7 different types of movements. It can either jump up, move up, jump up-left, jump up-right, move down, jump down-left or jump down-right.

The Bottom state is only reached when the row of the position is 9. Once the pawn is in this state, it can perform 4 different types of movements. It can either jump up, move up, jump up-left, jump up-right.

In the horizontal orthogonal state, the five states are Left, Almost Left, Middle, Almost Right, Right.

The Left state is only reached when the column of the position is 1. Once the pawn is in this state, it can perform 8 different types of movements. It can either jump up-right, jump right, move right or jump down-right.

The Almost Left state is only reached when the column of the position is 2. Once the pawn is in this state, it can perform 7 different types of movements. It can either jump left, move left, jump up-left, jump up-right, jump right, move right, jump down-left or jump down-right.

The Middle state is only reached when the column of the position is between 3 and 7. Once the pawn is in this state, it can perform 8 different types of movements. It can either jump left, move left, jump up-left, jump up-right, jump right, move right, jump down-left or jump down-right.

The Almost Right state is only reached when the column of the position is 8. Once the pawn is in this state, it can perform 7 different types of movements. It can either jump left, move left, jump up-left, jump up-right, move right, jump down-left or jump down-right.

The Right state is only reached when the column of the position is 9. Once the pawn is in this state, it can perform 4 different types of movements. It can either jump left, move left, jump up-left or jump down-left.