public (int time, List <DomainEvent> events) Run(string initialCargo) { var cargos = CargosFromCharArray(initialCargo.ToCharArray()); var events = new List <DomainEvent>(); transports.Add(new Transport(0, Place.Factory, Place.Factory, TransportType.Vehicle, 1, 0)); transports.Add(new Transport(1, Place.Factory, Place.Factory, TransportType.Vehicle, 1, 0)); transports.Add(new Transport(2, Place.Port, Place.Port, TransportType.Ship, 4, 1)); SimulationTime.Reset(); map[Place.Factory].SetCargo(cargos); while (true) { foreach (var t in transports) { events.AddRange(t.Work(map)); } if (cargos.All(c => c.ArrivedAtDestination)) { break; } SimulationTime.Elapse(); } return(SimulationTime.Now(), events); }
private IList <Cargo> Unload() { if (!isUnloading) { isUnloading = true; etaLoad = loadTime; } if (etaLoad == 0) { var toUnload = new List <Cargo>(cargo); foreach (var c in toUnload) { c.NextLeg(); } cargo.Clear(); isUnloading = false; GoToBase(); events.Add(new CargoUnloaded(SimulationTime.Now(), transportId, type, currentLocation, loadTime, toUnload.ToArray())); return(toUnload); } etaLoad--; return(new List <Cargo>()); }
private void Move() { if (currentDestination == currentLocation) { return; } if (eta == timeToDestination) { events.Add(new TransportDeparted(SimulationTime.Now(), transportId, type, currentLocation, currentDestination, cargo.ToArray())); } if (eta == 0) { currentLocation = currentDestination; events.Add(new TransportArrived(SimulationTime.Now(), transportId, type, currentLocation, cargo.ToArray())); } eta--; }
private void Load(Warehouse warehouse) { if (!isLoading) { var cargoToLoad = warehouse.GetCargoFor(type, capacity); isLoading = true; etaLoad = loadTime; cargo.AddRange(cargoToLoad); } if (etaLoad == 0) { var(destination, timeDistance) = cargo[0].GetDestinationFor(type); Start(destination, timeDistance); isLoading = false; events.Add(new CargoLoaded(SimulationTime.Now(), transportId, type, currentLocation, loadTime, cargo.ToArray())); } etaLoad--; }