示例#1
0
 def calc_moving_list(self):
     current_v_c = super(Knight, self).position.x
     current_h_c = super(Knight, self).position.y
     probable_obstacle_points = []
     probable_moving_points = []
     vs1 = (current_v_c + 1, current_v_c - 1)
     hs1 = (current_h_c,)
     vs2 = (current_v_c,)
     hs2 = (current_h_c + 1, current_h_c - 1)
     creat_points(probable_obstacle_points, vs1, hs1)
     creat_points(probable_obstacle_points, vs2, hs2)
     current_color = super(Knight, self).is_red
     for point in probable_obstacle_points:
         if super(Knight, self).border_check(point.x, point.y):
             chessman = super(Knight, self).chessboard.get_chessman(
                 point.x, point.y)
             if chessman is None:
                 if point.x == current_v_c:
                     probable_moving_points.append(
                         Point.Point(point.x + 1, 2 * point.y - current_h_c))
                     probable_moving_points.append(
                         Point.Point(point.x - 1, 2 * point.y - current_h_c))
                 else:
                     probable_moving_points.append(
                         Point.Point(2 * point.x - current_v_c, point.y + 1))
                     probable_moving_points.append(
                         Point.Point(2 * point.x - current_v_c, point.y - 1))
     super(Knight, self).add_from_probable_points(
         probable_moving_points, current_color)
示例#2
0
 def calc_moving_list(self):
     current_v_c = super(Pawn, self).position.x
     current_h_c = super(Pawn, self).position.y
     probable_moving_points = []
     current_color = super(Pawn, self).is_red
     probable_moving_points.append(
         Point.Point(current_v_c, current_h_c + self.__direction))
     if current_h_c * self.__direction >= self.__river * self.__direction:
         probable_moving_points.append(
             Point.Point(current_v_c + 1, current_h_c))
         probable_moving_points.append(
             Point.Point(current_v_c - 1, current_h_c))
     super(Pawn, self).add_from_probable_points(
         probable_moving_points, current_color)
示例#3
0
 def __init__(self, name_cn, name, is_red, chessboard):
     self.__name = name
     self.__is_red = is_red
     self.__chessboard = chessboard
     self.__position = Point.Point(None, None)
     self.__moving_list = []
     self.__top = 9
     self.__bottom = 0
     self.__left = 0
     self.__right = 8
     self.__is_alive = True
     self.__name_cn = name_cn
示例#4
0
 def calc_moving_list(self):
     current_v_c = super(Cannon, self).position.x
     current_h_c = super(Cannon, self).position.y
     left = super(Cannon, self).chessboard.get_left_first_chessman(
         current_v_c, current_h_c)
     right = super(Cannon, self).chessboard.get_right_first_chessman(
         current_v_c, current_h_c)
     top = super(Cannon, self).chessboard.get_top_first_chessman(
         current_v_c, current_h_c)
     bottom = super(Cannon, self).chessboard.get_bottom_first_chessman(
         current_v_c, current_h_c)
     tar_left = super(Cannon, self).chessboard.get_left_second_chessman(
         current_v_c, current_h_c)
     tar_right = super(Cannon, self).chessboard.get_right_second_chessman(
         current_v_c, current_h_c)
     tar_top = super(Cannon, self).chessboard.get_top_second_chessman(
         current_v_c, current_h_c)
     tar_bottom = super(Cannon, self).chessboard.get_bottom_second_chessman(
         current_v_c, current_h_c)
     super(Cannon, self).calc_moving_path(left, (left.position.x if left != None else None),
                                          current_v_c, current_h_c, 1, 0, True, True)
     super(Cannon, self).calc_moving_path(right, (right.position.x if right != None else None),
                                          current_v_c, current_h_c, -1, 8, True, True)
     super(Cannon, self).calc_moving_path(top, (top.position.y if top != None else None),
                                          current_h_c, current_v_c, -1, 9, False, True)
     super(Cannon, self).calc_moving_path(bottom, (bottom.position.y if bottom != None else None),
                                          current_h_c, current_v_c, 1, 0, False, True)
     current_color = super(Cannon, self).is_red
     if tar_left != None and tar_left.is_red != current_color:
         super(Cannon, self).moving_list.append(
             Point.Point(tar_left.position.x, tar_left.position.y))
     if tar_right != None and tar_right.is_red != current_color:
         super(Cannon, self).moving_list.append(
             Point.Point(tar_right.position.x, tar_right.position.y))
     if tar_top != None and tar_top.is_red != current_color:
         super(Cannon, self).moving_list.append(
             Point.Point(tar_top.position.x, tar_top.position.y))
     if tar_bottom != None and tar_bottom.is_red != current_color:
         super(Cannon, self).moving_list.append(
             Point.Point(tar_bottom.position.x, tar_bottom.position.y))
示例#5
0
    def calc_moving_path(self, direction_chessman, direction_vertical_coordinate, current_vertical_coordinate, direction_parallel_coordinate, direction, border_vertical_coordinate, h_or_v, ignore_color=False):
        if direction_chessman != None:
            if direction_chessman.is_red == self.is_red or ignore_color:
                for i in range(direction_vertical_coordinate + direction, current_vertical_coordinate, direction):
                    self.__moving_list.append(
                        Point.Point(i, direction_parallel_coordinate) if h_or_v else Point.Point(direction_parallel_coordinate, i))

            else:
                for i in range(direction_vertical_coordinate, current_vertical_coordinate, direction):
                    self.__moving_list.append(
                        Point.Point(i, direction_parallel_coordinate) if h_or_v else Point.Point(direction_parallel_coordinate, i))
        else:
            for i in range(border_vertical_coordinate, current_vertical_coordinate, direction):
                self.__moving_list.append(
                    Point.Point(i, direction_parallel_coordinate) if h_or_v else Point.Point(direction_parallel_coordinate, i))
示例#6
0
def creat_points(list_points, list_vs, list_hs):
    for v in list_vs:
        for h in list_hs:
            list_points.append(Point.Point(v, h))