public void MoveTrainHorizontally(double trainSpeed)
        {
            var random = new Random(123123);

            for (var i = 0; i < 100; i++)
            {
                var world = new World(TileType.GetTileTypes(), new DateTime());

                var train = new Train(0, trainSpeed, true, 0);

                var gridX = random.Next(World.MinGridPosition.X, World.MaxGridPosition.X);
                var gridY = random.Next(World.MinGridPosition.Y, World.MaxGridPosition.Y);

                var trackLength = 5;
                for (var j = 0; j < trackLength; j++)
                {
                    var tile = world.CreateFromName("railStraight", new Int2(j + gridX, gridY), 0);
                    if (j == 0)
                    {
                        tile = tile.With(data: new TileRail(new[] { train }.ToImmutableList()));
                    }
                    world.AddTile(tile);
                }

                var startPos = world.GetTrainPosition(train.Id) ?? new Double2();

                world.MoveTrains(new DateTime() + TimeSpan.FromSeconds(1));

                var endPos = world.GetTrainPosition(train.Id) ?? new Double2();

                Assert.AreEqual(startPos.X + Math.Min(trainSpeed, trackLength), endPos.X, 0.0001);
                Assert.AreEqual(gridY + 0.5, endPos.Y, 0.0001);
            }
        }
        public void ClickingOnDepotSendsOutTrain()
        {
            var world = new World(TileType.GetTileTypes(), new DateTime());

            var depot = world.CreateFromName("depot", new Int2(), 2);

            world.AddTile(depot);
            world.AddTile(world.CreateFromName("railStraight", new Int2(6, 1), 0));

            Assert.IsTrue(world.ClickTile(depot.BaseData));
            var expected = new[]
            {
                depot.With(data: new TileDepot(new[] { new Train(1, World.TrainSpeed, false, 0) }.ToImmutableList(), false))
            };

            Assert.AreEqual(expected, world.RailTiles);
        }
        public void TrainFlipsTurnFork()
        {
            var world = new World(TileType.GetTileTypes(), new DateTime());

            var depot = world.CreateFromName("depot", new Int2(), 2);

            world.AddTile(depot);
            var rail = world.CreateFromName("railSplitLeft", new Int2(5, 1), 1);

            world.AddTile(rail);

            world.ClickTile(depot.BaseData);

            world.MoveTrains(new DateTime() + TimeSpan.FromSeconds(3));

            var expected = new[]
            {
                rail.With(data: new TileRailFork(new[] { new Train(0, World.TrainSpeed, false, 0) }.ToImmutableList(), true))
            };

            Assert.AreEqual(expected, world.RailTiles);
        }
        public void TrainTurn(bool turnUp)
        {
            var world = new World(TileType.GetTileTypes(), new DateTime());

            var depot = world.CreateFromName("depot", new Int2(), 2);

            world.AddTile(depot);
            var rail = world.CreateFromName("railTurn", new Int2(5, turnUp ? -1 : 1), turnUp ? 0 : 1);

            world.AddTile(rail);

            world.ClickTile(depot.BaseData);

            world.MoveTrains(new DateTime() + TimeSpan.FromSeconds(3));

            var expected = new[]
            {
                rail.With(data: new TileRail(new[] { new Train(turnUp ? 1 : 0, World.TrainSpeed, turnUp, 0) }.ToImmutableList()))
            };

            Assert.AreEqual(expected, world.RailTiles);
        }
        public void AddAndGetTile(int tileX, int tileY, int superGridX, int superGridY, bool tileInRegion)
        {
            var world = new World(_tileTypes, new DateTime());

            world.AddTile("redHouse", new Int2(tileX, tileY), 0);

            var result = world.GetRegion(new Int2(superGridX, superGridY));

            var expected = tileInRegion
                ? new[] { world.CreateFromName("redHouse", new Int2(tileX, tileY), 0) }
                : new Tile[0];

            Assert.AreEqual(expected, result);
        }
        public void PathRotatesCorrectly(int rotation, double expectedX, double expectedY)
        {
            var random = new Random(123123);

            for (var i = 0; i < 100; i++)
            {
                var gridX = random.Next(World.MinGridPosition.X, World.MaxGridPosition.X);
                var gridY = random.Next(World.MinGridPosition.Y, World.MaxGridPosition.Y);

                var world = new World(TileType.GetTileTypes(), new DateTime());

                var tile = world.CreateFromName("depot", new Int2(gridX, gridY), rotation);
                var size = world.GetTileSize(tile);
                var path = world.GetGridPath(tile);

                Assert.AreEqual(gridX + expectedX, path(0).X, 0.01);
                Assert.AreEqual(gridY + expectedY, path(0).Y, 0.01);
            }
        }