-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
75 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import clubs | ||
|
||
|
||
class BaseAgent: | ||
def __init__(self): | ||
def __init__(self) -> None: | ||
pass | ||
|
||
def act(self, obs): | ||
def act(self, obs: clubs.poker.engine.ObservationDict) -> int: | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,80 @@ | ||
import random | ||
|
||
import clubs | ||
|
||
from . import base | ||
|
||
|
||
class NashKuhnAgent(base.BaseAgent): | ||
def __init__(self, alpha): | ||
def __init__(self, alpha: float) -> None: | ||
super().__init__() | ||
if alpha < 0 or alpha > 1 / 3: | ||
raise ValueError( | ||
f"invalid alpha value, expected 0 <= alpha <= 1/3, got {alpha}" | ||
) | ||
self.alpha = alpha | ||
|
||
def player_1_check(self, obs): | ||
if obs["hole_cards"][0].rank == "Q": | ||
def player_1_check(self, obs: clubs.poker.engine.ObservationDict) -> int: | ||
rank = obs["hole_cards"][0].rank | ||
if rank == "Q": | ||
if random.random() < self.alpha: | ||
return 1 | ||
return 0 | ||
if obs["hole_cards"][0].rank == "K": | ||
if rank == "K": | ||
return 0 | ||
if obs["hole_cards"][0].rank == "A": | ||
if rank == "A": | ||
if random.random() < 3 * self.alpha: | ||
return 1 | ||
return 0 | ||
raise ValueError("got invalid card rank, expected one of [Q, K, A] got {f.}") | ||
|
||
def player_1_bet(self, obs): | ||
if obs["hole_cards"][0].rank == "Q": | ||
def player_1_bet(self, obs: clubs.poker.engine.ObservationDict) -> int: | ||
rank = obs["hole_cards"][0].rank | ||
if rank == "Q": | ||
return 0 | ||
if obs["hole_cards"][0].rank == "K": | ||
if rank == "K": | ||
if random.random() < 1 / 3 + self.alpha: | ||
return 1 | ||
return 0 | ||
if obs["hole_cards"][0].rank == "A": | ||
if rank == "A": | ||
return 1 | ||
raise ValueError("got invalid card rank, expected one of [Q, K, A] got {f.}") | ||
|
||
def _player_1(self, obs): | ||
def _player_1(self, obs: clubs.poker.engine.ObservationDict) -> int: | ||
if obs["pot"] == 2: | ||
return self.player_1_check(obs) | ||
return self.player_1_bet(obs) | ||
|
||
def _player_2_check(self, obs): | ||
if obs["hole_cards"][0].rank == "Q": | ||
def _player_2_check(self, obs: clubs.poker.engine.ObservationDict) -> int: | ||
rank = obs["hole_cards"][0].rank | ||
if rank == "Q": | ||
if random.random() < 1 / 3: | ||
return 1 | ||
return 0 | ||
if obs["hole_cards"][0].rank == "K": | ||
if rank == "K": | ||
return 0 | ||
if obs["hole_cards"][0].rank == "A": | ||
if rank == "A": | ||
return 1 | ||
raise ValueError("got invalid card rank, expected one of [Q, K, A] got {f.}") | ||
|
||
def _player_2_bet(self, obs): | ||
if obs["hole_cards"][0].rank == "Q": | ||
def _player_2_bet(self, obs: clubs.poker.engine.ObservationDict) -> int: | ||
rank = obs["hole_cards"][0].rank | ||
if rank == "Q": | ||
return 0 | ||
if obs["hole_cards"][0].rank == "K": | ||
if rank == "K": | ||
if random.random() < 1 / 3: | ||
return 1 | ||
return 0 | ||
if obs["hole_cards"][0].rank == "A": | ||
if rank == "A": | ||
return 1 | ||
raise ValueError("got invalid card rank, expected one of [Q, K, A] got {f.}") | ||
|
||
def _player_2(self, obs): | ||
def _player_2(self, obs: clubs.poker.engine.ObservationDict) -> int: | ||
if obs["pot"] == 2: | ||
return self._player_2_check(obs) | ||
return self._player_2_bet(obs) | ||
|
||
def act(self, obs): | ||
def act(self, obs: clubs.poker.engine.ObservationDict) -> int: | ||
if obs["action"] == 0: | ||
return self._player_1(obs) | ||
return self._player_2(obs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters