public void GenerateField() { Random random = new Random(); int minesToInsert = Constants.MinesToInsert; while (minesToInsert > 0) { for (int i = 0; i < this.field.GetLength(0); i++) { if (minesToInsert == 0) { break; } for (int j = 0; j < this.field.GetLength(1); j++) { if (minesToInsert == 0) { break; } int randomNumber = random.Next(0, 3); if (randomNumber == 1) { this.field[i, j] = Constants.MinesSymbol; minesToInsert--; } } } } this.field = MatrixGenerator.GenerateMatrix(this.field, Constants.MinesSymbol); }
private static void Main() { var matrix = MatrixGenerator.GenerateMatrix(); MatrixGeneratorLogic.SetMatrixValues(matrix); MatrixGenerator.PrintMatrix(matrix); }
public void Start() { //gameInProgress = true; // cellsOpened = 0; this.playerMatrix = new char[Constants.MatrixRow, Constants.MatrixColumn]; this.matrix = new char[Constants.MatrixRow, Constants.MatrixColumn]; matrix = MinesGenerator.GenerateMinesweeperInMatrix(matrix, minesSimbol: Constants.MinesSymbol); matrix = MatrixGenerator.GenerateMatrix(matrix, symbolToSkip: Constants.MinesSymbol); for (int i = 0; i < playerMatrix.GetLength(0); i++) { for (int j = 0; j < playerMatrix.GetLength(1); j++) { playerMatrix[i, j] = Constants.Symbol; } } renderer.WriteLine(String.Empty); renderer.WriteLine(String.Empty); renderer.WriteLine("Welcome to the game “Minesweeper”. Try to reveal all cells without mines. " + "Use 'top' to view the scoreboard, 'restart' to start a new game and 'exit' " + "to quit the game."); renderer.WriteLine(String.Empty); PrintMatrix(playerMatrix); while (gameInProgress) { Commands(); } }
private IObjectiveFunction CreateObjectiveFunction(DataTable cases) { var gen = new MatrixGenerator(new PythagoreanCalculator()); var matrix = gen.GenerateMatrix(cases, new EastingNorthingColumnIndexer(0, 1)); var objective = new SimpleTourLengthCalculator(matrix); return(objective); }
private void RestartGame() { Console.WriteLine(Messages.Welcome); this.tiles = MatrixGenerator.GenerateMatrix(); this.tiles = MatrixGenerator.ShuffleMatrix(this.tiles); this.isGameFinished = Gameplay.IsMatrixSolved(this.tiles); Gameplay.PrintMatrix(this.tiles); this.gameState = State.InGame; }
/// <summary> /// Starts the matrix generation. /// </summary> /// <param name="logger">The logger that will be used by the generator.</param> /// <param name="config">The configuration that will be used by the generator.</param> /// <param name="searchFolder">The folder containing the media samples.</param> static void StartMatrixGenerator(ILogger logger, ConfigManager config, string searchFolder) { MatrixGenerator generator = new MatrixGenerator(logger, config, searchFolder); generator.ProgressReporter = new ConsoleReporter(logger); try { generator.GenerateMatrix(); } catch (Exception e) { Logger.Error(e); } }
public void GenerateMatrixTest() { IList <ITile> tiles = new List <ITile>(); for (int index = 1; index < 16; index++) { tiles.Add(new Tile(index.ToString(), index - 1)); } tiles.Add(new Tile(string.Empty, 15)); IList <ITile> generatedTiles = MatrixGenerator.GenerateMatrix(); for (int index = 0; index < generatedTiles.Count; index++) { Assert.AreEqual(generatedTiles[index].Position, tiles[index].Position); Assert.AreEqual(generatedTiles[index].Label, tiles[index].Label); } }
private static void MatrixTest(DataTable tableOutput, ref ExcelWorkBookAdaptor adapter, ref Point topLeft, PythagoreanCalculator calc) { var generator = new MatrixGenerator(calc); var matrix = generator.GenerateMatrix(tableOutput, new EastingNorthingColumnIndexer(0, 1)); if (null != matrix) { adapter = new ExcelWorkBookAdaptor(); adapter.NewBook(); adapter.Show(); var tableAdapter = new DataTableToExcelAdaptor(adapter[0], matrix); tableAdapter.Write(topLeft); } var len = new SimpleTourLengthCalculator(matrix); Console.WriteLine(len.TourLength(Enumerable.Range(0, 4).ToList <int>()).ToString()); Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
/// <summary> /// Main method of the program. /// </summary> public static void Main() { List <Tile> tilesMatrix = new List <Tile>(); int movesCount = 0; string currentCommand = "restart"; bool isMatrixSolved = false; while (currentCommand != "exit") { if (!isMatrixSolved) { switch (currentCommand) { case "restart": { string welcomeMessage = "Welcome to the game “15”. Please try to arrange the numbers sequentially." + "\nUse 'top' to view the top scoreboard, 'restart' to start a new game and 'exit'\nto quit the game."; Console.WriteLine(); Console.WriteLine(welcomeMessage); tilesMatrix = MatrixGenerator.GenerateMatrix(); tilesMatrix = MatrixGenerator.ShuffleMatrix(tilesMatrix); isMatrixSolved = Gameplay.IsMatrixSolved(tilesMatrix); Console.WriteLine(Gameplay.GetMatrixAsString(tilesMatrix)); break; } case "top": { Console.WriteLine(Scoreboard.PrintScoreboard()); break; } } Console.Write("Enter a number to move: "); currentCommand = Console.ReadLine(); int tileLabel; bool isMovingCommand = int.TryParse(currentCommand, out tileLabel); if (isMovingCommand) { try { Gameplay.MoveTiles(tilesMatrix, tileLabel); movesCount++; Console.WriteLine(Gameplay.GetMatrixAsString(tilesMatrix)); isMatrixSolved = Gameplay.IsMatrixSolved(tilesMatrix); } catch (Exception exception) { Console.WriteLine(exception.Message); } } else { currentCommand = currentCommand.ToLower(); if (!Enum.GetNames(typeof(Command)).Any(x => x.ToLower().Equals(currentCommand))) { Console.WriteLine("Invalid command"); } } } else { if (movesCount == 0) { Console.WriteLine("Your matrix was solved by default :) Come on - NEXT try"); } else { Console.WriteLine("Congratulations! You won the game in {0} moves.", movesCount); if (Scoreboard.CheckPlayerScores(movesCount)) { Console.Write("Please enter your name for the top scoreboard: "); string playerName = Console.ReadLine(); Player player = new Player(playerName, movesCount); Scoreboard.AddPlayer(player); } else { Console.WriteLine("Your scores are not at top five."); } Console.WriteLine(Scoreboard.PrintScoreboard()); } currentCommand = "restart"; isMatrixSolved = false; movesCount = 0; } } }