Ejemplo n.º 1
0
        //-----------------------property-----------------------

        //-----------------------public変数-----------------------


        //-----------------------コンストラクタ-----------------------
        /// <summary>
        /// BebebeSolverコンストラクタ
        /// </summary>
        /// <param name="table"></param>
        public Solver_Random(GameTable table, int seed) : base(table)
        {
            Console.WriteLine("Solver Random コンストラクタ Seed:" + seed);
            this._Random = new Random(seed);
            Seed         = seed;

            MyTask = Task.Run(() => this.Solve(0));
        }         //End_Constructor
Ejemplo n.º 2
0
        }                                    //End_Constructor

        /// <summary>
        /// 計算用コンストラクタ
        /// </summary>
        /// <param name="table"></param>
        protected Solver_Abstract(GameTable table, Agent agent)
        {
            Console.WriteLine("Solver_Abstract コンストラクタ");
            //Agentを受け取る
            this.MyAgent = new Agent(agent);

            //Tableをコピーして受け取る
            this.CopyFromGameTable(table);

            //ResultAgentBehaviorにとりあえずstayを入れる
            this.ResultAgentsBehavior = new AgentBehavior(3, 0, 0);
        }         //End_Constructor
Ejemplo n.º 3
0
        }         //End_Destractor

        //-----------------------privateメソッド-----------------------
        /// <summary>
        /// コピーする
        /// </summary>
        /// <param name="gt"></param>
        protected void CopyFromGameTable(GameTable gt)
        {
            this.Table             = new GameTable();
            this.Table.ElapsedTurn = gt.ElapsedTurn;
            this.Table.FieldWidth  = gt.FieldWidth;
            this.Table.FieldHeight = gt.FieldHeight;
            this.Table.AgentNum    = gt.AgentNum;
            this.Table.Field       = new Tile[gt.FieldHeight][];
            for (int i = 0; i < gt.FieldHeight; ++i)
            {
                this.Table.Field[i] = new Tile[gt.FieldWidth];
                for (int j = 0; j < gt.FieldWidth; ++j)
                {
                    this.Table.Field[i][j] = new Tile(gt.Field[i][j].Point, gt.Field[i][j].TeamID);
                }         //End_For
            }             //End_For
            this.Table.MyTeam = new Team(gt.MyTeam);
            this.Table.OpTeam = new Team(gt.OpTeam);
        }         //End_Method
Ejemplo n.º 4
0
        }         //End_Method

        /// <summary>
        /// 現在の盤面情報を取得する
        /// </summary>
        /// <returns></returns>
        private static bool GetFieldInfo()
        {
            //すでに取得してたらなにもしない
            if (GameMaster.IsAlreadyGotFiledInfo)
            {
                Console.WriteLine("このターンはすでにフィールド情報を取得していますよ");
                return(false);
            }             //End_If
            bool flag;
            var  json = ComuSaba.GetFieldInformationEachTurn(out flag);

            //正常に取得できればフィールドを更新
            if (flag && json != "")
            {
                GameMaster.Table = JsonToMyFormat.FieldInfoToMyGameTable(json);
            }             //ガバ
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("フィールド情報取得失敗");
                Console.ForegroundColor = ConsoleColor.White;
            }     //End_IfElse
            return(flag);
        }         //End_Method
Ejemplo n.º 5
0
        }         //End_Method

        //-----------------------Public メソッド-----------------------
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="table"></param>
        public Solver_Kumano(GameTable table) : base(table)
        {
        }
Ejemplo n.º 6
0
        }         //End_Method

        /// <summary>
        /// 各ターン最初に受信するフィールド情報をGameTableクラスに反映
        /// </summary>
        /// <param name="json">サバから受信したJSONデータ</param>
        public static GameTable FieldInfoToMyGameTable(string json)
        {
            //受信したJSONデータを変換用クラスに変換
            var gt = new _GameTable();

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(json))) {
                var serializer = new DataContractJsonSerializer(typeof(_GameTable));
                gt = (_GameTable)serializer.ReadObject(stream);
            }             //End_Using

            //試合開始時間を更新
            GameMaster.StartedAtUnixTime = gt.StartedAtUnixTime * (long)1000;

            //return用変数
            var result = new GameTable();

            //各種変数を更新
            result.FieldWidth  = gt.Width;
            result.FieldHeight = gt.Height;
            result.AgentNum    = gt.Teams[0].Agents.Length;
            result.ElapsedTurn = gt.Turn;

            //盤面を作成
            result.Field = new Tile[gt.Height][];
            for (int y = 0; y < gt.Height; ++y)
            {
                result.Field[y] = new Tile[gt.Width];
                for (int x = 0; x < gt.Width; ++x)
                {
                    result.Field[y][x] = new Tile(gt.Points[y][x], gt.Tiled[y][x]);
                }         //End_For
            }             //End_For

            //自チームの状態を作成
            result.MyTeam = new Team();
            for (int i = 0; i < gt.Teams.Length; ++i)
            {
                if (gt.Teams[i].TeamID == GameMaster.MyTeamID)
                {
                    //ポイントを更新
                    result.MyTeam.TeamID    = gt.Teams[i].TeamID;
                    result.MyTeam.TilePoint = gt.Teams[i].TilePoint;
                    result.MyTeam.AreaPoint = gt.Teams[i].AreaPoint;
                    //エージェントを更新
                    result.MyTeam.Agents = new Agent[gt.Teams[i].Agents.Length];
                    for (int j = 0; j < gt.Teams[i].Agents.Length; ++j)
                    {
                        result.MyTeam.Agents[j] = new Agent(gt.Teams[i].Agents[j].AgentID, gt.Teams[i].Agents[j].X - 1, gt.Teams[i].Agents[j].Y - 1);
                        if (GameMaster.Table != null)
                        {
                            result.MyTeam.Agents[j].Solver = GameMaster.Table.MyTeam.Agents[j].Solver;
                        } //End_If
                    }     //End_For
                }         //End_If
            }             //End_For

            //相手チームの状態を作成
            result.OpTeam = new Team();
            for (int i = 0; i < gt.Teams.Length; ++i)
            {
                if (gt.Teams[i].TeamID != GameMaster.MyTeamID)
                {
                    //ポイントを更新
                    result.OpTeam.TeamID    = gt.Teams[i].TeamID;
                    result.OpTeam.TilePoint = gt.Teams[i].TilePoint;
                    result.OpTeam.AreaPoint = gt.Teams[i].AreaPoint;
                    //エージェントを更新
                    result.OpTeam.Agents = new Agent[gt.Teams[i].Agents.Length];
                    for (int j = 0; j < gt.Teams[i].Agents.Length; ++j)
                    {
                        result.OpTeam.Agents[j] = new Agent(gt.Teams[i].Agents[j].AgentID, gt.Teams[i].Agents[j].X, gt.Teams[i].Agents[j].Y);
                    }     //End_For
                }         //End_If
            }             //End_For

            //更新完了
            return(result);
        }         //End_Method
Ejemplo n.º 7
0
        }         //End_Constructor

        /// <summary>
        /// BebebeSolverコンストラクタ
        /// 読む手数を指定
        /// </summary>
        /// <param name="table"></param>
        /// <param name="depth"></param>
        public Solver_Bebebe(GameTable table, Agent agent, int depth) : base(table, agent)
        {
            this.Depth = depth;
            this.Init();
        }         //End_Constructor
Ejemplo n.º 8
0
        //-----------------------property-----------------------

        //-----------------------public変数-----------------------

        //-----------------------コンストラクタ-----------------------
        /// <summary>
        /// BebebeSolverコンストラクタ
        /// </summary>
        /// <param name="table"></param>
        public Solver_Bebebe(GameTable table, Agent agent) : base(table, agent)
        {
            this.Init();
        }         //End_Constructor