public void ShouldParseTile() { // Arrange var lines = new List <string> { "Tile 3001:", "..##.#..#.", "##..#.....", "#...##..#.", "####.#...#", "##.##.###.", "", }; // Act var tile = new TileParser().Parse(lines); // Assert tile.Id.Should().Be(3001); tile.GetPixel(0, 0).Should().Be('.'); tile.GetPixel(9, 0).Should().Be('.'); tile.GetPixel(0, 1).Should().Be('#'); tile.GetPixel(9, 0).Should().Be('.'); tile.GetPixel(0, 2).Should().Be('#'); tile.GetPixel(0, 3).Should().Be('#'); tile.GetPixel(0, 4).Should().Be('#'); tile.GetPixel(9, 4).Should().Be('.'); }
public override void OnInspectorGUI() { TileParser tp = (TileParser)target; // DrawDefaultInspector(); EditorGUILayout.Space(); hSliderValue = GUILayout.HorizontalSlider(hSliderValue, 10f, 150f); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUILayout.Button("Start Parse")) { tp.OnParseTileImage(hSliderValue); } if (GUILayout.Button("Save Parse")) { var _png = tp.parsedResult.EncodeToPNG(); Utility.SaveFile("Assets/Parser", "test", _png); } }
public bool PlaceTile([FromBody] PlaceTileDto tileDto) { Guid GameId = Guid.Empty; Guid PlayerId = Guid.Empty; if (Guid.TryParse(tileDto.gameId, out GameId) && Guid.TryParse(tileDto.playerId, out PlayerId)) { var tile = TileParser.Parse(tileDto.tileProps); if (Math.Abs(tileDto.RotateAngle) % 90 != 0) { return(false); } for (int i = 0; i < Math.Abs(tileDto.RotateAngle) / 90; i++) { if (tileDto.RotateAngle < 0) { tile.Rotate(-90); } else if (tileDto.RotateAngle > 0) { tile.Rotate(90); } } return(gamePlayService.PlaceTile(GameId, PlayerId, tile, new Coordinates(tileDto.coordinateX, tileDto.coordinateY))); } return(false); }
/// <inheritdoc/> public bool TouchVertex(VertexId vertexId) { if (_loadedTiles.Contains(vertexId.TileId)) { // tile was already loaded. return(false); } lock (_loadedTiles) { if (_loadedTiles.Contains(vertexId.TileId)) { // tile was already loaded. return(false); } var tile = Tile.FromLocalId(vertexId.TileId, _zoom); var url = _baseUrl + $"/{tile.Zoom}/{tile.X}/{tile.Y}"; using (var stream = TileParser.DownloadFunc(url)) { var parse = stream?.Parse(tile); if (parse == null) { return(false); } var result = _routerDb.AddOsmTile(_idMap, tile, parse); _loadedTiles.Add(vertexId.TileId); return(result); } } }
public void RotateLeftTest() { var input = @"Tile 2311:|..##.#..#.|##..#.....|#...##..#.|####.#...#|##.##.###.|##...#.###|.#.#.#..##|..#....#..|###...#.#.|..###..###".Replace("|", Environment.NewLine); var expectedOutput = @"Tile 2311:|...#.##..#|#.#.###.##|....##.#.#|....#...#.|#.##.##...|.##.#....#|#..##.#..#|#..#...###|.#.####.#.|.#####..#.".Replace("|", Environment.NewLine); var tiles = TileParser.Parse(input); var expectedOutputTiles = TileParser.Parse(expectedOutput); var output = tiles[0].RotateLeft(); var maxX = output.Spaces.Values.Max(s => s.Position.X); var maxY = output.Spaces.Values.Max(s => s.Position.Y); for (var x = 0; x <= maxX; x++, x++) { for (var y = 0; y <= maxY; y++) { var position = new Position(x, y); var expected = expectedOutputTiles[0].GetSpaceAtPosition(position); var actual = output.GetSpaceAtPosition(position); Assert.Equal(expected, actual); } } }
public void FindMatches() { var input = @"Tile 2311:|..##.#..#.|##..#.....|#...##..#.|####.#...#|##.##.###.|##...#.###|.#.#.#..##|..#....#..|###...#.#.|..###..###".Replace("|", Environment.NewLine); var tiles = TileParser.Parse(input); var outerEdges = tiles[0].GetOuterEdges(); var top = new List <bool> { false, false, true, true, false, true, false, false, true, false }; var left = new List <bool> { false, true, true, true, true, true, false, false, true, false }; var right = new List <bool> { false, false, false, true, false, true, true, false, false, true }; var bottom = new List <bool> { false, false, true, true, true, false, false, true, true, true }; Assert.Equal(top, outerEdges.Edges[Side.Top].Select(x => x.IsActivated).ToList()); Assert.Equal(left, outerEdges.Edges[Side.Left].Select(x => x.IsActivated).ToList()); Assert.Equal(right, outerEdges.Edges[Side.Right].Select(x => x.IsActivated).ToList()); Assert.Equal(bottom, outerEdges.Edges[Side.Bottom].Select(x => x.IsActivated).ToList()); }
public Tile(string propertiesAsString) { var tile = TileParser.Parse(propertiesAsString); if (tile is Tile) { Directions = tile.Directions; Speciality = tile.Speciality; } }
public Guid CreateGameSession(string playerName) { var tileStack = new TileParser().TileStack; var randomNumberGenerator = new Random(); var newGamePlay = new GamePlay(tileStack, randomNumberGenerator); Controller.AddGamePlay(newGamePlay); PlayerService.Subscribe(newGamePlay.Id, playerName); return(newGamePlay.Id); }
public void Puzzle1() { var input = new FileReader() .GetResource("AdventOfCode2020.Tests.Day19.PuzzleInput.txt"); var tiles = TileParser.Parse(input); var matches = EdgeMatchFinder.FindMatchingEdges(tiles); var corners = matches.Where(x => x.Matches.Count == 2); Assert.Equal(12519494280967, corners.Aggregate(1L, (current, match) => current * match.Tile.Id)); }
public void TileParserTests() { var input = @"Tile 2311:|..##.#..#.|##..#.....|#...##..#.|####.#...#|##.##.###.|##...#.###|.#.#.#..##|..#....#..|###...#.#.|..###..###".Replace("|", Environment.NewLine); var tiles = TileParser.Parse(input); var tile = Assert.Single(tiles); var space = tile.GetSpaceAtPosition(new Position(0, 0)); Assert.False(space.IsActivated); space = tile.GetSpaceAtPosition(new Position(0, 1)); Assert.True(space.IsActivated); }
public void Puzzle2Example() { var input = new FileReader() .GetResource("AdventOfCode2020.Tests.Day19.Puzzle1Example.txt"); var tiles = TileParser.Parse(input); var matches = EdgeMatchFinder.FindMatchingEdges(tiles); var map = MapBuilder.BuildMap(MapBuilder.PlaceMap(matches)); var maxX = map.Tiles.Values.Max(x => x.Position.X); var maxY = map.Tiles.Values.Max(x => x.Position.Y); for (var y = 0; y <= maxY; y++) { var spaces = ""; for (var x = 0; x <= maxX; x++) { var position = new Position(x, y); spaces += map.Tiles[position.GetUniqueKey()].GetString(); } _testOutputHelper.WriteLine(spaces); } }