private int EdgeCoverage(Color[,] board)
        {
            bool[,] continuousVisited = new bool[board.Height(), board.Width()];
            bool[,] edgesVisited      = new bool[board.Height(), board.Width()];
            int covered = EdgeCoverage(0, 0, continuousVisited, edgesVisited, board);

            return(covered);
        }
Esempio n. 2
0
        //private static TreeNode[,] ToTreeNode(MapNode[,] lookup)
        //{
        //    TreeNode[,] treeLookup = new TreeNode[lookup.Height(), lookup.Width()];
        //    for (int y = 0; y < lookup.Height(); y++)
        //    {
        //        for (int x = 0; x < lookup.Width(); x++)
        //        {
        //            TreeNode treeNode = new TreeNode(lookup.GetAt(x, y).Color);
        //            treeLookup.SetAt(x, y, treeNode);
        //            throw new NotImplementedException("Doesn't keep the same reference for touching colors");
        //        }
        //    }
        //    return treeLookup;
        //}

        private static MapNode[,] BuildLookupGrid(Color[,] board)
        {
            MapNode[,] lookup = new MapNode[board.Height(), board.Width()];

            //build lookup
            for (int y = 0; y < board.Height(); y++)
            {
                for (int x = 0; x < board.Width(); x++)
                {
                    //Create MapNode
                    bool isLeftSame  = board.CanGetLeft(x) && board.GetAt(x, y) == board.GetLeftOf(x, y);
                    bool isAboveSame = board.CanGetAbove(y) && board.GetAt(x, y) == board.GetAboveOf(x, y);

                    if (isLeftSame && isAboveSame) //check above & to the left
                    {
                        MapNode left  = lookup.GetLeftOf(x, y);
                        MapNode above = lookup.GetAboveOf(x, y);
                        lookup.SetAt(x, y, left);
                        if (left != above)
                        {
                            left.Merge(above);
                            //update "above's" references to left
                            for (int updateY = y; updateY >= 0; updateY--)
                            {
                                for (int updateX = x; updateX >= 0; updateX--)
                                {
                                    if (lookup.GetAt(updateX, updateY) == above)
                                    {
                                        lookup.SetAt(updateX, updateY, left);
                                    }
                                }
                            }
                        }
                    }
                    else if (isLeftSame) // check to the left
                    {
                        lookup.SetAt(x, y, lookup.GetLeftOf(x, y));
                    }
                    else if (isAboveSame) // check above
                    {
                        lookup.SetAt(x, y, lookup.GetAboveOf(x, y));
                    }
                    else
                    {
                        lookup.SetAt(x, y, new MapNode(board.GetAt(x, y)));
                    }
                }
            }
            return(lookup);
        }
        public static Bitmap FromColorsMatrix(Color[,] colors)
        {
            var bitmap = new Bitmap(colors.Width(), colors.Height());

            for (int y = 0; y < bitmap.Height; y++)
            {
                for (int x = 0; x < bitmap.Width; x++)
                {
                    bitmap.SetPixel(x, y, colors[y, x]);
                }
            }

            return(bitmap);
        }
Esempio n. 4
0
        public void DisplayBoard(Color[,] board)
        {
            int           estimatedLength = (board.GetLength(0) * board.GetLength(1)) * 2;
            StringBuilder sb = new StringBuilder(estimatedLength);

            for (int y = 0; y < board.Height(); y++)
            {
                for (int x = 0; x < board.Width(); x++)
                {
                    sb.Append((char)Board.ColorToLetter(board.GetAt(x, y)));
                    sb.Append(' ');
                }
                sb.AppendLine();
            }
            Console.WriteLine(sb);
        }
 private static Color[] GetNeighbourPixels(Color[,] pixels, int x, int y)
 {
     return(GetNeigbourPoints(x, y)
            .Where(p => p.IsInRange(pixels.Height(), pixels.Width()))
            .Select(p => pixels[p.Y, p.X]).ToArray());
 }