本文整理汇总了Python中position.Position.get_legal_moves方法的典型用法代码示例。如果您正苦于以下问题:Python Position.get_legal_moves方法的具体用法?Python Position.get_legal_moves怎么用?Python Position.get_legal_moves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类position.Position
的用法示例。
在下文中一共展示了Position.get_legal_moves方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_single_step_pawn_move
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import get_legal_moves [as 别名]
def test_single_step_pawn_move(self):
"""Tests that single step pawn moves are possible."""
pos = Position()
a3 = Move.from_uci('a2a3')
self.assertTrue(a3 in pos.get_pseudo_legal_moves())
self.assertTrue(a3 in pos.get_legal_moves())
pos.get_move_info(a3)
pos.make_move(a3)
示例2: setUp
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import get_legal_moves [as 别名]
def setUp(self):
p = Position()
self.moves = p.get_legal_moves()
m1 = Move.from_uci('e2e4')
m2 = Move.from_uci('b1c3')
self.san = SanNotation(p, m1)
self.san_dup = SanNotation(p, m1)
self.san_other = SanNotation(p, m2)
self.position = p
self.m1 = m1
self.m2 = m2
示例3: test_scholars_mate
# 需要导入模块: from position import Position [as 别名]
# 或者: from position.Position import get_legal_moves [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")