public void Simple3x3FieldWith1MineInMiddle() { // Arrange IUnityContainer container = new UnityContainer(); FieldSettings fieldSettings = new FieldSettings() { Mines = 1, Rows = 3, Columns = 3 }; container.RegisterInstance(fieldSettings); container.RegisterType <IMineSetter, MineSetter3x3With1Mine>(); container.RegisterType <INeighbourMinesCalculator, NeighbourMinesCalculator>(); var fieldGenerator = new FieldGenerator(container); // Act fieldGenerator.Generate(); var field = container.Resolve <Field>(); // Assert int[,] solution = new int[, ] { { 1, 1, 1 }, { 1, 0, 1 }, { 1, 1, 1 } }; for (int columnIndex = 0; columnIndex < field.Columns; columnIndex++) { for (int rowIndex = 0; rowIndex < field.Rows; rowIndex++) { Assert.IsTrue(field[columnIndex, rowIndex].NeighbourMines == solution[columnIndex, rowIndex]); } } }
static void Game() { Console.Clear(); Field fieldOne; Field fieldTwo; if (placementMode == "Automatic") { fieldOne = FieldGenerator.Generate(size); fieldTwo = FieldGenerator.Generate(size); } else { if (playMode == "PVE") { fieldOne = CreateField("Player 1"); fieldTwo = FieldGenerator.Generate(size); } else { fieldOne = CreateField("Player 1"); fieldTwo = CreateField("Player 2"); } } Play(fieldOne, fieldTwo); }
public void Generate_EnterCertainSize_FieldCreatedWithCertainSize(int size) { var f = FieldGenerator.Generate(size); Assert.NotNull(f); Assert.AreEqual(size, f.Size); }
public void Generate_PassNoParams_ReturnFieldWithSize10() { var f = FieldGenerator.Generate(); Assert.NotNull(f); Assert.AreEqual(10, f.Size); }
private void Generate_Z_Mines_InXxYField(int rowCount, int columnCount, int mines) { // Arrange IUnityContainer container = new UnityContainer(); FieldSettings fieldSettings = new FieldSettings() { Mines = mines, Rows = rowCount, Columns = columnCount }; container.RegisterInstance(fieldSettings); container.RegisterType <IMineSetter, MineSetter>(); container.RegisterType <INeighbourMinesCalculator, NeighbourMinesCalculator>(); var fieldGenerator = new FieldGenerator(container); // Act fieldGenerator.Generate(); var field = container.Resolve <Field>(); int minesCount = 0; for (int columnIndex = 0; columnIndex < field.Columns; columnIndex++) { for (int rowIndex = 0; rowIndex < field.Rows; rowIndex++) { if (field[columnIndex, rowIndex].IsMine) { minesCount++; } } } // Assert Assert.IsTrue(minesCount == mines); }
protected override void Initialize() { AudioManager.PlayMusic(bgms[stageIndex - 1]); base.Initialize(); var stageData = StageTable.GetStageData(stageIndex); CostManager.instance.Earn(stageData.defaultCost); SummonTower.instance.SetTowerCount(stageData.towerCount); fieldGenerator.Generate(stageData.column, stageData.row); waveDatas = StageTable.GetStage(stageIndex); ghostPools = new Dictionary <string, LocalObjectPool <Ghost> >(); HashSet <string> ghostIds = new HashSet <string>( from wave in waveDatas from data in wave select data.id ); foreach (var id in ghostIds) { Ghost prefab = (Ghost)GhostTable.GetStatus(id).prefab; var holder = new GameObject($"{id} Holder").transform; var pool = new LocalObjectPool <Ghost>(prefab, holder, 15); ghostPools.Add(id, pool); } StartCoroutine(Staging()); }
public void RandomizeShips_EnterCorrectData_ShipsRandomized() { var f = FieldGenerator.Generate(15); FieldGenerator.RandomizeShips(f); var ships = f.Ships.Where(x => x.Size == 3).ToList(); Assert.AreNotEqual(ships[0].Points.ToList()[0], ships[1].Points.ToList()[0]); }
private void RunFieldGeneratorTest(TestCase testCase) { var fieldNode = Helpers.GetFirstNodeOfType <FieldDeclarationSyntax>(testCase.Code); FieldGenerator generator = new FieldGenerator(null); var newFieldNode = generator.Generate(fieldNode, 0); foreach (var VarDec in newFieldNode.Declaration.Variables) { Assert.IsTrue(VarDec.Identifier.ToString().Contains(FieldGenerator.VAR_PREFIX)); } }
public static IEnumerable <FieldDeclarationSyntax> Build( IEnumerable <MethodDescription> methodsDescription) { var fieldGenerator = new FieldGenerator(); foreach (var description in methodsDescription) { var refField = GenerateMethodRefFieldDescription(description); yield return(fieldGenerator.Generate(refField)); } }
public void StartGame() { isGameStart = true; SetMenuActive(false); fieldGenerator.Generate(whichSize.FieldSize); field = new int[whichSize.FieldSize, whichSize.FieldSize]; CreateEmptyField(); if (whichFirst.SelectedFigure == whichGame.EnemyFigure) { Vector2 enemyIndexes = bot.NextTurn(); placeFigure.Put(whichGame.EnemyFigure, enemyIndexes); field[(int)enemyIndexes.x, (int)enemyIndexes.y] = (int)whichGame.EnemyFigure; } StartCoroutine(GameCoroutine()); }
public static IEnumerable <FieldDeclarationSyntax> Build( string classRefName, string jObjectName, string lockObjectName) { var classRefDescription = new FieldDescription( classRefName, GLOBAL_REF_TYPE, new List <ModifierDescription>()); var jObjectDescription = new FieldDescription( jObjectName, GLOBAL_REF_TYPE, new List <ModifierDescription> { ModifierDescription.FINAL }); var monitorDescription = new FieldDescription( lockObjectName, "object", new List <ModifierDescription> { ModifierDescription.FINAL, ModifierDescription.STATIC }); var fieldGenerator = new FieldGenerator(); return(new[] { classRefDescription, jObjectDescription, monitorDescription } .Select(el => { if (el.Name == "monitor") { fieldGenerator = fieldGenerator.InitializedWith(GetMonitorFieldInitExpression()); } return fieldGenerator.Generate(el); }) .ToArray()); }
public void RandomGameTest() { Console.SetIn(new StringReader( @"5 0 4 3 1")); int expectedMoves = 2; int size = UserInterface.ReadSize(); Field field = new Field(size, size); FieldGenerator generator = new FieldGenerator(field, new Random(0)); generator.Generate(); Engine engine = new Engine(field); engine.OnGameOver += (obj, numberOfMoves) => { Assert.AreEqual(expectedMoves, numberOfMoves); }; engine.Run(); string[] expectedField = { "-", "-", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", "-", "X", "X", "X", "X", "-" }; CollectionAssert.AreEquivalent(expectedField, field.Value); }
static void Main(string[] args) { for (int i = 2; i < 16; i++) { FieldGenerator generator = new FieldGenerator(i); for (int j = 0; j < 100; j++) { Field f = generator.Generate(); FieldSolver solver = new FieldSolver(f); if (solver.Solve()) { Console.WriteLine($"[{i}][{j}] solved"); } else { Console.WriteLine($"[{i}][{j}] not solved"); } } } Console.ReadKey(); }
/// <summary> /// Generates code for the specified field information. /// </summary> /// <param name="fieldInfo">The field information.</param> /// <returns>System.String.</returns> public string Generate(FieldInfo fieldInfo) => _fieldGenerator.Generate(fieldInfo);