Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dickreuter committed Feb 25, 2024
1 parent 5461a50 commit faaa0f1
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion agents/agent_consider_equity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Random player"""

from gym_env.env import Action
from gym_env.enums import Action


class Player:
Expand Down
2 changes: 1 addition & 1 deletion agents/agent_keras_rl_dqn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion agents/agent_keypress.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""manual keypress agent"""

from gym_env.env import Action
from gym_env.enums import Action


class Player:
Expand Down
2 changes: 1 addition & 1 deletion agents/agent_random.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Random player"""
import random

from gym_env.env import Action
from gym_env.enums import Action


class Player:
Expand Down
28 changes: 28 additions & 0 deletions gym_env/enums.py
Original file line number Diff line number Diff line change
@@ -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
30 changes: 2 additions & 28 deletions gym_env/env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Groupier functions"""
import logging
from enum import Enum

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -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
Expand Down Expand Up @@ -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"""

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_gym_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit faaa0f1

Please sign in to comment.