Exemplo n.º 1
0
 def boss(self, active: ChessPiece, dest_piece: ChessPiece, origin: {}, dest: {}):
     # 判断是否将帅见面,这种情况下可以移动到对方大本营里吃对方主将
     if active.get_type() == constants.CHESS_BOSS and dest_piece.get_type() == constants.CHESS_BOSS and origin['x'] == dest['x']:
         middle_count = 0
         for idx in range(min(origin['y'], dest['y']) + 1, max(origin['y'], dest['y'])):
             if self.pieces[idx][dest['x']].get_type() != constants.CHESS_PIECE:
                 middle_count += 1
                 break
         if middle_count == 0:
             return True
     # 判断是否走的直线且距离为1
     if abs(dest['x'] - origin['x']) + abs(dest['y'] - origin['y']) != 1:
         return False
     # 判断是否移出左右边界
     if dest['x'] < self._boss_x_left or dest['x'] > self._boss_x_right:
         return False
     # 判断是否移出Y轴边界
     if self._red_up:
         if active.get_camp() == constants.CAMP_RED:
             if dest['y'] > self._boss_y_red:
                 return False
         else:
             if dest['y'] < self._boss_y_white:
                 return False
     else:  # 红方在下面
         if active.get_camp() == constants.CAMP_RED:
             if dest['y'] < self._boss_y_red:
                 return False
         else:
             if dest['y'] > self._boss_y_white:
                 return False
     return True
Exemplo n.º 2
0
 def xiang(self, active: ChessPiece, origin: {}, dest: {}):
     # 判断是否是田字走法
     if abs(origin['x'] - dest['x']) != 2 or abs(origin['y'] - dest['y']) != 2:
         return False
     # 判断是否拗象脚
     tmpx = (dest['x'] - origin['x'])//2 + origin['x']
     tmpy = (dest['y'] - origin['y'])//2 + origin['y']
     if self.pieces[tmpy][tmpx].get_camp() != constants.CAMP_NONE:
         return False
     # 象不能过河的判断
     if self._red_up:
         if active.get_camp() == constants.CAMP_RED:
             if dest['y'] > self._red_line:
                 return False
         else:
             if dest['y'] < self._white_line:
                 return False
     else:  # 红方在下面
         if active.get_camp() == constants.CAMP_RED:
             if dest['y'] < self._red_line:
                 return False
         else:
             if dest['y'] > self._white_line:
                 return False
     return True
Exemplo n.º 3
0
    def pao(self, dest_piece: ChessPiece, origin: {}, dest: {}):
        if not self.is_straight(origin, dest):
            return False

        middle_count = 0
        if origin['x'] - dest['x'] != 0:  # 横着走
            for idx in range(min(origin['x'], dest['x']) + 1, max(origin['x'], dest['x'])):
                if self.pieces[dest['y']][idx].get_type() != constants.CHESS_PIECE:
                    middle_count += 1
        else:  # 竖着走
            for idx in range(min(origin['y'], dest['y']) + 1, max(origin['y'], dest['y'])):
                if self.pieces[idx][dest['x']].get_type() != constants.CHESS_PIECE:
                    middle_count += 1
        if middle_count > 1:
            return False
        if middle_count == 1 and dest_piece.get_camp() == constants.CAMP_NONE:
            return False
        if middle_count == 0 and dest_piece.get_camp() != constants.CAMP_NONE:
            return False
        return True
Exemplo n.º 4
0
 def bing(self, active: ChessPiece, origin: {}, dest: {}):
     # 存在斜着走判定
     if not self.is_straight(origin, dest):
         return False
     # 存在移动超过多步判定
     if abs(origin['x'] - dest['x']) > 1 or abs(origin['y'] - dest['y']) > 1:
         return False
     # 不能后退判定和过了河才能左右移动判定
     if self._red_up:
         if active.get_camp() == constants.CAMP_RED:
             if dest['y'] - origin['y'] < 0:
                 return False
             # 过河才能左右移动
             if abs(dest['x'] - origin['x']) > 0:
                 if origin['y'] <= self._red_line:
                     return False
         else:
             if dest['y'] - origin['y'] > 0:
                 return False
             # 过了河才能左右移动
             if abs(dest['x'] - origin['x']) > 0:
                 if origin['y'] >= self._white_line:
                     return False
     else:  # 红方在下面
         if active.get_camp() == constants.CAMP_RED:
             if dest['y'] - origin['y'] > 0:
                 return False
             # 过了河才能左右移动
             if abs(dest['x'] - origin['x']) > 0:
                 if origin['y'] >= self._white_line:
                     return False
         else:
             if dest['y'] - origin['y'] < 0:
                 return False
             # 过了河才能左右移动
             if abs(dest['x'] - origin['x']) > 0:
                 if origin['y'] <= self._white_line:
                     return False
     return True
Exemplo n.º 5
0
 def shi(self, active: ChessPiece, origin: {}, dest: {}):
     # 判断是否走的斜线且距离为1
     if abs((dest['x'] - origin['x']) * (dest['y'] - origin['y'])) != 1:
         return False
     # 判断是否移出左右边界
     if dest['x'] < self._boss_x_left or dest['x'] > self._boss_x_right:
         return False
     # 判断是否移出Y轴边界
     if self._red_up:
         if active.get_camp() == constants.CAMP_RED:
             if dest['y'] > self._boss_y_red:
                 return False
         else:
             if dest['y'] < self._boss_y_white:
                 return False
     else:  # 红方在下面
         if active.get_camp() == constants.CAMP_RED:
             if dest['y'] < self._boss_y_red:
                 return False
         else:
             if dest['y'] > self._boss_y_white:
                 return False
     return True