コード例 #1
0
 def test_raises_eq(self):
     r1 = GameAction(GameAction.RAISE, 10)
     r2 = GameAction(GameAction.RAISE, 30)
     self.assertNotEqual(r1, r2)
     self.assertTrue(r1.is_raise())
     self.assertEquals("Raise", r1.name())
     self.assertEquals("<GameAction type=R, amount=10>", repr(r1))
コード例 #2
0
 def test_write(self):
     self.log.action("bot_1", GameAction(GameAction.FOLD))
     output = tempfile.SpooledTemporaryFile()
     self.log.to_file(output)
     output.seek(0)
     written = output.read()
     self.assertEqual(written, '{"initial_stacks": {}, "actions": [{"player": "bot_1", "data": 0, "event": "Fold", "ts": 10}]}')
コード例 #3
0
 def test_bet(self):
     self.log.action("bot_1", GameAction(GameAction.RAISE, 10))
     the_raise = {
         "player": "bot_1", "ts": 10, "event": "Raise",
         "data": 10
     }
     self.assertEqual([the_raise], self.log.actions)
コード例 #4
0
    def test_actions_eq(self):
        call = GameAction(GameAction.CALL)
        self.assertTrue(call.is_call())
        self.assertEqual("Call", call.name())

        check = GameAction(GameAction.CHECK)
        self.assertTrue(check.is_check())
        self.assertEquals("<GameAction type=C, amount=0>", repr(check))
        self.assertNotEqual(call, check)
コード例 #5
0
    def test_hand_log_writing(self):
        arena = LocalIOArena()
        arena.key = "fake-uuid-woo-boom"
        temp = tempfile.mkdtemp()
        arena.output_directory = temp
        arena.current_round = 0

        log = HandLog({})
        log.unix_epoch_s = lambda: 10
        log.action("bot_1", GameAction(GameAction.FOLD))
        arena.write_hand_log(log)

        written_file = os.path.join(temp, arena.key, "hand_0.json")
        written_handle = open(written_file, 'r')
        contents = written_handle.read()
        self.assertEquals(
            contents,
            '{"initial_stacks": {}, "actions": [{"player": "bot_1", "data": 0, "event": "Fold", "ts": 10}]}'
        )

        shutil.rmtree(temp)
コード例 #6
0
ファイル: poker.py プロジェクト: noke8868/poker
    def __do_action(self, action):
        current_better = self.current_better
        br = self.br
        if action is None:
            action = GameAction(GameAction.FOLD)

        to_call = br.to_call(current_better)

        if action.is_fold():
            br.post_fold(current_better)
        elif action.is_raise():
            if action.amount < br.minimum_raise:
                action.amount = br.minimum_raise
            action.amount += to_call
            self.__check_bet(br, current_better, action)
        elif action.is_call():
            action.amount = to_call
            self.__check_bet(br, current_better, action)
        elif action.is_check():
            br.post_bet(current_better, 0)

        self.parent.say_action(current_better, action)
        self.log.action(current_better, action)
コード例 #7
0
ファイル: poker.py プロジェクト: gnmerritt/poker
    def __do_action(self, action):
        current_better = self.current_better
        br = self.br
        if action is None:
            action = GameAction(GameAction.FOLD)

        to_call = br.to_call(current_better)

        if action.is_fold():
            br.post_fold(current_better)
        elif action.is_raise():
            if action.amount < br.minimum_raise:
                action.amount = br.minimum_raise
            action.amount += to_call
            self.__check_bet(br, current_better, action)
        elif action.is_call():
            action.amount = to_call
            self.__check_bet(br, current_better, action)
        elif action.is_check():
            br.post_bet(current_better, 0)

        self.parent.say_action(current_better, action)
        self.log.action(current_better, action)
コード例 #8
0
ファイル: poker.py プロジェクト: noke8868/poker
 def call(ignored):
     self.__got_action_callback(GameAction(GameAction.CALL))