Beispiel #1
0
    private void MatchBattleOver(object sender, EventArgs args)
    {
        // Reset values when match is over
        if (battleOn)
        {
            AgentResults agent0 = m_simulator.Agent0Results;
            AgentResults agent1 = m_simulator.Agent1Results;

            if (agent0.winner && !agent1.winner)
            {
                m_singleWon++;
            }
            else if (agent1.winner && !agent0.winner)
            {
                m_multiWon++;
            }

            m_singleDamage += agent0.damageGiven;
            m_multiDamage  += agent1.damageGiven;

            m_singleHealth += agent0.healthRemaining;
            m_multiHealth  += agent1.healthRemaining;

            battleOn = false;
        }
    }
Beispiel #2
0
    // Reset the values for all agents.
    public void ResetAgents()
    {
        // Create new sheets of results for next match.
        result_agent0 = new AgentResults();
        result_agent1 = new AgentResults();

        // Reset the position and rotation of agents.
        behave_agent0.SetNavpos(startPos_agent0);
        behave_agent0.SetRot(startRot_agent0);
        behave_agent1.SetNavpos(startPos_agent1);
        behave_agent1.SetRot(startRot_agent1);

        // Reset values on behaviours of agents.
        behave_agent0.ResetValues();
        behave_agent1.ResetValues();
    }
Beispiel #3
0
    void Awake()
    {
        // Make sure simulation runs in background during built application
        Application.runInBackground = true;

        // Find prefab of healthPack for respawning purposes.
        m_hpPrefab = Resources.Load("healthPack") as GameObject;
        if (m_hpPrefab == null)
        {
            Debug.LogError("No healthPack prefab found in resources.");
        }
        // Save spawning positions of healthpacks
        GameObject[] hpArray = GetHealthPacks();
        foreach (GameObject hp in hpArray)
        {
            m_hpPositions.Add(hp.transform.position);
        }

        liveSimulationScale = simulationTimeScale;
        if (agent0 != null || agent1 != null)
        {
            // Set default values of agents when found.
            startPos_agent0 = agent0.transform.position;
            startPos_agent1 = agent1.transform.position;
            startRot_agent0 = agent0.transform.rotation;
            startRot_agent1 = agent1.transform.rotation;
            behave_agent0   = agent0.GetComponent <ShooterAgent>();
            behave_agent1   = agent1.GetComponent <ShooterAgent>();
            bt_agent0       = agent0.GetComponent <AgentBT>();
            bt_agent1       = agent1.GetComponent <AgentBT>();
            result_agent0   = new AgentResults();
            result_agent1   = new AgentResults();
        }
        else
        {
            Debug.LogError("MatchSimulator missing agents.");
        }
        if (startGameOnStartup)
        {
            StartMatch();
        }
        else
        {
            Time.timeScale = 0.0f;
        }
    }
Beispiel #4
0
    // Simulate genomes against the currently best one and save results of match
    protected IEnumerator Simulate(List <Genome> genomes)
    {
        //Debug.Log("Simulating " + genomes.Count + " genomes.");
        // Simulate the genomes against the current best ones.
        foreach (Genome g in genomes)
        {
            // Set the agent BTs and start match.
            m_simulator.SetAgentBTs(g.RootNode, bestGenome.RootNode);
            m_simulator.StartMatch();
            simulating = true;
            // Yield until simulation of match is over.
            yield return(new WaitUntil(() => !simulating));

            AgentResults results = m_simulator.Agent0Results;
            // Save results in actual genome structure for later evaluation.
            g.DamageGiven     = results.damageGiven;
            g.HealthRemaining = results.healthRemaining;
            g.WonLastMatch    = results.winner;
        }
        simulationDone = true;

        yield return(null);
    }
Beispiel #5
0
        public MazeGenerationResults GenerateMaze(MazeGenerationSettings settings)
        {
            IMazeCarver carver         = null;
            var         modelBuildTime = _timeRecorder.GetRunningTime(() =>
            {
                var model = _mazeModelFactory.BuildMaze(settings);
                carver    = _mazeFactory.GetMazeCarver(model);
            });

            AlgorithmRunResults results = null;
            int extraWallsAdded         = 0;
            var generationTime          = _timeRecorder.GetRunningTime(() =>
            {
                switch (settings.Algorithm)
                {
                case Algorithm.None:
                    throw new ArgumentException("None not supported");

                case Algorithm.GrowingTreeAlgorithm:
                    results = _growingTreeAlgorithm.GenerateMaze(carver, settings);
                    break;

                case Algorithm.RecursiveBacktrackerAlgorithm:
                    results = _recursiveBacktrackerAlgorithm.GenerateMaze(carver, settings);
                    break;

                case Algorithm.BinaryTreeAlgorithm:
                    results = _binaryTreeAlgorithm.GenerateMaze(carver, settings);
                    break;

                default:
                    throw new ArgumentException("Unsupported algorithm type");
                }
                carver          = results.Carver;
                extraWallsAdded = _extraWall.Calulate(carver.Size);
                _randomCarver.CarveRandomWalls(carver, settings.ExtraWalls, extraWallsAdded);
            });

            DeadEndFillerResult deadEndFillerResults = null;
            var deadEndFillerTime = _timeRecorder.GetRunningTime(() =>
            {
                deadEndFillerResults = _deadEndFiller.Fill(carver);
            });
            AgentResults result = null;
            var          agentGenerationTime = _timeRecorder.GetRunningTime(() =>
            {
                if (settings.AgentType != AgentType.None)
                {
                    result = _agentFactory.MakeAgent(settings.AgentType).RunAgent(carver);
                }
            });

            HeuristicsResults heuristicsResults = null;
            var heuristicsTime = _timeRecorder.GetRunningTime(() =>
            {
                heuristicsResults = _heuristicsGenerator.GetResults(results);
            });

            var times     = new [] { modelBuildTime, generationTime, deadEndFillerTime, agentGenerationTime, heuristicsTime };
            var totalTime = times.Aggregate(new TimeSpan(), (seed, value) => seed.Add(value));

            return(new MazeGenerationResults
            {
                MazeJumper = carver.CarvingFinished(),
                HeuristicsResults = heuristicsResults,
                DirectionsCarvedIn = results.DirectionsCarvedIn,
                DeadEndFillerResults = deadEndFillerResults,
                ModelTime = modelBuildTime,
                AgentResults = result,
                GenerationTime = generationTime,
                DeadEndFillerTime = deadEndFillerTime,
                AgentGenerationTime = agentGenerationTime,
                HeuristicsTime = heuristicsTime,
                TotalTime = totalTime
            });
        }