kubn cfr:0
This commit is contained in:
61
src/game/kuhn_poker.py
Normal file
61
src/game/kuhn_poker.py
Normal file
@@ -0,0 +1,61 @@
|
||||
class KuhnPoker:
|
||||
def __init__(self):
|
||||
self.cards = ['J', 'Q', 'K']
|
||||
self.actions = [0, 1] # Check/Fold=0, Bet/Call=1
|
||||
|
||||
def is_terminal(self, history):
|
||||
return history in ['00', '10', '010', '011', '11']
|
||||
|
||||
def get_profit(self, cards, history, player):
|
||||
if not self.is_terminal(history):
|
||||
return 0.0
|
||||
|
||||
card_values = {'J': 0, 'Q': 1, 'K': 2}
|
||||
p0_cardv = card_values[cards[0]]
|
||||
p1_cardv = card_values[cards[1]]
|
||||
|
||||
p0_wins = p0_cardv > p1_cardv
|
||||
if history == '00':
|
||||
if p0_wins:
|
||||
return 1.0 if player == 0 else -1.0
|
||||
else:
|
||||
return -1.0 if player == 0 else 1.0
|
||||
|
||||
elif history == '10':
|
||||
return 1.0 if player == 0 else -1.0
|
||||
|
||||
elif history == '010':
|
||||
return -1.0 if player == 0 else 1.0
|
||||
|
||||
elif history == '011':
|
||||
if p0_wins:
|
||||
return 2.0 if player == 0 else -2.0
|
||||
else:
|
||||
return -2.0 if player == 0 else 2.0
|
||||
|
||||
elif history == '11':
|
||||
if p0_wins:
|
||||
return 2.0 if player == 0 else -2.0
|
||||
else:
|
||||
return -2.0 if player == 0 else 2.0
|
||||
|
||||
return 0.0
|
||||
|
||||
def get_Info_set(self, card, history, player):
|
||||
return f"{card}.{history}"
|
||||
|
||||
def get_cur_player(self, history):
|
||||
if self.is_terminal(history):
|
||||
return -1
|
||||
return len(history) % 2
|
||||
|
||||
def get_valid_act(self, history):
|
||||
if self.is_terminal(history):
|
||||
return []
|
||||
return [0, 1]
|
||||
|
||||
def get_act_name(self, history, action):
|
||||
if history == "01":
|
||||
return "Fold" if action == 0 else "Call"
|
||||
else:
|
||||
return "Check" if action == 0 else "Bet"
|
||||
Reference in New Issue
Block a user