示例#1
0
 def __set_from_points(self, white_amazons, black_amazons, blockers_pos):
     for white_amazon in white_amazons:
         self.board[get_raw_index(white_amazon.y, self.size)][get_col_index(
             white_amazon.x, self.size)] = Constants.WHITE_AMAZON_VAL
     for black_amazon in black_amazons:
         self.board[get_raw_index(black_amazon.y, self.size)][get_col_index(
             black_amazon.x, self.size)] = Constants.BLACK_AMAZON_VAL
     for blocker_pos in blockers_pos:
         self.board[get_raw_index(blocker_pos.y, self.size)][get_col_index(
             blocker_pos.x, self.size)] = Constants.BLOCKED_CELL_VAL
示例#2
0
 def shoot_blocking_rock(self, rock_target_pos):
     if self.board[get_raw_index(rock_target_pos.y, self.size)][get_col_index(rock_target_pos.x, self.size)] == \
             Constants.EMPTY_CELL_VAL:
         self.board[get_raw_index(rock_target_pos.y, self.size)][get_col_index(rock_target_pos.x, self.size)] = \
             Constants.BLOCKED_CELL_VAL
         logging.debug("<shoot_blocking_rock()>, shooting is valid")
         return True
     else:
         logging.error(
             "<shoot_blocking_rock()> Error, you tried to shoot to non-empty cell"
         )
         return False
示例#3
0
 def get_available_moves_to_the_north(self,
                                      current_board_game,
                                      amazona,
                                      distance=None):
     return self.__get_available_moves_to_the_north(
         current_board_game,
         (get_raw_index(amazona.get_y(), current_board_game.get_size()),
          get_col_index(amazona.get_x(), current_board_game.get_size())))
 def is_shoot_valid(self, game_board, src, dst):
     # first stage, is to verify weather current_pos exists, and desired pos exists
     try:
         board_size = game_board.get_size()
         src_x = get_col_index(src.get_x(), board_size)
         src_y = get_raw_index(src.get_y(), board_size)
         if 0 <= src_x < board_size and 0 <= src_y < board_size:
             dst_x = get_col_index(dst.get_x(), board_size)
             dst_y = get_raw_index(dst.get_y(), board_size)
             if 0 <= dst_x <= board_size and 0 <= dst_y <= board_size:
                 if self.__is_path_valid(game_board, src_x, src_y, dst_x,
                                         dst_y):
                     return True
     except IndexError as e:
         logging.error(
             "<TurnValidator::is_shoot_valid() Caught exception: " + str(e))
     logging.error("<TurnValidator::is_shoot_valid()> step_is_invalid")
     return False
示例#5
0
 def update_move(self, amazon_to_update, new_position, amazon_color):
     # input validation
     if ((amazon_color == "BLACK"
          and self.is_black_amazon(amazon_to_update.y, amazon_to_update.x))
             or (amazon_color == "WHITE") and self.is_white_amazon(
                 amazon_to_update.y, amazon_to_update.x)):
         self.board[get_raw_index(new_position.y, self.size)][get_col_index(new_position.x, self.size)] = \
             self.board[get_raw_index(amazon_to_update.y, self.size)][get_col_index(amazon_to_update.x, self.size)]
         self.board[get_raw_index(amazon_to_update.y,
                                  self.size)][get_col_index(
                                      amazon_to_update.x,
                                      self.size)] = Constants.EMPTY_CELL_VAL
         logging.debug("<update_move()> move updated successfully!")
         return True
     else:
         logging.error(
             "<update_move()> Tried to move to non-empty spot. update failed"
         )
         return False
示例#6
0
    def __init__(self,
                 size,
                 points_ctor=False,
                 white_amazons=None,
                 black_amazons=None,
                 blockers_pos=None):
        self.size = size
        self.board = numpy.zeros((self.size, self.size), dtype=numpy.int)

        if white_amazons is None and black_amazons is None and blockers_pos is None:
            logging.info(
                "<BoardGame::BoardGame()> Placing amazons in the board. Board size is: "
                + str(size))
            try:
                if self.size == Constants.LARGE_BOARD_SIZE:
                    self.board[get_raw_index(7, self.size)][get_col_index(
                        'A', self.size)] = Constants.BLACK_AMAZON_VAL
                    self.board[get_raw_index(10, self.size)][get_col_index(
                        'D', self.size)] = Constants.BLACK_AMAZON_VAL
                    self.board[get_raw_index(10, self.size)][get_col_index(
                        'G', self.size)] = Constants.BLACK_AMAZON_VAL
                    self.board[get_raw_index(7, self.size)][get_col_index(
                        'J', self.size)] = Constants.BLACK_AMAZON_VAL
                    self.board[get_raw_index(4, self.size)][get_col_index(
                        'A', self.size)] = Constants.WHITE_AMAZON_VAL
                    self.board[get_raw_index(1, self.size)][get_col_index(
                        'D', self.size)] = Constants.WHITE_AMAZON_VAL
                    self.board[get_raw_index(1, self.size)][get_col_index(
                        'G', self.size)] = Constants.WHITE_AMAZON_VAL
                    self.board[get_raw_index(4, self.size)][get_col_index(
                        'J', self.size)] = Constants.WHITE_AMAZON_VAL

                elif self.size == Constants.SMALL_BOARD_SIZE:
                    self.board[get_raw_index(4, self.size)][get_col_index(
                        'A', self.size)] = Constants.BLACK_AMAZON_VAL
                    self.board[get_raw_index(3, self.size)][get_col_index(
                        'F', self.size)] = Constants.BLACK_AMAZON_VAL
                    self.board[get_raw_index(1, self.size)][get_col_index(
                        'C', self.size)] = Constants.WHITE_AMAZON_VAL
                    self.board[get_raw_index(6, self.size)][get_col_index(
                        'D', self.size)] = Constants.WHITE_AMAZON_VAL
            except IndexError as err:
                print(err)
        else:
            logging.info("<BoardGame::BoardGame()> setting the board for us")
            if points_ctor:
                self.__set_from_points(white_amazons, black_amazons,
                                       blockers_pos)
            else:
                self.__set_from_tuples(white_amazons, black_amazons,
                                       blockers_pos)
示例#7
0
 def is_white_amazon(self, raw, col):
     return self.board[get_raw_index(raw, self.size)][get_col_index(
         col, self.size)] == Constants.WHITE_AMAZON_VAL
示例#8
0
 def is_black_amazon(self, raw, col):
     return self.board[get_raw_index(raw, self.size)][get_col_index(
         col, self.size)] == Constants.BLACK_AMAZON_VAL