Ejemplo n.º 1
0
    public void InitializeGame(VGDLGameAndLevel gameToRun, int randomSeed = -1)
    {
        VGDLParser.verbose = verbose;

        //Try to remove all the old reference stuff...
        game?.reset();
        game = null;

        game = LoadGame(gameToRun);


        if (players == null || players.Length < game.no_players)
        {
            var playerArr = new VGDLPlayerInterface[game.no_players];

            for (int i = 0; i < playerArr.Length; i++)
            {
                if (players.Length > i)
                {
                    playerArr[i] = players[i];
                }
                else
                {
                    var agent = new VGDLHumanAgent();
                    agent.PlayerID = i;
                    playerArr[i]   = agent;
                }
            }
        }

        game.prepareGame(players, randomSeed);

        started = false;
        ended   = false;

        Time.captureFramerate = frameRateTarget;
    }
Ejemplo n.º 2
0
    private IEnumerator RunGameRandomly(BasicGame game)
    {
        var agents = new VGDLPlayerInterface[game.no_players];

        for (int i = 0; i < agents.Length; i++)
        {
            agents[i] = new VGDLRandomAgent();
        }

        game.prepareGame(agents);


        var ended = false;

        var stepsUntilRendering = 1;

        while (!ended && game.getGameTick() < maxSteps)
        {
            try
            {
                game.updateGameState();
            }
            catch (Exception e)
            {
                parserTestErrors++;
                Debug.LogException(e);
                Debug.LogWarning("PARSER TESTS FAILED: " + parserTestErrors);

                //StopCoroutine("parserTest");
                //Debug.Break();
                break;
            }

            if (stepsUntilRendering <= 0)
            {
                shouldRender        = true;
                stepsUntilRendering = StepsBetweenRendering;
                yield return(null);
            }

            stepsUntilRendering--;

            if (!game.isEnded)
            {
                continue;
            }

            ended = true;

            var scores = game.handleResult();

            Debug.Log("GAME OVER!\n" + (game.gameResult.playerOutcomes[0] == VGDLPlayerOutcomes.PLAYER_WINS ? "YOU WON!" : "YOU LOST!") + " Score: " + game.gameResult.playerScores[0]);
        }

        if (game.getGameTick() >= maxSteps)
        {
            Debug.Log("TIMEOUT!\n");
        }

        yield return(null);
    }