def menu(): print("choose player 1:") print("Human, Easy Bot, Impossible Bot") p1_type = input("enter one of (human, easy, impossible): ").upper() while p1_type not in ["HUMAN", "EASY", "IMPOSSIBLE"]: p1_type = input("huh? make sure you enter one of these: (human, easy, impossible). try again: ").upper() print("choose player 2:") print("Human, Easy Bot, Impossible Bot") p2_type = input("enter one of (human, easy, impossible): ").upper() while p2_type not in ["HUMAN", "EASY", "IMPOSSIBLE"]: p2_type = input("huh? make sure you enter one of these: (human, easy, impossible). try again: ").upper() p1 = [Human("X"), RandomBot("X"), Bot("X")][["HUMAN", "EASY", "IMPOSSIBLE"].index(p1_type)] p2 = [Human("O"), RandomBot("O"), Bot("O")][["HUMAN", "EASY", "IMPOSSIBLE"].index(p2_type)] return [p1, p2]
def run(): bot1 = RandomBot() bot2 = RandomBot() bots = [bot1, bot2] pos = Position() send_settings(bot1, pos) send_settings(bot2, pos) time_limit = 10000 while not is_game_over(): bot1.parse_command("action move " + str(time_limit)) if (is_game_over(pos)): break bot2.parse_command("action move " + str(time_limit)) return get_winner(pos)
def main(): game = board.GameState.new_game() bots = {Player.x: RandomBot(), Player.o: RandomBot()} while not game.is_over(): time.sleep(0.3) print_board(game.board) bot_move = bots[game.next_player].select_move(game) game = game.apply_move(bot_move) if game.is_over(): print_board(game.board) winner = game.winner() winner_str = '' if winner is Player.x: winner_str = 'X' elif winner is Player.o: winner_str = 'O' else: winner_str = 'no one, it\'s a draw!' print('Winner is ' + winner_str)
def random_action(channel, action=None, **kwargs): """Determine which action to perform based on parameter. For roll die if a kwarg of sides is passed in and it's a valid integer roll a dSIDES die """ # Create a new CoinBot random_bot = RandomBot(channel) if action == "coin": message = random_bot.flip_coin() elif action == "die": sides = kwargs.get("sides", None) if sides is None or isinstance(sides, int) is False: message = random_bot.roll_die() else: print(f"We got here. Sides: {sides}") message = random_bot.roll_die(sides) elif action == "card": message = random_bot.random_card() # Post the onboarding message in Slack slack_web_client.chat_postMessage(**message)
logging.basicConfig(format='RANDOMBOT %(levelname)s: %(message)s', level=logging.DEBUG) root = logging.getLogger() errfilename = "test"+".err" errfilehandler = logging.FileHandler(errfilename, delay=True) errfilehandler.setLevel(logging.WARNING) formatter = logging.Formatter('RANDOMBOT %(levelname)s: %(message)s') errfilehandler.setFormatter(formatter) root.addHandler(errfilehandler) logfilename = "test"+".log" logfilehandler = logging.FileHandler(logfilename, delay=True) logfilehandler.setLevel(logging.DEBUG) formatter = logging.Formatter('RANDOMBOT %(levelname)s: %(message)s') logfilehandler.setFormatter(formatter) root.addHandler(logfilehandler) logging.info("starting logging") pos = Position() bot = RandomBot() while True: try: instr = raw_input() logging.info("instr {}".format(instr)) except Exception as e: logging.warn('error reading input {}'.format(e)) sys.stderr.write('error reading input') outstr = parse_command(instr, bot, pos) sys.stdout.write(outstr) sys.stdout.flush()
from slack import WebClient from randombot import RandomBot import os # Create a slack client slack_web_client = WebClient(token=os.environ.get("SLACKBOT_TOKEN")) # Get a new CoinBot coin_bot = RandomBot("#bot-testing") # Get the onboarding message payload message = coin_bot.roll_die() # Post the onboarding message in Slack slack_web_client.chat_postMessage(**message)