From faaa0f1c4391b8bfb39f5abdc2558d9d97761418 Mon Sep 17 00:00:00 2001 From: Nicolas Dickreuter Date: Sun, 25 Feb 2024 01:55:29 +0000 Subject: [PATCH] minor refactor --- agents/agent_consider_equity.py | 2 +- agents/agent_keras_rl_dqn.py | 2 +- agents/agent_keypress.py | 2 +- agents/agent_random.py | 2 +- gym_env/enums.py | 28 ++++++++++++++++++++++++++++ gym_env/env.py | 30 ++---------------------------- tests/test_gym_env.py | 3 ++- 7 files changed, 36 insertions(+), 33 deletions(-) create mode 100644 gym_env/enums.py diff --git a/agents/agent_consider_equity.py b/agents/agent_consider_equity.py index 4c02a7a..3cfeda0 100644 --- a/agents/agent_consider_equity.py +++ b/agents/agent_consider_equity.py @@ -1,6 +1,6 @@ """Random player""" -from gym_env.env import Action +from gym_env.enums import Action class Player: diff --git a/agents/agent_keras_rl_dqn.py b/agents/agent_keras_rl_dqn.py index b868adf..dd9a4fd 100644 --- a/agents/agent_keras_rl_dqn.py +++ b/agents/agent_keras_rl_dqn.py @@ -5,7 +5,7 @@ import numpy as np -from gym_env.env import Action +from gym_env.enums import Action import tensorflow as tf import json diff --git a/agents/agent_keypress.py b/agents/agent_keypress.py index 06935bc..270f92b 100644 --- a/agents/agent_keypress.py +++ b/agents/agent_keypress.py @@ -1,6 +1,6 @@ """manual keypress agent""" -from gym_env.env import Action +from gym_env.enums import Action class Player: diff --git a/agents/agent_random.py b/agents/agent_random.py index c30b8c5..687e87e 100644 --- a/agents/agent_random.py +++ b/agents/agent_random.py @@ -1,7 +1,7 @@ """Random player""" import random -from gym_env.env import Action +from gym_env.enums import Action class Player: diff --git a/gym_env/enums.py b/gym_env/enums.py new file mode 100644 index 0000000..93e2bc4 --- /dev/null +++ b/gym_env/enums.py @@ -0,0 +1,28 @@ +"""Enums""" +from enum import Enum + + +class Action(Enum): + """Allowed actions""" + + FOLD = 0 + CHECK = 1 + CALL = 2 + RAISE_3BB = 3 + RAISE_HALF_POT = 3 + RAISE_POT = 4 + RAISE_2POT = 5 + ALL_IN = 6 + SMALL_BLIND = 7 + BIG_BLIND = 8 + + +class Stage(Enum): + """Allowed actions""" + + PREFLOP = 0 + FLOP = 1 + TURN = 2 + RIVER = 3 + END_HIDDEN = 4 + SHOWDOWN = 5 diff --git a/gym_env/env.py b/gym_env/env.py index f850ac8..5171ed7 100644 --- a/gym_env/env.py +++ b/gym_env/env.py @@ -1,6 +1,5 @@ """Groupier functions""" import logging -from enum import Enum import matplotlib.pyplot as plt import numpy as np @@ -9,6 +8,7 @@ from gym.spaces import Discrete from gym_env.cycle import PlayerCycle +from gym_env.enums import Action, Stage from gym_env.rendering import PygletWindow, WHITE, RED, GREEN, BLUE from tools.hand_evaluator import get_winner from tools.helper import flatten @@ -60,32 +60,6 @@ def __init__(self): self.stack = None -class Action(Enum): - """Allowed actions""" - - FOLD = 0 - CHECK = 1 - CALL = 2 - RAISE_3BB = 3 - RAISE_HALF_POT = 3 - RAISE_POT = 4 - RAISE_2POT = 5 - ALL_IN = 6 - SMALL_BLIND = 7 - BIG_BLIND = 8 - - -class Stage(Enum): - """Allowed actions""" - - PREFLOP = 0 - FLOP = 1 - TURN = 2 - RIVER = 3 - END_HIDDEN = 4 - SHOWDOWN = 5 - - class HoldemTable(Env): """Pokergame environment""" @@ -385,7 +359,7 @@ def _process_decision(self, action): # pylint: disable=too-many-statements else: raise RuntimeError("Illegal action.") - if contribution > self.min_call and not (action==Action.BIG_BLIND or action==Action.SMALL_BLIND): + if contribution > self.min_call and not (action == Action.BIG_BLIND or action == Action.SMALL_BLIND): self.player_cycle.mark_raiser() self.current_player.stack -= contribution diff --git a/tests/test_gym_env.py b/tests/test_gym_env.py index 149d212..8f47f09 100644 --- a/tests/test_gym_env.py +++ b/tests/test_gym_env.py @@ -2,7 +2,8 @@ import pytest from gym_env.cycle import PlayerCycle -from gym_env.env import HoldemTable, Action, Stage +from gym_env.env import HoldemTable +from gym_env.enums import Action, Stage def _create_env(n_players,