本文整理汇总了Python中position.Position.is_checkmate方法的典型用法代码示例。如果您正苦于以下问题:Python Position.is_checkmate方法的具体用法?Python Position.is_checkmate怎么用?Python Position.is_checkmate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类position.Position
的用法示例。
在下文中一共展示了Position.is_checkmate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scholars_mate
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import is_checkmate [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")
示例2: TestPosition
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import is_checkmate [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())