/// <summary> /// エージェントを動かしたときに、状態がどう変化するか計算します。 /// </summary> /// <param name="team">どのチームが動くか指定します。</param> /// <param name="agentNumber">どのエージェントが動くか指定します。</param> /// <param name="action">どうエージェントが動くか指定します。</param> /// <returns>エージェントを動かしたときの計算データが返ってきます。</returns> public Calc Simulate(Team team, AgentNumber agentNumber, AgentActivityData action) { var c = new Calc(this); c.MoveAgent(team, agentNumber, new AgentActivityData(action)); return(c); }
/// <summary> /// エージェントを動かしたときに、状態がどう変化するか計算します。 /// </summary> /// <param name="action">どうエージェントが動くか指定します。</param> /// <returns>エージェントを動かしたときの計算データが返ってきます。</returns> public Calc Simulate(AgentsActivityData action) { var c = new Calc(this); c.MoveAgent(new AgentsActivityData(action)); return(c); }
/// <summary> /// エージェントを動かしたときに、状態がどう変化するか計算します。 /// </summary> /// <param name="team">どのチームが動くか指定します。</param> /// <param name="action">どうエージェントが動くか指定します。</param> /// <returns>エージェントを動かしたときの計算データが返ってきます。</returns> public Calc Simulate(Team team, AgentActivityData[] action) { var c = new Calc(this); c.MoveAgent(team, new AgentActivityData[2] { new AgentActivityData(action[0]), new AgentActivityData(action[1]) }); return(c); }
private Task Run(CancellationToken cancellationToken) { var log = new Logger(new RichTextBox()); var tasks = new List <Task>(); var random = new Random(); return(Task.Run(() => { var id = FieldGenerator.GetRandomID(random.Next()); var field_generator = new FieldGenerator(id); var field = field_generator.Generate(); var agents = new Agents(); var coordinates = field_generator.AgentPositionGenerate(field); var bot = new dynamic[2]; if (Bot[(int)Team.A].AssemblyName.Name != "Human") { Assembly m = Assembly.LoadFrom(Bot[(int)Team.A].Path); MatchCollection mc = Regex.Matches(Bot[(int)Team.A].Path, @"^[A-Z]:\\(.*\\)+(?<file>.*).dll$"); foreach (Match match in mc) { bot[(int)Team.A] = Activator.CreateInstance(m.GetType("nitkagoshima_sysken.Procon29." + match.Groups["file"].Value + "." + match.Groups["file"].Value)); } } if (Bot[(int)Team.B].AssemblyName.Name != "Human") { Assembly m = Assembly.LoadFrom(Bot[(int)Team.B].Path); MatchCollection mc = Regex.Matches(Bot[(int)Team.B].Path, @"^[A-Z]:\\(.*\\)+(?<file>.*).dll$"); foreach (Match match in mc) { bot[(int)Team.B] = Activator.CreateInstance(m.GetType("nitkagoshima_sysken.Procon29." + match.Groups["file"].Value + "." + match.Groups["file"].Value)); } } agents[Team.A, AgentNumber.One].Position = coordinates[0]; agents[Team.A, AgentNumber.Two].Position = coordinates[1]; agents[Team.B, AgentNumber.One].Position = new Coordinate(MainForm.ComplementEnemysPosition(field, coordinates[0])); agents[Team.B, AgentNumber.Two].Position = new Coordinate(MainForm.ComplementEnemysPosition(field, coordinates[1])); var calc = new Calc(MainForm.MaxTurn, field, agents); Invoke( new add_delegate(Add), id, calc.Turn, calc.Field.Sum(cell => cell.Point), calc.Field.TotalPoint(Team.A), calc.Field.TotalPoint(Team.B), ((double)calc.Field.Count(cell => cell.IsTileOn[Team.A]) / calc.Field.Count()).ToString("P"), ((double)calc.Field.Count(cell => cell.IsTileOn[Team.B]) / calc.Field.Count()).ToString("P")); while (calc.Turn < calc.MaxTurn) { var action = new AgentsActivityData(); if (bot[0] != null) { dynamic answer; lock (bot[0]) { bot[0].OurTeam = Team.A; bot[0].Log = log; bot[0].Question(new Calc(calc)); answer = bot[0].Answer(); } action[Team.A, AgentNumber.One] = answer[0]; action[Team.A, AgentNumber.Two] = answer[1]; } if (bot[1] != null) { dynamic answer; lock (bot[1]) { bot[1].OurTeam = Team.B; bot[1].Log = log; bot[1].Question(new Calc(calc)); answer = bot[1].Answer(); } action[Team.B, AgentNumber.One] = answer[0]; action[Team.B, AgentNumber.Two] = answer[1]; } if (cancellationToken.IsCancellationRequested) { Console.WriteLine("Canceled!"); return "Canceled"; } calc.MoveAgent(action); Invoke( new edit_delegate(Edit), id, calc.Turn, calc.Field.Sum(cell => cell.Point), calc.Field.TotalPoint(Team.A), calc.Field.TotalPoint(Team.B), ((double)calc.Field.Count(cell => cell.IsTileOn[Team.A]) / calc.Field.Count()).ToString("P"), ((double)calc.Field.Count(cell => cell.IsTileOn[Team.B]) / calc.Field.Count()).ToString("P")); } Invoke(new end_delegate(End), id); return "Succeed"; })); }