Esempio n. 1
0
        /// <summary>
        /// Scans the board bitmap for Vitae marbles (there is no highlight button for Mors and Vitae).
        /// </summary>
        /// <param name="boardBmp">Bitmap of the game board.</param>
        /// <param name="potentialPoints">Points with board coordinates to look for on the board.</param>
        private List <Point> ScanBoardForVitae(Bitmap boardBmp, IEnumerable <Point> potentialPoints)
        {
            var highlightedPoints = new List <Point>();

            // Browse the board
            foreach (var point in potentialPoints)
            {
                if (!SigmarCoordinateHelper.IsValidBoardCoordinate(point.X, point.Y))
                {
                    // Invalid coordinate. Don't bother.
                    continue;
                }

                // Get the rectangle on the image matching the marble to recognize at the current board position
                var targetRectangle = SigmarCoordinateHelper.GetMarbleRectangle(point.X, point.Y);

                // Get some pixel in the center of the first pixel row and try to approximate it as the highlight color
                var arrowPixel  = boardBmp.GetPixel(targetRectangle.Left + 26, targetRectangle.Top + 26);
                var marblePixel = boardBmp.GetPixel(targetRectangle.Left + 26, targetRectangle.Top + 41);
                if (arrowPixel.GetBrightness() > marblePixel.GetBrightness())
                {
                    highlightedPoints.Add(point);
                }
            }

            return(highlightedPoints);
        }
Esempio n. 2
0
        /// <summary>
        /// Scans the board bitmap for highlighted marbles and returns their positions.
        /// </summary>
        /// <param name="boardBmp">Bitmap of the game board.</param>
        private List <Point> ScanBoardForHighlightedMarbles(Bitmap boardBmp)
        {
            var highlightedPoints = new List <Point>();

            // Browse the board
            for (int boardX = 0; boardX < SigmarCoordinateHelper.BoardSize; boardX++)
            {
                for (int boardY = 0; boardY < SigmarCoordinateHelper.BoardSize; boardY++)
                {
                    if (!SigmarCoordinateHelper.IsValidBoardCoordinate(boardX, boardY))
                    {
                        // Invalid coordinate. Don't bother.
                        continue;
                    }

                    // Get the rectangle on the image matching the marble to recognize at the current board position
                    var targetRectangle = SigmarCoordinateHelper.GetMarbleRectangle(boardX, boardY);

                    // Get some pixels around the marble and figure out if they are bright enough to be highlights
                    var targetColorBottom = boardBmp.GetPixel(targetRectangle.X + targetRectangle.Width / 2, targetRectangle.Bottom - 2);
                    var targetColorTop    = boardBmp.GetPixel(targetRectangle.X + targetRectangle.Width / 2 - 8, targetRectangle.Top);
                    if (targetColorBottom.GetBrightness() > 0.85f || targetColorTop.GetBrightness() > 0.85f)
                    {
                        highlightedPoints.Add(new Point(boardX, boardY));
                    }
                }
            }

            return(highlightedPoints);
        }