/// <summary> /// Samples the specified inputs. /// </summary> /// <param name="performanceVariance">The performance variance.</param> /// <param name="playerIndices">The player indices.</param> /// <param name="truth">The truth.</param> /// <param name="startIndex">The start index.</param> /// <returns> /// The <see cref="GameCollection" />. /// </returns> public static GameCollection Sample(double performanceVariance, int[][] playerIndices, Marginals truth, int startIndex = 0) { // var random = new Random(0); var players = truth.Skills.Keys.ToArray(); var games = new GameCollection(ia => ia.Id); int count = playerIndices.Length; for (int i = 0; i < count; i++) { // Because this model relies on the fact that the game scores are provided in descending order, // we need to randomise the player order var randomIndices = playerIndices[i].OrderBy(ia => Guid.NewGuid()).ToArray(); // Skills var skills = playerIndices[i].Select(ia => truth.Skills[players[ia]].Point).ToArray(); // Sample peformances to get scores var scores = skills.Select(ia => new Gaussian(ia, performanceVariance).Sample()).ToArray(); var game = new MultiPlayerGame { Id = (startIndex + i + 1).ToString("D") }; for (int j = 0; j < playerIndices[i].Length; j++) { // game.Teams.Add(new Team { Players = new[] { players[randomIndices[j]] }, Score = (int)scores[j] }); game.Players.Add(players[randomIndices[j]]); game.Scores.Add((int)scores[j]); } games.Add(game); } return(games); }
/// <summary> /// tojson /// </summary> /// <param name="multiPlayerGame">multi game</param> /// <param name="direction">direction to move</param> /// <returns></returns> public string ToJson(MultiPlayerGame multiPlayerGame, string direction) { dynamic playJson = new JObject(); playJson.Name = multiPlayerGame.getMaze().Name; playJson.Direction = direction; return(playJson.ToString()); }
/// <summary> /// implement execute /// </summary> /// <param name="args">args of action</param> /// <param name="client">client</param> /// <returns></returns> public string Execute(string[] args, TcpClient client) { string move = args[0]; MultiPlayerGame multiPlayerGame = model.playGame(client); NetworkStream stream = multiPlayerGame.getOtherClient(client).GetStream(); StreamWriter writer = new StreamWriter(stream); writer.WriteLine(ToJson(multiPlayerGame, move)); writer.Flush(); return(null); }
/// <summary> /// implement execute /// </summary> /// <param name="args">args of command</param> /// <param name="client">client</param> /// <returns></returns> public string Execute(string[] args, TcpClient client) { //send message for the two clients to close string name = args[0]; MultiPlayerGame gameToClose = model.closeGame(client, name); NetworkStream stream = gameToClose.getOtherClient(client).GetStream(); StreamReader reader = new StreamReader(stream); StreamWriter writer = new StreamWriter(stream); writer.WriteLine(ToJson(name)); NetworkStream stream1 = client.GetStream(); StreamReader reader1 = new StreamReader(stream1); StreamWriter writer1 = new StreamWriter(stream1); writer1.WriteLine(ToJson(name)); writer1.Flush(); writer.Flush(); return("close command actviated..."); }