#pragma once
#include "Board.hpp"
#include "Player.hpp"
#include <SFML/Graphics/View.hpp>
#include <vector>
#include <SFML/Audio/Music.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/System/Sleep.hpp>
#include <SFML/System/Time.hpp>
#include <SFML/Window/Event.hpp>

class Engine {
	public:
		Engine();

		// Przygotowanie zmiennych
		void addPlayer(const std::string& name, unsigned int seed, short color);
		void initializeGame();

		// Pętla gry
		void startGame(Board board);
		bool isGameOver() const;

		// Logika gry
		void nextTurn();
		int rollDice(unsigned int seed, unsigned int moveNumber);
		short spawnPiece(short color, short pawnId);
		short takePawns(short color, short field);
		short tryTakingPawns(short color, short field);
		bool movePiece(short color, short field, short steps);
		short getFirstPawnAtBase(short color);
		short getFirstPawnNotAtBase(short color);
		short fieldToFirstPawnId(short color, short field);
		bool isMoveLegal(short color, short field, short steps);
		short checkPossibleMoves(short color, short steps);
		short fieldToColor(short field);

		// Audio
		bool dicerollLoaded = true;
		bool pawnmoveLoaded = true;
		bool     tadaLoaded = true;
		bool  invalidLoaded = true;
		sf::Music dicerollBuffer;
		sf::Music pawnmoveBuffer;
		sf::Music     tadaBuffer;
		sf::Music  invalidBuffer;

		// Pomocnicze
		std::string winnerNickname = "";
		unsigned int turnCounter = 0;

		// Z Game
		Board board;

	private:
		std::vector<Player> players;
		short currentPlayerIndex;

		// Pomocnicze
		void announceWinner(const Player& player) const;
};