Esempio n. 1
0
    } // end of loadFilesInGame

    /*
     * save the tables in text files
     */
    void saveFilesInGame()
    {
        if (coadapt)
        {
            //save both files
            fileManager.writeFile(relativePath + "/Results/Prey/coadapt/Qtable/", "preycoadaptQ", preyQlearning.printQTable());
            fileManager.writeFile(relativePath + "/Results/Prey/coadapt/states/", "preycoadaptStates", preyStateArray.printStates());
            fileManager.writeFile(relativePath + "/Results/Prey/coadapt/reward/", "preycoadaptreward", preyQlearning.printRewardList());
            fileManager.writeFile(relativePath + "/Results/Prey/coadapt/timer/", "preycoadapttimer", timerToString(timePrey));
            fileManager.writeFile(relativePath + "/Results/Predator/coadapt/Qtable/", "predatorcoadaptQ", predatorQlearning.printQTable());
            fileManager.writeFile(relativePath + "/Results/Predator/coadapt/states/", "predatorcoadaptStates", predatorStateArray.printStates());
            fileManager.writeFile(relativePath + "/Results/Predator/coadapt/reward/", "predatorcoadaptreward", predatorQlearning.printRewardList());
            fileManager.writeFile(relativePath + "/Results/Predator/coadapt/timer/", "predatorcoadapttimer", timerToString(timePredator));
        }
        else if (preysolo)
        {
            // save prey files
            fileManager.writeFile(relativePath + "/Results/Prey/solotrain/Qtable/", "preysoloQ", preyQlearning.printQTable());
            fileManager.writeFile(relativePath + "/Results/Prey/solotrain/states/", "preysoloStates", preyStateArray.printStates());
            fileManager.writeFile(relativePath + "/Results/Prey/solotrain/reward/", "preysoloreward", preyQlearning.printRewardList());
            fileManager.writeFile(relativePath + "/Results/Prey/solotrain/timer/", "preysolotimer", timerToString(timePrey));
        }
        else if (predatorsolo)
        {
            //save predator files
            fileManager.writeFile(relativePath + "/Results/Predator/solotrain/Qtable/", "predatorsoloQ", predatorQlearning.printQTable());
            fileManager.writeFile(relativePath + "/Results/Predator/solotrain/states/", "predatorsoloStates", predatorStateArray.printStates());
            fileManager.writeFile(relativePath + "/Results/Predator/solotrain/reward/", "predatorsoloreward", predatorQlearning.printRewardList());
            fileManager.writeFile(relativePath + "/Results/Predator/solotrain/timer/", "predatorsolotimer", timerToString(timePredator));
        }
    } // end of save files
Esempio n. 2
0
    } // end of start

    // Update is called once per frame
    void Update()
    {
        timer += Time.deltaTime;

        if ((counter % tempSave) == 0 && savedRound)
        {
            savedRound = false;
            save       = true;
            //Debug.Log("SAVE AND EXIT AT 10 RUNS");
        }
        if ((counter % totalRuns) == 0)
        {
            save = true;
            exit = true;
        }

        // load files
        if (loadFiles)
        {
            loadFiles = false;
            loadFilesInGame();
        }

        // save files
        if (save)
        {
            save = false;
            saveFilesInGame();
        }
        if (exit)
        {
            exitGame();
        }

        if (Input.GetKey(KeyCode.H))   // save progress
        {
            save = true;
        }

        if (Input.GetKey(KeyCode.T)) // print q
        {
            Debug.Log(preyQlearning.printQTable());
        }

        if (Input.GetKey(KeyCode.Y)) // print states
        {
            Debug.Log(preyStateArray.printStates());
        }

        // reset
        if (Input.GetKey(KeyCode.R))
        {
            preyQlearning.bestaction     = false;
            predatorQlearning.bestaction = false;
            resetAgents();
        }
        if (Input.GetKey(KeyCode.F))
        {
            preyQlearning.bestaction     = true;
            predatorQlearning.bestaction = true;
            resetAgents();
        }

        if (prey.GetComponent <Controller>().isDead() || predator.GetComponent <Controller>().isDead() || timer > maxRoundTimer)
        {
            resetAgents();
        }
    } // end of update
Esempio n. 3
0
    } // end of resetAgents

    void saveFiles()
    {
        // save prey files
        fileManager.writeFile(relativePath + "/Results/Prey/solotrain/Qtable/", "preysoloQ", preyQlearning.printQTable());
        fileManager.writeFile(relativePath + "/Results/Prey/solotrain/states/", "preysoloStates", preyStateArray.printStates());
        fileManager.writeFile(relativePath + "/Results/Prey/solotrain/reward/", "preysoloreward", preyQlearning.printRewardList());
        fileManager.writeFile(relativePath + "/Results/Prey/solotrain/timer/", "preysolotimer", timerToString(timePrey));
    }