Exemple #1
0
        /// <summary>
        /// Create the grid of gem slots
        /// </summary>
        /// <param name="playAreaResolution">The resolution of the game</param>
        /// <returns>The grid of gem slots in the [row,column] format</returns>
        public GemSlot[,] CreateGemslots(Size playAreaResolution)
        {
            //each gem slot is 40x40
            //row 1 column 0 top left is at 175,149
            //row 0 column 0 top left should be at 175,109
            GemSlot[,] gemSlots = new GemSlot[8,8];
            Point baseOffset;
            Size gemAreaSize;
            if (playAreaResolution.Width == 760 && playAreaResolution.Height == 596)
            {
                baseOffset = new Point(175, 109);
                gemAreaSize = new Size(40, 40);
            }
            else
            {
                throw new Exception("Wrong resolution, only 760x596 is accepted");
            }
            for (int row = 0; row < 8; row++)
            {
                for (int column = 0; column < 8; column++)
                {
                    Point offset = new Point(column*gemAreaSize.Width, row*gemAreaSize.Height);
                    Point topLeft = new Point(baseOffset.X + offset.X, baseOffset.Y + offset.Y);
                    gemSlots[row, column] = new GemSlot(new Rectangle(topLeft, gemAreaSize));
                }

            }
            return gemSlots;
        }
        /// <summary>
        /// Extracts each gems rectangle in the image
        /// </summary>
        /// <param name="screenshot">An image of the current playing area (without windowborders)</param>
        /// <param name="gemSlots"></param>
        /// <returns>A two-dimensional array of images in the [row,column] format</returns>
        public Image<Bgr, byte>[,] ExtractGemSlots(Image<Bgr, byte> screenshot, GemSlot[,] gemSlots)
        {
            #if SAVEIMAGES
            string basePath = "abc\\";
            foreach(GemColor color in Enum.GetValues(typeof(GemColor)))
            {
                if (!System.IO.Directory.Exists(basePath + color))
                    System.IO.Directory.CreateDirectory(basePath + color);
            }

            #endif
            Image<Bgr, byte>[,] gemSlotImages = new Image<Bgr, byte>[8,8];
            for (int row = 0; row < 8; row++)
            {
                for (int column = 0; column < 8; column++)
                {
                    Rectangle gemSlotRectangle = gemSlots[row, column].Rectangle;
                    gemSlotImages[row, column] = screenshot.Copy(gemSlotRectangle);
            #if SAVEIMAGES
                    Random rand = new Random();
                    Gem prediction = (new SimpleGemClassifier().ClassifyGem(gemSlotImages[row, column]));
                    gemSlotImages[row, column].Save("abc\\" + prediction.Color.ToString() + "\\" + rand.Next() + "." + row + "." + column + ".png");
            #endif
                }
            }
            return gemSlotImages;
        }
Exemple #3
0
 public PlayArea(GemSlot[,] gemSlots)
 {
     GemSlots = gemSlots;
 }