//
// Created by sebastian on 02.08.26.
//

#ifndef COLORRACE_TURNBASEDGAMEMODE_H
#define COLORRACE_TURNBASEDGAMEMODE_H
#include <cstdint>

#include "GameMode.h"


namespace engine {
    using PlayerID = uint32_t;

    template<typename Command, typename Event, typename State>
    class TurnBasedGameMode : public GameMode<Command, Event, State> {
    public:
        explicit TurnBasedGameMode(std::vector<PlayerID> playerOrder) : m_playerOrder(std::move(playerOrder)) {}
        [[nodiscard]] PlayerID getCurrentPlayer() const { return m_playerOrder[m_currentPlayerIndex]; }
        [[nodiscard]] bool isCurrentPlayer(PlayerID playerID) const { return getCurrentPlayer() == playerID; }
        [[nodiscard]] std::vector<PlayerID> getPlayerOrder() const { return m_playerOrder; }
    protected:
        void endTurn(bool extraTurn = false) {
            if (!extraTurn) m_currentPlayerIndex = (m_currentPlayerIndex + 1) % m_playerOrder.size();
        }

    private:
        std::vector<PlayerID> m_playerOrder;
        size_t m_currentPlayerIndex = 0;
    };
}

#endif //COLORRACE_TURNBASEDGAMEMODE_H
