当前位置: 首页>>代码示例>>Python>>正文


Python Position.is_game_over方法代码示例

本文整理汇总了Python中position.Position.is_game_over方法的典型用法代码示例。如果您正苦于以下问题:Python Position.is_game_over方法的具体用法?Python Position.is_game_over怎么用?Python Position.is_game_over使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在position.Position的用法示例。


在下文中一共展示了Position.is_game_over方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_scholars_mate

# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import is_game_over [as 别名]
    def test_scholars_mate(self):
        """Tests the scholars mate."""
        pos = Position()
        self.assertTrue(pos.get_castling_right("q"))

        e4 = Move.from_uci('e2e4')
        self.assertTrue(e4 in pos.get_legal_moves())
        pos.make_move(e4)
        self.assertTrue(pos.get_castling_right("q"))

        e5 = Move.from_uci('e7e5')
        self.assertTrue(e5 in pos.get_legal_moves())
        self.assertFalse(e4 in pos.get_legal_moves())
        pos.make_move(e5)
        self.assertTrue(pos.get_castling_right("q"))

        Qf3 = Move.from_uci('d1f3')
        self.assertTrue(Qf3 in pos.get_legal_moves())
        pos.make_move(Qf3)
        self.assertTrue(pos.get_castling_right("q"))

        Nc6 = Move.from_uci('b8c6')
        self.assertTrue(Nc6 in pos.get_legal_moves())
        pos.make_move(Nc6)
        self.assertTrue(pos.get_castling_right("q"))

        Bc4 = Move.from_uci('f1c4')
        self.assertTrue(Bc4 in pos.get_legal_moves())
        pos.make_move(Bc4)
        self.assertTrue(pos.get_castling_right("q"))

        Rb8 = Move.from_uci('a8b8')
        self.assertTrue(Rb8 in pos.get_legal_moves())
        pos.make_move(Rb8)
        self.assertFalse(pos.get_castling_right("q"))

        self.assertFalse(pos.is_check())
        self.assertFalse(pos.is_checkmate())
        self.assertFalse(pos.is_game_over())
        self.assertFalse(pos.is_stalemate())

        Qf7_mate = Move.from_uci('f3f7')
        self.assertTrue(Qf7_mate in pos.get_legal_moves())
        pos.make_move(Qf7_mate)

        self.assertTrue(pos.is_check())
        self.assertTrue(pos.is_checkmate())
        self.assertTrue(pos.is_game_over())
        self.assertFalse(pos.is_stalemate())

        self.assertEqual(pos.fen, "1rbqkbnr/pppp1Qpp/2n5/4p3/2B1P3/8/PPPP1PPP/RNB1K1NR b KQk - 0 4")
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:53,代码来源:old_test_position.py

示例2: TestPosition

# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import is_game_over [as 别名]
class TestPosition(unittest.TestCase):
    
    def setUp(self):
        self.pos = Position()
        self.pos_dup = Position()
        self.pos_other = Position()
        self.pos_other.make_move(Move.from_uci('e2e4'))

    def test___delitem__(self):
        del self.pos['a1']
        self.assertIs(None, self.pos['a1'])

    def test___eq__(self):
        self.assertEqual(True, self.pos == self.pos_dup)
        self.assertEqual(False, self.pos == self.pos_other)

    def test___getitem__(self):
        self.assertEqual(True, self.pos['e1'] == 'K')

    def test___hash__(self):
        self.assertEqual(True, hash(self.pos) == hash(self.pos_dup))
        self.assertEqual(False, hash(self.pos) != hash(self.pos_other))

    def test___ne__(self):
        self.assertEqual(False, self.pos != self.pos_dup)
        self.assertEqual(True, self.pos != self.pos_other)

    def test___repr__(self):
        self.assertEqual("Position('%s')" % Fen(), repr(self.pos))

    def test___setitem__(self):
        self.pos['a1'] = 'K'
        self.assertEqual('K', self.pos['a1'])

    def test___str__(self):
        self.assertEqual(str(Fen()), str(self.pos))
        self.assertEqual(False, str(self.pos) == str(self.pos_other))

    def test_copy(self):
        copy = self.pos.copy()
        self.assertEqual(copy, self.pos)

    def test_is_check(self):
        self.assertEqual(False, self.pos.is_check())

    def test_is_checkmate(self):
        self.assertEqual(False, self.pos.is_checkmate())

    def test_is_game_over(self):
        self.assertEqual(False, self.pos.is_game_over())

    def test_is_insufficient_material(self):
        self.assertEqual(False, self.pos.is_insufficient_material())

    def test_is_king_attacked(self):
        self.assertEqual(False, self.pos.is_king_attacked(WHITE))

    def test_is_stalemate(self):
        self.assertEqual(False, self.pos.is_stalemate())
开发者ID:arthurfait,项目名称:kivy-chess,代码行数:61,代码来源:test_position.py


注:本文中的position.Position.is_game_over方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。