Sudoku
Bases: Environment[State, MultiDiscreteArray, Observation]
A JAX implementation of the sudoku game.
-
observation:
Observation
- board: jax array (int32) of shape (9,9): empty cells are represented by -1, and filled cells are represented by 0-8.
- action_mask: jax array (bool) of shape (9,9,9): indicates which actions are valid.
-
action: multi discrete array containing the square to write a digit, and the digits to input.
-
reward: jax array (float32): 1 at the end of the episode if the board is valid 0 otherwise
-
state:
State
-
board: jax array (int32) of shape (9,9): empty cells are represented by -1, and filled cells are represented by 0-8.
-
action_mask: jax array (bool) of shape (9,9,9): indicates which actions are valid (empty cells and valid digits).
-
key: jax array (int32) of shape (2,) used for seeding initial sudoku configuration.
-
1 2 3 4 5 6 7 8 |
|
Source code in jumanji/environments/logic/sudoku/env.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
action_spec: specs.MultiDiscreteArray
cached
property
#
Returns the action spec. An action is composed of 3 integers: the row index, the column index and the value to be placed in the cell.
Returns:
Name | Type | Description |
---|---|---|
action_spec |
MultiDiscreteArray
|
|
observation_spec: specs.Spec[Observation]
cached
property
#
Returns the observation spec containing the board and action_mask arrays.
Returns:
Type | Description |
---|---|
Spec[Observation]
|
Spec containing all the specifications for all the |
animate(states, interval=200, save_path=None)
#
Creates an animated gif of the board based on the sequence of states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states
|
Sequence[State]
|
a list of |
required |
interval
|
int
|
the delay between frames in milliseconds, default to 200. |
200
|
save_path
|
Optional[str]
|
the path where the animation file should be saved. If it is None, the plot will not be saved. |
None
|
Returns:
Type | Description |
---|---|
FuncAnimation
|
animation.FuncAnimation: the animation object that was created. |
Source code in jumanji/environments/logic/sudoku/env.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
render(state)
#
Renders the current state of the sudoku.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state
|
State
|
the current state to be rendered. |
required |
Source code in jumanji/environments/logic/sudoku/env.py
170 171 172 173 174 175 176 |
|