//Used for creating children
 public WallDiffNode(WallDiffNode n, string move)
 {
     MoveMade = move;
     Board    = new AIBoard(n.Board);
     Board.MakeMove(move);
     Depth        = n.Depth + 1;
     PreviousDiff = n.Diff;
 }
        //This returns all walls adjacent to the wall move made in
        public List <WallDiffNode> GetChildren()
        {
            List <WallDiffNode> children      = new List <WallDiffNode>();
            List <string>       adjacentWalls = DictionaryLookup.PerformWallsOfInterestLookup(MoveMade);

            foreach (string wall in adjacentWalls)
            {
                AIBoard tempBoard = new AIBoard(Board);
                tempBoard.MakeMove(wall);
                if (BoardAnalysis.CheckPathExists(tempBoard, true) && BoardAnalysis.CheckPathExists(tempBoard, false))
                {
                    children.Add(new WallDiffNode(this, wall));
                }
            }
            return(children);
        }
Beispiel #3
0
        //If risk is very high will return 1, low risk is higher return value.
        private int GetMoveRisk(string move)
        {
            int     riskValue = 100;
            AIBoard tempBoard = new AIBoard(CurrentBoard);

            tempBoard.MakeMove(move);
            WallDiffNode rootNode = new WallDiffNode(tempBoard);

            List <string> wallPlacements = tempBoard.GetWallMoves();

            foreach (string wall in wallPlacements)
            {
                riskValue = Math.Min(riskValue, RiskIterate(new WallDiffNode(rootNode, wall), 0));
            }

            return(riskValue);
        }
Beispiel #4
0
        //Constructs a list of treenodes that result from every move made that is possible.
        //Pruning function (SetNodesOfInterest) will cut of many nodes that are not of interest.
        public List <TreeNode> GetChildren()
        {
            List <TreeNode> children = new List <TreeNode>();

            foreach (string move in Board.GetPawnMoves())
            {
                //This checks to make sure walls are valid
                AIBoard tempBoard = new AIBoard(Board);
                tempBoard.MakeMove(move);
                children.Add(new TreeNode(tempBoard, move));
            }

            //This gets only valid walls but is done here so that it will only check walls of interest.
            //This avoids checking if a ton of walls are valid that we don't care about.
            //This is why we do not just call GetWallMoves()
            if ((Board.GetIsPlayerOneTurn() && Board.GetPlayerOneNumWalls() == 0) ||
                (!Board.GetIsPlayerOneTurn() && Board.GetPlayerTwoNumWalls() == 0))
            {
            }
            else
            {
                HashSet <string> wallMoves = Board.GetAllValidWalls();
                SetNodesOfInterest(ref wallMoves);
                foreach (string wall in wallMoves)
                {
                    //This checks to make sure walls are valid
                    AIBoard tempBoard = new AIBoard(Board);
                    tempBoard.MakeMove(wall);
                    if (BoardAnalysis.CheckPathExists(tempBoard, true) && BoardAnalysis.CheckPathExists(tempBoard, false))
                    {
                        children.Add(new TreeNode(tempBoard, wall));
                    }
                }
            }

            //end of wall selection

            return(children);
        }