Python Forum
Error in python code 'import callbot'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in python code 'import callbot'
#1
I am having trouble making the ode work at this site.

https://www.data-blogger.com/2017/11/01/...in-python/

Everything works until i get down to the line:


from callbot import CallBot


The interpreter says that it cannot find the module callbot. There is no module available called callbot.

Now when I try to install callbot like so

pip install callbot

conda install callbot

both fail. This is how I import all modules until this error occurred.


There is a callbot function in the python code itself towards the end. But this is actually in the python code so why do I need to import that?

I am somewhat green in importing callbot or module in general unless it can be installed as shown above.

So how do I modify the program to eliminate the error?

Any help appreciated. Thanks in advance.

Respectfully,

Lou Reed
Reply
#2
Read the directions more closely.
You need to create the module callbot.py, it tells you what to put into it.
Reply
#3
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))))
Reply
#4
Yea, I read it.
What you've posted here appears to be one long file. The directions indicate that you will be making multiple files. Do you have multiple files made from the directions, one of which is called callbot.py?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error on import: SyntaxError: source code string cannot contain null bytes kirkwilliams2049 7 6,179 Aug-03-2023, 06:00 PM
Last Post: Gribouillis
  Code error from Fundamentals of Python Programming van Richard L. Halterman Heidi 12 1,602 Jul-25-2023, 10:32 PM
Last Post: Skaperen
  Syntax error while executing the Python code in Linux DivAsh 8 1,454 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,492 Mar-27-2023, 07:38 AM
Last Post: buran
  import module error tantony 5 3,380 Dec-15-2022, 01:55 PM
Last Post: Lauraburmrs
  Error in if-then-else python code Led_Zeppelin 6 2,287 Jul-27-2022, 07:53 PM
Last Post: deanhystad
  Cryptic Error with import statement Led_Zeppelin 2 2,479 Jan-11-2022, 01:13 PM
Last Post: Led_Zeppelin
  Install any library via pip get an error cannot import name 'SCHEME_KEYS' from 'pip. Anldra12 2 10,495 Jan-04-2022, 01:05 PM
Last Post: Anldra12
  import module with syntax error Skaperen 7 5,165 Jun-22-2021, 10:38 AM
Last Post: Skaperen
  Import Error Christian 3 3,131 Apr-17-2021, 11:27 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020