Ejemplo n.º 1
0
        public SuggestedMoves GetPath(Color[,] board)
        {
            //Get the farthest nodes
            TreeNode        head          = MapBuilder.BuildTree(board);
            ISet <TreeNode> farthestNodes = new HashSet <TreeNode>();
            int             highestDepth  = 0;

            foreach (TreeNode node in head.BFS()) //DFS would be better
            {
                int depth = GetDepth(node);
                if (depth > highestDepth)
                {
                    highestDepth = depth;
                    farthestNodes.Clear();
                    farthestNodes.Add(node);
                }
                else if (depth == highestDepth)
                {
                    farthestNodes.Add(node);
                }
            }

            //get the color that would step towards each color
            IDictionary <Color, int> tally = new Dictionary <Color, int>();

            foreach (TreeNode farthestNode in farthestNodes)
            {
                TreeNode currentNode = farthestNode;
                while (currentNode.Parent != head)
                {
                    currentNode = currentNode.Parent;
                }
                if (!tally.ContainsKey(currentNode.Color))
                {
                    tally.Add(currentNode.Color, 1);
                }
                else
                {
                    tally[currentNode.Color]++;
                }
            }
            SuggestedMoves suggestedMoves = new SuggestedMoves();

            suggestedMoves.AddFirst(new SuggestedMove(tally.OrderByDescending(kvp => kvp.Value).Select(n => n.Key)));
            return(suggestedMoves);
        }
        public override SuggestedMoves ChooseColor(Color[,] board)
        {
            MapNode head = MapBuilder.BuildMap(board);

            MapNodeDecisionTree decisionTree            = BuildDecisionTree(head.Clone(), _lookAheadLevel);
            Stack <Color>       currentDecisionTreePath = new Stack <Color>();
            SurfaceAreaResult   bestSurfaceArea         = GetBest(decisionTree, new SurfaceAreaResult {
                SurfaceArea = 0, Path = new Color[0]
            }, currentDecisionTreePath);

            //convert the result to SuggestedMove
            SuggestedMoves moves = new SuggestedMoves();

            for (int i = 0; i < bestSurfaceArea.Path.Length - 1; i++)
            {
                moves.AddFirst(new SuggestedMove(bestSurfaceArea.Path[i]));
            }
            return(moves);
        }
Ejemplo n.º 3
0
        public override SuggestedMoves ChooseColor(Model.Color[,] board)
        {
            SuggestedMove move = new SuggestedMove();

            foreach (Color color in Enum.GetValues(typeof(Color)))
            {
                if (!recentColors.Contains(color))
                {
                    move.AddSuggestion(color, 100);
                }
            }
            int index = 1;

            foreach (Color color in recentColors)
            {
                move.AddSuggestion(color, index++);
            }

            var moves = new SuggestedMoves();

            moves.AddFirst(move);
            return(moves);
        }
Ejemplo n.º 4
0
        public override SuggestedMoves ChooseColor(Color[,] board)
        {
            MapNode        head                  = MapBuilder.BuildMap(board);
            ISet <MapNode> firstLayer            = head.GetNeighbors();
            List <Color>   possibleColorsToClear = firstLayer.Select(node => node.Color).ToList();

            IEnumerator <MapNode> breathFirstSearch = head.BFS().GetEnumerator();

            while (breathFirstSearch.MoveNext() && possibleColorsToClear.Count > 0)
            {
                MapNode currentNode = breathFirstSearch.Current;
                if (!firstLayer.Contains(currentNode))
                {
                    //can't wipe out that color, it is behind the first layer
                    possibleColorsToClear.Remove(currentNode.Color);
                }
            }

            SuggestedMove  move  = new SuggestedMove(possibleColorsToClear);
            SuggestedMoves moves = new SuggestedMoves();

            moves.AddFirst(move);
            return(moves);
        }