public void TestInitialize() { IUIManager consoleUIManager = new UIManager(new ConsoleRenderer(), new ConsoleReader()); game = new MinesweeperGameEasy(consoleUIManager); parser = new CommandParser(game); }
/// <summary> /// Initializes a new instance of the <see cref="CmdShowScores"/> class. /// </summary> /// <param name="game">The <see cref="MinesweeperGame"/> object on which the action will be invoked.</param> public CmdShowScores(MinesweeperGame game) { if (game == null) { throw new ArgumentNullException("game"); } this.game = game; }
/// <summary> /// Initializes a new instance of the <see cref="CmdOpenCell"/> class. /// </summary> /// <param name="game">The <see cref="MinesweeperGame"/> object on which the action will be invoked.</param> /// <param name="cellToOpen">The position of the cell on which the action will be invoked.</param> public CmdOpenCell(MinesweeperGame game, CellPos cellToOpen) { if (game == null) { throw new ArgumentNullException("game"); } this.game = game; this.cellToOpen = cellToOpen; }
public void Score_WhenValid_5() { MinesweeperGame mineswGame = new MinesweeperGame(10, 10, 5); mineswGame.Score = 5; int actual = mineswGame.Score; int expected = 5; Assert.AreEqual(expected, actual); }
/// <summary> /// Initializes a new instance of the <see cref="CmdFlagCell"/> class. /// </summary> /// <param name="game">The <see cref="MinesweeperGame"/> object on which the action will be invoked.</param> /// <param name="targetCell">The position of the cell on which the action will be invoked.</param> public CmdFlagCell(MinesweeperGame game, CellPos targetCell) { if (game == null) { throw new ArgumentNullException("game"); } this.game = game; this.targetCell = targetCell; }
public void Scoreboard_WhenValidScoreBoard() { MinesweeperGame mineswGame = new MinesweeperGame(10, 10, 5); ScoreRecord player1 = new ScoreRecord("Ivan", 4); ScoreRecord player2 = new ScoreRecord("Ivan", 5); List <ScoreRecord> board = new List <ScoreRecord>() { player1, player2 }; mineswGame.ScoreBoard = board; int actual = mineswGame.ScoreBoard.Count; int expected = 2; Assert.AreEqual(expected, actual); }
/// <summary> /// 载入游戏时的操作 /// </summary> /// <param name="gameType"></param> public void LoadGame(GameType gameType) { CurrentGame?.UnloadGame(); switch (gameType) { case GameType.Minesweeper: CurrentGame = new MinesweeperGame(this); break; case GameType.SlideJigsaw: CurrentGame = new SlideJigsawGame(this); break; case GameType.TwoZeroFourEight: CurrentGame = new TwoZeroFourEightGame(this); break; } btnStartGame_ButtonClick(btnQuickStartA, new RoutedEventArgs()); }
// 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)); }
// this method runs on a different thread. gameNumber can be changed by clicking chosing a new game from the UI thread. private static GameStatus AutoPlayRunner(MinesweeperGame game) { //long start = DateTime.Now.Ticks; SolverActionHeader solverActions; GameResult result = game.ProcessActions(firstPlay); SolverInfo solverInfo = new SolverInfo(game.description); while (result.status == GameStatus.InPlay) { solverInfo.AddInformation(result); // let the solver know what has happened solverActions = SolverMain.FindActions(solverInfo); // pass the solver info into the solver and see what it comes up with if (solverActions.solverActions.Count == 0) { Write("No actions returned by the solver!!"); break; } result = game.ProcessActions(solverActions.solverActions); //Write("Game controller returned " + result.actionResults.Count + " results from this action"); //foreach (SolverAction action in solverActions) { // Write("Playing " + action.AsText() + " probability " + action.safeProbability); //} } //long end = DateTime.Now.Ticks; //Write("game took " + (end - start) + " ticks"); return(result.status); }
static void Main(string[] args) { GameDescription description = GameDescription.EXPERT_SAFE; //GameDescription description = new GameDescription(30, 24, 225, GameType.Safe); //GameDescription description = new GameDescription(100, 100, 1500, GameType.Zero); //GameDescription description = new GameDescription(50, 50, 500, GameType.Safe); //GameDescription description = new GameDescription(8, 8, 34, GameType.Safe); if (description.gameType == GameType.Zero) { firstPlay = new GameAction[] { new GameAction(3, 3, ActionType.Clear) }; } else { firstPlay = new GameAction[] { new GameAction(0, 0, ActionType.Clear) }; } int seedGen = new Random().Next(); //int seedGen = 1104105816; Random rng = new Random(seedGen); int run = 100000; int steps = 100; int won = 0; int lost = 0; int deaths = 0; SolverMain.Initialise(); Write("using generation seed " + seedGen + " to run " + run + " games of minesweeper " + description.AsText()); Write("--- Press Enter to start ---"); Console.ReadLine(); long start = DateTime.Now.Ticks; for (int i = 0; i < run; i++) { int seed = rng.Next(); MinesweeperGame game = new MinesweeperGame(description, seed, !playUntilWin); //Write("Seed " + game.seed + " starting"); GameStatus status = AutoPlayRunner(game); int died = game.GetDeaths(); if (died < deathTable.Length) { deathTable[died]++; } else { deathTable[deathTable.Length - 1]++; } deaths = deaths + died; if (status == GameStatus.Lost) { lost++; } else if (status == GameStatus.Won) { won++; if (pauseOnWin) { Write("Seed " + game.seed + " won"); Write("--- Press Enter to continue ---"); Console.ReadLine(); } } else { Write("Seed " + game.seed + " : Unexpected game status from autoplay " + status); } if ((i + 1) % steps == 0) { Write("Seed " + game.seed + " finished. Games won " + won + " out of " + (i + 1)); } } long duration = (DateTime.Now.Ticks - start) / 10000; Write("Games won " + won + ", lost " + lost + " out of " + run + " in " + duration + " milliseconds."); double winRate = (won * 10000 / run) / 100d; Write("Win rate " + winRate + "%"); Write("Deaths " + deaths + " average deaths per game " + (deaths * 1000 / run) / 1000d); for (int i = 0; i < deathTable.Length - 1; i++) { Write("Died " + i + " times in " + deathTable[i] + " games"); } Write("Died >=" + (deathTable.Length - 1) + " times in " + deathTable[deathTable.Length - 1] + " games"); Console.ReadLine(); }
private void start_Click(object sender, EventArgs e) { if (t1 != null) { t1.Abort(); } Game = true; beginning = new Point(0, 0); if (textBoxX.Text.Length == 0 || Convert.ToInt32(textBoxX.Text) < 5) { textBoxX.Text = "5"; } if (textBoxY.Text.Length == 0 || Convert.ToInt32(textBoxY.Text) < 4) { textBoxY.Text = "4"; } X = Convert.ToInt32(textBoxX.Text); Y = Convert.ToInt32(textBoxY.Text); arrayField = new byte[X, Y]; arrayOpen = new byte[X, Y]; image = new Bitmap(21 * X, 21 * Y); field = Graphics.FromImage(image); if (domainUpDown2.Text == "обычный") { Mode = 0; } else if (domainUpDown2.Text == "зеркальный") { Mode = 1; } else if (domainUpDown2.Text == "зацыклиный") { Mode = 2; } else if (domainUpDown2.Text == "без флагов") { Mode = 3; } if (Mode == 2) { image1 = new Bitmap(21 * X, 21 * Y); field1 = Graphics.FromImage(image1); t1 = new Thread(move); } if (domainUpDown1.Text == "хардкор") { New = new MinesweeperGame(X, Y, X * Y / 4); } else if (domainUpDown1.Text == "сложно") { New = new MinesweeperGame(X, Y, X * Y / 5); } else if (domainUpDown1.Text == "средне") { New = new MinesweeperGame(X, Y, X * Y / 6); } else { New = new MinesweeperGame(X, Y, X * Y / 8); } Brush p = new SolidBrush(Color.Gray); field.Clear(Color.White); for (int i = 0; i < X; i++) { for (int j = 0; j < Y; j++) { field.FillRectangle(p, i * 21, j * 21, 20, 20); } } int MinimumX = image.Width, MinimumY = image.Height; if (MinimumX < 4110) { MinimumY = MinimumY * 4110 / MinimumX; MinimumX = 4110; } if (MinimumY < 1750) { MinimumX = MinimumX * 1750 / MinimumY; MinimumY = 1750; } this.MinimumSize = new Size(MinimumX / 10 + 40, MinimumY / 10 + 90); picture.Image = GraphicsWork.ImageResize(image, picture.Width, picture.Height); StartTime = Stopwatch.StartNew(); if (Mode == 2) { t1.Start(); } }
public void DrawCellsTests() { Assert.That(MinesweeperGame.CreateCells(10, 10), Is.True); Assert.That(MinesweeperGame.CreateCells(0, 0), Is.False); }
public void Grid_Getter() { MinesweeperGame mineGame = new MinesweeperGame(10, 10, 5); Assert.IsNotNull(mineGame.Grid); }
public void ResetBoard() { Game = new MinesweeperGame(GAME_WIDTH, GAME_HEIGHT, NUM_MINES); Clients.All.Refresh(); }
public void Score_WhenLessThan0_ShouldThrowException() { MinesweeperGame mineswGame = new MinesweeperGame(10, 10, 5); mineswGame.Score = -1; }
public void Scoreboard_WhenNull_ShouldThrowException() { MinesweeperGame mineGame = new MinesweeperGame(10, 10, 5); mineGame.ScoreBoard = null; }
void NewGame() { sampleindex++; MinesweeperGame.CreateNewGame(); vh.UpdateVisualMinesweeperComplete(gamestate); }
/// <summary> /// Rebuilds the form and all of its buttons and things. /// </summary> /// <param name="mg">The MinesweeperGame object.</param> void SetUpTheForm(MinesweeperGame mg) { currentBoardWidth = mg.CurrentGridSize; hasLostGame = false; hasWonGame = false; // Reset clicked bombs mineCount = 0; clickedMineCount = 0; foreach (GridCell cell in mg.Cells) { if (cell.HasMine) { mineCount++; } } // Flush pictures if (pictureBoxs != null) { foreach (PictureBox pictureBox in pictureBoxs) { Controls.Remove(pictureBox); } } pictureBoxs = new List <PictureBox>(); // Flush the buttons and set the window size if (gameButtons != null) { int tmp = gameButtons.GetLength(0); for (int i = 0; i < tmp; i++) { for (int j = 0; j < tmp; j++) { Controls.Remove(gameButtons[i, j]); } } } gameButtons = new MinesweeperButton[mg.CurrentGridSize, mg.CurrentGridSize]; // Define the form size and locations Width = (currentBoardWidth * (ButtonSize + BufferSize)) + Shim; Height = (TopOffset + (currentBoardWidth * (ButtonSize + BufferSize)) + (3 * Shim)) - 10; timerTextBox.Location = new Point(((Width / 2) - timerTextBox.Width) + Shim, 13); aboutButton.Location = new Point(Width - aboutButton.Width - 13 - Shim, 13); // Create the buttons for (int i = 0; i < currentBoardWidth; i++) { for (int j = 0; j < currentBoardWidth; j++) { gameButtons[i, j] = new MinesweeperButton(msGame.Cells[i, j]) { Size = new Size(ButtonSize, ButtonSize), Left = i * (ButtonSize + BufferSize), Top = (j * (ButtonSize + BufferSize)) + TopOffset, Height = ButtonSize, Width = ButtonSize, BackColor = Color.AntiqueWhite }; gameButtons[i, j].Click += ProcessClick; gameButtons[i, j].MouseDown += ProcessFlagging; gameButtons[i, j].Show(); Controls.Add(gameButtons[i, j]); PutImageUnderButton(gameButtons[i, j], gameButtons[i, j].Cell.Image); } } // Start the timer gameTimer.Interval = 1000; gameTimer.Enabled = true; gameTime = 0; }