“士”走棋算法

4.1 说明

“士”的走棋算法,与“将”的走棋算法很类似

        elif clicked_chess.name == "s":  # 士
            # 因为士是不能过河的,所以要计算出它们可以移动的行的范围
            row_start, row_stop = (0, 2) if team == "b" else (7, 9)
            if row - 1 >= row_start and col - 1 >= 3 and (not map_[row - 1][col - 1] or map_[row - 1][col - 1].team != team):
                put_down_chess_pos.append((row - 1, col - 1))
            if row - 1 >= row_start and col + 1 <= 5 and (not map_[row - 1][col + 1] or map_[row - 1][col + 1].team != team):
                put_down_chess_pos.append((row - 1, col + 1))
            if row + 1 <= row_stop and col - 1 >= 3 and (not map_[row + 1][col - 1] or map_[row + 1][col - 1].team != team):
                put_down_chess_pos.append((row + 1, col - 1))
            if row + 1 <= row_stop and col + 1 <= 5 and (not map_[row + 1][col + 1] or map_[row + 1][col + 1].team != team):
                put_down_chess_pos.append((row + 1, col + 1))

image-20210821190340930

4.2 运行效果

img

Copyright © itprojects.cn 2021 all right reserved,著作权归itprojects.cn所有,由王铭东编写该文件修订时间: 2021-08-21 20:33:04