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); }
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 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); } }