示例#1
0
 def test_select_move_black(self):
     s = State(turn='b')
     a = ValueNetworkAgent()
     move = a.select_move(s)
     is_legal = True
     try:
         s.get_child(*move)
     except IllegalMoveException:
         is_legal = False
     self.assertTrue(is_legal, 'White select move')
示例#2
0
    def test_valid_move(self):
        """
        STS-1 Test 1
        """
        s = State()
        request = s.to_dict()
        request.pop('winner', None)
        request['piece'] = 1
        request['target'] = 18

        result = self.app.post('/move',
                               data=json.dumps(request),
                               headers={'content-type': 'application/json'})

        self.assertEqual(200, result.status_code, 'Status is OK')
        expected = s.get_child(1 << 1, 1 << 18)

        expected = expected.to_dict()

        jd = json.loads(result.data)

        jd['prev_move'] = tuple(jd['prev_move'])
        jd['can_castle'] = tuple(jd['can_castle'])

        # subset because we're not considering jd['valid_moves']
        self.assertTrue(expected.items() <= jd.items(), 'Returned response')
示例#3
0
    def play_and_update(self):
        self.setup_iteration()
        n_moves = 0
        result = GameResult.NONTERMINAL
        states = []
        state = State()
        while n_moves < self.max_iter and result == GameResult.NONTERMINAL:
            states.append(state)
            move = self.select_move(state)
            state = state.get_child(*move)
            result = state.is_terminal()
            n_moves += 1

        self.update(states, result)
        self.teardown_iteration()
示例#4
0
    def test_capture(self):
        s = State(wp=0x0800F000, bp=0x1000000000)

        request = s.to_dict()
        request.pop('winner', None)
        request['piece'] = 27
        request['target'] = 36

        result = self.app.post('/move',
                               data=json.dumps(request),
                               headers={'content-type': 'application/json'})

        self.assertEqual(200, result.status_code, 'Status is OK')
        expected = s.get_child(1 << 27, 1 << 36)
        expected = expected.to_dict()
        jd = json.loads(result.data)

        jd['prev_move'] = tuple(jd['prev_move'])
        jd['can_castle'] = tuple(jd['can_castle'])
        self.assertTrue(expected.items() <= jd.items(), 'Returned response')
示例#5
0
    def test_valid_nowin(self):
        s = State()
        request = s.to_dict()
        request.pop('winner', None)
        request['piece'] = 1
        request['target'] = 18

        result = self.app.post('/moveai',
                               data=json.dumps(request),
                               headers={'content-type': 'application/json'})

        self.assertEqual(200, result.status_code, 'Status is OK')

        move_one = s.get_child(1 << 1, 1 << 18)
        possible_children = set(move_one.get_children())
        data = json.loads(result.data)

        actual = State.from_dict(data['pieces'], data['turn'],
                                 data['in_check'], data['can_castle'],
                                 data['prev_move'])
        self.assertTrue(actual in possible_children, 'Valid responding move')