# Used to test stuff

from Poker_Bot import Game_State
from deuces import Card
from deuces import Deck
import numpy as np

gs = Game_State()
deck = Deck()
gs.set_player_cards(deck.draw(2))
gs.set_opponent_cards(deck.draw(2))
gs.set_flop(deck.draw(3))
gs.append_action('B')
gs.append_action('B')

gs.print_player_cards()
gs.print_opponent_cards()
gs.print_player_hand()
gs.print_opponent_hand()
print(gs.is_winner())
print gs.get_current_state_id()

# Used to test Policy class

from Poker_Bot import Policy
p = Policy.create_uniform()
opt_state_action = (1, 2, 4, ('Ch', 'B'), 'B')
p.update(opt_state_action)

# Used to test State_Action_Value_Function class
示例#2
0
bot_name_2 = "bot_predet_2"

p1 = Policy(predetermined_policy())
print("New predetermined policy function created for " + bot_name_1)
p2 = Policy(predetermined_policy())
print("New predetermined policy function created for " + bot_name_2)
q1 = State_Action_Value_Function.create_uniform()
print("New zero SAVF created for " + bot_name_1)
q2 = State_Action_Value_Function.create_uniform()
print("New zero SAVF created for " + bot_name_2)

# Main training loop
# The program will conduct no_rounds training rounds, and then check if the file "quit" is present in
# the same folder as this script
# Note that bot 1 is treated as "player" and bot 2 is treated as the opponent
gs = Game_State()
learning_rate = 0.0001
#epsilon = 0.20

no_training_rounds = 100000
no_completed_epochs = 0
while True:
    for training_round in range(no_training_rounds):
        # Start new round and deal cards
        gs.clear_state()
        deck = Deck()
        gs.set_player_cards(deck.draw(2))
        gs.set_opponent_cards(deck.draw(2))
        gs.set_flop(deck.draw(3))
        pot = 0.0
        player_turn = training_round % 2  # Player 1 starts if 0, otherwise player 2 starts
# This script runs a game for the poker AI against a human player

from deuces import Card
from deuces import Deck
from deuces import Evaluator
from Poker_Bot import Game_State
from Poker_Bot import Policy
from Poker_Bot import State_Action_Value_Function
import os

human_capital = 0.0
ai_capital = 0.0
gs = Game_State()
round_count = 1
learning_rate = 0.05
epsilon = 0.05
is_button = 1  # If AI is button

policy_suffix = ".policy"
savf_suffix = ".savf"
obj_path = "obj/"

bot_name = "bot_1"  # Name of bot to play against. Will load existing bot or create new one.

# Load/create bot
if os.path.isfile(obj_path + bot_name +
                  policy_suffix) and os.path.isfile(obj_path + bot_name +
                                                    savf_suffix):
    print("Loading existing data for " + bot_name + "...")
    p = Policy.create_from_file(bot_name + policy_suffix)
    print("Loaded " + bot_name + " policy file")