as can be seen from my previous post, I have included the link to the source code that generates this error.
The error says that module not found 'callbot'. Yet it is in the source code at the bottom.
What is the search sequence when python program imports a module? Why can't it find a module that is in the source code?
I am including the relevant source code.
from pypokerengine.engine.hand_evaluator import HandEvaluator
from pypokerengine.players import BasePokerPlayer
from pypokerengine.utils.card_utils import (
_pick_unused_card,
_fill_community_card,
gen_cards,
)
# Estimate the ratio of winning games given the current state of the game
def estimate_win_rate(nb_simulation, nb_player, hole_card, community_card=None):
if not community_card:
community_card = []
# Make lists of Card objects out of the list of cards
community_card = gen_cards(community_card)
hole_card = gen_cards(hole_card)
win_count = sum(
[
montecarlo_simulation(nb_player, hole_card, community_card)
for _ in range(nb_simulation)
]
)
return 1.0 * win_count / nb_simulation
def montecarlo_simulation(nb_player, hole_card, community_card):
# Do a Monte Carlo simulation given the current state of the game by evaluating the hands
community_card = _fill_community_card(
community_card, used_card=hole_card + community_card
)
unused_cards = _pick_unused_card((nb_player - 1) * 2, hole_card + community_card)
opponents_hole = [unused_cards[2 * i : 2 * i + 2] for i in range(nb_player - 1)]
opponents_score = [
HandEvaluator.eval_hand(hole, community_card) for hole in opponents_hole
]
my_score = HandEvaluator.eval_hand(hole_card, community_card)
return 1 if my_score >= max(opponents_score) else 0
class DataBloggerBot(BasePokerPlayer):
def _init_self(self):
super()._init_()
self.wins = 0
self.losses = 0
# In[6]:
def declare_action(self, valid_actions, hole_card, round_state):
# Estimate the win rate
win_rate = estimate_win_rate(
100, self.num_players, hole_card, round_state["community_card"]
)
# Check whether it is possible to call
can_call = len([item for item in valid_actions if item["action"] == "call"]) > 0
if can_call:
# If so, compute the amount that needs to be called
call_amount = [item for item in valid_actions if item["action"] == "call"][0][
"amount"
]
else:
call_amount = 0
amount = None
# if win rate is large enough, then raise
if win_rate > 0.5:
raise_amount_options = [
item for item in valid_actions if item["action"] == "raise"
][0]["amount"]
if win_rate > 0.85:
# If it is extremely likely to win, then raise as much as possible
action = "raise"
amount = raise_amount_options["max"]
elif win_rate > 0.75:
# If it is likely to win, then raise by the minimum amount possible
action = "raise"
amount = raise_amount_options["min"]
else:
# If there is a chance to win, then call
action = "call"
else:
action = "call" if can_call and call_amount == 0 else "fold"
# Set the amount
if amount is None:
items = [item for item in valid_actions if item["action"] == action]
amount = items[0]["amount"]
return actions, amount
# In[ ]:
def receive_game_start_message(self, game_info):
self.num_players = game_info["player_num"]
def receive_round_start_message(self, round_count, hole_card, seats):
pass
def receive_street_start_message(self, street, round_state):
pass
def receive_game_update_message(self, action, round_state):
pass
def receive_round_result_message(self, winners, hand_info, round_state):
is_winner = self_uuid in [item["uuid"] for item in winners]
self.wins += int(is_winner)
self.losses += int(not is_winner)
def setup_ai():
return DataBloggerBot()
databloggerbot.py
from pypokerengine.players import BasePokerPlayer
import numpy as np
from sklearn.neural_networt import MLPRegressor
class CallBot(BasePokerPoker):
def declare_action(self, valid_actions, hole_card, roundstate):
actions = [item for item in valid_actions if ["action"] in ["call"]]
return list(np.random.choice(actions).values())
def receive_game_start_message(self, game_info):
pass
# In[ ]:
def receive_round_start_message(self, round_count, hole_card, seats):
pass
def receive_street_start_message(self, action, round_state):
pass
def receive_game_update_message(self, street, round_state):
pass
def receive_round_result_message(self, winners, hsnd_info, round_state):
def setup_ai():
return CallBot()
callbot.py
from pypokerengine.api.game import start_poker, setup_config
from callbot import CallBot
from databloggerbot import DataBloggerbot
import numpy as np
# In[ ]:
if__name__ == '__main__':
blogger_bot = DataBloggerBot()
# The stack log contains the stacks of the Data Blogger bot after each game (the initial stack is 100)
stack_log=[]
for round in range(1000):
p1, p2 = blogger_bot,CallBot()
config=setup_config(max_round=5, initial_stack=100, small_blind+amount=5)
config.register_player(name="p1", algorithm=p1)
config.register_player(name="p1", algorithm=p2)
game_result = start_poker(config, verbose=0)
stack_log.append([player['stack'] for player in game_result['players'] if player['uuid'] == blogger_bot.uuid])
print('Avg. stack:', '%d'%(int(np.mean(stack_log))))