示例#1
0
文件: ai.py 项目: Zolomon/reversi-ai
    def testAi(self):
        b = Board(False)

        b.set_white(4, 0)
        b.set_white(5, 0)
        b.set_white(6, 0)
        b.set_white(7, 0)
        b.set_white(3, 4)
        b.set_white(4, 4)
        b.set_white(4, 3)
        b.set_white(5, 3)
        b.set_white(5, 1)
        b.set_white(6, 1)

        b.set_black(1, 5)
        b.set_black(2, 0)
        b.set_black(2, 3)
        b.set_black(2, 4)
        b.set_black(3, 1)
        b.set_black(3, 2)
        b.set_black(3, 3)
        b.set_black(4, 1)
        b.set_black(4, 2)
        b.set_black(5, 2)
        b.set_black(6, 2)
        b.set_black(7, 1)
        b.set_black(7, 2)

        print(b.draw())

        ai = AiController(0, WHITE)
        move = ai.next_move(b)

        #self.assertEqual(, )
        self.assertIn(move, [p.get_position() for p in b.get_move_pieces(WHITE)])
示例#2
0
 def _make_controller(self, colour, controller_type):
     """ Returns a controller with the specified colour.
         'player' == PlayerController,
         'ai' == AiController.
     """
     if controller_type == 'player':
         return PlayerController(colour)
     else:
         self.ai_counter += 1
         return AiController(self.ai_counter, colour, self.max_depth)
示例#3
0
 def mk_ctrler(self, colour, ctrler_type):
     """ Returns a controller with the specified colour.
         'player' == PlayerController,
         'ai' == AiController.
     """
     if ctrler_type == 'player':
         return PlayerController(colour)
     elif ctrler_type == 'random':
         return RandomController(colour)
     else:
         self.ai_counter += 1
         return AiController(self.ai_counter, colour, self.timeout)
示例#4
0
    def testAi(self):
        b = Board(False)

        b.set_white(4, 0)
        b.set_white(5, 0)
        b.set_white(6, 0)
        b.set_white(7, 0)
        b.set_white(3, 4)
        b.set_white(4, 4)
        b.set_white(4, 3)
        b.set_white(5, 3)
        b.set_white(5, 1)
        b.set_white(6, 1)

        b.set_black(1, 5)
        b.set_black(2, 0)
        b.set_black(2, 3)
        b.set_black(2, 4)
        b.set_black(3, 1)
        b.set_black(3, 2)
        b.set_black(3, 3)
        b.set_black(4, 1)
        b.set_black(4, 2)
        b.set_black(5, 2)
        b.set_black(6, 2)
        b.set_black(7, 1)
        b.set_black(7, 2)

        print(b.draw())

        ai = AiController(0, WHITE)
        move = ai.next_move(b)

        #self.assertEqual(, )
        self.assertIn(move,
                      [p.get_position() for p in b.get_move_pieces(WHITE)])