// Copyright 2019 DeepMind Technologies Ltd. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <random>

#include "open_spiel/algorithms/kriegspiel/random_bot.h"

#include "open_spiel/algorithms/evaluate_bots.h"
#include "open_spiel/games/chess/pgn.h"

#include "open_spiel/abseil-cpp/absl/random/distributions.h"

namespace open_spiel {
namespace {

void PlayGamesWhite() {
  std::mt19937 rng(time(nullptr));


  algorithms::RandomBot random_bot = algorithms::RandomBot(absl::Uniform(rng, 0, std::numeric_limits<int>::max()));
  algorithms::RandomBotHeuristic random_heuristic_bot = algorithms::RandomBotHeuristic(absl::Uniform(rng, 0, std::numeric_limits<int>::max()));


  std::vector<Bot *> bot_ptrs;
  bot_ptrs.push_back(&random_heuristic_bot);
  bot_ptrs.push_back(&random_bot);

  for (int i = 0; i < 100; ++i) {

    auto game = open_spiel::LoadGame("kriegspiel");
    std::unique_ptr<open_spiel::State> state = game->NewInitialState();
    auto returns = EvaluateBots(state.get(), bot_ptrs,absl::Uniform<int>(rng, 0, std::numeric_limits<int>::max()));


    pgn::KriegspielPGN pgn = pgn::KriegspielPGN(
        down_cast<kriegspiel::KriegspielState>(*state),
        "Vojtech Foret Master Thesis",
        i,
        "Uniform Random",
        "Random Heuristic",
        chess::Color::kEmpty);

    std::cout << pgn << std::endl;
  }
}

void PlayGamesBlack() {
  std::mt19937 rng(time(nullptr));

  algorithms::RandomBot random_bot = algorithms::RandomBot(absl::Uniform(rng, 0, std::numeric_limits<int>::max()));
  algorithms::RandomBotHeuristic random_heuristic_bot = algorithms::RandomBotHeuristic(absl::Uniform(rng, 0, std::numeric_limits<int>::max()));


  std::vector<Bot *> bot_ptrs;
  bot_ptrs.push_back(&random_bot);
  bot_ptrs.push_back(&random_heuristic_bot);

  for (int i = 0; i < 100; ++i) {

    auto game = open_spiel::LoadGame("kriegspiel");
    std::unique_ptr<open_spiel::State> state = game->NewInitialState();
    auto returns = EvaluateBots(state.get(), bot_ptrs, absl::Uniform<int>(rng, 0, std::numeric_limits<int>::max()));


    pgn::KriegspielPGN pgn = pgn::KriegspielPGN(
        down_cast<kriegspiel::KriegspielState>(*state),
        "Vojtech Foret Master Thesis",
        i,
        "Random Heuristic",
        "Uniform Random",
        chess::Color::kEmpty);

    std::cout << pgn << std::endl;
  }
}

}  // namespace
}  // namespace open_spiel

int main(int argc, char** argv) {
  open_spiel::PlayGamesWhite();
  open_spiel::PlayGamesBlack();
  //open_spiel::PlayGames();
}
