0.0.1-alpha1
Actions to be dispatched.
Dispatch actionTypes.SCORES_UPDATED.
Type of actions to be dispatched.
Component that renders the value of a Cell.
Extends Component
Functional Component that renders a Game.
Functional Component that renders an overlay when a Game ends.
Functional Component that renders the score of a Player.
Functional Component that renders the Token in a Game.
Container to connect a CellComp.
Container to connect a GameComp.
Container to connect a GameEndComp.
Container to connect a ScoreComp.
(object)
Name | Description |
---|---|
props.playerName number
|
Flag to identify a Player . See flags.TURNS . |
Container to connect a WildCardComp.
Class to save and retrieve the state of the application in local storage. It is based on this code.
Class representing an agent. An agent is a Player that plays the game following a certain criteria. It is considered a type of AI.
Extends Player
Get the position of the highest value in a matrix. The position is either in the column or row of the Token, depending on the agent's direction.
In the following matrix, the token is located at position [3, 3]
| 2 3 4 7 8 |
| 1 -1 3 5 6 |
| 2 7 6 4 1 |
| 5 2 9 0 2 |
| 8 7 9 2 1 |
If the direction of the agent is HORIZONTAL, the algorithm determines the
highest value in the row where the Token is located. Only the values greater
than 0 are considered. The highest value is 9
; therefore, the output of the
will be the position of that value: [3, 2]
.
If the direction of the agent is VERTICAL, the algorithm determines the
highest value in the column where the Token is located. Only the values greater
than 0 are considered. The highest value is 7
; therefore, the output of the
will be the position of that value: [0, 3]
.
If all the values of the row or column are lower than 0, the output will be
[-1, -1]
.
array
:
Array with 2 numbers defining the row and column of the highest value.
Get the position of the value with the best gain in a matrix. The position is either in the column or row of the Token, depending on the agent's direction.
The algorithm relies on the utils.getBestGain function.
array
:
Array with 2 numbers defining the row and column of the value
with best gain.
Get the position of the value with the best average difference in a matrix. The position is either in the column or row of the Token. depending on the agent's direction.
In the following matrix, the token is located at position [3, 3]
| 1 2 3 4 5 6 7|
|-1 6 4 7 3 -1 5|
| 1 2 3 -1 5 6 7|
| 1 2 3 0 5 6 7|
|-1 -1 -1 8 -1 -1 -1|
| 4 -1 5 9 9 1 2|
|-1 1 2 3 -1 9 3|
If the direction of the agent is HORIZONTAL, the algorithm evaluates each
row, to find the average value. The evaluation is not performed in the row
of the token nor in rows which value in the same column of the Token
is less than 0
.
In the above matrix, the evaluation is not done in rows 2
and 3
.
That evaluation do not consider the values less than 0.
The average of a row is the sum of valid values divided by the number of
valid values. In the first row the average is (1 + 2 + 3 + 5 + 6 + 7) / 6
,
in the second row, the average is (6 + 4 + 3 + 5) / 4
. In the third
column the average is 0
since there are no valid values.
Once each row is evaluated, the average values are subtracted from the main value (the value in the same column of the token). For the above matrix, there are the following values:
row main average difference
0 4 4 0
1 7 4.5 2.5
2 -1 Not considered, invalid value
3 0 Not considered, token's position
4 8 0 8
5 9 4.2 4.8
6 3 3.75 -0.75
The row with the highest difference is selected. The output is the selected row,
and the column of the Token, in this example [4, 3]
.
The process is similar if the direction of the agent is VERTICAL.
array
:
Array with 2 numbers defining the row and column of
the best average value.
Class representing a board. A board has a matrix of Cells.
(number)
(array?)
2 dimensional array of numbers.
If this parameter is given,
boardSize
is ignored.
Update the value of the Cells based on the current
and old positions of the Token. The value of the Cell in
the current position of the Token is set to 0
.
The value of the Cell in the old position of the Token
is set to -1
.
If the current and old position of the Token is the same,
the value of the corresponding Cell is set to 0
.
(Token)
Class representing a cell. A cell is a positioned element in the Board that contains a value.
Flags used in the logic's game.
Define the status of the game.
RESTING: The token is static.
MOVING_TOKEN: The token is moving.
Identify active player.
PLAYER1: Human player.
PLAYER2: AI player.
Identify players' directions.
NONE: Set at the begining of every match.
VERTICAL
HORIZONTAL
Define continuity of game.
CONTINUE: The game can go on.
OVER: The game has finished. When the board has no more numbers, or the current player is not able to select a number.
Class representing a game. A game is made of a Board a Token and 2 Players, one of them is an Agent.
Move the Token to the given position. If the Players' directions have not been set yet, the function defines them.
In the following board, the token is located at position [3, 3]
| 2 3 4 7 8 |
| 1 -1 3 5 6 |
| 2 7 6 4 1 |
| 5 2 9 0 2 |
| 8 7 9 2 1 |
When the directions are not set yet, the Player that makes the first move can move the Token along its row or column.
If the move is along the row, the direction of the Player is set to HORIZONTAL; therefore, the direction of the other Player is set to VERTICAL.
If the move is along the column, the direction of the Player is set to VERTICAL; therefore, the direction of the other Player is set to HORIZONTAL.
Update the last value based on the Cell located in the token's position. The corresponding field in the game is updated.
Update the status of the game. For possible values see flags.GAME_STATUSES.
(number)
Use the Token to update the values of the Cells in the Board. See Board#update.
Update the score of the current Player.
Pass the token to the other Player.
Update the continuity of the game. For possible values see flags.GAME_CONTINUITY.
Get the current Player, the one that has to move the Token.
Get the next Player, the one that does not have to move the Token.
Serialize game. See Token#serialize Board#serialize Player#serialize
object
:
Serialized game.
Update game from literal. See Token#updateFromObject Board#updateFromVector Player#updateFromObject
(object)
Class representing a player. A player has a direction of playing and a score.
Class representing a token. A token is the element that moves in the Board to select a Cell.
Utility functions for the logic's game.
Rotate a square matrix clockwisely.
The following matrix:
| 1 2 3 |
| 4 5 6 |
| 7 8 9 |
It is converted to the next one:
| 7 4 1 |
| 8 5 2 |
| 9 6 3 |
(array)
2 dimensional array of number representing a square matrix.
array
:
2 dimensional array of number representing a rotated square matrix.
Rotate a square matrix counter-clockwisely.
The following matrix:
| 1 2 3 |
| 4 5 6 |
| 7 8 9 |
It is converted to the next one:
| 3 6 9 |
| 2 5 8 |
| 1 4 7 |
(array)
2 dimensional array of number representing a square matrix.
array
:
2 dimensional array of number representing a rotated square matrix.
Rotate row and column indices of an element in a square matrix clockwisely.
In the following 5x5 matrix, take the element located at position [3, 3]
| 2 3 4 7 8 |
| 1 -1 3 5 6 |
| 2 7 6 4 1 |
| 5 2 9 0 2 |
| 8 7 9 2 1 |
The matrix rotated clockwisely will be the next one:
| 8 5 2 1 2 |
| 7 2 7 -1 3 |
| 9 9 6 3 4 |
| 2 0 4 5 7 |
| 1 2 1 6 8 |
Then, the output will be [3, 1]
array
:
Array with two numbers defining the rotated row and column indices.
Rotate row and column indices of an element in a square matrix counter-clockwisely.
In the following 5x5 matrix, take the element located at position [3, 3]
| 2 3 4 7 8 |
| 1 -1 3 5 6 |
| 2 7 6 4 1 |
| 5 2 9 0 2 |
| 8 7 9 2 1 |
The matrix rotated clockwisely will be the next one:
| 8 6 1 2 1 |
| 7 5 4 0 2 |
| 4 3 6 9 9 |
| 3 -1 7 2 7 |
| 2 1 2 5 8 |
Then, the output will be [1, 3]
array
:
Array with two numbers defining the rotated row and column indices.
Get the horizontal gains of a matrix given a column. The gains are calculated by subtracting the values of each column in the matrix from the column which index is passed as argument.
In the following matrix, the token is located in the position [3, 3]
| 2 3 4 7 8 |
| 1 -1 3 5 6 |
| 2 7 6 4 1 |
| 5 2 9 0 2 |
| 8 7 9 2 1 |
The output will be the following matrix:
| 5 4 3 0 -1 |
| 4 0 2 0 -1 |
| 2 -3 -2 0 3 |
| 0 0 0 0 0 |
|-6 -5 -7 0 1 |
Notice how the elements in the row and column of the token are set to 0
.
Also, the positions where the value is less than 0
are set to 0
as well
e.g. position [1, 1]
.
(number)
Index of the column.
(array)
2 dimensional array of numbers representing a square matrix.
array
:
2 dimensional array of numbers representing the matrix of gains.
Get the indices of the element in the game matrix which gain is the highest. VERTICAL direction assumed.
Given the following game and gain matrices:
| 2 3 4 7 8 | | 5 4 3 0 -1 |
| 1 -1 3 5 5 | | 4 0 2 0 0 |
| 2 7 6 4 1 | | 2 -3 -2 0 3 |
| 5 2 9 0 2 | | 0 0 0 0 0 |
| 8 7 9 2 1 | |-6 -5 -7 0 1 |
Where the token is at position [3, 3]
. The objective is to
select the element in the same column of the token, which value
gives the overall best gain. For each row, the best gain is the
element with the lowest value, except the element in the same
column of the token:
row: 0, lowest value: -1, column: 4
row: 1, lowest value: 0, column: 4
row: 2, lowest value: -3, column: 1
row: 3, this is the column of the token, it is not considered.
row: 4, lowest value: -7, column: 2
Notice in row 2
, the lowest values are at columns 1
and 4
.
Generally, the lowest column is selected. But in this case,
the value at [1, 1]
in the game matrix is less than 0
. Thus,
that element is not considered.
The resulting lowest values are the following:
row 0: -1
row 1: 0
row 2: -3
row 3: Not considered, the token is here.
row 4: -7
The chosen value is the highest one: 0
. Therefore, the row of that
value is selected: row 1
.
In case, there are more than one highest value, the first one
is selected.
The output will be the selected row and the column of the token:
row 1
, column 3
.
(number)
(number)
(array)
2 dimensional array of numbers representing a square gains matrix.
(array)
2 dimensional array of numbers representing a square board matrix.
array
:
Array with two numbers defining the row and column of the element
with the best gain.
Update the state of the game based on the received actions