示例#1
0
        //Meが動くとする。「Meのスコア - Enemyのスコア」の最大値を返す。
        private int NegaMax(int deepness, SearchState state, int alpha, int beta, int count, PointEvaluator.Base evaluator)
        {
            if (deepness == 0)
            {
                return(evaluator.Calculate(ScoreBoard, state.MeBoard, 0) - evaluator.Calculate(ScoreBoard, state.EnemyBoard, 0));
            }

            Ways ways = state.MakeMoves(WayEnumerator);

            SortMoves(ScoreBoard, state, ways, count);

            for (int i = 0; i < ways.Count; i++)
            {
                if (CancellationToken.IsCancellationRequested == true)
                {
                    return(alpha);
                }                                                                                           //何を返しても良いのでとにかく返す
                SearchState backup = state;
                state.Move(ways[i].Agent1Way, ways[i].Agent2Way);
                int res = -NegaMax(deepness - 1, state, -beta, -alpha, count + 1, evaluator);
                if (alpha < res)
                {
                    alpha = res;
                    dp[count].UpdateScore(alpha, ways[i].Agent1Way, ways[i].Agent2Way);
                    if (alpha >= beta)
                    {
                        return(beta);                                   //βcut
                    }
                }
                state = backup;
            }
            ways.Erase();
            WaysPool.Return(ways);
            return(alpha);
        }
示例#2
0
        //遷移順を決める.  「この関数においては」MeBoard…手番プレイヤのボード, Me…手番プレイヤ、とします。
        //引数: stateは手番プレイヤが手を打つ前の探索状態、(way1[i], way2[i])はi番目の合法手(移動量)です。
        //以下のルールで優先順を決めます.
        //ルール1. Killer手(優先したい手)があれば、それを優先する
        //ルール2. 次のmoveで得られる「タイルポイント」の合計値が大きい移動(の組み合わせ)を優先する。
        //ルール2では, タイル除去によっても「タイルポイント」が得られるとして計算する。
        private void SortMoves(sbyte[,] ScoreBoard, SearchState state, Ways way, int deep)
        {
            var Killer = dp[deep].Score == int.MinValue ? new Player(new Point(114, 514), new Point(114, 514)) : new Player(state.Me.Agent1 + dp[deep].Agent1Way, state.Me.Agent2 + dp[deep].Agent2Way);

            for (int i = 0; i < way.Count; i++)
            {
                int   score = 0;
                Point next1 = state.Me.Agent1 + way[i].Agent1Way;
                Point next2 = state.Me.Agent2 + way[i].Agent2Way;

                if (Killer.Agent1 == next1 && Killer.Agent2 == next2)
                {
                    score = 100;
                }

                if (state.EnemyBoard[next1])
                {
                    score += ScoreBoard[next1.X, next1.Y];
                }                                                                           //タイル除去によって有利になる
                else if (!state.MeBoard[next1])
                {
                    score += ScoreBoard[next1.X, next1.Y];
                }                                                                           //移動でMeの陣地が増えて有利になる
                if (state.EnemyBoard[next2])
                {
                    score += ScoreBoard[next2.X, next2.Y];
                }
                else if (!state.MeBoard[next2])
                {
                    score += ScoreBoard[next2.X, next2.Y];
                }
                way[i].Point = score;
            }
            way.Sort();
        }
示例#3
0
        public string GetRowString(int i = 0)
        {
            var maxWayLength = Ways.Max(way => WayToString(way).Length) + 2;

            return(string.Format("| {0, -5} | {1, " + -maxWayLength + "} | {2, -6} | {3, -6} |", i + 1,
                                 WayToString(Ways[i]), Sums[i], Budgets[i]));
        }
示例#4
0
        public void PrintTable()
        {
            var maxWayLength = Ways.Max(way => WayToString(way).Length) + 2;

            Console.WriteLine();
            PrintBr();
            Console.WriteLine(string.Format("| {0, -5} | {1, " + -maxWayLength + "} | {2, -6} | {3, -6} |", "Index",
                                            "Way", "Cost", "Budget"));
            PrintBr();
            for (var i = 0; i < Ways.Count; i++)
            {
                if (i == IndexCrit)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(GetRowString(i));
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Console.WriteLine(GetRowString(i));
                }

                PrintBr();
            }
        }
示例#5
0
        //Meが動くとする。「Meのスコア - Enemyのスコア」の最大値を返す。
        private int NegaMax(int deepness, SearchState state, int alpha, int beta, int count, PointEvaluator.Base evaluator, Decided ngMove, int greedyDepth)
        {
            if (deepness == 0)
            {
                for (int j = 0; j < greedyDepth; j++)
                {
                    Way move = state.MakeGreedyMove(ScoreBoard, WayEnumerator);
                    state.Move(move.Agent1Way, move.Agent2Way);
                    //Ways moves = state.MakeMoves(WayEnumerator);
                    //SortMoves(ScoreBoard, state, moves, 49, null);
                    //state.Move(moves[0].Agent1Way, moves[1].Agent2Way);
                }
                int score = evaluator.Calculate(ScoreBoard, state.MeBoard, 0) - evaluator.Calculate(ScoreBoard, state.EnemyBoard, 0);
                if (greedyDepth % 2 == 1)
                {
                    return(-score);
                }
                return(score);
            }

            Ways ways = state.MakeMoves(WayEnumerator);

            SortMoves(ScoreBoard, state, ways, count, ngMove);

            for (int i = 0; i < ways.Count; i++)
            {
                if (CancellationToken.IsCancellationRequested == true)
                {
                    return(alpha);
                }                                                                           //何を返しても良いのでとにかく返す
                //if (count == 0 && !(ngMove is null) && new Decided(ways[i].Agent1Way, ways[i].Agent2Way).Equals(ngMove)) { continue; }	//競合手を避ける場合
                if (count == 0 && !(ngMove is null) && (ways[i].Agent1Way.Equals(ngMove.MeAgent1) || ways[i].Agent2Way.Equals(ngMove.MeAgent2)))
                {
                    continue;
                }                                                                                                                                                 //2人とも競合手とは違う手を指す

                SearchState nextState = state;
                nextState.Move(ways[i].Agent1Way, ways[i].Agent2Way);
                int res = -NegaMax(deepness - 1, nextState, -beta, -alpha, count + 1, evaluator, ngMove, greedyDepth);
                if (alpha < res)
                {
                    alpha = res;
                    if (ngMove is null)
                    {
                        dp1[count].UpdateScore(alpha, ways[i].Agent1Way, ways[i].Agent2Way);
                    }
                    else
                    {
                        dp2[count].UpdateScore(alpha, ways[i].Agent1Way, ways[i].Agent2Way);
                    }
                    if (alpha >= beta)
                    {
                        return(beta);               //βcut
                    }
                }
            }
            ways.Erase();
            WaysPool.Return(ways);
            return(alpha);
        }
示例#6
0
        //Meが動くとする。「Meのスコア - Enemyのスコア」の最大値を返す。
        //NegaMaxではない
        private int NegaMax(int deepness, SearchState state, int alpha, int count, PointEvaluator.Base evaluator, Decision ngMove, Unsafe8Array <Way> nextways, int nowAgent)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            if (deepness == 0)
            {
                return(evaluator.Calculate(ScoreBoard, state.MeBoard, 0, state.Me, state.Enemy) - evaluator.Calculate(ScoreBoard, state.EnemyBoard, 0, state.Enemy, state.Me));
            }

            Ways ways = state.MakeMoves(AgentsCount, ScoreBoard);

            int i = 0;

            foreach (var way in ways.Data[nowAgent])
            {
                if (CancellationToken.IsCancellationRequested == true)
                {
                    return(alpha);
                }                                                                           //何を返しても良いのでとにかく返す
                if (way.Direction == new VelocityPoint())
                {
                    continue;
                }
                i++;

                int j = 0;
                for (j = 0; j < nowAgent; ++j)
                {
                    if (dp[0].Ways[j].Locate == way.Locate)
                    {
                        break;
                    }
                }
                if (j != nowAgent)
                {
                    continue;
                }

                Unsafe8Array <Way> newways = new Unsafe8Array <Way>();
                newways[nowAgent] = way;
                SearchState backup = state;
                state = state.GetNextState(AgentsCount, newways);

                int res = NegaMax(deepness - 1, state, alpha, count + 1, evaluator, ngMove, nextways, nowAgent);
                if (alpha < res)
                {
                    nextways[nowAgent] = way;
                    alpha = res;
                    dp[count].UpdateScore(alpha, nextways);
                }

                state = backup;
            }

            sw.Stop();
            //Log("NODES : {0} nodes, elasped {1} ", i, sw.Elapsed);
            ways.End();
            return(alpha);
        }
示例#7
0
        /// <summary>
        /// Returns the the way with the given id
        /// </summary>
        /// <param name="id">The id to use for lookup</param>
        /// <returns>The way if it exists in the collection, null otherwise</returns>
        public Way GetWay(long id)
        {
            Way way = null;

            Ways.TryGetValue(id, out way);

            return(way);
        }
示例#8
0
        public Geometry ToThick()
        {
            var nodeLookup = Nodes.ToDictionary(n => n.Id, n => n.ToThick());
            var wayLookup  = Ways.ToDictionary(w => w.Id, w => w.ToThick(nodeLookup));
            var relations  = Relations.Select(r => r.ToThick(wayLookup));

            return(new Geometry(nodeLookup.Values.ToArray(), wayLookup.Values.ToArray(), relations.ToArray()));
        }
示例#9
0
 public ThinRelation ToThin()
 {
     return(new ThinRelation
     {
         Id = Id,
         Ways = Ways.Select(w => w.Id).ToArray(),
         Tags = Tags.Count == 0 ? null : Tags
     });
 }
示例#10
0
 public ThinGeometry ToThin()
 {
     return(new ThinGeometry
     {
         Nodes = Nodes.Select(n => n.ToThin()).ToArray(),
         Ways = Ways.Select(w => w.ToThin()).ToArray(),
         Relations = Relations.Select(r => r.ToThin()).ToArray()
     });
 }
示例#11
0
        public Connection(Ways way, GameObject objectA, GameObject objectB)
        {
            this.Way     = way;
            this.ObjectA = objectA;
            this.ObjectB = objectB;

            this.PositionA = objectA.transform.position;
            this.PositionB = objectB.transform.position;
        }
示例#12
0
        /// <summary>
        /// Initializes the OsmGeoCollection object
        /// </summary>
        public override void Initialize()
        {
            _node_enumerator     = Nodes.GetEnumerator();
            _way_enumerator      = Ways.GetEnumerator();
            _relation_enumerator = Relations.GetEnumerator();

            _node_enumerator.Reset();
            _way_enumerator.Reset();
            _relation_enumerator.Reset();

            _current = null;
        }
示例#13
0
    public void createWay()
    {
        for (int i = 0; i < ways.Count; i++)
        {
            GameObject go  = gameObject.transform.GetChild(i).gameObject;
            Ways       way = ways[i];

            go.GetComponent <WaysUI_Intro>().setWayModel(way);
            go.GetComponent <WaysUI_Intro>().createUI();
            go.SetActive(true);
        }
    }
示例#14
0
        protected void _PreprocBoardItems()
        {
            _AddNewBoard();
            ResetCurrentBoard();

            _ways = new Ways();
            _used = new bool[_board.rows, _board.columns];

            _sortedItems = _GetSortedElements(_board);
            _currentItem = 0;
            _currentEdge = -1;
        }
示例#15
0
        //遷移順を決める.  「この関数においては」MeBoard…手番プレイヤのボード, Me…手番プレイヤ、とします。
        //引数: stateは手番プレイヤが手を打つ前の探索状態、(way1[i], way2[i])はi番目の合法手(移動量)です。
        //以下のルールで優先順を決めます.
        //ルール1. Killer手(優先したい手)があれば、それを優先する
        //ルール2. 次のmoveで得られる「タイルポイント」の合計値が大きい移動(の組み合わせ)を優先する。
        //ルール2では, タイル除去によっても「タイルポイント」が得られるとして計算する。
        private void SortMoves(sbyte[,] ScoreBoard, SearchState state, Ways way, int deep, Decision ngMove)
        {
            Unsafe8Array <Point> Killer;

            DP[] dp = ngMove is null ? dp1 : dp2;
            if (dp[deep].Score == int.MinValue)
            {
                Killer = Unsafe8Array <Point> .Create(new Point(114, 191), new Point(114, 191), new Point(114, 191), new Point(114, 191), new Point(114, 191), new Point(114, 191), new Point(114, 191), new Point(114, 191));
            }
            else
            {
                Killer = new Unsafe8Array <Point>();
                for (int i = 0; i < AgentsCount; ++i)
                {
                    Killer[i] = state.Me[i] + dp[deep].AgentsWay[i];
                }
            }

            for (int i = 0; i < way.Count; i++)
            {
                int score = 0;
                Unsafe8Array <Point> nexts = new Unsafe8Array <Point>();
                for (int n = 0; n < AgentsCount; ++i)
                {
                    nexts[n] = state.Me[n] + way[i].AgentWays[n];
                }

                if (Killer.Agent1 == next1 && Killer.Agent2 == next2)
                {
                    score = 100;
                }

                if (state.EnemyBoard[next1])
                {
                    score += ScoreBoard[next1.X, next1.Y];
                }                                                                           //タイル除去によって有利になる
                else if (!state.MeBoard[next1])
                {
                    score += ScoreBoard[next1.X, next1.Y];
                }                                                                           //移動でMeの陣地が増えて有利になる
                if (state.EnemyBoard[next2])
                {
                    score += ScoreBoard[next2.X, next2.Y];
                }
                else if (!state.MeBoard[next2])
                {
                    score += ScoreBoard[next2.X, next2.Y];
                }
                way[i].Point = score;
            }
            way.Sort();
        }
示例#16
0
        //Meが動くとする。「Meのスコア - Enemyのスコア」の最大値を返す。
        private int NegaMax(int deepness, SearchState state, int alpha, int beta, int count, PointEvaluator.Base evaluator, int greedyDepth)
        {
            if (deepness == 0)
            {
                //深さgreedyDepth分だけ貪欲をしてから、評価関数を呼び出す
                for (int i = 0; i < greedyDepth; i++)
                {
                    Ways moves = state.MakeMoves(WayEnumerator);
                    SortMoves(ScoreBoard, state, moves, dp.Length - 1);
                    state.Move(moves[0].Agent1Way, moves[0].Agent2Way);
                }
                int eval = evaluator.Calculate(ScoreBoard, state.MeBoard, 0) - evaluator.Calculate(ScoreBoard, state.EnemyBoard, 0);
                if (greedyDepth % 2 == 1)
                {
                    return(-eval);
                }
                return(eval);
            }

            Ways ways = state.MakeMoves(WayEnumerator);

            SortMoves(ScoreBoard, state, ways, count);

            for (int i = 0; i < ways.Count; i++)
            {
                if (CancellationToken.IsCancellationRequested == true)
                {
                    return(alpha);
                }                                                                           //何を返しても良いのでとにかく返す
                if (count == 0 && ngMove != null && new Decided(ways[i].Agent1Way, ways[i].Agent2Way).Equals(ngMove) == true)
                {
                    continue;
                }                                                                                                                                               //競合手は指さない

                SearchState backup = state;
                state.Move(ways[i].Agent1Way, ways[i].Agent2Way);
                int res = -NegaMax(deepness - 1, state, -beta, -alpha, count + 1, evaluator, greedyDepth);
                if (alpha < res)
                {
                    alpha = res;
                    dp[count].UpdateScore(alpha, ways[i].Agent1Way, ways[i].Agent2Way);
                    if (alpha >= beta)
                    {
                        return(beta);               //βcut
                    }
                }
                state = backup;
            }
            ways.Erase();
            WaysPool.Return(ways);
            return(alpha);
        }
示例#17
0
    static void Main(string[] args)
    {
        // 注册序列化类型
        PKG.AllTypes.Register();

        // 填充 ways
        Ways.Fill();

        // 填充 frames, fishFrames
        SpriteFrames.Fill();

        // 创建配置实例
        var cfg = new PKG.CatchFish.Configs.Config();

        cfg.cannons     = new xx.List <PKG.CatchFish.Configs.Cannon>();
        cfg.fishs       = new xx.List <PKG.CatchFish.Configs.Fish>();
        cfg.sitPositons = new xx.List <xx.Pos>();
        cfg.stages      = new xx.List <PKG.CatchFish.Stages.Stage>();
        cfg.fixedWays   = new xx.List <PKG.CatchFish.Way>();
        cfg.weapons     = new xx.List <PKG.CatchFish.Configs.Weapon>();

        // 基于 1280 x 720 的设计尺寸
        cfg.sitPositons.Add(new xx.Pos {
            x = -250, y = -335
        });
        cfg.sitPositons.Add(new xx.Pos {
            x = 250, y = -335
        });
        cfg.sitPositons.Add(new xx.Pos {
            x = 250, y = 335
        });
        cfg.sitPositons.Add(new xx.Pos {
            x = -250, y = 335
        });
        cfg.aimTouchRadius          = 20;
        cfg.normalFishMaxRadius     = 150;
        cfg.enableBulletFastForward = false;

        // 有前后依赖
        Cannons.Fill(cfg);
        Weapons.Fill(cfg);
        Fishs.Fill(cfg);
        Stages.Fill(cfg);

        // cfg 序列化存盘
        var bb = new xx.BBuffer();

        bb.WriteRoot(cfg);
        File.WriteAllBytes(Path.Combine(outputPath, "cfg.bin"), bb.DumpData());
        bb.ReadRoot(ref cfg);   // test read
    }
示例#18
0
    public Tiles[] ControllStraightTiles(Ways way, int size, bool Bi_direction = false)
    {
        if (Bi_direction == true)
        {
            Tiles[] BI_result = new Tiles[size * 2];
            BI_result = SumTiles(SearchTiles(null, way, size), SearchTiles(null, ((int)way > 2) ? way - 3 : way + 3, size));
            return(BI_result);
        }

        Tiles[] result = new Tiles[size];

        result = SearchTiles(null, way, size);
        return(result);
    }
示例#19
0
    Tiles[] SearchTiles(Tiles[] Searched, Ways way, int size)
    {
        if (size == 0)
        {
            return(null);
        }

        Debug.Log(size.ToString());

        if (ArroundTiles[(int)way] == this)
        {
            return(ArroundTiles[(int)way].SearchTiles(Searched, way, 0) + this);
        }

        return(ArroundTiles[(int)way].SearchTiles(Searched, way, size - 1) + this);
    }
示例#20
0
    public void readJson()
    {
        ways = new List <Ways>();
        string levelPath = string.Format("Package_999/level_1");

        TextAsset file       = Resources.Load(levelPath) as TextAsset;
        string    dataAsJson = file.ToString();

        string[] jsonObjects = dataAsJson.Trim().Split(new char[] { '=' });

        for (int i = 0; i < jsonObjects.Length; i++)
        {
            Ways way = JsonUtility.FromJson <Ways>(jsonObjects[i]);
            ways.Add(way);
        }
    }
示例#21
0
        public ICollection <Way> RemoveEndRoads()
        {
            var endRoads = new HashSet <Way>();

            var e = GetEdges().Where(a => a.Value.Count < 2).Select(a => a.Key).ToList();

            foreach (var way in Ways.ToList())
            {
                if (e.Contains(way.Start) || e.Contains(way.End))
                {
                    endRoads.Add(way);
                    Ways.Remove(way);
                }
            }

            return(endRoads);
        }
示例#22
0
文件: Registro.cs 项目: Cdrix/SM
 //will add an new building to it list dependeing on catefory
 void AddSpecToList(Ca cat)
 {
     if (cat == Ca.Way)
     {
         Way f = BuildingPot.Control.CurrentSpawnBuild as Way;
         f = (Way)CheckIfOnDict(_ways, f);
         Ways.Add(f.MyId, f);
     }
     else if (cat == Ca.Structure || cat == Ca.Shore)
     {
         Structure f = BuildingPot.Control.CurrentSpawnBuild as Structure;
         f = (Structure)CheckIfOnDict(Structures, f);
         Structures.Add(f.MyId, f);
     }
     else if (cat == Ca.DraggableSquare)
     {
         DragSquare f = BuildingPot.Control.CurrentSpawnBuild as DragSquare;
         f = (DragSquare)CheckIfOnDict(DragSquares, f);
         DragSquares.Add(f.MyId, f);
     }
 }
示例#23
0
        //Meが動くとする。「Meのスコア - Enemyのスコア」の最大値を返す。
        private int NegaMax(int deepness, SearchState state, int alpha, int beta, int count, PointEvaluator.Base evaluator)
        {
            var sw = System.Diagnostics.Stopwatch.StartNew();

            if (deepness == 0)
            {
                return(evaluator.Calculate(ScoreBoard, state.MeBoard, 0, state.Me, state.Enemy) - evaluator.Calculate(ScoreBoard, state.EnemyBoard, 0, state.Enemy, state.Me));
            }

            Ways ways = state.MakeMoves(AgentsCount, ScoreBoard);

            int i = 0;

            foreach (var way in ways.GetEnumerator(AgentsCount))
            {
                i++;
                if (CancellationToken.IsCancellationRequested == true)
                {
                    return(alpha);
                }                                                                                           //何を返しても良いのでとにかく返す
                SearchState backup = state;
                state = state.GetNextState(AgentsCount, way);
                state = state.ChangeTurn();
                int res = -NegaMax(deepness - 1, state, -beta, -alpha, count + 1, evaluator);
                if (alpha < res)
                {
                    alpha = res;
                    dp[count].UpdateScore(alpha, way);
                    if (alpha >= beta)
                    {
                        return(beta);                                   //βcut
                    }
                }
                state = backup;
            }
            sw.Stop();
            Log("NODES : {0} nodes, elasped {1} ", i, sw.Elapsed);
            ways.End();
            return(alpha);
        }
示例#24
0
        public ICollection <Way> RemoveDeadNodes()
        {
            var edges    = GetEdges();
            var deadWays = new HashSet <Way>();

            var visited = new HashSet <long>();
            var queue   = new Queue <long>();

            queue.Enqueue(Ways.First().Start);

            while (queue.Any())
            {
                var node = queue.Dequeue();
                foreach (var neighbour in edges[node])
                {
                    if (visited.Contains(neighbour))
                    {
                        continue;
                    }

                    visited.Add(neighbour);
                    queue.Enqueue(neighbour);
                }
            }

            foreach (var way in Ways.ToList())
            {
                if (visited.Contains(way.Start))
                {
                    continue;
                }

                Ways.Remove(way);
                deadWays.Add(way);
            }

            return(deadWays);
        }
示例#25
0
        private void GetWays(int curr)
        {
            var nextAbove = -1;

            for (var i = curr + 1; i < Coordinates.Count; ++i)
            {
                if (nextAbove == -1)
                {
                    nextAbove = i;
                }
                else
                {
                    Ways.Add(Coordinates[i]);
                    Ways.Add(Coordinates[curr]);
                }
            }

            if (nextAbove != -1)
            {
                Ways.Add(Coordinates[nextAbove]);
                GetWays(nextAbove);
                Ways.Add(Coordinates[curr]);
            }
        }
示例#26
0
        //Meが動くとする。「Meのタイルポイント - Enemyのタイルポイント」の最大値を返す。
        private int NegaMax(int deepness, SearchState state, int alpha, int beta, int count, int tilePoint)
        {
            if (deepness == 0)
            {
                return(tilePoint);
            }

            VelocityPoint[] WayEnumerator = CurrentTurn * 2 + deepness <= 50 ? WayEnumerator1 : WayEnumerator2;
            Ways            ways          = state.MakeMoves(WayEnumerator);

            SortMoves(ScoreBoard, state, ways, count);

            for (int i = 0; i < ways.Count; i++)
            {
                if (CancellationToken.IsCancellationRequested == true)
                {
                    return(alpha);
                }                                                                                           //何を返しても良いのでとにかく返す
                SearchState backup = state;
                state.Move(ways[i].Agent1Way, ways[i].Agent2Way);
                int res = -NegaMax(deepness - 1, state, -beta, -alpha, count + 1, -(tilePoint + ways[i].Point));
                if (alpha < res)
                {
                    alpha = res;
                    dp[count].UpdateScore(alpha, ways[i].Agent1Way, ways[i].Agent2Way);
                    if (alpha >= beta)
                    {
                        return(beta);                                   //βcut
                    }
                }
                state = backup;
            }
            ways.Erase();
            WaysPool.Return(ways);
            return(alpha);
        }
示例#27
0
        //Meが動くとする。「Meのスコア - Enemyのスコア」の最大値を返す。
        private int NegaMax(int deepness, SearchState state, int alpha, int beta, int count, PointEvaluator.Base evaluator, Decision ngMove, int greedyDepth)
        {
            if (deepness == 0)
            {
                //for (int j = 0; j < greedyDepth; j++)
                //{
                //Unsafe8Array<VelocityPoint> move = state.MakeGreedyMove(ScoreBoard, WayEnumerator, AgentsCount);
                //state.Move(move, AgentsCount);
                //Ways moves = state.MakeMoves(AgentsCount, ScoreBoard);
                //SortMoves(ScoreBoard, state, moves, 49, null);
                //state.Move(moves[0].Agent1Way, moves[1].Agent2Way);
                //}
                int score = evaluator.Calculate(ScoreBoard, state.MeBoard, 0, state.Me, state.Enemy) - evaluator.Calculate(ScoreBoard, state.EnemyBoard, 0, state.Enemy, state.Me);
                if (greedyDepth % 2 == 1)
                {
                    return(-score);
                }
                return(score);
            }

            Ways      ways  = state.MakeMoves(AgentsCount, ScoreBoard);
            SmallWays sways = new SmallWays(AgentsCount);

            //ways => sways
            foreach (var way in ways.GetEnumerator(AgentsCount))
            {
                sways.Add(new SmallWay(way));
            }
            SortMoves(ScoreBoard, state, sways, count, ngMove);

            for (int i = 0; i < sways.Count; ++i)
            {
                if (CancellationToken.IsCancellationRequested == true)
                {
                    return(alpha);
                }                                       //何を返しても良いのでとにかく返す
                //if (count == 0 && !(ngMove is null) && new Decided(ways[i].Agent1Way, ways[i].Agent2Way).Equals(ngMove)) { continue; }	//競合手を避ける場合
                if (count == 0 && !(ngMove is null))    //2人とも競合手とは違う手を指す
                {
                    int j;
                    for (j = 0; j < AgentsCount; ++j)
                    {
                        if (sways[i].Equals(ngMove.Agents[j]))
                        {
                            break;
                        }
                    }
                    if (j != AgentsCount)
                    {
                        continue;
                    }
                }

                SearchState nextState = state;
                nextState = nextState.GetNextState(AgentsCount, sways[i].AgentsWay);
                nextState = nextState.ChangeTurn();
                int res = -NegaMax(deepness - 1, nextState, -beta, -alpha, count + 1, evaluator, ngMove, greedyDepth);
                if (alpha < res)
                {
                    alpha = res;
                    if (ngMove is null)
                    {
                        dp1[count].UpdateScore(alpha, sways[i].AgentsWay);
                    }
                    else
                    {
                        dp2[count].UpdateScore(alpha, sways[i].AgentsWay);
                    }
                    if (alpha >= beta)
                    {
                        return(beta);               //βcut
                    }
                }
            }
            sways.Erase();
            //WaysPool.Return(ways);
            return(alpha);
        }
示例#28
0
        /// <summary>
        /// Completes the collection, fetching optional missing elements
        /// </summary>
        /// <param name="source">The source to search for missing elements from</param>
        /// <param name="relation_nodes">Find missing nodes from relations?</param>
        /// <param name="relation_ways">Find missing ways from relations?</param>
        /// <param name="relation_relations">Find missing relations from relations?</param>
        public OsmGeoCollection Complete(IDataSourceReadOnly source,
                                         bool relation_nodes     = false,
                                         bool relation_ways      = false,
                                         bool relation_relations = false)
        {
            var missing_node_ids = new List <long>();
            var missing_way_ids  = new List <long>();

            // search relations for missing relations
            if (relation_relations)
            {
                var missing_relation_ids = new List <long>();

                do
                {
                    foreach (var relation in Relations)
                    {
                        foreach (var member in relation.Value.Members)
                        {
                            if (member.MemberType.Value == OsmGeoType.Relation)
                            {
                                if (!Relations.ContainsKey(member.MemberId.Value))
                                {
                                    missing_relation_ids.Add(member.MemberId.Value);
                                }
                            }
                        }
                    }

                    var found_relations = source.GetRelations(missing_relation_ids);

                    foreach (var found_relation in found_relations)
                    {
                        if (!Relations.ContainsKey(found_relation.Id.Value))
                        {
                            Relations.Add(found_relation.Id.Value, found_relation);
                        }
                    }
                } while (missing_relation_ids.Count > 0);
            }

            // search relations for missing ways and nodes
            if (relation_ways || relation_nodes)
            {
                foreach (var relation in Relations)
                {
                    foreach (var member in relation.Value.Members)
                    {
                        if (member.MemberType.Value == OsmGeoType.Node)
                        {
                            if (relation_nodes)
                            {
                                if (!Nodes.ContainsKey(member.MemberId.Value))
                                {
                                    missing_node_ids.Add(member.MemberId.Value);
                                }
                            }
                        }
                        else if (member.MemberType.Value == OsmGeoType.Way)
                        {
                            if (relation_ways)
                            {
                                if (!Ways.ContainsKey(member.MemberId.Value))
                                {
                                    missing_way_ids.Add(member.MemberId.Value);
                                }
                            }
                        }
                        else if (member.MemberType.Value == OsmGeoType.Relation)
                        {
                            if (relation_relations)
                            {
                                if (!Relations.ContainsKey(member.MemberId.Value))
                                {
                                    throw new NotImplementedException();
                                }
                            }
                        }
                    }
                }
            }

            // fetch missing ways
            var found_ways = source.GetWays(missing_way_ids);

            foreach (var found_way in found_ways)
            {
                Ways.Add(found_way.Id.Value, found_way);
            }

            // search ways for missing nodes
            foreach (var way in Ways)
            {
                foreach (var node_id in way.Value.Nodes)
                {
                    if (!Nodes.ContainsKey(node_id))
                    {
                        missing_node_ids.Add(node_id);
                    }
                }
            }

            // fetch missing nodes
            var found_nodes = source.GetNodes(missing_node_ids);

            foreach (var found_node in found_nodes)
            {
                Nodes.Add(found_node.Id.Value, found_node);
            }

            return(this);
        }
示例#29
0
 //создание массива путей из одной точки в другую, исходя из названия города и его частей улиц
 public void createWays()
 {
     ways = new Ways(nameOfTown, paths);
 }
示例#30
0
 //Установка состояния движения
 public void SetWays(Ways ways)
 {
     this.ways = ways;
 }