Linear Environment

from dgisim import LinearEnv

LinearEnv is a simple RL enviroment that can take an action and return the reward and the resulting game state.

An example of a simple set up is.

from dgisim import LinearEnv

env = LinearEnv()
rl_net = ...  # your RL network

for _ in range(100):
    env.reset()
    game_state, encoded_state, reward, turn, done = env.view()

    while not done:
        action = rl_net(encoded_state)  # this is just an example, your network
                                        # doesn't have to directly generate an action
        game_state, encoded_state, reward, turn, done = env.step(action)
class LinearEnv(mode: ~dgisim.mode.Mode = <dgisim.mode.DefaultMode object>, encoding_plan: ~dgisim.encoding.encoding_plan.EncodingPlan = <dgisim.encoding.encoding_plan.EncodingPlan object>, reward_method: ~typing.Callable[[~dgisim.state.game_state.GameState], int | float] = <function real_reward>, invalid_action_penalty: int | float = -0.1)
__init__(mode: ~dgisim.mode.Mode = <dgisim.mode.DefaultMode object>, encoding_plan: ~dgisim.encoding.encoding_plan.EncodingPlan = <dgisim.encoding.encoding_plan.EncodingPlan object>, reward_method: ~typing.Callable[[~dgisim.state.game_state.GameState], int | float] = <function real_reward>, invalid_action_penalty: int | float = -0.1)
Parameters:
  • mode – the mode of the game.

  • encoding_plan – the encoding plan of the game.

  • reward_method – the reward method of the game.

  • invalid_action_penalty – the penalty for invalid action.

full_view() GameState
Returns:

the game state without any perspective (all cards & dice visible).

reset() None

Repeats the last reset method.

reset_random() None

Resets the game state by with random decks under the mode.

reset_with_decks(deck1: Deck, deck2: Deck) None

Resets the game state with the given decks.

step(action: list[int] | PlayerAction) tuple[dgisim.state.game_state.GameState, list[int], int | float, int, bool]
Parameters:

action – the action to take. It can either be a list of int as the encoded action, or a PlayerAction object.

Returns:

game state, encoded state, reward, turn, done

The game state is in the perspective view of the current player.

The turn indicates the player that should take action next.

An invalid action will result-in the same state with a penalty.

view() tuple[dgisim.state.game_state.GameState, list[int], int | float, int, bool]
Returns:

game state, encoded state, reward, turn, done

The game state is in the perspective view of the current player.

The turn indicates the player that should take action next.