//
// Created by Dan Crosby on 12/5/21.
//

#ifndef EAGLE0_GAMESTATEGUESSER_HPP
#define EAGLE0_GAMESTATEGUESSER_HPP

#include <optional>
#include <unordered_map>

#include "src/main/cpp/net/eagle0/shardok/library/GameStateW.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/map/Coordinates.hpp"
#include "src/main/cpp/net/eagle0/shardok/library/settings/GameSettings.hpp"
#include "src/main/protobuf/net/eagle0/shardok/api/game_state_view.pb.h"
#include "src/main/protobuf/net/eagle0/shardok/common/hex_map.pb.h"

namespace shardok {

using GameStateView = net::eagle0::shardok::api::GameStateView;
using HexMapProto = net::eagle0::shardok::common::HexMap;
using UnitViewProto = net::eagle0::shardok::api::UnitView;

struct AverageStats {
    double armament;
    double training;
};

auto KnownUnitStats(const GameStateView &gameStateView)
        -> std::unordered_map<PlayerId, AverageStats>;

// Guess where an enemy mage might be targeting with their meteor.
// Priority: (1) largest unit of targetPlayerId, (2) any unit of targetPlayerId,
// (3) any castle not occupied by the caster's player, (4) first valid tile in range.
auto GuessMeteorTarget(
        const SettingsGetter &settings,
        const HexMapProto &hexMap,
        const Coords &mageLocation,
        PlayerId targetPlayerId,
        PlayerId casterPlayerId,
        const google::protobuf::RepeatedPtrField<UnitViewProto> &units) -> std::optional<Coords>;

class GameStateGuesser {
public:
    [[nodiscard]] static auto GuessedState(
            PlayerId pid,
            const SettingsGetter &settings,
            const GameStateView &gameStateView) -> GameStateW;
};

}  // namespace shardok

#endif  // EAGLE0_GAMESTATEGUESSER_HPP
