示例#1
0
        // create the non-graphical parts of the game
        private void InitializeTiles1()
        {
            gameNumber++;
            logicalLock = false;

            minesLeftSize = Math.Max(3, (int)Math.Log10(gameDescription.mines) + 1);

            MinesLeftHolder.Width = 24 * minesLeftSize + 8;
            for (int i = 0; i < digits.Length; i++)
            {
                if (i < minesLeftSize)
                {
                    digits[i].Visibility = Visibility.Visible;
                }
                else
                {
                    digits[i].Visibility = Visibility.Hidden;
                }
            }

            int seed = 0;

            if (useSeed.IsChecked == true)
            {
                try {
                    seed = int.Parse(SeedTextBox.Text);
                } catch (Exception) {
                }
            }

            //game = new MinesweeperGame(gameDescription, seed);
            game       = new MinesweeperGame(gameDescription, seed, (hardcore.IsChecked == true));
            solverInfo = new SolverInfo(gameDescription, verbose);

            RenderMinesLeft();

            long start = DateTime.Now.Ticks;

            tiles         = new ActionResult[gameDescription.width, gameDescription.height];
            solverActions = new SolverActionHeader();   // remove any hints from the previous game

            Utility.Write("Ticks to build screen " + (DateTime.Now.Ticks - start));
        }
示例#2
0
        // this method runs on a different thread. gameNumber is changed by clicking chosing a new game from the UI thread.
        private void AutoPlayRunner()
        {
            Dispatcher.Invoke(() => gameCanvas.Cursor = Cursors.Wait);
            logicalLock = true;

            int runningGameNumber = gameNumber;  // remember the game number we are solving

            //Utility.Write("AutoRunning thread starting");

            solverActions = SolverMain.FindActions(solverInfo);   // pass the solver info into the solver and see what it comes up with
            Dispatcher.Invoke(() => RenderHints());

            while (IsAutoPlayValid() && gameNumber == runningGameNumber)
            {
                long start = DateTime.Now.Ticks;

                GameResult result = game.ProcessActions(solverActions.solverActions);

                //Utility.Write("Game controller returned " + result.actionResults.Count + " results from this action");

                long end1 = DateTime.Now.Ticks;
                // do the rendering while we are stil playing the same game
                if (gameNumber == runningGameNumber)
                {
                    gameCanvas.Dispatcher.Invoke(() => RenderResults(result));
                }
                else
                {
                    break;
                }
                //Utility.Write("After RenderResults took " + (DateTime.Now.Ticks - start) + " ticks");

                solverInfo.AddInformation(result);  // let the solver know what has happened

                // nothing more to do if we have won or lost
                if (result.status == GameStatus.Lost || result.status == GameStatus.Won)
                {
                    Dispatcher.Invoke(() => DisplayFinalOutcome(result));
                    break;
                }

                solverActions = SolverMain.FindActions(solverInfo);   // pass the solver info into the solver and see what it comes up with

                //foreach (SolverAction action in solverActions) {
                //    Utility.Write("Playing " + action.AsText() + " probability " + action.safeProbability);
                //}

                //long end2 = DateTime.Now.Ticks;
                // do the rendering while we are stil playing the same game
                if (gameNumber == runningGameNumber)
                {
                    Dispatcher.Invoke(() => RenderHints());
                }
                else
                {
                    break;
                }
                //Utility.Write("After RenderHints took " + (DateTime.Now.Ticks - start) + " ticks");
                Utility.Write("Tiles remaining " + solverInfo.GetTilesLeft());

                long end = DateTime.Now.Ticks;

                int milliseconds = (int)((end - start) / 10000);

                int wait = Math.Max(0, autoPlayMinDelay - milliseconds);

                //Utility.Write("Autoplay processing took " + milliseconds + " milliseconds (" + (end - start) + " ticks)");
                //Console.WriteLine("Autoplay processing took " + milliseconds + " milliseconds");

                if (!IsAutoPlayValid())
                {
                    break;
                }

                Thread.Sleep(wait);  // wait until all the time is used up
            }

            logicalLock = false;
            Dispatcher.Invoke(() => gameCanvas.Cursor = Cursors.Arrow);

            //Utility.Write("AutoRunning thread ending");
        }