// 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.

#ifndef OPEN_SPIEL_ALGORITHMS_KRIEGSPIEL_COMMON_H_
#define OPEN_SPIEL_ALGORITHMS_KRIEGSPIEL_COMMON_H_

#include <string>

#include "open_spiel/games/chess.h"
#include "open_spiel/games/kriegspiel.h"
#include "open_spiel/games/chess/chess_board.h"


namespace open_spiel {
namespace algorithms {


const std::string kPartialFENs[2] =
    {"rnbqkbnr/pppppppp/8/8/8/8/8/8 w - - 0 1",
     "8/8/8/8/8/8/PPPPPPPP/RNBQKBNR w - - 0 1"};

// Hash function for chess board so that we can store it in a hash table (unordered_map)
struct ChessBoardHash {
  size_t operator() (const chess::ChessBoard &board) const {
    return board.HashValue();
  }
};

// Hash function for chess move so that we can store it in a hash table (unordered_map)
struct ChessMoveHash {
  size_t operator() (const chess::Move &move) const {
    return chess::MoveToAction(move);
  }
};

// Hash function for chess move so that we can store it in a hash table (unordered_map)
struct UmpireMessageHash {
  size_t operator() (const kriegspiel::KriegspielUmpireMessage &msg) const {
    return std::hash<std::string>{}(msg.ToString());
  }
};

class Named {
 public:
  virtual std::string Name() const = 0;
};

// does not recognise threefold repetition
bool IsTerminal(const chess::ChessBoard& board);
double GetReturn(const chess::ChessBoard& board, chess::Color color);

ActionsAndProbs GetPolicy(const State &state, Player player);
Action RandomStep(const State &state, std::mt19937 rng_, Player player);

}  // namespace algorithms
}  // namespace open_spiel


#endif  // OPEN_SPIEL_ALGORITHMS_KRIEGSPIEL_COMMON_H_
