Exemplo n.º 1
0
        private async void IPhoneScreen_Click(object sender, RoutedEventArgs e)
        {
            ScreenEnabled = false;

            FindIphoneWindow();

            //CaptureScreen.FoundNumbers.Clear();

            var nextNums = await CaptureScreen.CaptureNextNumbers(iphoneScreen);

            NextNumbers = nextNums;

            var nums = await CaptureScreen.Capture(iphoneScreen);

            var newNumbers = new Square[36];

            for (var i = 0; i < 36; i++)
            {
                newNumbers[i] = new Square(nums[i]);
            }

            CurrentBoard = newNumbers;

            ScreenEnabled = true;
        }
Exemplo n.º 2
0
        private async void ContMove_Click(object sender, RoutedEventArgs e)
        {
            stop          = false;
            ScreenEnabled = false;

            while (!stop)
            {
                await NextMove();

                int hash         = 0;
                int previousHash = 0;

                do
                {
                    using (var screenStream = new MemoryStream())
                    {
                        using (var screenBmp = new Bitmap(300, 60, PixelFormat.Format32bppArgb))
                        {
                            using (var bmpGraphics = Graphics.FromImage(screenBmp))
                            {
                                bmpGraphics.CopyFromScreen(iphoneScreen.Left + 300, iphoneScreen.Top + 400, 0, 0, screenBmp.Size);
                            }

                            hash = CaptureScreen.GetHash(screenBmp);

                            if (previousHash == 0)
                            {
                                previousHash = hash;
                            }

                            if (Math.Abs(hash - previousHash) < 3)
                            {
                                await Task.Delay(100);
                            }
                            else
                            {
                                await Task.Delay(1000);

                                using (var bmpGraphics = Graphics.FromImage(screenBmp))
                                {
                                    bmpGraphics.CopyFromScreen(iphoneScreen.Left + 300, iphoneScreen.Top + 400, 0, 0, screenBmp.Size);
                                }

                                hash = CaptureScreen.GetHash(screenBmp);
                            }
                        }
                    }
                } while (Math.Abs(hash - previousHash) < 3 && !stop);

                previousHash = hash;
            }
            ScreenEnabled = true;
        }
Exemplo n.º 3
0
        public async Task NextMove()
        {
            Directory.GetFiles(@".\", @"*.png").ToList().ForEach((f) =>
            {
                File.Delete(f);
            });

            var check = new List <(int, int)>();

            var movedBoard = MoveOneBoard ?? CurrentBoard;

            for (int y = 0; y < 6; y += 1)
            {
                for (int x = 0; x < 6; x += 1)
                {
                    var num = movedBoard[x + (y * 6)];
                    if (num.IsEmpty || num.IsMatched || num.IsTrail)
                    {
                        check.Add((x, y));
                    }
                }
            }

            MoveOneBoard = null;
            MoveTwoBoard = null;

            var nums = CurrentBoard.Select(n => n.Number).ToArray();

            var nextNums = await CaptureScreen.CaptureNextNumbers(iphoneScreen);

            await CaptureScreen.Capture(iphoneScreen, nums, check);

            var squares     = new Square[6, 6];
            var curBoard    = new Square[36];
            var futureSpots = new List <(int, int)>();

            for (int y = 0; y < 6; y += 1)
            {
                for (int x = 0; x < 6; x += 1)
                {
                    var num = nums[x + (y * 6)];
                    if (num > 0 && num < 10)
                    {
                        squares[x, y] = new Square(num)
                        {
                            IsEmpty = false
                        };
                    }
                    else
                    {
                        squares[x, y] = new Square(0)
                        {
                            IsEmpty = true
                        };
                    }

                    curBoard[x + (y * 6)] = squares[x, y];

                    if (num == 10)
                    {
                        futureSpots.Add((x, y));
                    }
                }
            }

            CurrentBoard = curBoard;

            await Task.Yield();

            var board = new Board(squares);

            var blockSquares = new Square[] { Square.BlockSquare(), Square.BlockSquare(), Square.BlockSquare() };

            Square[] newSquares = new Square[] { new Square(nextNums[0]), new Square(nextNums[1]), new Square(nextNums[2]) };

            NextNumbers = nextNums;

            var newDup = newSquares.Select(x => x.Number).Distinct().Count();

            if (newDup == 1 && nextNums[0] != 0)
            {
                blockSquares = newSquares;
            }


            var nextMoves = Turn.Moves(board, blockSquares, futureSpots);

            // BEST!!!
            var bestMoves = nextMoves
                            .OrderBy(m => m.Board.Count)
                            .ThenBy(m => m.ParentMove.Board.Count)
                            .ThenByDescending(m => m.ParentMove.Board.Points)
                            .ThenByDescending(m => m.Board.Points)
                            .ThenBy(m => m.Board.CenterCount)
                            .ThenBy(m => m.Board.Sum)
                            .FirstOrDefault();

            if (bestMoves != null)
            {
                var bestMove = bestMoves.ParentMove;

                var newNumbers = new Square[36];
                var secondMove = new Square[36];

                for (int y = 0; y < 6; y += 1)
                {
                    for (int x = 0; x < 6; x += 1)
                    {
                        var s = bestMove.Board.Squares[x, y];
                        newNumbers[x + (y * 6)] = s;
                        secondMove[x + (y * 6)] = bestMoves.Board[x, y];
                    }
                }

                MoveOneBoard = newNumbers;
                MoveTwoBoard = secondMove;
            }
            else
            {
                MoveOneBoard = null;
                MoveTwoBoard = null;
            }
        }