Beispiel #1
0
        private void OnClickStartPlaytest(object sender, EventArgs e)
        {
            try {
                AgentStorageManager storageManager = new AgentStorageManager();

                agent = storageManager.LoadAgentBinary(openAgentTextBox.Text);
                level = storageManager.LoadObject <SnakeLevel>(openLevelTextBox.Text);

                level.SnakeSettings.RandomNumberGenerator = new RandomNumberGenerator();

                SnakePlayTestSimulator snakePlayTestSimulator = new SnakePlayTestSimulator(level);
                Playtest playtest = new Playtest(snakePlayTestSimulator, (TestType)playtestTypesList.SelectedIndex);
                playtestResults = playtest.RunPlaytest(agent, Convert.ToInt32(numberOfSimulations.Value));

                failedSimulationsAbsolute.Text = $"Number of failed tests: {playtestResults.NumberOfFailedTests} of {playtestResults.TestResults.Count}";
                failedSimulationsPercent.Text  = $"Percentage tests failed: {playtestResults.FailedPercentage}%";

                resultsChart.Series[0].Points.Clear();
                resultsChart.Series[1].Points.Clear();
                resultsChart.Series[0].Points.AddXY("Failed", playtestResults.FailedPercentage);
                resultsChart.Series[1].Points.AddXY("Passed", 100 - playtestResults.FailedPercentage);

                resultsLayout.Show();
            }
            catch (Exception exception) {
                MessageBox.Show($"Playtest failed! Error: {exception.Message}");
            }
        }
Beispiel #2
0
    // Loads a difficulty level
    void LoadLevel(int levelIndex)
    {
        print("Loading difficulty: " + levelIndex);
        SnakeLevel level = scriptManager.transform.FindChild("Level" + levelIndex).GetComponent <SnakeLevel>();

        minTimeBetweenAttacks      = level.minTimeBetweenAttacks;
        maxTimeBetweenAttacks      = level.maxTimeBetweenAttacks;
        HydraHead.attackTime       = level.attackTime;
        HydraHead.waitTime         = level.waitTime;
        HydraHead.pausedTime       = level.pausedTime;
        HydraHead.retreatTime      = level.retreatTime;
        HydraHead.regenWaitTime    = level.regenWaitTime;
        HydraHead.regenSegmentTime = level.regenSegmentTime;
        HydraHead.regenHeadTime    = level.regenHeadTime;
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        goal  = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        level = FindObjectOfType <SnakeLevel>();
        goal.transform.position    = startPosition;
        snakeBodySegments          = new List <GameObject>();
        snakeBodySegmentDirections = new List <Direction>();
        stopGame = false;
        GameObject head = Instantiate(snakeBodyPrefab);

        head.transform.position = goal.transform.position;
        level.BlockNode(new Vector2(head.transform.position.x, head.transform.position.z));
        snakeBodySegments.Add(head);
        snakeBodySegmentDirections.Add(Direction.NONE);
        pathIndex       = 0;
        waitTimeCounter = 0.0f;
        score           = 0;
        iterationCount  = 0;
        cumulativeScore = 0;
    }
        private void SaveLevelClicked()
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            SnakeSettings snakeSettingsLogic = ConvertSettingsGUIToLogic(snakeSettings);

            Field[,] logicFields = new Field[snakeSettings.RowCount, snakeSettings.ColumnCount];
            for (int i = 0; i < snakeSettings.RowCount; i++)
            {
                for (int j = 0; j < snakeSettings.ColumnCount; j++)
                {
                    if (fields[i, j] is WallGUI)
                    {
                        logicFields[i, j] = new Wall(fields[i, j].Point);
                    }
                    else if (fields[i, j] is EmptyGUI)
                    {
                        logicFields[i, j] = new Empty(fields[i, j].Point);
                    }
                }
            }
            Grid savedGrid = new Grid(logicFields);

            Grid       grid       = new Grid(snakeSettings.RowCount, snakeSettings.ColumnCount);
            SnakeLevel savedLevel = new SnakeLevel(savedGrid, snakeSettingsLogic);

            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.InitialDirectory = Path.GetFullPath(Path.Combine(Application.StartupPath, @"..\..\SavedLevels\"));
            saveFileDialog.Title            = "Save Snake level";
            saveFileDialog.ShowHelp         = true;

            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                try {
                    storageManager.SaveObject(savedLevel, saveFileDialog.FileName);
                }
                catch (IOException) {
                    MessageBox.Show("ERROR! Could not save. Is file in use by another process?");
                }
            }
        }
 /// <summary>
 /// Creates a play test simulator based on the given snake level.
 /// </summary>
 /// <param name="snakeLevel"></param>
 public SnakePlayTestSimulator(SnakeLevel snakeLevel)
 {
     this.snakeLevel = snakeLevel;
 }