Struct Move
Struct that encapsulates a swap of adjacent cells.
A Move can be constructed from either a starting row, column, and direction,
or from a "move index" between 0 and NumPotentialMoves()-1.
Moves are enumerated as the internal edges of the game grid.
Left/right moves come first. There are (maxCols - 1) * maxRows of these.
Up/down moves are next. There are (maxRows - 1) * maxCols of these.
Syntax
Fields
Column
Column of the cell that will be moved.
Declaration
Field Value
Direction
Direction that the cell will be moved.
Declaration
public Direction Direction
Field Value
MoveIndex
Index of the move, from 0 to NumPotentialMoves-1.
Declaration
Field Value
Row
Row of the cell that will be moved.
Declaration
Field Value
Methods
FromMoveIndex(Int32, BoardSize)
Construct a Move from its move index and the board size.
This is useful for iterating through all the Moves on a board, or constructing
the Move corresponding to an Agent decision.
Declaration
public static Move FromMoveIndex(int moveIndex, BoardSize maxBoardSize)
Parameters
Type |
Name |
Description |
Int32 |
moveIndex |
Must be between 0 and NumPotentialMoves(maxRows, maxCols).
|
BoardSize |
maxBoardSize |
|
Returns
FromPositionAndDirection(Int32, Int32, Direction, BoardSize)
Construct a Move from the row, column, direction, and board size.
Declaration
public static Move FromPositionAndDirection(int row, int col, Direction dir, BoardSize maxBoardSize)
Parameters
Returns
InRangeForBoard(BoardSize)
Check if the move is valid for the given board size.
This will be passed the return value from AbstractBoard.GetCurrentBoardSize().
Declaration
public bool InRangeForBoard(BoardSize boardSize)
Parameters
Returns
Next(BoardSize)
Increment the Move to the next MoveIndex, and update the Row, Column, and Direction accordingly.
Declaration
public void Next(BoardSize maxBoardSize)
Parameters
NumPotentialMoves(BoardSize)
Return the number of potential moves for a board of the given size.
This is equivalent to the number of internal edges in the board.
Declaration
public static int NumPotentialMoves(BoardSize maxBoardSize)
Parameters
Returns
OtherCell()
Get the other row and column that correspond to this move.
Declaration
public (int Row, int Column) OtherCell()
Returns
OtherDirection()
Get the opposite direction of this move.
Declaration
public Direction OtherDirection()
Returns