/// <summary> /// Called when user is ready for the next trial. Queries AEPsych server for the optimal test case. /// </summary> /// <param name="strategyId"></param> IEnumerator AskForNewConfig(AEPsychStrategy strat) { // Initialize strat if we haven't yet if (strat.stratId == -1) { yield return(StartCoroutine(strat.InitStrat(client, configPath: configPath, true))); } // Resume this strat if AEPsych Client was previously handling a different one if (client.currentStrat != strat.stratId) { SetState(ExperimentState.WaitingForResumeResponse); yield return(StartCoroutine(client.Resume(strat.stratId))); } strategy.currentTrial++; AEPsychClient.Log("strat " + strategy.stratId + " trial# " + strat.currentTrial); SetState(ExperimentState.WaitingForAskResponse); yield return(StartCoroutine(client.Ask())); }
// Start is called before the first frame update IEnumerator Start() { AEPsychStrats = new List <AEPsychStrategy>() { }; config = new TrialConfig(); string configPath = "Assets/StreamingAssets/configs/single_lse_2d.ini"; for (int i = 0; i < numStrats; i++) { AEPsychStrategy b = gameObject.AddComponent <AEPsychStrategy>() as AEPsychStrategy; AEPsychStrats.Add(b); yield return(StartCoroutine(b.InitStrat(client, configPath: configPath))); } //start with strat 0 yield return(StartCoroutine(client.Resume(AEPsychStrats[currentStrat].stratId))); SetText("Welcome. Press Y to begin."); yield return(new WaitUntil(() => Input.GetKeyDown(KeyCode.Y))); yield return(StartCoroutine(RunExperiment())); }
/// <summary> /// Called when this game object becomes active. Generates strategies if they are un-initialized /// </summary> public IEnumerator ConnectAndGenerateStrategies() { yield return(new WaitForSeconds(0.2f)); // Set status change callback, which enables our study state machine logic client.onStatusChanged += OnStatusChanged; // Set up experiment params TrialConfig baseConfig = new TrialConfig() { }; // Quit if experiment params are invalid if (!configGenerator.CheckParamValidity()) { Debug.Break(); } if (configGenerator.isAutomatic) // Initialize the automatically generated strategy { if (PlayerPrefs.GetString(configGenerator.experimentName + "config") == "Empty") { Debug.LogError("Config has zero dimensions. Terminating Experiment..."); TerminateExperiment(); yield return(null); } else { strategy = gameObject.AddComponent <AEPsychStrategy>(); configPath = configGenerator.GetConfigText(); //configPath = PlayerPrefs.GetString(configGenerator.experimentName + "config"); yield return(StartCoroutine(strategy.InitStrat(client, configPath: configPath, false))); } } else // Initialize each manually added strategy { // Ensure that the user has provided at least one strategy config if (configGenerator.manualConfigFile == null) { Debug.LogError("Must assign at least one strategy config file if using manual configs. Assign a config file in the inspector."); TerminateExperiment(); yield return(null); } if (strategy == null) { configPath = Path.Combine(Application.dataPath, "../", AssetDatabase.GetAssetPath(configGenerator.manualConfigFile)); strategy = gameObject.AddComponent <AEPsychStrategy>(); yield return(StartCoroutine(strategy.InitStrat(client, configPath: configPath))); } } // Initialize a CSV Writer for each strategy if (recordToCSV) { if (csvFile == null) { csvFile = new CSVWriter(GetName()); } } SetState(ExperimentState.WaitingForResumeResponse); // All strategies created. if (startMode == StartType.Automatic) { BeginExperiment(); } else if (startMode == StartType.PressAnyKey) { StartCoroutine(WaitForAnyInput()); } }