public void Create_EnterNoData_CreatedFieldWithSize10() { Field f = FieldCreator.Create(); Assert.NotNull(f); Assert.AreEqual(10, f.Size); }
public void Place_PlacedToIncorrectPlace_ReturnedFalse() { var ship1 = new Ship { Direction = ShipDirection.Vertical, Hp = 4, Size = 3, Points = new List <Point> { new Point(0, 0), new Point(0, 1), new Point(0, 2), new Point(0, 3), } }; var ship2 = new Ship { Direction = ShipDirection.Vertical, Hp = 3, Size = 3, Points = new List <Point> { new Point(0, 0), new Point(0, 1), new Point(0, 2), } }; FieldCreator.Place(ship1, field); var res = FieldCreator.Place(ship2, field); Assert.IsFalse(res); }
public void Create_EnterSize_CreatedFieldWithCertainSize() { Field f = FieldCreator.Create(15); Assert.NotNull(f); Assert.AreEqual(15, f.Size); }
public void FieldCreatorShouldMakeNewFieldIfNumberRead() { var fieldCreator = new FieldCreator(); var lineRetriever = new LineRetriever(new[] { "11", ".", "22", "..", "*.", "00" }); var allFields = fieldCreator.ReadFields(lineRetriever); Assert.Equal(2, allFields.Count); }
public void ShouldMakeArrayBasedOnFieldSize(string [] input, int rank, int length) { var fieldCreator = new FieldCreator(); var lineRetriever = new LineRetriever(input); var allFields = fieldCreator.ReadFields(lineRetriever); var fieldArray = HintFieldCalculator.ConvertToArray(allFields[0]); Assert.Equal(rank, fieldArray.Rank); Assert.Equal(length, fieldArray.Length); }
/// <summary> /// Initializes the parallel processor. /// </summary> /// <param name="imageSize">Image size.</param> /// <param name="destImageCreator">Destination image creator.</param> /// <param name="processPatch">Process patch func. The function will execute on every patch.</param> /// <param name="parallelOptions">Parallel options.</param> /// <param name="minPatchHeight">Minimal patch height. Put 0 if there are no preferences.</param> protected void Initialize(Size imageSize, FieldCreator destImageCreator, ProcessPatch processPatch, ParallelOptions2D parallelOptions, int minPatchHeight) { this.imageSize = imageSize; this.destImageCreator = destImageCreator; this.processPatch = processPatch; this.runParallel = parallelOptions.ShouldProcessParallel(imageSize); //assume depth = sizeof(byte) if (runParallel) //do not build structures if they are not needed { makePatches(imageSize, minPatchHeight, out patches); } }
public void ShouldConvertFieldToArray() { var fieldCreator = new FieldCreator(); var lineRetriever = new LineRetriever(new [] { "22", "..", "*.", "00" }); var allFields = fieldCreator.ReadFields(lineRetriever); var hintArray = HintFieldCalculator.ConvertToArray(allFields[0]); Assert.Equal(4, hintArray.Length); Assert.Equal(CellType.Empty, hintArray[0, 0]); Assert.Equal(CellType.Empty, hintArray[0, 1]); Assert.Equal(CellType.Mine, hintArray[1, 0]); Assert.Equal(CellType.Empty, hintArray[1, 1]); }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); GameDirector gameDirector = new GameDirector(); MainForm mainForm = new MainForm(); FieldCreator fieldCreator = new FieldCreator(args); PackmanController packmanController = new PackmanController(mainForm, gameDirector, fieldCreator); Application.Run(mainForm); }
public void ShouldMakeFieldFromFile() { var mock = new Mock <IInputReader>(); mock.Setup(input => input.ReadFile("")).Returns(new[] { "22", "..", ".*", "00" }); var fieldCreator = new FieldCreator(); var lineRetriever = new LineRetriever(mock.Object.ReadFile("")); var fields = fieldCreator.ReadFields(lineRetriever); Assert.Equal(new [] { "22", "..", ".*", "00" }, mock.Object.ReadFile("")); Assert.Equal(new List <CellType> { CellType.Empty, CellType.Empty }, fields[0].GetRow(0)); Assert.Equal(new List <CellType> { CellType.Empty, CellType.Mine }, fields[0].GetRow(1)); }
private void OnDrawGizmos() { Timer timer = new Timer("OnDrawGizmos"); fieldCreator = gameObject.GetComponent <FieldCreator>(); //field = fieldCreator.GeneratePerlinField(); //fieldCreator.DrawFieldGizmo(field); Brush brush = gameObject.GetComponent <Brush>(); fieldCreator.DrawFieldGizmo(brush.CalculateBrushweight(new Vector3Int(field.GetLength(0), field.GetLength(1), field.GetLength(2)))); if (Input.GetMouseButton(0)) { Debug.Log("Adding Terrain"); field = brush.AddToFieldWeight(field, 1); } if (Input.GetMouseButton(1)) { Debug.Log("Removeing Terrain"); field = brush.AddToFieldWeight(field, -1); } CreateCubes(field); gameObject.GetComponent <MeshFilter>().mesh = GenerateCombinedMesh(); foreach (MarchingCube cube in marchingCubes) { foreach (Vector3 item in cube.IntersectionPoints) { //Gizmos.color = new Color(0, 0, 1, 0.75f); //Gizmos.DrawCube(item, Vector3.one * 0.1f); } } timer.End(); }
public void SetUp() { field = FieldCreator.Create(); ship = new Ship { Direction = ShipDirection.Horizontal, Hp = 4, Size = 4, Points = new List <Point> { new Point(0, 0), new Point(1, 0), new Point(2, 0), new Point(3, 0) } }; FieldCreator.Place(ship, field); process = new GameProcess(); }
public static void loadNew() { FieldCreator.setNumber(1); Application.LoadLevel("free"); }
void Awake() { s_Instance = this; }
static Field CreateField(string name) { Console.Clear(); Console.CursorVisible = true; //placement Field field = FieldCreator.Create(); field.Size = size; var shipsBuffer = FieldGenerator.CreateBlankShips(); int selected = 1; while (shipsBuffer.Count > 0) { Console.SetCursorPosition(8, 0); Console.Write($"{name}'s field"); Console.SetCursorPosition(0, 2); Console.Write(" \t"); for (int i = 0; i < field.Size; i++) { Console.Write(((char)(65 + i))); Console.Write(" "); } Console.WriteLine("\n"); for (int i = 0; i < field.Size; i++) { Console.Write(i + 1 + "\t"); for (int j = 0; j < field.Size; j++) { bool b = false; foreach (var ship in field.Ships) { if (ship.Points.Contains(new Point(j, i))) { Console.Write("■ "); b = true; break; } } if (!b) { Console.Write(". "); } } Console.WriteLine(); } var groupped = shipsBuffer.GroupBy(x => x.Size); int added = 4; int selectedKey = 0; for (int i = 0; i < groupped.Count(); i++) { Console.SetCursorPosition(field.Size + 30, added++); if (selected == i + 1) { Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; selectedKey = groupped.ToList()[i].Key; } else { Console.ResetColor(); } Console.Write(groupped.ToList()[i].Count() + " "); var str = new string('■', groupped.ToList()[i].Key * 2); Console.Write(str); Console.ResetColor(); } var k = Console.ReadKey().Key; if (k == ConsoleKey.DownArrow) { if (selected < groupped.Count()) { selected++; } } else if (k == ConsoleKey.UpArrow) { if (selected > 1) { selected--; } } else if (k == ConsoleKey.Enter) { var ship = shipsBuffer.Find(x => x.Size == selectedKey); Console.SetCursorPosition(field.Size + 30, added++); Console.Write("Direction? h/v"); Console.SetCursorPosition(field.Size + 30, added++); var key = Console.ReadKey().Key; if (key == ConsoleKey.H) { ship.Direction = ShipDirection.Horizontal; } if (key == ConsoleKey.V) { ship.Direction = ShipDirection.Vertical; } Console.SetCursorPosition(field.Size + 30, added++); Console.Write("Enter start's position"); Console.SetCursorPosition(field.Size + 30, added++); var pos = Console.ReadLine().Split(' '); Console.SetCursorPosition(field.Size + 30, added++); try { var x = Convert.ToChar(pos[0]) - 65; var y = Convert.ToInt32(pos[1]) - 1; ship.Points = new List <Point>(); for (int i = 0; i < ship.Size; i++) { if (ship.Direction == ShipDirection.Horizontal) { ship.Points.Add(new Point(x++, y)); } else { ship.Points.Add(new Point(x, y++)); } } var b = FieldCreator.Place(ship, field); if (b) { shipsBuffer.Remove(ship); } } catch { } Console.Clear(); } else if (k == ConsoleKey.Escape) { Console.CursorVisible = false; Menu(); } } Console.CursorVisible = false; return(field); }
private void OnValidate() { fieldCreator = gameObject.GetComponent <FieldCreator>(); field = fieldCreator.GeneratePerlinField(); }
/// <summary> /// Creates parallel patch processor. /// </summary> /// <param name="imageSize">2D structure size.</param> /// <param name="destFieldCreator">Function that creates destination structure.</param> /// <param name="processPatch">Function that performs patch processing.</param> public ParallelProcessor(Size imageSize, FieldCreator destFieldCreator, ProcessPatch processPatch) : this(imageSize, destFieldCreator, processPatch, new ParallelOptions2D(), 0) { }
/// <summary> /// Creates parallel patch processor. /// </summary> /// <param name="imageSize">2D structure size.</param> /// <param name="destFieldCreator">Function that creates destination structure.</param> /// <param name="processPatch">Function that performs patch processing.</param> /// <param name="parallelOptions">Parallel options.</param> /// <param name="minPatchHeight">Minimal patch height. Patches that has lower size will not be created.</param> public ParallelProcessor(Size imageSize, FieldCreator destFieldCreator, ProcessPatch processPatch, ParallelOptions2D parallelOptions, int minPatchHeight = 0) { Initialize(imageSize, destFieldCreator, processPatch, parallelOptions, minPatchHeight); }