//返回节点 极大极小
    private List <MiniMaxNode> GetList(ChessType[,] grid, ChessType chess, bool mySelf)
    {
        List <MiniMaxNode> nodeList = new List <MiniMaxNode>();
        MiniMaxNode        node;

        for (int i = 0; i < 15; i++)
        {
            for (int j = 0; j < 15; j++)
            {
                Vector2Int pos = new Vector2Int(i, j);
                if (grid[pos.x, pos.y] != 0)
                {
                    continue;
                }

                node       = new MiniMaxNode();
                node.pos   = pos;
                node.chess = chess;
                node.child = new List <MiniMaxNode>();
                if (mySelf)
                {
                    node.value = GetScore(grid, pos);
                }
                else
                {
                    node.value = -GetScore(grid, pos);
                }
                if (nodeList.Count < 4)
                {
                    nodeList.Add(node);
                }
                else
                {
                    foreach (var item in nodeList)
                    {
                        if (mySelf)//极大点
                        {
                            if (node.value > item.value)
                            {
                                nodeList.Remove(item);
                                nodeList.Add(node);
                                break;
                            }
                        }
                        else//极小点
                        {
                            if (node.value < item.value)
                            {
                                nodeList.Remove(item);
                                nodeList.Add(node);
                                break;
                            }
                        }
                    }
                }
            }
        }

        return(nodeList);
    }
Exemplo n.º 2
0
    float AlphaBeta(MiniMaxNode node, int depth, bool myself, float alpha, float beta)
    {
        //  float value, best;
        if (node.value == float.MaxValue || node.value == float.MinValue || depth == 0)
        {
            return(node.value);
        }
        if (!myself)
        {
            // best = float.MaxValue;
            foreach (var child in node.child)
            {
                beta = Mathf.Min(beta, AlphaBeta(child, depth - 1, !myself, alpha, beta));
                if (beta <= alpha)
                {
                    return(beta);
                }
            }
            return(beta);
        }
        else
        {
            // best = float.MinValue;
            foreach (var child in node.child)
            {
                alpha = Mathf.Max(alpha, AlphaBeta(child, depth - 1, !myself, alpha, beta));

                if (alpha >= beta)
                {
                    return(alpha);
                }
            }
            return(alpha);
        }
    }
    public override void PlayChess()
    {
        if (chessBoardManager.chessInfoStack.Count == 0)
        {
            AIPlayChess(7, 7);
        }

        MiniMaxNode node = null;

        foreach (var item in GetList(chessBoardManager.GridArray, ChessType, true))
        {
            CreateTree(item, (ChessType[, ])chessBoardManager.GridArray.Clone(), 3, false);
            float a = -maxScore;
            float b = +maxScore;
            item.value += AlphaBeta(item, 3, false, a, b);
            if (node != null)
            {//挑选最大的下旗点
                if (node.value < item.value)
                {
                    node = item;
                }
            }
            else
            {
                node = item;
            }
        }
        AIPlayChess(node.pos.x, node.pos.y);
    }
Exemplo n.º 4
0
    public override void PlayChess()
    {
        if (ChessBoard.Instance.chessStack.Count == 0)
        {
            if (ChessBoard.Instance.PlayerChess(new int[2] {
                7, 7
            }))
            {
                ChessBoard.Instance.timer = 0;
            }
            return;
        }

        MiniMaxNode node = null;

        foreach (var item in GetList(ChessBoard.Instance.grid, (int)chessColor, true))
        {
            CreatTree(item, (int[, ])ChessBoard.Instance.grid.Clone(), 3, false);
            float a = float.MinValue;
            float b = float.MaxValue;
            item.value += AlphaBeta(item, 3, false, a, b);
            if (node != null)
            {
                if (node.value < item.value)
                {
                    node = item;
                }
            }
            else
            {
                node = item;
            }
        }
        ChessBoard.Instance.PlayerChess(node.pos);
    }
Exemplo n.º 5
0
    float Minimax(MiniMaxNode node, int depth, bool myself)
    {
        float beta = float.MaxValue, alpha = float.MinValue;

        // float value, best;
        if (node.value == float.MaxValue || depth == 0)
        {
            return(node.value);
        }
        if (!myself)
        {
            foreach (var child in node.child)
            {
                beta = Mathf.Min(beta, Minimax(child, depth - 1, !myself));
            }
            return(beta);
        }
        else
        {
            foreach (var child in node.child)
            {
                alpha = Mathf.Max(alpha, Minimax(child, depth - 1, !myself));
            }
            return(alpha);
        }
    }
Exemplo n.º 6
0
    public float AlphaBeta(MiniMaxNode node, int deep, bool myself, float alpha, float beta)
    {
        if (deep == 0 || node.value == float.MaxValue || node.value == float.MinValue)
        {
            return(node.value);
        }

        if (myself)
        {
            foreach (var child in node.child)
            {
                alpha = Mathf.Max(alpha, AlphaBeta(child, deep - 1, !myself, alpha, beta));

                if (alpha >= beta)
                {
                    return(alpha);
                }
            }
            return(alpha);
        }
        else
        {
            foreach (var child in node.child)
            {
                beta = Mathf.Min(beta, AlphaBeta(child, deep - 1, !myself, alpha, beta));

                if (alpha >= beta)
                {
                    return(beta);
                }
            }
            return(beta);
        }
    }
Exemplo n.º 7
0
        private MiniMaxNode MiniMax(BeamNode node)
        {
            if (node.Children.Count == 0)
            {
                return(new MiniMaxNode(node.Evaluation));
            }

            var best = new MiniMaxNode(node.State.PlayerToMove == Player.One ? int.MinValue : int.MaxValue);

            foreach (var child in node.Children)
            {
                var test = MiniMax(child);

                if (node.State.PlayerToMove == Player.One)
                {
                    if (test.Evaluation > best.Evaluation)
                    {
                        best.Move       = child.Move;
                        best.Evaluation = test.Evaluation;
                    }
                }
                else
                {
                    if (test.Evaluation < best.Evaluation)
                    {
                        best.Move       = child.Move;
                        best.Evaluation = test.Evaluation;
                    }
                }
            }

            return(best);
        }
Exemplo n.º 8
0
 /// <summary>
 /// 通过alpha和beta来进行筛选,这里的alpha和beta控制的是范围
 /// 每一层递归,alpha和beta的位置都进行了一次互换,所以返回的值都是alpha和beta
 /// </summary>
 /// <param name="node"></param>
 /// <param name="deep"></param>
 /// <param name="alpha"></param>
 /// <param name="beta"></param>
 /// <param name="mySelf"></param>
 /// <returns>当前决策树最佳的策略的结果</returns>
 public float AlphaBeta(MiniMaxNode node, int deep, float alpha, float beta, bool mySelf)
 {
     if (deep == 0 || (node.value == float.MaxValue) || (node.value == float.MinValue))
     {
         return(node.value);
     }
     if (mySelf)
     {
         foreach (MiniMaxNode item in node.child)
         {
             alpha = Mathf.Max(alpha, AlphaBeta(item, deep - 1, alpha, beta, !mySelf));//通过遍历子节点找到最优解,从而抬高alpha的值
             if (alpha >= beta)
             {
                 return(alpha);
             }
         }
         return(alpha);
     }
     else
     {
         foreach (MiniMaxNode item in node.child)
         {
             beta = Mathf.Min(beta, AlphaBeta(item, deep - 1, alpha, beta, !mySelf));//通过遍历子节点找到最优解,从而抬高alpha的值
             if (alpha >= beta)
             {
                 return(beta);
             }
         }
         return(beta);
     }
 }
Exemplo n.º 9
0
    protected override void PlayChess()
    {
        if (ChessBoard.Instance.chessStack.Count == 0)
        {
            if (ChessBoard.Instance.PlayChess(new int[2] {
                7, 7
            }))
            {
                ChessBoard.Instance.timer = 0;
            }
            return;
        }
        MiniMaxNode node = null;

        foreach (MiniMaxNode item in GetList(ChessBoard.Instance.grid, (int)chessColor, true))
        {
            CreateTree(item, 3, (int[, ])ChessBoard.Instance.grid.Clone(), false);
            item.value += AlphaBeta(item, 3, float.MinValue, float.MaxValue, false);//其实每一步都有一个决策的分数,最终的分数算的是总和
            if (node != null)
            {
                if (node.value < item.value)
                {
                    node = item;
                }
            }
            else
            {
                node = item;
            }
        }
        ChessBoard.Instance.PlayChess(node.pos);
    }
Exemplo n.º 10
0
    List <MiniMaxNode> GetList(int[,] grid, int chess, bool mySelf)
    {
        List <MiniMaxNode> list = new List <MiniMaxNode>();
        MiniMaxNode        node;

        for (int i = 0; i < 15; i++)
        {
            for (int j = 0; j < 15; j++)
            {
                int[] pos = new int[2] {
                    i, j
                };
                if (grid[pos[0], pos[1]] != 0)
                {
                    continue;
                }
                node       = new MiniMaxNode();
                node.chess = chess;
                node.pos   = pos;
                if (mySelf)
                {
                    node.value = GetScore(grid, pos);
                }
                else
                {
                    node.value = -GetScore(grid, pos);
                }
                if (list.Count < 4)
                {
                    list.Add(node);
                }
                else
                {
                    foreach (MiniMaxNode item in list)
                    {
                        if (mySelf && item.value < node.value)//极大点
                        {
                            list.Remove(item);
                            list.Add(node);
                            break;
                        }
                        if (!mySelf && item.value > node.value)//极小点
                        {
                            list.Remove(item);
                            list.Add(node);
                            break;
                        }
                    }
                }
            }
        }
        return(list);
    }
 //创建树
 public void CreateTree(MiniMaxNode node, ChessType[,] grid, int deep, bool mySelf)
 {
     if (deep == 0 || node.value == maxScore)
     {
         return;
     }
     grid[node.pos.x, node.pos.y] = node.chess;
     node.child = GetList(grid, node.chess, !mySelf);
     foreach (var item in node.child)
     {
         CreateTree(item, (ChessType[, ])grid.Clone(), deep - 1, !mySelf);
     }
 }
Exemplo n.º 12
0
 public void GreatTree(MiniMaxNode node, int[,] grid, int depth, bool myself)
 {
     if (depth == 0 || node.value == float.MaxValue)
     {
         return;
     }
     grid[node.pos[0], node.pos[1]] = node.chess;
     node.child = GetList(grid, node.chess, !myself);
     foreach (var child in node.child)
     {
         GreatTree(child, (int[, ])grid.Clone(), depth - 1, !myself);
     }
 }
Exemplo n.º 13
0
 public void CreatTree(MiniMaxNode node, int[,] grid, int deep, bool myself)
 {
     if (deep == 0 || node.value == float.MaxValue)
     {
         return;
     }
     grid[node.pos[0], node.pos[1]] = node.chess;
     node.child = GetList(grid, node.chess, !myself);
     foreach (var item in node.child)
     {
         CreatTree(item, (int[, ])grid.Clone(), deep - 1, !myself);
     }
 }
Exemplo n.º 14
0
    public void CreateTree(MiniMaxNode node, int[,] grid, int deep, bool mySelf)
    {
        //if five chess together we can stop creating tree
        if (deep == 0 || node.value == float.MaxValue)
        {
            return;
        }

        grid[node.pos[0], node.pos[1]] = node.chess;

        node.childNode = GetList(grid, node.chess, !mySelf);
        foreach (var item in node.childNode)
        {
            //every child node continu to create tree
            //use clone to copy and save every gird
            CreateTree(item, (int[, ])grid.Clone(), deep - 1, !mySelf);
        }
    }
Exemplo n.º 15
0
    public override void putChess()
    {
        if (ChessBoard.Instacne.chessStack.Count == 0)
        {
            if (ChessBoard.Instacne.ChessPos(new int[2] {
                7, 7
            }))
            {
                ChessBoard.Instacne.timer = 0;
            }
            return;
        }

        MiniMaxNode node = null;

        foreach (var Node in GetList(ChessBoard.Instacne.grid, (int)chessColor, true))
        {
            CreateTree(Node, (int[, ])ChessBoard.Instacne.grid.Clone(), 3, false);

            float a = float.MinValue;
            float b = float.MaxValue;

            Node.value += AlphaBeta(Node, 3, false, a, b);

            if (node != null)
            {
                if (node.value < Node.value)
                {
                    node = Node;
                }
            }
            else
            {
                node = Node;
            }
        }
        // put the chess in this position with minmum value
        if (ChessBoard.Instacne.ChessPos(node.pos))
        {
            ChessBoard.Instacne.timer = 0;
        }
    }
Exemplo n.º 16
0
    //找好節點後,創建樹
    public void CreateTree(MiniMaxNode node, int[,] grid, int deep, bool mySelf)
    {
//這條件用來判斷是否可以不用創建樹了
        if (deep == 0 || node.value == float.MaxValue)
        {
            return;
        }
//如果要創建樹
//先把棋子下進來
        grid[node.pos[0], node.pos[1]] = node.chess;     //定義棋盤位置上的棋子顏色
//賦予節點子節點,就會變成樹
        node.child = GetList(grid, node.chess, !mySelf); //注意這邊參數是!mySelf,因為下一輪的4個節點是輪到對手下棋,所以要找不是自己的
        foreach (var item in node.child)
        {
//每個子節點又去創建樹,形成孫子節點
            CreateTree(item, (int[, ])grid.Clone(), deep - 1, !mySelf);
            //注意這邊參數!mySelf,因為子節點都跟自己顏色相反
            //grid這邊使用.Clone(),把母節點的grid複製保存下來
            //所以無論母節點的選擇如何不同,子節點會保存下來
        }
    }
Exemplo n.º 17
0
    //寫好剪枝後,寫下棋函式
    public override void PlayeChess()
    {   //如果AI是黑棋的話,讓AI先下棋盤中心點
        if (ChessBoard.Instacne.chessStack.Count == 0)
        {
            if (ChessBoard.Instacne.PlayChess(new int[2] {
                7, 7
            }))
            {
                ChessBoard.Instacne.timer = 0;
            }
            return;
        }

        MiniMaxNode node = null;//先給一個空節點,先幫節點佔位置的意思,之後存放節點進來

        //遍歷節點清單中的每個節點,節點清單偷過函式返回而得到
        foreach (var item in GetList(ChessBoard.Instacne.grid, (int)chessColor, true))
        {   //針對每個節點去生成樹
            CreateTree(item, (int[, ])ChessBoard.Instacne.grid.Clone(), 3, false);
            //然後尋找Alpha、Beta值
            float a = float.MinValue;
            float b = float.MaxValue;
            //每個節點的價值原本是空的(null),透過AlphaBeta()找到值、給予節點價值
            item.value += AlphaBeta(item, 3, false, a, b);
            //如果node賦值過,給予最大值
            if (node != null)
            {//挑最大值的節點去下棋
                if (node.value < item.value)
                {
                    node = item;
                }
            }
            else//如果node沒賦值過,給予值
            {
                node = item;
            }
        }
        ChessBoard.Instacne.PlayChess(node.pos);
    }
Exemplo n.º 18
0
//Beta是可能解決方案 的最小上限
//Alpha是可能解決方案 的最大下限
//剪枝:找節點中最大最小值,把最小的那個分支剪掉
    public float AlphaBeta(MiniMaxNode node, int deep, bool mySelf, float alpha, float beta)
    {
        if (deep == 0 || node.value == float.MaxValue || node.value == float.MinValue)
        {
            return(node.value);
        }
        //是自己的話,遍歷子節點找最大值
        if (mySelf)
        {
            foreach (var child in node.child)
            {   //找最大值,和自己(alpha)、下一層節點的值比
                //Mathf.Max(A,B); 意思是A、B取誰最大
                alpha = Mathf.Max(alpha, AlphaBeta(child, deep - 1, !mySelf, alpha, beta));

                //alpha剪枝

                if (alpha >= beta)
                {
                    return(alpha);
                }
            }
            return(alpha);
        }
        //不是自己的話,遍歷子節點取最小值
        else
        {
            foreach (var child in node.child)
            {
                beta = Mathf.Min(beta, AlphaBeta(child, deep - 1, !mySelf, alpha, beta));

                //beta剪枝
                if (alpha >= beta)
                {
                    return(beta);
                }
            }
            return(beta);
        }
    }
Exemplo n.º 19
0
    public float AlphaBeta(MiniMaxNode node, int deep, bool mySelf, float alpha, float beta)
    {
        if (deep == 0 || node.value == float.MaxValue || node.value == float.MinValue)
        {
            return(node.value);
        }
        //if is the player's turn, we need to find the max value position
        if (mySelf)
        {
            foreach (var child in node.childNode)
            {
                //look for max value,  comparing to the Alpha value
                alpha = Mathf.Max(alpha, AlphaBeta(child, deep - 1, !mySelf, alpha, beta));

                //alpha
                if (alpha >= beta)
                {
                    return(alpha);
                }
            }
            return(alpha);
        }

        // AI turn, look for the min vlaue position
        else
        {
            foreach (var child in node.childNode)
            {
                beta = Mathf.Min(beta, AlphaBeta(child, deep - 1, !mySelf, alpha, beta));

                //beta
                if (alpha >= beta)
                {
                    return(beta);
                }
            }
            return(beta);
        }
    }
Exemplo n.º 20
0
    public override void PlayChess()
    {
        if (chessboard.step.Count == 0)
        {
            chessboard.PlayChess(new int[2] {
                7, 7
            }); return;
        }
        //if (Input.GetKey(KeyCode.Space))
        {
            MiniMaxNode node = null;
            foreach (var item in GetList(chessboard.grid, (int)chessColor, true))
            {
                GreatTree(item, (int[, ])chessboard.grid.Clone(), 3, false);
                float a = float.MinValue, b = float.MaxValue;
                //tempitem.value = item.value;
                item.value += AlphaBeta(item, 3, false, a, b);
                //item.value += Minimax(item,3, false);
                if (node != null)
                {
                    if (node.value < item.value)
                    {
                        node = item;
                    }
                }
                else
                {
                    node = item;
                }

                // Debug.Log(item.value + ":" + item.pos[0] + "," + item.pos[1]);


                // Debug.Log("==========="+ tempitem.value + ":" + item.pos[0] + "," + item.pos[1]);
            }
            chessboard.PlayChess(node.pos);
            // Debug.Log("____________________________");
        }
    }
Exemplo n.º 21
0
    //返回節點 使用極大極小法
    List <MiniMaxNode> GetList(int[,] grid, int chess, bool mySelf)
    //這函式要返回list,list內容是node(也就是每一種下棋狀況的節點)
    {
        List <MiniMaxNode> nodeList = new List <MiniMaxNode>(); //新增一個list
        MiniMaxNode        node;                                //聲明節點,之後才定義

//先找節點~
        //去遍歷棋盤上每個位置
        for (int i = 0; i < 15; i++)
        {
            for (int j = 0; j < 15; j++)
            {
                int[] pos = new int[2] {
                    i, j
                };
                if (grid[pos[0], pos[1]] != 0)
                {
                    continue;                   //如果這位置有放棋子的話
                }
                node       = new MiniMaxNode(); //新增node,接下來開始定義
                node.pos   = pos;               //每個節點有一些資訊,包含:棋子位置、棋子顏色、節點所價值的分數
                node.chess = chess;
                //如果是自己方的棋子
                if (mySelf)
                {
                    node.value = GetScore(grid, pos);//去計算此節點的分數
                }
                //是敵方的,加上負號
                else
                {
                    node.value = -GetScore(grid, pos);
                }

//找到節點,加入list,如果超過4個就比較誰該加進來
                //每個節點下方還會有4個節點,因為一個棋子最多有四個方位可以放棋子
                //所以如果節點數量小於4,就還可以再加入節點
                //找到node(節點),要把節點加入節點list之中
                if (nodeList.Count < 4)
                {
                    nodeList.Add(node);
                }
                else //如果大於4,比較誰該放進來,因為list最多只能放四個節點
                {
                    foreach (var item in nodeList)//遍歷清單內的節點
                    {
                        if (mySelf)//對於自己方,找極大值的節點加入進來
                        {
                            if (node.value > item.value)
                            {
                                nodeList.Remove(item);
                                nodeList.Add(node);
                                break;
                            }
                        }
                        else//對於敵方,找極小值的節點加入進來
                        {
                            if (node.value < item.value)
                            {
                                nodeList.Remove(item);
                                nodeList.Add(node);
                                break;
                            }
                        }
                    }
                }
            }
        }

        return(nodeList);
    }
Exemplo n.º 22
0
        private MiniMaxNode MiniMaxAlphaBeta(IState state, int depth, int maxDepth, int alpha, int beta)
        {
            if (depth >= maxDepth)
            {
                evaluations++;
                return(new MiniMaxNode(state.Evaluate(depth)));
            }

            if (cancel.Cancelled)
            {
                return(new MiniMaxNode(true));
            }

            var moves = state.GetAllMoves();

            if (moves.Count == 0)
            {
                evaluations++;
                return(new MiniMaxNode(state.Evaluate(depth)));
            }

            var best = new MiniMaxNode(state.PlayerToMove == Player.One ? int.MinValue : int.MaxValue);

            foreach (var move in moves)
            {
                var copy = state.Clone();
                copy.MakeMove(move);

                var test = MiniMaxAlphaBeta(copy, depth + 1, maxDepth, alpha, beta);

                if (test.Cancelled)
                {
                    return(test);
                }

                if (state.PlayerToMove == Player.One)
                {
                    if (test.Evaluation > best.Evaluation)
                    {
                        best.Evaluation = test.Evaluation;
                        best.Move       = move;
                    }
                    if (test.Evaluation > alpha)
                    {
                        alpha = test.Evaluation;
                    }
                    if (alpha >= beta)
                    {
                        break;
                    }
                }
                else
                {
                    if (test.Evaluation < best.Evaluation)
                    {
                        best.Evaluation = test.Evaluation;
                        best.Move       = move;
                    }
                    if (test.Evaluation < beta)
                    {
                        beta = test.Evaluation;
                    }
                    if (alpha >= beta)
                    {
                        break;
                    }
                }
            }

            return(best);
        }
Exemplo n.º 23
0
    List <MiniMaxNode> GetList(int[,] grid, int chess, bool mySelf)

    {
        List <MiniMaxNode> nodeList = new List <MiniMaxNode>();
        MiniMaxNode        node;

        //loop through all the position in the board
        for (int i = 0; i < 15; i++)
        {
            for (int j = 0; j < 15; j++)
            {
                // this postion have chess then skip
                int[] pos = new int[2] {
                    i, j
                };
                if (grid[pos[0], pos[1]] != 0)
                {
                    continue;
                }

                //add a node
                node       = new MiniMaxNode();
                node.pos   = pos;
                node.chess = chess;

                if (mySelf)
                {
                    //for human player
                    //look for max value
                    node.value = Score(grid, pos);
                }

                else
                {
                    //for AI player
                    //look for min value
                    node.value = -Score(grid, pos);
                }

                //four directions to put chess
                //if less then four we add node to it
                if (nodeList.Count < 4)
                {
                    nodeList.Add(node);
                }

                //if number of nodes more then four we need to compare it
                else
                {
                    //check each node in nodelist
                    //to compare which one should keep or remove
                    foreach (var item in nodeList)
                    {
                        if (mySelf)
                        {
                            if (node.value > item.value)
                            {
                                nodeList.Remove(item);
                                nodeList.Add(node);
                                break;
                            }
                        }
                        else
                        {
                            if (node.value < item.value)
                            {
                                nodeList.Remove(item);
                                nodeList.Add(node);
                                break;
                            }
                        }
                    }
                }
            }
        }

        return(nodeList);
    }
Exemplo n.º 24
0
    List <MiniMaxNode> GetList(int[,] grid, int chess, bool myself)
    {
        List <MiniMaxNode> nodeList = new List <MiniMaxNode>();

        MiniMaxNode node;

        for (int i = 0; i < 15; i++)
        {
            for (int j = 0; j < 15; j++)
            {
                int[] pos = new int[2] {
                    i, j
                };
                if (grid[pos[0], pos[1]] != 0)
                {
                    continue;
                }

                node       = new MiniMaxNode();
                node.pos   = pos;
                node.chess = chess;
                if (myself)
                {
                    if (chess == 1)
                    {
                        node.value = GetScore(grid, pos, 1);
                    }
                    else
                    {
                        node.value = GetScore(grid, pos, 2);
                    }
                }
                else
                {
                    if (chess == 1)
                    {
                        node.value = -GetScore(grid, pos, 2);
                    }
                    {
                        node.value = GetScore(grid, pos, 1);
                    }
                }


                if (nodeList.Count < 4)
                {
                    nodeList.Add(node);
                }
                else
                {
                    foreach (var item in nodeList)
                    {
                        if (myself)
                        {
                            if (node.value > item.value)
                            {
                                nodeList.Remove(item);
                                nodeList.Add(node);
                                break;
                            }
                        }
                        else
                        {
                            if (node.value < item.value)
                            {
                                nodeList.Remove(item);
                                nodeList.Add(node);
                                break;
                            }
                        }
                    }
                }
            }
        }

        return(nodeList);
    }