示例#1
0
 public override void AgentOnDone()
 {
     PCGMazeGeneratorArea.ResetArea();
 }
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        startTime = DateTime.UtcNow;
        MazeNumber++;

        // Call once on demand
        MazeRows    = (int)vectorAction[0] + 2;
        MazeColumns = (int)vectorAction[1] + 2;

        Seed = $"" +
               $"{(int)vectorAction[2] + 1}" +
               $"{(int)vectorAction[3] + 1}" +
               $"{(int)vectorAction[4] + 1}" +
               $"{(int)vectorAction[5] + 1}" +
               $"{(int)vectorAction[6] + 1}" +
               $"{(int)vectorAction[7] + 1}" +
               $"{(int)vectorAction[8] + 1}" +
               $"{(int)vectorAction[9] + 1}" +
               $"{(int)vectorAction[10] + 1}" +
               $"{(int)vectorAction[11] + 1}" +
               $"{(int)vectorAction[12] + 1}" +
               $"{(int)vectorAction[13] + 1}" +
               $"{(int)vectorAction[14] + 1}" +
               $"{(int)vectorAction[15] + 1}" +
               $"{(int)vectorAction[16] + 1}" +
               $"{(int)vectorAction[17] + 1}" +
               $"{(int)vectorAction[18] + 1}" +
               $"{(int)vectorAction[19] + 1}" +
               $"{(int)vectorAction[20] + 1}" +
               $"{(int)vectorAction[21] + 1}";

        if (!PcgHKMG.IsSeedValid(Seed))
        {
            // Reward(-1f);
            // Done();
            MazeGeneratorArea.MazeGeneratorPlayerAgent.mazeReady = false;
            MistakesMade++;
            MazeGeneratorArea.ResetArea();
            return;
        }

        // initialize maze
        mazeCells = PcgHKMG.InitializeMaze(gameObject, MazeRows, MazeColumns, WallPrefab, CellLocationPrefab, CellSize, MazeGeneratorArea, PlayerGoal);
        PcgHKMG.CreateMaze(mazeCells, Seed);
        PcgHKMG.CompleteMaze(mazeCells, MazeRows, MazeColumns);
        distanceFromStartToEnd = PcgHKMG.CellDistanceToEnd(mazeCells[0, 0], FromCell.start);

        MazeGeneratorArea.scoreTotal       = Mathf.CeilToInt(distanceFromStartToEnd * 1.5f);
        MazeGeneratorArea.penaltyThreshold = distanceFromStartToEnd;

        PerfectMazesGenerated++;

        // CAPTURE DATA
        generationTime = DateTime.UtcNow - startTime;

        MazeComplexity = PcgHKMG.CalculateMazeComplexity(mazeCells);
        MazeGeneratorArea.complexity = MazeComplexity;

        if (CaptureData)
        {
            var data = new List <string>()
            {
                GeneratorName,
                GeneratorType,
                StepsTrained.ToString(),
                PerfectMazesGenerated.ToString(),
                MistakesMade.ToString(),
                MazeNumber.ToString(),
                MazeRows.ToString(),
                MazeColumns.ToString(),
                $"[{Seed}]",
                MazeComplexity.ToString(), // TO DO
                observationTime.TotalMilliseconds.ToString(),
                generationTime.TotalMilliseconds.ToString()
            };
            DataRecorder.WriteRecordToCSV(data, CSVFilePath);
        }

        MazeGeneratorArea.MazeGeneratorPlayerAgent.mazeReady = true;
    }