def enemyCommon(coordinate): (x, y) = coordinate if not util.validCoordinates(x, y): return False if board[x][y][0] == -1 * player and board[x][y][ 1] == util.COMMON: return True else: return False
def removePiece(self, x, y): assert util.validCoordinates( x, y), "removePiece: position is out of bounds" player = self.board[x][y][0] rank = self.board[x][y][1] if player == util.EMPTY: return current_player_pieces = self.getPlayerPieces(player) current_player_pieces.remove((x, y, rank)) self.board[x][y] = (util.EMPTY, util.EMPTY) if (x, y) not in self.empty_squares: self.empty_squares.append((x, y))
def cannon10(summon_x, summon_y, vector): fup1 = action[3] (old_x, old_y) = (summon_x, summon_y) while True: (des_x, des_y) = util.getAdjacent(old_x, old_y, fup1) # go up to edge of the board if not util.validCoordinates(des_x, des_y): return True if tk.board[des_x][des_y][1] == util.COMMON: if tk.board[des_x][des_y][0] == -1 * tk.current_player: tk.pieces_destroyed[0] += 1 tk.removePiece(des_x, des_y) (old_x, old_y) = (des_x, des_y) return True
def bomb04(summon_x, summon_y, vector): # last action: nothing happens if tk.remaining_game_actions == 1: return True for direction in util.CARDINAL_DIRECTIONS: (des_x, des_y) = util.getAdjacent(summon_x, summon_y, direction) if not util.validCoordinates(des_x, des_y): continue if tk.board[des_x][des_y][1] == util.COMMON: if tk.board[des_x][des_y][0] == -1 * tk.current_player: tk.pieces_destroyed[0] += 1 tk.removePiece(des_x, des_y) # self destruct tk.removePiece(summon_x, summon_y) return True
def placePiece(self, player, rank, x, y): assert util.validCoordinates( x, y), "placePiece: position is out of bounds" assert rank == util.COMMON or rank == util.HEROIC, "invalid rank" current_player_pieces = self.getPlayerPieces(player) if len(current_player_pieces) >= util.MAX_PIECES: print("not enough pieces") return # clear whatever piece may already be on that square self.removePiece(x, y) current_player_pieces.append((x, y, rank)) self.board[x][y] = (player, rank) if (x, y) in self.empty_squares: self.empty_squares.remove((x, y))
def gunTower18(summon_x, summon_y, vector): fup1 = action[3] if fup1 == "": return True kill_count = 0 (old_x, old_y) = (summon_x, summon_y) while True: (des_x, des_y) = util.getAdjacent(old_x, old_y, fup1) # go up to edge of the board if not util.validCoordinates(des_x, des_y): return True if tk.board[des_x][des_y][0] != EMPTY: kill_count += 1 if tk.board[des_x][des_y][0] == -1 * tk.current_player: if tk.board[des_x][des_y][1] == util.COMMON: tk.pieces_destroyed[0] += 1 elif tk.board[des_x][des_y][1] == util.HEROIC: tk.pieces_destroyed[1] += 1 tk.removePiece(des_x, des_y) if kill_count == 2: return True return True
def getPossibleLocations(self, player, player_pieces, board): result = set() for piece in player_pieces: piece_x = piece[0] piece_y = piece[1] possible_formations = self.allFormations() formations = possible_formations[0] vectors = possible_formations[1] # check each of 8 formations for formation in formations: # check each tuple in the formation for player ownership, except for the summoning square # for the last tuple (summoning square), enforce equal or lesser rank valid_formation = True for i in range(len(formation)): form_piece = formation[i] new_x = piece_x + form_piece[0] new_y = piece_y + form_piece[1] if not util.validCoordinates(new_x, new_y): valid_formation = False break check_piece = board[new_x][new_y] # summoning square if i == len(formation) - 1: if check_piece[1] > self.rank: valid_formation = False break continue # pattern square if check_piece[0] != player: valid_formation = False break if valid_formation: vector = vectors[formations.index(formation)] summoning_square = formation[len(formation) - 1] #print "previous rank at summoning square: ",board[piece_x + summoning_square[0]][piece_y + summoning_square[1]][1] result.add((piece_x + summoning_square[0], piece_y + summoning_square[1], vector)) return result
def assassin06(summon_x, summon_y, vector): fup = [[""]] (x, y) = util.getAdjacent(summon_x, summon_y, vector) if not util.validCoordinates(x, y): return fup if board[x][y][0] == util.EMPTY: fup.append([vector]) return fup