private List <Cell> MapRouteWhile(List <Route.Specs> routesSpecs, bool bubble) { if (bubble) { Write.Print($"° bubble o O"); } List <Cell> missingCells = new List <Cell>(); while (this.Grid.PendingPacketsNumber > 0 && this.PendingDrones.Count() > 0) { Path path = new Path(this.Grid.StartCell, this.Grid); Route route = null; if (bubble == true) { route = path.MapBubbleRoute(routesSpecs); } else { route = path.MapRoute(routesSpecs); } if (route != null) { this.PendingDrones.FirstOrDefault()?.SetRoute(route); Write.Print($"route mapped : {this.Routes.Count()}, packet assigned : {this.Grid.AssignedPacketsNumber} packets left : {this.Grid.PendingPacketsNumber} missing cells : {missingCells.Count()}, drone left : {this.PendingDrones.Count()}"); } else { Cell missingPacket = path.ClosestPendingPath(this.Grid.StartCell).ReachCell; missingCells.Add(missingPacket); this.Grid.SetPacketState(missingPacket, Packet.State.Missing); Write.Print($"missing cells : {missingPacket} failed to get any route from : {string.Join(" or ", routesSpecs)}"); } } this.Grid.ResetMissingPackets(); return(missingCells); }
/// <summary>Gets delivery score from estimation</summary> /// <returns>score as int</returns> public int Score() { IEnumerable <Drone> drones = from i in this.Drones where i.Route != null select i; List <Route> routes = (from i in drones select i.Route).ToList(); int movesNumber = (from i in routes select i.MovesCount).Sum(); int score = this.Grid.DeliveredPacketsNumber * ((this.MaxRound * this.Drones.Count()) - movesNumber); if (this.Grid.DeliveredPacketsNumber == this.Grid.Packets.Count()) { score += this.Grid.Packets.Count() * 10; Write.Print($"score:{score} = deliveredPacketNumber:{this.Grid.DeliveredPacketsNumber} * ((maxRound:{this.MaxRound} * dronesCount:{this.Drones.Count()}) - movesCount:{movesNumber}) + bonus:Packets*10:{this.Grid.Packets.Count() * 10}"); } else { Write.Print($"score:{score} = deliveredPacketNumber:{this.Grid.DeliveredPacketsNumber} * ((maxRound:{this.MaxRound} * dronesCount:{this.Drones.Count()}) - movesCount:{movesNumber})"); } return(score); }