colosseumrl.envs.blokus.computation module

Author: Caleb Pitts Date: 3/15/19

Summary: - Contains computation methods that board.py uses to

manage valid move seeks and piece placement.

  • Methods use Numba with jit decorator that precompiles types and makes runtime faster than normal python.

colosseumrl.envs.blokus.computation.check_shifted[source]
Shifts entire piece N times were N is how many cells the piece takes up.

All shifted offsets are checked for the current orientation to see whether the shifted set of offsets is a valid move.

Parameters:

board_contents: 20 by 20 numpy matrix representing the current state of the board played_color: int representing current player color index: int tuple that specifies the index coordinate on the board (the coord the piece will rotate around) orientation: string specifying which orientation is being checked shifted_offsets: list of a list of tuples where each element in the main list represents a different set of coords

for a shifted piece.

Returns:

Returns the list of ints representing the shifted offsets ids where the piece can be placed at that set of shifted offsets

Type

Description

colosseumrl.envs.blokus.computation.flip_piece_x[source]

Takes the difference between index x and point x, then applies reverse difference to the index point. y stays the same

colosseumrl.envs.blokus.computation.flip_piece_y[source]

Takes the difference between index y and point y, then applies reverse difference to the index point. x stays the same

colosseumrl.envs.blokus.computation.get_all_shifted_offsets[source]
Compiles a list of all shifted offsets for a piece at a specific orientation.

Returns a numpy array, which is a list of a list of tuples which each contain a shifted offset.

Parameters:

offsets: numpy array of tuples containing the coords of offsets needing do be shifted orientation: string specifying the orientation that the shifts should take place

Returns:

list of all shifted orientations a piece can make at a given orientation

Type

Description

colosseumrl.envs.blokus.computation.is_valid_adjacents[source]

Invalid coord if left, right, bottom, or top cell is the same color as the current player. Parameters:

board_contents: 20 by 20 numpy matrix representing the current state of the board x: int x coord of the cell y: int y coord of the cell player_color: int representing current player color

Returns:

bool indicating whether the cell is a valid adjacent

Type

Description

colosseumrl.envs.blokus.computation.is_valid_cell[source]
If the cell x, y is empty, has no adjacent cells that are the same color,

and is not out of bounds of the 20x20 board, then the cell is valid to put a part of a piece on it.

Parameters:

board_contents: 20 by 20 numpy matrix representing the current state of the board x: int x coord of the cell y: int y coord of the cell player_color: int representing current player color

Returns:

bool indicating whether the cell is a valid cell

Type

Description

colosseumrl.envs.blokus.computation.rotate_by_deg[source]

Rotates each point on piece around the index by the given angle

colosseumrl.envs.blokus.computation.rotate_default_piece[source]

Rotates the initial default piece orientation for shifting. Parameters:

offsets: numpy array of tuples indicated all corresponding offsets to a specific piece type orientation: string indicating the orientation to rotate the offset pieces

Returns:

numpy list of all offsets for given orientation

Type

Description

colosseumrl.envs.blokus.computation.rotate_piece[source]

Orients piece around the index point Parameters:

index: int tuple that specifies the index coordinate on the board (the coord the piece will rotate around) offset: int tuple that specifies the offset from the index coord for the current cell piece_orientation: string specifying what new orientation you want the point at

Returns:

2 ints x and y that are the new rotated piece coords

Type

Description

colosseumrl.envs.blokus.computation.shift_offsets[source]

Shifts the offsets so that the offset that corresponds to the offset_id is the new index Parameters:

offsets: numpy array of tuples containing the coords of offsets needing do be shifted offset_id: identifies which coord becomes the new index in the list of offsets

Returns:

numpy array of tuples containing the newly shifted offsets

Type

Description