def main(): player_first = '' player_second = '' print("Меню".center(32, '*')) print("1. знакомится с правилами игры") print("2. Играть с другим человеком") print("3. Играть с роботом") print("4. посмотреть игру двух роботов") print("5. Для выхода из программы нажмите '-1' ") while True: choice_you = choice() if choice_you == 1: with open("tictactoe/rules_of_the_game", "r", encoding='utf-8') as file: rules_the_game = file.read() print(rules_the_game) return 0 elif choice_you == 2: player_first, player_second = main_human() elif choice_you == -1: return 0 elif choice_you == 3: player_first, player_second = main_robotic_human() elif choice_you == 4: player_first, player_second = main_robotic() game = Game(player_one=player_first, player_two=player_second) game.run()
def main_human(): game = Game(players=[ HumanPlayer(name="Fedor", symbol_class=X), HumanPlayer(name="Julia", symbol_class=O), ]) Game(players="Bentsi") game.run()
def test_run_3(self): input_stream = StringIO( 'John Doe\nMichael Doe\n2\n6\n2\n8\n5\n4\n7\n3\n1\n9\n') output_stream = StringIO() game = Game(input_stream=input_stream, output_stream=output_stream) output_stream.truncate(0) output_stream.seek(0) game.run() with open(join(dirname(__file__), 'sample2.txt')) as file: sample = file.read() self.assertEqual(output_stream.getvalue(), sample)
def test_run_2(self): input_stream = StringIO('John Doe\nMichael Doe\n2\n1') output_stream = StringIO() game = Game(n=1, input_stream=input_stream, output_stream=output_stream) output_stream.truncate(0) output_stream.seek(0) game.run() self.assertEqual( output_stream.getvalue(), ' 1 \n\n' + 'John Doe, choose a box to place an \'X\' into:\n>> \n' 'That is not a valid box.\n' 'John Doe, choose a box to place an \'X\' into:\n>> \n\n' ' X \n\n' + 'Congratulations John Doe! You have won.\n')
def main(): print("pycrosses, v1.0") try: while True: while True: try: human_players = int(input("How many human players? [2]> ")) human_players = human_players if human_players <= 2 else 2 break except ValueError: print("Not a number") player_names = [ input(f"Enter player {i + 1} name> ") for i in range(human_players) ] game = Game(players=[]) symbols = cycle([X, O]) for v in player_names: game.add_player(HumanPlayer(name=v, symbol_class=next(symbols))) for _ in range(2 - human_players): game.add_player( RoboticPlayer(symbol_class=next(symbols), gamestate=game)) game.run() answer = input("Play again? y/n> ") if (answer == 'y'): continue break except EOFError: exit(1) except KeyboardInterrupt: exit(1)
def main(): player_first = "" player_second = "" print("Menu".center(32, ' ')) print("1. Check rules of the game" + "\n" + "2. Human VS Human" + "\n" + "3. Human VS Robot" + "\n" + "4. Robot VS Robot" + "\n" + "5. To exist the game push the '5' ") while True: your_choice = choice() if your_choice == 1: with open("rules_of_the_game.txt", "r", encoding='utf-8') as f: rules_of_the_game = f.read() print(rules_of_the_game) return main() elif your_choice == 2: player_first, player_second = main_human() elif your_choice == 3: player_first, player_second = main_robot_human() elif your_choice == 4: player_first, player_second = main_robots() elif your_choice == 5: return 0 game = Game(player_one=player_first, player_two=player_second) game.run()
def main_robotic_human(): game = Game(players=[ HumanPlayer(name="Fedor", symbol_class=X), ]) game.add_player(RoboticPlayer(symbol_class=O, gamestate=game)) game.run()
def main_robotic(): game = Game(players=[]) game.add_player(RoboticPlayer(symbol_class=X, gamestate=game)) game.add_player(RoboticPlayer(symbol_class=O, gamestate=game)) game.run()