def test_is_player1_to_move(self): controller = GameController() controller._to_move = controller._player1 self.assertTrue(controller.is_player1_to_move()) controller._to_move = controller._player2 self.assertFalse(controller.is_player1_to_move())
def _play_game(engine1_path, engine2_path, log_filename=''): engine1 = EngineWrapper(engine1_path) engine2 = EngineWrapper(engine2_path) controller = GameController( player1_name=engine1_path, player2_name=engine2_path, log_filename=log_filename, ) new_game_data = controller.start_new_game() engine1.init(new_game_data['trump']) engine2.init(new_game_data['trump']) engine1.deal( new_game_data['player1_cards'], controller.get_game_data_for(controller.PLAYER1) ) engine2.deal( new_game_data['player2_cards'], controller.get_game_data_for(controller.PLAYER2) ) while True: if controller.state == controller.States.MOVING: if controller.is_player1_to_move(): engine_to_move = engine1 else: engine_to_move = engine2 card = engine_to_move.move( controller.on_table, controller.get_game_data_for(controller.MOVER) ) controller.register_move(card) elif controller.state == controller.States.RESPONDING: if controller.is_player1_to_move(): engine_to_respond = engine2 else: engine_to_respond = engine1 card = engine_to_respond.respond( controller.on_table, controller.get_game_data_for(controller.RESPONDER) ) controller.register_response(card) elif controller.state == controller.States.GIVING_MORE: if controller.is_player1_to_move(): engine_to_give_more = engine1 else: engine_to_give_more = engine2 cards = engine_to_give_more.give_more( controller.on_table, controller.get_game_data_for(controller.MOVER) ) controller.register_give_more(cards) elif controller.state == controller.States.DEALING: deal_data = controller.deal() engine1.deal( deal_data['player1_cards'], controller.get_game_data_for(controller.PLAYER1) ) engine2.deal( deal_data['player2_cards'], controller.get_game_data_for(controller.PLAYER2) ) if controller.is_game_over(): break engine1.game_end() engine2.game_end() if controller.winner == controller.PLAYER1: return ENGINE1 elif controller.winner == controller.PLAYER2: return ENGINE2 else: return DRAW
def _play_game(engine1_path, engine2_path, log_filename=''): engine1 = EngineWrapper(engine1_path) engine2 = EngineWrapper(engine2_path) controller = GameController( player1_name=engine1_path, player2_name=engine2_path, log_filename=log_filename, ) new_game_data = controller.start_new_game() engine1.init(new_game_data['trump']) engine2.init(new_game_data['trump']) engine1.deal(new_game_data['player1_cards'], controller.get_game_data_for(controller.PLAYER1)) engine2.deal(new_game_data['player2_cards'], controller.get_game_data_for(controller.PLAYER2)) while True: if controller.state == controller.States.MOVING: if controller.is_player1_to_move(): engine_to_move = engine1 else: engine_to_move = engine2 card = engine_to_move.move( controller.on_table, controller.get_game_data_for(controller.MOVER)) controller.register_move(card) elif controller.state == controller.States.RESPONDING: if controller.is_player1_to_move(): engine_to_respond = engine2 else: engine_to_respond = engine1 card = engine_to_respond.respond( controller.on_table, controller.get_game_data_for(controller.RESPONDER)) controller.register_response(card) elif controller.state == controller.States.GIVING_MORE: if controller.is_player1_to_move(): engine_to_give_more = engine1 else: engine_to_give_more = engine2 cards = engine_to_give_more.give_more( controller.on_table, controller.get_game_data_for(controller.MOVER)) controller.register_give_more(cards) elif controller.state == controller.States.DEALING: deal_data = controller.deal() engine1.deal(deal_data['player1_cards'], controller.get_game_data_for(controller.PLAYER1)) engine2.deal(deal_data['player2_cards'], controller.get_game_data_for(controller.PLAYER2)) if controller.is_game_over(): break engine1.game_end() engine2.game_end() if controller.winner == controller.PLAYER1: return ENGINE1 elif controller.winner == controller.PLAYER2: return ENGINE2 else: return DRAW