Пример #1
0
 /// <summary>
 /// TurnDataを初期化します。
 /// </summary>
 public TurnData(TurnData turnData)
 {
     Agents             = new Agents(turnData.Agents);
     AgentsActivityData = new AgentsActivityData(turnData.AgentsActivityData);
     Field = new Field(turnData.Field.Width, turnData.Field.Height);
     for (int x = 0; x < Field.Width; x++)
     {
         for (int y = 0; y < Field.Height; y++)
         {
             Field[x, y] = new Cell(turnData.Field[x, y]);
         }
     }
 }
        /// <summary>
        /// Calcを初期化します。
        /// </summary>
        /// <param name="turn">最大ターン数を設定します。</param>
        /// <param name="field">フィールドのポイントを設定します。</param>
        /// <param name="agents">エージェントを設定します。</param>
        public Calc(int turn, Field field, Agents agents)
        {
            MaxTurn = turn;

            // TurnData作成
            History.Add(new TurnData(new Field(field.Width, field.Height), new Agents()));
            Field  = field;
            Agents = agents;
            foreach (var agent in Agents)
            {
                PutTile(team: agent.Team, agent: agent.AgentNumber);
            }
        }
Пример #3
0
 /// <summary>
 /// XML化するために宣言します
 /// </summary>
 /// <param name="xmlTurnData">対象のXmlTurnData</param>
 public TurnData(XmlTurnData xmlTurnData)
 {
     Agents = new Agents();
     for (int i = 0; i < 4; i++)
     {
         Agents[(Team)(i / 2), (AgentNumber)(i % 2)] = xmlTurnData.Agents[i];
     }
     AgentsActivityData = xmlTurnData.AgentActivityDatas;
     Field = new Field(xmlTurnData.Width, xmlTurnData.Height);
     for (int x = 0; x < xmlTurnData.Width; x++)
     {
         for (int y = 0; y < xmlTurnData.Height; y++)
         {
             Field[x, y] = new Cell(xmlTurnData.Field[y * xmlTurnData.Width + x]);
         }
     }
 }
 /// <summary>
 /// ターンエンドします。
 /// </summary>
 public void TurnEnd()
 {
     if (Turn < MaxTurn)
     {
         // TurnData作成
         var a = new Agents();
         for (Team team = 0; (int)team < Enum.GetValues(typeof(Team)).Length; team++)
         {
             for (AgentNumber agent = 0; (int)agent < Enum.GetValues(typeof(AgentNumber)).Length; agent++)
             {
                 a[team, agent] = new Agent(Agents[team, agent]);
             }
         }
         History.Add(new TurnData(new Field(Field), a));
         Turn++;
     }
 }
Пример #5
0
 /// <summary>
 /// 初期化します
 /// </summary>
 /// <param name="field">フィールドを表します</param>
 /// <param name="agents">エージェントたちを表します</param>
 public TurnData(Field field, Agents agents)
 {
     Field              = field;
     Agents             = agents;
     AgentsActivityData = new AgentsActivityData();
 }
Пример #6
0
 /// <summary>
 /// 初期化します
 /// </summary>
 /// <param name="field">フィールドを表します</param>
 /// <param name="agents">エージェントたちを表します</param>
 /// <param name="agentActivityDatas">エージェントの行動データを表します</param>
 public TurnData(Field field, Agents agents, AgentsActivityData agentActivityDatas)
 {
     Field              = field;
     Agents             = agents;
     AgentsActivityData = agentActivityDatas;
 }
Пример #7
0
        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";
            }));
        }