public static void doOneTwoThreeSimControl() { string adaptID = "Game difficulty - Player skill"; string gameID = "OneTwoThree"; // [SC] create Bridge instance MyBridge bridge = new MyBridge(); // [SC] instantiate the TwoA asset TwoA twoA = new TwoA(bridge); // [SC] a lis of player in order of gameplays in datafile List <DataRecord> dataRecordList = new List <DataRecord>(); // [SC] contains info about scenarios such as level and mirror group Dictionary <string, ScenarioData> scenarioDatabase = new Dictionary <string, ScenarioData>(); // [SC] load the data file Dictionary <int, PlayerData> playerDatabase = parseOneTwoThreeDatafile(twoA, adaptID, gameID, dataRecordList, scenarioDatabase); if (playerDatabase == null) { return; } foreach (DataRecord dataRecord in dataRecordList) { twoA.UpdateRatings(adaptID, gameID, "" + dataRecord.PlayerID, dataRecord.ScenarioID, dataRecord.RT, dataRecord.Accuracy, false); } // [SC] creating a file with final ratings using (StreamWriter ratingfile = new StreamWriter(Path.Combine(OneTwoThreeSimResultsPath, "ratings_control.txt"))) { string line = "" + "\"ScenarioID\"" + "\t" + "\"Rating\"" + "\t" + "\"PlayCount\"" + "\t" + "\"Uncertainty\"" + "\t" + "\"MirrorID\"" + "\t" + "\"SetLevel\""; ratingfile.WriteLine(line); foreach (ScenarioData scenarioData in scenarioDatabase.Values) { line = "" + "\"" + scenarioData.ScenarioID + "\"" + "\t" + "\"" + twoA.ScenarioRating(adaptID, gameID, scenarioData.ScenarioID) + "\"" + "\t" + "\"" + twoA.ScenarioPlayCount(adaptID, gameID, scenarioData.ScenarioID) + "\"" + "\t" + "\"" + twoA.ScenarioUncertainty(adaptID, gameID, scenarioData.ScenarioID) + "\"" + "\t" + "\"" + scenarioData.MirrorID + "\"" + "\t" + "\"" + scenarioData.SetLevel + "\""; ratingfile.WriteLine(line); } } // [SC] creating a file with history of gameplays including player and scenario ratings using (StreamWriter datafile = new StreamWriter(Path.Combine(OneTwoThreeSimResultsPath, "gameplay_control.txt"))) { GameplaysData gameplays = twoA.GameplaysData; TwoAAdaptation adaptNode = gameplays.Adaptation.First(p => p.AdaptationID.Equals(adaptID)); TwoAGame gameNode = adaptNode.Game.First(p => p.GameID.Equals(gameID)); string line = "" + "ID" + "\t" + "PlayerID" + "\t" + "ScenarioID" //+ "\t" + "Timestamp" + "\t" + "RT" + "\t" + "ccuracy" + "\t" + "PlayerRating" + "\t" + "ScenarioRating"; datafile.WriteLine(line); int id = 1; foreach (TwoAGameplay gp in gameNode.Gameplay) { /*line = "" + "\"" + id++ + "\"" + "\t" + "\"" + gp.PlayerID + "\"" + "\t" + "\"" + gp.ScenarioID + "\"" + "\t" + "\"" + gp.Timestamp + "\"" + "\t" + "\"" + gp.RT + "\"" + "\t" + "\"" + gp.Accuracy + "\"" + "\t" + "\"" + gp.PlayerRating + "\"" + "\t" + "\"" + gp.ScenarioRating + "\"";*/ line = "" + id++ + "\t" + gp.PlayerID + "\t" + gp.ScenarioID + "\t" + gp.RT + "\t" + gp.Accuracy + "\t" + Math.Round(gp.PlayerRating, 5) + "\t" + Math.Round(gp.ScenarioRating, 5); datafile.WriteLine(line); } } }
public static void doOneTwoThreeSim() { string adaptID = "Game difficulty - Player skill"; string gameID = "OneTwoThree"; // [SC] create Bridge instance MyBridge bridge = new MyBridge(); // [SC] instantiate the TwoA asset TwoA twoA = new TwoA(bridge); double distMean = 0.75; double distSD = 0.1; double lowerLimit = 0.5; double upperLimit = 1.0; twoA.SetTargetDistribution(distMean, distSD, lowerLimit, upperLimit); // [SC] a lis of player in order of gameplays in datafile List <DataRecord> dataRecordList = new List <DataRecord>(); // [SC] contains info about scenarios such as level and mirror group Dictionary <string, ScenarioData> scenarioDatabase = new Dictionary <string, ScenarioData>(); // [SC] load the data file Dictionary <int, PlayerData> playerDatabase = parseOneTwoThreeDatafile(twoA, adaptID, gameID, dataRecordList, scenarioDatabase); if (playerDatabase == null) { return; } int blockSize = 20; foreach (string mode in new string[] { "old", "new" }) { for (int blockIndex = 0; blockIndex < blockSize; blockIndex++) { int lastCounted = 0; int counter = 0; int counterInterval = 10000; // [SC] approach 1 /*foreach (DataRecord dataRecord in dataRecordList) { * int playerID = dataRecord.PlayerID; * * // [SC] decide which scenario this player should play * string scenarioID = twoA.TargetScenarioIDOld(adaptID, gameID, "" + playerID, true); * * // [SC] obtain response time and accuracy * PlayerData playerData = playerDatabase[playerID]; * ScenarioData scenarioData = playerData.GetScenario(scenarioID); * if (scenarioData == null) { // [SC] the player has not played the scenario * // [SC] use another scenario of similar set level * int setLevel = scenarioDatabase[scenarioID].SetLevel; * scenarioData = playerData.GetScenario(setLevel); // [TODO] possible error point * } * if (scenarioData == null) { * ScenarioData scenarioDataOverall = scenarioDatabase[scenarioID]; * twoA.UpdateRatings(adaptID, gameID, "" + playerID, scenarioID * , scenarioDataOverall.GetAvgRT(), scenarioDataOverall.GetAvgAccuracy(), false); * } * else { * ScenarioRecord scenarioRecord = scenarioData.GetRecord(); * twoA.UpdateRatings(adaptID, gameID, "" + playerID, scenarioID, scenarioRecord.RT, scenarioRecord.Accuracy, false); * } * * if (++counter - lastCounted == counterInterval) { * lastCounted = counter; * printMsg("" + counter); * } * }*/ // [SC] approach 2 foreach (DataRecord dataRecord in dataRecordList) { int playerID = dataRecord.PlayerID; // [SC] decide which scenario this player should play string scenarioID; if (mode.Equals("old")) { scenarioID = twoA.TargetScenarioIDOld(adaptID, gameID, "" + playerID, true); } else { scenarioID = twoA.TargetScenarioID(adaptID, gameID, "" + playerID); } // [SC] obtain response time and accuracy PlayerData playerData = playerDatabase[playerID]; ScenarioData scenarioData = playerData.GetScenario(scenarioID); ScenarioRecord scenarioRecord; if (scenarioData == null) // [SC] the player has not played the scenario // [SC] use a random record from all players of the scenario { ScenarioData scenarioDataOverall = scenarioDatabase[scenarioID]; scenarioRecord = scenarioDataOverall.GetRandomRecord(); } else { scenarioRecord = scenarioData.GetRecord(); } twoA.UpdateRatings(adaptID, gameID, "" + playerID, scenarioID, scenarioRecord.RT, scenarioRecord.Accuracy, false); if (++counter - lastCounted == counterInterval) { lastCounted = counter; printMsg("" + counter); } } // [SC] approach 3 /*foreach (DataRecord dataRecord in dataRecordList) { * //int playerID = dataRecord.PlayerID; * int playerID = dataRecordList[0].PlayerID; * * // [SC] decide which scenario this player should play * string scenarioID; * if (mode.Equals("old")) { * scenarioID = twoA.TargetScenarioIDOld(adaptID, gameID, "" + playerID, true); * } * else { * scenarioID = twoA.TargetScenarioID(adaptID, gameID, "" + playerID); * } * * ScenarioData scenarioDataOverall = scenarioDatabase[scenarioID]; * ScenarioRecord scenarioRecord = scenarioDataOverall.GetRandomRecord(); * twoA.UpdateRatings(adaptID, gameID, "" + playerID, scenarioID, scenarioRecord.RT, scenarioRecord.Accuracy, false); * * if (++counter - lastCounted == counterInterval) { * lastCounted = counter; * printMsg("" + counter); * } * }*/ // [SC] creating a file with final ratings using (StreamWriter ratingfile = new StreamWriter(Path.Combine(OneTwoThreeSimResultsPath, "ratings_" + mode + "_" + blockIndex + ".txt"))) { string line = "" + "\"ScenarioID\"" + "\t" + "\"Rating\"" + "\t" + "\"PlayCount\"" + "\t" + "\"Uncertainty\"" + "\t" + "\"MirrorID\"" + "\t" + "\"SetLevel\""; ratingfile.WriteLine(line); foreach (ScenarioData scenarioData in scenarioDatabase.Values) { ScenarioNode scenarioNode = twoA.Scenario(adaptID, gameID, scenarioData.ScenarioID); line = "" + "\"" + scenarioData.ScenarioID + "\"" + "\t" + "\"" + scenarioNode.Rating + "\"" + "\t" + "\"" + scenarioNode.PlayCount + "\"" + "\t" + "\"" + scenarioNode.Uncertainty + "\"" + "\t" + "\"" + scenarioData.MirrorID + "\"" + "\t" + "\"" + scenarioData.SetLevel + "\""; ratingfile.WriteLine(line); // [SC] reseting scenario data scenarioNode.Rating = 0.001; scenarioNode.PlayCount = 0; scenarioNode.KFactor = 0.0075; scenarioNode.Uncertainty = 1.0; scenarioNode.LastPlayed = "2012-12-31T11:59:59"; } } // [SC] creating a file with history of gameplays including player and scenario ratings using (StreamWriter datafile = new StreamWriter(Path.Combine(OneTwoThreeSimResultsPath, "gameplay_" + mode + "_" + blockIndex + ".txt"))) { GameplaysData gameplays = twoA.GameplaysData; TwoAAdaptation adaptNode = gameplays.Adaptation.First(p => p.AdaptationID.Equals(adaptID)); TwoAGame gameNode = adaptNode.Game.First(p => p.GameID.Equals(gameID)); string line = "" + "ID" + "\t" + "PlayerID" + "\t" + "ScenarioID" //+ "\t" + "Timestamp" + "\t" + "RT" + "\t" + "Accuracy" + "\t" + "PlayerRating" + "\t" + "ScenarioRating"; datafile.WriteLine(line); int id = 1; foreach (TwoAGameplay gp in gameNode.Gameplay) { /*line = "" + "\"" + id++ + "\"" + "\t" + "\"" + gp.PlayerID + "\"" + "\t" + "\"" + gp.ScenarioID + "\"" + "\t" + "\"" + gp.Timestamp + "\"" + "\t" + "\"" + gp.RT + "\"" + "\t" + "\"" + gp.Accuracy + "\"" + "\t" + "\"" + gp.PlayerRating + "\"" + "\t" + "\"" + gp.ScenarioRating + "\"";*/ line = "" + id++ + "\t" + gp.PlayerID + "\t" + gp.ScenarioID + "\t" + gp.RT + "\t" + gp.Accuracy + "\t" + Math.Round(gp.PlayerRating, 5) + "\t" + Math.Round(gp.ScenarioRating, 5); datafile.WriteLine(line); } // [SC] clearing all gameplay gameNode.Gameplay.Clear(); } // [SC] resetting player data List <PlayerNode> playerNodeList = twoA.AdaptationData.AdaptationList.First(p => p.AdaptationID.Equals(adaptID)).GameList.First(p => p.GameID.Equals(gameID)).PlayerData.PlayerList; foreach (PlayerNode playerNode in playerNodeList) { playerNode.Rating = 0.001; playerNode.PlayCount = 0; playerNode.KFactor = 0.0075; playerNode.Uncertainty = 1.0; playerNode.LastPlayed = "2012-12-31T11:59:59"; } } } }