예제 #1
0
def play_game(gamemap: array_hlt.GameMap, turns, prod_to_str_ratio):
    prods = []
    strs = []
    for turn in range(0, turns):
        play_a_turn(gamemap, prod_to_str_ratio)
        prods.append(gamemap.my_total_production())
        strs.append(gamemap.my_total_strength())
        # sys.stdout.write(str(turn) + "\t")
    print(str(prod_to_str_ratio) + "\t" + str(gamemap.my_total_production()))
    print(gamemap)
    return prods, strs
예제 #2
0
    def calculate_best_moves(self, gamemap: GameMap):
        moves = []
        my_total_str = gamemap.my_total_strength()
        my_locations_list = gamemap.my_locations_list()
        num_my_location = len(my_locations_list)
        for square in my_locations_list:
            my_str = gamemap.strength[square]
            if my_str <= 0:
                moves.append((square, STILL))
                continue

            # gamemap.log("calculating best move for square: " + str(square) + '\n')
            # do inner area differently, but only if strength is less than half the max (if bigger, just gogo!)
            # also check for insignificance str of this square (compare it to average str)
            if self.step_distances[square] < 0 and my_str < 256 / 2 and my_str < my_total_str / num_my_location:
                moves.append((square, STILL))
                continue

            if my_str > 256 / 2:
                best_move = STILL
                optimal_score = -9999
                for step, move in zip([(0, -1), (1, 0), (0, 1), (-1, 0)], [WEST, SOUTH, EAST, NORTH]):
                    neighbour = ((square[0] + step[0]) % gamemap.height, (square[1] + step[1]) % gamemap.width)
                    # moving outward? if yes, then check for scores
                    if (self.step_distances[neighbour] > self.step_distances[square] \
                            and self.score[neighbour] > optimal_score
                            and my_str >= gamemap.strength[neighbour]):
                        # moving outward, great!
                        gamemap.log("finding move for strong square")
                        best_move = move
                        optimal_score = self.score[neighbour]

                if best_move == STILL:
                    gamemap.log("\nwtf. best move not yet found!\n")
                    gamemap.log_myself()
                    optimal_score = -9999
                    for step, move in zip([(0, -1), (1, 0), (0, 1), (-1, 0)], [WEST, SOUTH, EAST, NORTH]):
                        neighbour = ((square[0] + step[0]) % gamemap.height, (square[1] + step[1]) % gamemap.width)
                        # moving outward? if yes, then check for scores
                        if self.step_distances[neighbour] > self.step_distances[square] and self.score[neighbour] > optimal_score:
                            # moving outward, great!
                            best_move = move
                            optimal_score = self.score[neighbour]
                moves.append((square, best_move))
                continue

            best_move = STILL
            optimal_score = -9999
            for step, move in zip([(0, -1), (1, 0), (0, 1), (-1, 0)], [WEST, SOUTH, EAST, NORTH]):
                neighbour = ((square[0] + step[0]) % gamemap.height, (square[1] + step[1]) % gamemap.width)
                # next commented section NEVER HAPPENS as neighbours cannot be enemies because of rules
                # if gamemap.owners[neighbour] != 0 and gamemap.owners[neighbour] != gamemap.playerID: # neighbour is enemy
                #     optimal_score = self.score[neighbour] + 100 # just add some score for enemy locations
                #     best_move = move
                if self.score[neighbour] > optimal_score and my_str >= gamemap.strength[neighbour]:
                    # only move if target has better score or target isn't mine
                    if gamemap.owners[neighbour] != gamemap.playerID or self.score[square] < self.score[neighbour]:
                        optimal_score = self.score[neighbour]
                        best_move = move
                        # gamemap.log("updating best move to score " + str(optimal_score) + ", move: " + MOVES_STRINGS[move] + '\n')
            moves.append((square, best_move))
        return moves