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


Python Move.from_string方法代码示例

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


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

示例1: test_legal_moves_combined

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_legal_moves_combined(self):
        b = Board("""
                    1 W
                    ..k..
                    q..p.
                    .....
                    .P...
                    ....r
                    N...K
                    """)

        # get legal moves for all white pieces
        legal_moves = b.legal_moves()

        expected = []
        # knight
        expected.append(Move.from_string("a1-c2"))
        # king
        expected.append(Move.from_string("e1-e2"))
        expected.append(Move.from_string("e1-d2"))
        expected.append(Move.from_string("e1-d1"))
        # pawn
        expected.append(Move.from_string("b3-b4"))

        self.assertEqual(len(expected), len(legal_moves))
        for move in expected:
            self.assertIn(move, legal_moves)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:29,代码来源:BoardTest.py

示例2: test_scan_no_capture

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_scan_no_capture(self):
        b = Board("""
                    1 W
                    .....
                    .....
                    ..Qp.
                    .....
                    .....
                    .....
                    """)
        startpos = (3,4)
        
        # not capturing right
        movelist = []
        b.scan(movelist, startpos, 1, 0, no_capture=True)
        expected = []
        self.assertEqual(expected, movelist)

        # to the top
        movelist = []
        b.scan(movelist, startpos, 0, 1, no_capture=True)
        expected = []
        expected.append(Move.from_string("c4-c5"))
        expected.append(Move.from_string("c4-c6"))
        self.assertEqual(expected, movelist)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:27,代码来源:BoardTest.py

示例3: test_negamax

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_negamax(self):
        board = Board("""
                        1 W
                        ..k..
                        .....
                        .....
                        .....
                        ..Q..
                        ...K.
                        """)

        player = NegamaxPlayer()
        best_value, best_move = player.negamax(board, 1)
        self.assertEqual(Move.from_string("c2-c6"), best_move)


        random.seed(0)
        board = Board("""
                        1 W
                        kp...
                        .p...
                        .....
                        .....
                        .Q...
                        ...K.
                        """)

        player = NegamaxPlayer()
        best_value, best_move = player.negamax(board, 3)
        self.assertEqual(Move.from_string("b2-b4"), best_move)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:32,代码来源:NegamaxPlayerTest.py

示例4: test_scan_one_step

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_scan_one_step(self):
        b = Board("""
                    1 W
                    .....
                    .....
                    .....
                    .Kq..
                    .....
                    .....
                    """)
        startpos = (2,3)
        
        # capturing right
        movelist = []
        b.scan(movelist, startpos, 1, 0, one_step=True)
        expected = []
        expected.append(Move.from_string("b3-c3"))
        self.assertEqual(expected, movelist)

        # to the top
        movelist = []
        b.scan(movelist, startpos, 0, 1, one_step=True)
        expected = []
        expected.append(Move.from_string("b3-b4"))
        self.assertEqual(expected, movelist)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:27,代码来源:BoardTest.py

示例5: test_undo_last_move

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_undo_last_move(self):
        b = Board("""
            1 W
            ...k.
            ..P..
            .....
            .....
            .....
            .....
            """)
        b2 = Board("""
            1 W
            ...k.
            ..P..
            .....
            .....
            .....
            .....
            """)

        b.move(Move.from_string("c5-c6"))
        b.undo_last_move()
        self.assertEqual(b, b2)

        b.move(Move.from_string("c5-d6"))
        b.undo_last_move()
        self.assertEqual(b, b2)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:29,代码来源:BoardTest.py

示例6: test_equal_operator

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_equal_operator(self):
        b = Move.from_string("a1-a2")
        c = Move.from_string("a1-a2")
        self.assertEqual(b, c)

        b = Move.from_string("e1-a2")
        c = Move.from_string("a1-a4")
        self.assertNotEqual(b, c)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:10,代码来源:MoveTest.py

示例7: test_move_game_result

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_move_game_result(self):
        # white win
        b = Board("""
            1 W
            .k...
            P....
            .....
            .....
            .....
            .....
            """)
        result = b.move(Move.from_string("a5-b6"))
        self.assertEqual(result, 'W')

        # black win
        b = Board("""
            1 B
            ..r..
            .....
            .....
            .....
            ..K..
            .....
            """)
        result = b.move(Move.from_string("c6-c2"))
        self.assertEqual(result, 'B')

        # undecided
        b = Board("""
            1 W
            .....
            P....
            .....
            .....
            .....
            .....
            """)
        result = b.move(Move.from_string("a5-a6"))
        self.assertEqual(result, '?')

        # draw
        b = Board("""
            40 B
            .....
            p....
            .....
            .....
            .....
            .....
            """)
        result = b.move(Move.from_string("a5-a4"))
        self.assertEqual(result, '=')
开发者ID:jschmer,项目名称:MiniCheese,代码行数:54,代码来源:BoardTest.py

示例8: test_legal_moves_bishop

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_legal_moves_bishop(self):
        b = Board("""
                    1 W
                    .....
                    .....
                    ...p.
                    .p...
                    .B...
                    .....
                    """)
        
        # get legal moves for white bishop 'B'
        legal_moves = b.legal_moves()

        expected = []
        expected.append(Move.from_string("b2-a1"))
        expected.append(Move.from_string("b2-c3"))
        expected.append(Move.from_string("b2-d4"))
        expected.append(Move.from_string("b2-a3"))
        expected.append(Move.from_string("b2-c1"))
        
        expected.append(Move.from_string("b2-b1"))
        expected.append(Move.from_string("b2-a2"))
        expected.append(Move.from_string("b2-c2"))

        self.assertEqual(len(expected), len(legal_moves))
        for move in expected:
            self.assertIn(move, legal_moves)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:30,代码来源:BoardTest.py

示例9: test_legal_moves_rook

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_legal_moves_rook(self):
        b = Board("""
                    1 W
                    .....
                    .....
                    ..Rr.
                    .....
                    .....
                    .....
                    """)
        
        # get legal moves for white rook 'R'
        legal_moves = b.legal_moves()

        expected = []
        expected.append(Move.from_string("c4-d4"))
        expected.append(Move.from_string("c4-c3"))
        expected.append(Move.from_string("c4-c2"))
        expected.append(Move.from_string("c4-c1"))
        expected.append(Move.from_string("c4-b4"))
        expected.append(Move.from_string("c4-a4"))
        expected.append(Move.from_string("c4-c5"))
        expected.append(Move.from_string("c4-c6"))

        self.assertEqual(len(expected), len(legal_moves))
        for move in expected:
            self.assertIn(move, legal_moves)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:29,代码来源:BoardTest.py

示例10: test_try_move_and_score

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_try_move_and_score(self):
        b = Board("""
            1 W
            ..k..
            q..p.
            .....
            .P...
            ....r
            N...K
            """)
        self.assertEqual(b.score_after(Move.from_string("b3-b4")), 1150) # score for black!

        # moving pawn, no change in score, Black has advantage
        b.move(Move.from_string("b3-b4"))
        self.assertEqual(b.score_after(Move.from_string("e2-e1")), -100000) # score for white!
开发者ID:jschmer,项目名称:MiniCheese,代码行数:17,代码来源:BoardTest.py

示例11: test_scan_only_capture

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_scan_only_capture(self):
        b = Board("""
                    1 W
                    .....
                    ...p.
                    ..P..
                    ..K..
                    .....
                    .....
                    """)
        startpos = (3,4)
        
        # to the top
        movelist = []
        b.scan(movelist, startpos, 0, 1, only_capture=True)
        expected = []
        self.assertEqual(expected, movelist)

        # capturing enemy
        movelist = []
        b.scan(movelist, startpos, 1, 1, only_capture=True)
        expected = []
        expected.append(Move.from_string("c4-d5"))
        self.assertEqual(expected, movelist)

        # not capturing own
        movelist = []
        b.scan(movelist, startpos, 0, -1, only_capture=True)
        expected = []
        self.assertEqual(expected, movelist)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:32,代码来源:BoardTest.py

示例12: test_construct

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_construct(self): 
        b = Move((1, 1), (1, 2))
        self.assertEqual((1, 1), b.start)
        self.assertEqual((1, 2), b.end)

        b = Move.from_string("a1-a2")
        self.assertEqual((1, 1), b.start)
        self.assertEqual((1, 2), b.end)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:10,代码来源:MoveTest.py

示例13: test_scan_until_enemy

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
 def test_scan_until_enemy(self):
     b = Board("""
                 1 W
                 .....
                 .....
                 .....
                 ..q..
                 .....
                 Q....
                 """)
     startpos = (1,1)
     
     movelist = []
     b.scan(movelist, startpos, 1, 1)
     expected = []
     expected.append(Move.from_string("a1-b2"))
     expected.append(Move.from_string("a1-c3"))
     self.assertEqual(expected, movelist)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:20,代码来源:BoardTest.py

示例14: test_move_promotion

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
    def test_move_promotion(self):
        b1 = Board("""
            1 W
            .....
            P....
            .....
            .....
            .....
            ...kK
            """)

        b1.move(Move.from_string("a5-a6"))
        b2 = Board("""
            1 B
            Q....
            .....
            .....
            .....
            .....
            ...kK
            """)
        self.assertEqual(b1, b2)

        b3 = Board("""
            1 B
            k....
            .....
            .....
            .....
            ..p..
            ...K.
            """)
        b3.move(Move.from_string("c2-d1"))
        b4 = Board("""
            2 W
            k....
            .....
            .....
            .....
            .....
            ...q.
            """)
        self.assertEqual(b3, b4)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:45,代码来源:BoardTest.py

示例15: generate_move

# 需要导入模块: from Move import Move [as 别名]
# 或者: from Move.Move import from_string [as 别名]
 def generate_move(self, game):
     print("getting move from skirmish:")
     move = sys.stdin.readline()
     try:
         _, move = move.strip().split(" ")
     except:
         f = open("crap", "w")
         f.write(move)
         f.close()
     return Move.from_string(move)
开发者ID:jschmer,项目名称:MiniCheese,代码行数:12,代码来源:Player.py


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