<commit_before>package main.java.logic;

import java.util.*;

import main.java.logic.exceptions.PlayerNotExsistInGameException;
import main.java.logic.exceptions.*;

/**
 * Created by Stefan on 01.04.2014.
 */
public class Game {

    /**
     * Legt die mindestanzahl an Spielern fest, die für ein Spiel erforderlich sind
     */
    public static final int minCountPlayers = 3;

    /**
     * Legt die maximalanzahl an Spielern fest, die für ein Spiel erforderlich sind
     */
    public static final int maxCountPlayers = 5;

    public static enum gameStates {
        WAITING, // Wait for start input
        RUNNING, // The game passes through the rounds
        FINISHED // One player finished his order
    }

    /**
     * Representiert die Karte des Spiels
     */
    private Map map;
    /**
     * Listet alle Spieler auf, die aktiv am Spiel teilnehmen.
     */
    private final ArrayList<Player> players = new ArrayList<Player>();

    /**
     * The current game state, default => WAITING
     */
    private gameStates currentGameState = gameStates.WAITING;

    /**
     * Contains the current round , default null
     */
    private Round currentRound;

    /**
     * Die Game-Klasse dient zur verwaltung des gesammten Spiels
     */
    public Game() {
        this.map = new Map();
    }

    /**
     * Für dem Spiel einen neuen Spieler hinzu
     *
     * @param player - neuer Spieler
     */
    public void addPlayer(final Player player) {
        this.players.add(player);
    }

    /**
     * @return Liste der Spieler
     */
    public ArrayList<Player> getPlayers() {
        return this.players;
    }

    /**
     * Startet das Speil, sodass der Spielstatus und co aktualisiert werden
     *
     * @throws main.java.logic.exceptions.NotEnoughPlayerException
     */
    public void onGameStart() throws NotEnoughPlayerException, TooManyPlayerException, NotEnoughCountriesException, GameAllreadyStartedException {
        if (this.players.size() < Game.minCountPlayers) {
            throw new NotEnoughPlayerException(Game.minCountPlayers);
        } else if (this.players.size() > Game.maxCountPlayers) {
            throw new TooManyPlayerException(Game.maxCountPlayers);
        } else if (this.map.getCountries().size() < this.players.size()) {
            throw new NotEnoughCountriesException(this.map.getCountries().size());
        } else if (this.currentGameState != gameStates.WAITING) {
            throw new GameAllreadyStartedException();
        }
        distributeCountries();
        this.currentGameState = gameStates.RUNNING;
        this.setCurrentRound(new Round(players, map, Turn.getDefaultStepsFirstRound()));


    }

    /**
     * Setzt die aktuelle Runde
     *
     * @param r
     */
    public void setCurrentRound(Round r) {

        this.currentRound = r;
    }

    public void setNextRound() throws ToManyNewArmysException, RoundNotCompleteException {
        if (this.currentRound != null) {
            if (!this.currentRound.isComplete()) {
                throw new RoundNotCompleteException();
            }
        }
        this.currentRound = new Round(this.players, this.map);
    }

    /**
     * Gibt die aktuelle Runde des Spiels zurück
     *
     * @return
     */
    public Round getCurrentRound() throws GameNotStartedException {
        if (this.getCurrentGameState() == gameStates.WAITING) {
            throw new GameNotStartedException();
        }
        return this.currentRound;
    }

    /**
     * Gibt den aktuellen status des Games zurück
     *
     * @return
     */
    public gameStates getCurrentGameState() {
        return this.currentGameState;
    }

    /**
     * Kopiert die Liste aller L�nder in einen Stack
     *
     * @return<commit_msg>GameNotStatedException hinzugefügt<commit_after>package main.java.logic;

import java.util.*;

import main.java.logic.exceptions.PlayerNotExsistInGameException;
import main.java.logic.exceptions.*;

/**
 * Created by Stefan on 01.04.2014.
 */
public class Game {

    /**
     * Legt die mindestanzahl an Spielern fest, die für ein Spiel erforderlich sind
     */
    public static final int minCountPlayers = 3;

    /**
     * Legt die maximalanzahl an Spielern fest, die für ein Spiel erforderlich sind
     */
    public static final int maxCountPlayers = 5;

    public static enum gameStates {
        WAITING, // Wait for start input
        RUNNING, // The game passes through the rounds
        FINISHED // One player finished his order
    }

    /**
     * Representiert die Karte des Spiels
     */
    private Map map;
    /**
     * Listet alle Spieler auf, die aktiv am Spiel teilnehmen.
     */
    private final ArrayList<Player> players = new ArrayList<Player>();

    /**
     * The current game state, default => WAITING
     */
    private gameStates currentGameState = gameStates.WAITING;

    /**
     * Contains the current round , default null
     */
    private Round currentRound;

    /**
     * Die Game-Klasse dient zur verwaltung des gesammten Spiels
     */
    public Game() {
        this.map = new Map();
    }

    /**
     * Für dem Spiel einen neuen Spieler hinzu
     *
     * @param player - neuer Spieler
     */
    public void addPlayer(final Player player) {
        this.players.add(player);
    }

    /**
     * @return Liste der Spieler
     */
    public ArrayList<Player> getPlayers() {
        return this.players;
    }

    /**
     * Startet das Speil, sodass der Spielstatus und co aktualisiert werden
     *
     * @throws main.java.logic.exceptions.NotEnoughPlayerException
     */
    public void onGameStart() throws NotEnoughPlayerException, TooManyPlayerException, NotEnoughCountriesException, GameAllreadyStartedException {
        if (this.players.size() < Game.minCountPlayers) {
            throw new NotEnoughPlayerException(Game.minCountPlayers);
        } else if (this.players.size() > Game.maxCountPlayers) {
            throw new TooManyPlayerException(Game.maxCountPlayers);
        } else if (this.map.getCountries().size() < this.players.size()) {
            throw new NotEnoughCountriesException(this.map.getCountries().size());
        } else if (this.currentGameState != gameStates.WAITING) {
            throw new GameAllreadyStartedException();
        }
        distributeCountries();
        this.currentGameState = gameStates.RUNNING;
        this.setCurrentRound(new Round(players, map, Turn.getDefaultStepsFirstRound()));


    }

    /**
     * Setzt die aktuelle Runde
     *
     * @param r
     */
    public void setCurrentRound(Round r) {

        this.currentRound = r;
    }

    public void setNextRound() throws ToManyNewArmysException, RoundNotCompleteException,GameNotStartedException {
        if (this.currentRound != null) {
            if (!this.currentRound.isComplete()) {
                throw new RoundNotCompleteException();
            }
        }
        if (this.getCurrentGameState() == gameStates.WAITING){
            throw  new GameNotStartedException();
        }
        this.currentRound = new Round(this.players, this.map);
    }

    /**
     * Gibt die aktuelle Runde des Spiels zurück
     *
     * @return
     */
    public Round getCurrentRound() throws GameNotStartedException {
        if (this.getCurrentGameState() == gameStates.WAITING) {
            throw new GameNotStartedException();
        }
        return this.currentRound;
    }

    /**
     * Gibt den aktuellen status des Games zurück
     *
     * @return
     */
    public gameStates getCurrentGameState() {
        return this.currentGameState;
    }

    /**
     * Kopiert die Liste aller L�nder in einen Stack
     *
     * @return
{'fraction_non_alphanumeric': 0.094148244473342, 'fraction_numerical': 0.002600780234070221, 'mean_word_length': 2.339557099435519, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4651643', 'n_tokens_mistral': 2204, 'n_tokens_neox': 2152, 'n_words': 570}