• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

samsmithnz / PuzzleSolver / 4462687991

pending completion
4462687991

Pull #56

github

GitHub
Merge 1acbe737f into 6098e90ae
Pull Request #56: Optimizing paths

986 of 1076 branches covered (91.64%)

Branch coverage included in aggregate %.

169 of 169 new or added lines in 1 file covered. (100.0%)

1728 of 1838 relevant lines covered (94.02%)

1011480.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.66
/src/PuzzleSolver/Board.cs
1
using PuzzleSolver.Actions;
2
using PuzzleSolver.Entities;
3
using PuzzleSolver.Images;
4
using PuzzleSolver.Map;
5
using SixLabors.ImageSharp.PixelFormats;
6
using System.Collections.Generic;
7
using System.Diagnostics;
8
using System.Linq;
9
using System.Numerics;
10

11
namespace PuzzleSolver
12
{
13
    public class Board
14
    {
15
        public string[,] Map { get; set; }
309✔
16

17
        //Color Palette
18
        public List<Rgb24> ColorPalette { get; set; }
24✔
19

20
        //Pieces
21
        public Vector2 UnsortedPiecesLocation { get; set; }
14✔
22
        public Queue<Piece> UnsortedPieces { get; set; }
1,021✔
23
        public List<Piece> SortedPieces { get; set; }
100✔
24
        public List<SortedDropZone> SortedDropZones { get; set; }
726✔
25

26
        //Characters
27
        public List<Robot> Robots { get; set; }
1,101✔
28

29
        private Dictionary<int, int> _RobotProgress = new Dictionary<int, int>();
12✔
30

31
        //Constructor
32
        public Board(string[,] map,
12✔
33
            Vector2 unsortedPiecesLocation,
12✔
34
            List<Rgb24> colorPalette,
12✔
35
            List<Piece> unsortedPieceList,
12✔
36
            List<SortedDropZone> sortedDropZones,
12✔
37
            List<Robot> robots)
12✔
38
        {
12✔
39
            Map = map;
12✔
40
            UnsortedPiecesLocation = unsortedPiecesLocation;
12✔
41
            ColorPalette = colorPalette;
12✔
42
            UnsortedPieces = new Queue<Piece>();
12✔
43
            ImageColorGroups imageProcessing = new ImageColorGroups(ColorPalette);
12✔
44
            for (int i = 0; i < unsortedPieceList.Count; i++)
188✔
45
            {
82✔
46
                Piece piece = unsortedPieceList[i];
82✔
47
                piece.ImageStats = imageProcessing.ProcessStatsForImage(null, piece.Image);
82✔
48
                UnsortedPieces.Enqueue(piece);
82✔
49
            }
82✔
50
            SortedDropZones = sortedDropZones;
12✔
51
            SortedPieces = new List<Piece>();
12✔
52
            Robots = robots;
12✔
53
        }
12✔
54

55
        private int CountPiecesHeldByRobots()
56
        {
139✔
57
            int count = 0;
139✔
58
            foreach (Robot robot in Robots)
1,125✔
59
            {
354✔
60
                if (robot.Piece != null)
354✔
61
                {
119✔
62
                    count++;
119✔
63
                }
119✔
64
            }
354✔
65

66
            return count;
139✔
67
        }
139✔
68

69
        private int RobotsOutOfPosition()
70
        {
50✔
71
            int count = 0;
50✔
72
            foreach (Robot robot in Robots)
356✔
73
            {
103✔
74
                if (robot.Location != robot.PickupLocation)
103✔
75
                {
41✔
76
                    count++;
41✔
77
                }
41✔
78
            }
103✔
79

80
            return count;
50✔
81
        }
50✔
82

83
        public TimeLine RunRobotsMk2()
84
        {
10✔
85
            TimeLine timeline = new TimeLine();
10✔
86
            //Create a dictonary to track robot turn progress over time
87
            _RobotProgress = new Dictionary<int, int>();
10✔
88
            foreach (Robot robot in Robots)
66✔
89
            {
18✔
90
                _RobotProgress.Add(robot.RobotId, 0);
18✔
91
            }
18✔
92

93
            //Need to loop through all unsorted pieces until they are sorted
94
            int currentTurn = 0;
10✔
95
            while (UnsortedPieces.Count > 0 || CountPiecesHeldByRobots() > 0 || RobotsOutOfPosition() > 0)
518✔
96
            {
508✔
97
                currentTurn++;
508✔
98
                //Debug.WriteLine("Loop " + currentTurn.ToString());
99
                //Sort the progress list to find the robot with the least number of turns - this is the robot who should pick up next
100
                List<KeyValuePair<int, int>> orderedRobotProgress = _RobotProgress.OrderBy(x => x.Value).ToList();
1,590✔
101
                //For each robot
102
                foreach (Robot robot in Robots)
2,600✔
103
                {
792✔
104
                    //Process the robot with the least progress to ensure we process the robots turn by turn
105
                    if (orderedRobotProgress[0].Key == robot.RobotId)
792✔
106
                    {
508✔
107
                        RobotAction robotAction = new RobotAction(robot.RobotId);
508✔
108
                        //if (robot.RobotId == 1)
109
                        //{
110
                        //    int n = 0;
111
                        //}
112
                        switch (robot.RobotStatus)
508✔
113
                        {
114
                            case RobotStatus.RobotStatusEnum.LookingForJob:
115
                                //If there is still work to do, and the robot is not busy, find a job, or if the robot isn't in the pickup location
116
                                if (UnsortedPieces.Count > 0 | robot.Location != robot.PickupLocation)
137✔
117
                                {
91✔
118
                                    robot.RobotStatus = RobotStatus.RobotStatusEnum.MovingToPickupLocation;
91✔
119
                                }
91✔
120
                                else
121
                                {
46✔
122
                                    _RobotProgress[robot.RobotId]++;
46✔
123
                                }
46✔
124
                                break;
137✔
125

126
                            case RobotStatus.RobotStatusEnum.MovingToPickupLocation:
127
                                if (UnsortedPieces.Count > 0 || RobotsOutOfPosition() > 0)
101✔
128
                                {
101✔
129
                                    //move to pickup location to pickup a piece
130
                                    if (robot.Location != robot.PickupLocation)
101✔
131
                                    {
83✔
132
                                        robotAction.RobotPickupStartingLocation = robot.Location;
83✔
133
                                        PathFindingResult pathFindingResultForPickup = FindPathFindingWithTimeline(Map, robot.Location, robot.PickupLocation, robot.RobotId, Robots, timeline);
83✔
134
                                        if (pathFindingResultForPickup != null &&
83!
135
                                            pathFindingResultForPickup.Path != null)
83✔
136
                                        {
83✔
137
                                            robotAction.PathToPickup = pathFindingResultForPickup;
83✔
138
                                            robotAction.RobotPickupEndingLocation = pathFindingResultForPickup.Path.Last();
83✔
139
                                            robot.Location = pathFindingResultForPickup.Path.Last();
83✔
140
                                        }
83✔
141
                                        else
142
                                        {
×
143
                                            robotAction.RobotPickupEndingLocation = robot.Location;
×
144
                                        }
×
145
                                    }
83✔
146
                                    //If we are at the pickuplocation, move to the picking up package status
147
                                    if (robot.Location == robot.PickupLocation)
101✔
148
                                    {
91✔
149
                                        robot.RobotStatus = RobotStatus.RobotStatusEnum.PickingUpPackage;
91✔
150
                                    }
91✔
151
                                }
101✔
152
                                break;
101✔
153

154
                            case RobotStatus.RobotStatusEnum.PickingUpPackage:
155
                                if (UnsortedPieces.Count > 0)
82✔
156
                                {
74✔
157
                                    robot.Piece = UnsortedPieces.Dequeue();
74✔
158
                                    robotAction.PickupAction = new ObjectInteraction()
74✔
159
                                    {
74✔
160
                                        Location = robot.Piece.Location
74✔
161
                                    };
74✔
162
                                    robotAction.PieceId = robot.Piece.Id;
74✔
163
                                }
74✔
164
                                robot.RobotStatus = RobotStatus.RobotStatusEnum.MovingToDeliveryLocation;
82✔
165
                                break;
82✔
166

167
                            case RobotStatus.RobotStatusEnum.MovingToDeliveryLocation:
168
                                if (robot.Piece != null)
114✔
169
                                {
106✔
170
                                    //If the piece is picked up, move to dropoff
171
                                    Vector2? packageMovingDestinationLocation = GetPieceDestination(robot.Piece);
106✔
172
                                    //Get the best adjacent location to the destination - this is where the package is delivered
173
                                    Vector2? robotDestinationLocation = packageMovingDestinationLocation;
106✔
174
                                    if (packageMovingDestinationLocation != null)
106✔
175
                                    {
106✔
176
                                        robotDestinationLocation = GetAdjacentLocation((Vector2)packageMovingDestinationLocation, Map, SortedDropZones);
106✔
177
                                        if (robotDestinationLocation != null)
106✔
178
                                        {
106✔
179
                                            robotAction.PieceId = robot.Piece.Id;
106✔
180
                                            robotAction.RobotDropoffStartingLocation = robot.Location;
106✔
181
                                            PathFindingResult pathFindingResultForDropoff = FindPathFindingWithTimeline(Map, robot.Location, (Vector2)robotDestinationLocation, robot.RobotId, Robots, timeline);
106✔
182
                                            if (pathFindingResultForDropoff != null &&
106!
183
                                                pathFindingResultForDropoff.Path != null)
106✔
184
                                            {
106✔
185
                                                robotAction.PathToDropoff = pathFindingResultForDropoff;
106✔
186
                                                robotAction.RobotDropoffEndingLocation = pathFindingResultForDropoff.Path.Last();
106✔
187
                                                robot.Location = pathFindingResultForDropoff.Path.Last();
106✔
188
                                            }
106✔
189
                                            else
190
                                            {
×
191
                                                robotAction.RobotDropoffEndingLocation = robot.Location;
×
192
                                            }
×
193
                                        }
106✔
194
                                    }
106✔
195
                                    if (robot.Location == robotDestinationLocation)
106!
196
                                    {
74✔
197
                                        robot.RobotStatus = RobotStatus.RobotStatusEnum.DeliveringPackage;
74✔
198
                                    }
74✔
199
                                }
106✔
200
                                else
201
                                {
8✔
202
                                    robot.RobotStatus = RobotStatus.RobotStatusEnum.LookingForJob;
8✔
203
                                }
8✔
204
                                break;
114✔
205

206
                            case RobotStatus.RobotStatusEnum.DeliveringPackage:
207
                                //If we are at the dropoff location, drop off the piece
208
                                Vector2? packageDestinationLocation = GetPieceDestination(robot.Piece);
74✔
209
                                if (packageDestinationLocation != null)
74✔
210
                                {
74✔
211
                                    robotAction.DropoffAction = new ObjectInteraction()
74✔
212
                                    {
74✔
213
                                        Location = (Vector2)packageDestinationLocation
74✔
214
                                    };
74✔
215
                                    //Move the piece from the robot to the sorted pile
216
                                    robot.RobotStatus = RobotStatus.RobotStatusEnum.DeliveringPackage;
74✔
217
                                    robot.Piece.Location = robotAction.DropoffAction.Location;
74✔
218
                                    SortedPieces.Add(robot.Piece);
74✔
219
                                    foreach (SortedDropZone sortedDropZone in SortedDropZones)
666✔
220
                                    {
259✔
221
                                        if (sortedDropZone.Location == packageDestinationLocation)
259!
222
                                        {
74✔
223
                                            sortedDropZone.Count++;
74✔
224
                                            break;
74✔
225
                                        }
226
                                    }
185✔
227
                                    robotAction.PieceId = robot.Piece.Id;
74✔
228
                                    robot.Piece = null;
74✔
229
                                    robotAction.DropoffPieceCount = GetPieceCount(robotAction.DropoffAction.Location);
74✔
230
                                    robot.RobotStatus = RobotStatus.RobotStatusEnum.LookingForJob;
74✔
231
                                }
74✔
232
                                break;
74✔
233
                        }
234

235

236
                        //Add the action into the timeline
237
                        if (robotAction != null)
508✔
238
                        {
508✔
239
                            int turn = _RobotProgress[robot.RobotId];
508✔
240
                            int turnsNeeded = 0;
508✔
241

242
                            //move to pickup
243
                            if (robotAction.PathToPickup != null)
508✔
244
                            {
83✔
245
                                turnsNeeded += robotAction.PathToPickup.Path.Count;
83✔
246
                            }
83✔
247
                            //pickup piece
248
                            if (robotAction.PickupAction != null)
508✔
249
                            {
74✔
250
                                turnsNeeded++;
74✔
251
                            }
74✔
252
                            //move to drop off
253
                            if (robotAction.PathToDropoff != null)
508✔
254
                            {
106✔
255
                                turnsNeeded += robotAction.PathToDropoff.Path.Count;
106✔
256
                            }
106✔
257
                            //drop off piece
258
                            if (robotAction.DropoffAction != null)
508✔
259
                            {
74✔
260
                                turnsNeeded++;
74✔
261
                            }
74✔
262
                            //Initialize the turns needed for this robot to complete it's turn
263
                            for (int j = turn; j < turn + turnsNeeded; j++)
2,298✔
264
                            {
641✔
265
                                if (timeline.Turns.Any(t => t.TurnNumber == j + 1) == false)
18,060✔
266
                                {
431✔
267
                                    timeline.Turns.Add(new Turn(j + 1));
431✔
268
                                }
431✔
269
                            }
641✔
270

271
                            //Now populate the turns with the pickup path
272
                            int pickupCounter = 0;
508✔
273
                            if (robotAction.PathToPickup != null &&
508✔
274
                                robotAction.PathToPickup.Path != null &&
508✔
275
                                robotAction.PathToPickup.Path.Count > 0)
508✔
276
                            {
83✔
277
                                Robot robotPathRemaining = GetRobot(robotAction.RobotId);
83✔
278
                                if (robotPathRemaining != null)
83✔
279
                                {
83✔
280
                                    robotPathRemaining.RobotPath = new Queue<Vector2>(robotAction.PathToPickup.Path);
83✔
281
                                }
83✔
282
                                pickupCounter++;
83✔
283
                                timeline.Turns[turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToPickupLocation, null)
83✔
284
                                {
83✔
285
                                    Movement = new List<Vector2>() { robotAction.RobotPickupStartingLocation, robotAction.PathToPickup.Path[0] },
83✔
286
                                    PathRemaining = robotPathRemaining.RobotPath.ToList()
83✔
287
                                });
83✔
288
                                robotPathRemaining.RobotPath.Dequeue();
83✔
289
                                for (int j = 1; j <= robotAction.PathToPickup.Path.Count - 1; j++)
462✔
290
                                {
148✔
291
                                    pickupCounter++;
148✔
292
                                    timeline.Turns[turn + j].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToPickupLocation, null)
148✔
293
                                    {
148✔
294
                                        Movement = new List<Vector2>() { robotAction.PathToPickup.Path[j - 1], robotAction.PathToPickup.Path[j] },
148✔
295
                                        PathRemaining = robotPathRemaining.RobotPath.ToList()
148✔
296
                                    });
148✔
297
                                    robotPathRemaining.RobotPath.Dequeue();
148✔
298
                                }
148✔
299
                            }
83✔
300

301
                            if (robotAction.PickupAction != null)
508✔
302
                            {
74✔
303
                                timeline.Turns[pickupCounter + turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.PickingUpPackage, robotAction.PieceId)
74✔
304
                                {
74✔
305
                                    PickupAction = robotAction.PickupAction
74✔
306
                                });
74✔
307
                                pickupCounter++;
74✔
308
                                //robot.Location = robotAction.RobotPickupEndingLocation;
309
                            }
74✔
310

311
                            //Now populate the turns with the dropoff path
312
                            int dropoffCounter = 0;
508✔
313
                            if (robotAction.PathToDropoff != null &&
508✔
314
                                robotAction.PathToDropoff.Path != null &&
508✔
315
                                robotAction.PathToDropoff.Path.Count > 0)
508✔
316
                            {
106✔
317
                                Robot robotPathRemaining = GetRobot(robotAction.RobotId);
106✔
318
                                if (robotPathRemaining != null)
106✔
319
                                {
106✔
320
                                    robotPathRemaining.RobotPath = new Queue<Vector2>(robotAction.PathToDropoff.Path);
106✔
321
                                }
106✔
322
                                dropoffCounter++;
106✔
323
                                timeline.Turns[pickupCounter + turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToDeliveryLocation, robotAction.PieceId)
106✔
324
                                {
106✔
325
                                    Movement = new List<Vector2>() { robotAction.RobotDropoffStartingLocation, robotAction.PathToDropoff.Path[0] },
106✔
326
                                    PathRemaining = robotPathRemaining.RobotPath.ToList()
106✔
327
                                });
106✔
328
                                robotPathRemaining.RobotPath.Dequeue();
106✔
329
                                for (int j = 1; j <= robotAction.PathToDropoff.Path.Count - 1; j++)
524✔
330
                                {
156✔
331
                                    dropoffCounter++;
156✔
332
                                    timeline.Turns[pickupCounter + turn + j].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToDeliveryLocation, robotAction.PieceId)
156✔
333
                                    {
156✔
334
                                        Movement = new List<Vector2>() { robotAction.PathToDropoff.Path[j - 1], robotAction.PathToDropoff.Path[j] },
156✔
335
                                        PathRemaining = robotPathRemaining.RobotPath.ToList()
156✔
336
                                    });
156✔
337
                                    robotPathRemaining.RobotPath.Dequeue();
156✔
338
                                }
156✔
339
                            }
106✔
340

341
                            if (robotAction.DropoffAction != null)
508✔
342
                            {
74✔
343
                                robotAction.DropoffAction.DestinationPieceCount = GetPieceCount(robotAction.DropoffAction.Location);
74✔
344
                                timeline.Turns[pickupCounter + dropoffCounter + turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.DeliveringPackage, robotAction.PieceId)
74✔
345
                                {
74✔
346
                                    DropoffAction = robotAction.DropoffAction
74✔
347
                                });
74✔
348
                                dropoffCounter++;
74✔
349
                                //robot.Location = robotAction.RobotDropoffEndingLocation;
350
                            }
74✔
351
                            _RobotProgress[robot.RobotId] += pickupCounter + dropoffCounter;
508✔
352
                        }
508✔
353
                        break;
508✔
354
                    }
355
                }
284✔
356
            }
508✔
357

358
            return timeline;
10✔
359
        }
10✔
360

361
        private Vector2? GetPieceDestination(Piece piece)
362
        {
180✔
363
            // Process the unsorted piece to work out where the destination location is
364
            Vector2? destinationLocation = null;
180✔
365
            foreach (SortedDropZone sortedDropZone in SortedDropZones)
1,584✔
366
            {
612✔
367
                if (sortedDropZone.Color == piece.ImageStats.TopColorGroupColor)
612✔
368
                {
180✔
369
                    destinationLocation = sortedDropZone.Location;
180✔
370
                    break;
180✔
371
                }
372
            }
432✔
373
            if (destinationLocation == null)
180!
374
            {
×
375
                throw new System.Exception("Destination not found for piece " + piece.Id);
×
376
            }
377
            return destinationLocation;
180✔
378
        }
180✔
379

380
        public PathFindingResult FindPathFindingWithTimeline(string[,] map, Vector2 startLocation, Vector2 endLocation, int robotId, List<Robot> robots, TimeLine timeline)
381
        {
189✔
382
            //Get the robot turn
383
            int turn = _RobotProgress[robotId];
189✔
384

385
            //Get the path
386
            string[,] mapWithAllPaths = (string[,])map.Clone();
189✔
387
            foreach (Robot robot in robots)
1,385✔
388
            {
409✔
389
                if (robot.RobotId != robotId)
409✔
390
                {
220✔
391
                    //Reserve pickup zones and current robot locations
392
                    mapWithAllPaths[(int)robot.PickupLocation.X, (int)robot.PickupLocation.Y] = "P";
220✔
393
                    mapWithAllPaths[(int)robot.Location.X, (int)robot.Location.Y] = "P";
220✔
394
                }
220✔
395
            }
409✔
396
            foreach (SortedDropZone sortedDropZone in SortedDropZones)
3,727✔
397
            {
1,580✔
398
                //Research pickup zones from dropzones (potentially this could be improved to only include dropzones with pieces on them)
399
                mapWithAllPaths[(int)sortedDropZone.Location.X, (int)sortedDropZone.Location.Y] = "D";
1,580✔
400
            }
1,580✔
401
            if (timeline.Turns.Count > 0 && timeline.Turns.Count >= turn)
189!
402
            {
189✔
403
                for (int i = turn; i < timeline.Turns.Count; i++)
1,066✔
404
                {
344✔
405
                    foreach (RobotTurnAction robotTurnAction in timeline.Turns[i].RobotActions)
1,982✔
406
                    {
475✔
407
                        if (robotTurnAction.PathRemaining != null &&
475✔
408
                            robotTurnAction.PathRemaining.Count > 0)
475✔
409
                        {
458✔
410
                            foreach (Vector2 pathLocation in robotTurnAction.PathRemaining)
4,334✔
411
                            {
1,480✔
412
                                if (mapWithAllPaths[(int)pathLocation.X, (int)pathLocation.Y] == "")
1,480✔
413
                                {
301✔
414
                                    mapWithAllPaths[(int)pathLocation.X, (int)pathLocation.Y] = "X";
301✔
415
                                    string mapString = MapCore.GetMapString(mapWithAllPaths);
301✔
416
                                }
301✔
417
                            }
1,480✔
418
                        }
458✔
419
                    }
475✔
420
                }
344✔
421
            }
189✔
422
            PathFindingResult pathFindingResult = PathFinding.FindPath(mapWithAllPaths, startLocation, endLocation);
189✔
423
            //Don't allow paths that are too long
424
            if (pathFindingResult != null &&
189!
425
                pathFindingResult.Path.Count > 15)
189✔
426
            {
1✔
427
                pathFindingResult.Path = new List<Vector2>();
1✔
428
                pathFindingResult.Tiles = new List<MapTile>();
1✔
429
            }
1✔
430
            if (pathFindingResult != null &&
189✔
431
                pathFindingResult.Path.Count > 0 &&
189✔
432
                robots.Count > 1)
189✔
433
            {
76✔
434
                //Check the timeline to see if there are conflicts
435
                //Look at every turn
436
                for (int i = turn; i <= timeline.Turns.Count - 1; i++)
466✔
437
                {
157✔
438
                    //Look at every robot action in that turn
439
                    foreach (RobotTurnAction robotTurnAction in timeline.Turns[i].RobotActions)
851✔
440
                    {
190✔
441
                        //Only look at robots that aren't this one
442
                        if (robotTurnAction.RobotId != robotId)
190✔
443
                        {
190✔
444
                            if (robotTurnAction.Movement != null &&
190✔
445
                                robotTurnAction.Movement.Count > 0)
190✔
446
                            {
185✔
447
                                //Loop through the path
448
                                for (int k = 0; k < pathFindingResult.Path.Count - 1; k++)
1,776✔
449
                                {
713✔
450
                                    //Check that the location the robot is moving too isn't the destination of another robot
451
                                    if ((pathFindingResult.Path[k].X == robotTurnAction.Movement[0].X &&
713✔
452
                                        pathFindingResult.Path[k].Y == robotTurnAction.Movement[0].Y) ||
713✔
453
                                        (pathFindingResult.Path[k].X == robotTurnAction.Movement[1].X &&
713✔
454
                                        pathFindingResult.Path[k].Y == robotTurnAction.Movement[1].Y))
713✔
455
                                    {
10✔
456
                                        //Add a wait action to the path
457
                                        if (k == 0)
10✔
458
                                        {
3✔
459
                                            pathFindingResult.Path.Insert(0, startLocation);
3✔
460
                                        }
3✔
461
                                        else
462
                                        {
7✔
463
                                            pathFindingResult.Path.Insert(k, new Vector2(pathFindingResult.Path[k - 1].X, pathFindingResult.Path[k - 1].Y));
7✔
464
                                        }
7✔
465
                                        break;
10✔
466
                                    }
467
                                }
703✔
468
                            }
185✔
469
                        }
190✔
470
                    }
190✔
471
                }
157✔
472
            }
76✔
473
            else if (pathFindingResult != null &&
113!
474
                pathFindingResult.Path.Count == 0)
113✔
475
            {
43✔
476
                //Add a wait action to the path
477
                pathFindingResult.Path.Insert(0, startLocation);
43✔
478
            }
43✔
479

480
            return pathFindingResult;
189✔
481
        }
189✔
482

483
        //public PathFindingResult FindPickupPathToLocation(Robot robot, Vector2 destination, TimeLine timeline)
484
        //{
485
        //    PathFindingResult pathFindingResult = null;
486
        //    if (robot.Location != destination)
487
        //    {
488
        //        robot.RobotStatus = RobotStatus.RobotStatusEnum.MovingToPickupLocation;
489
        //        //Move the robot to the pickup zone - By doing this first we ensure we don't pick up a piece until we are there.
490
        //        //Vector2 currentRobotLocation = robot.Location;
491
        //        //Vector2 pickupLocation = robot.PickupLocation;
492

493
        //        // Move to unsorted pile
494
        //        //robotAction.RobotPickupStartingLocation = currentRobotLocation;
495
        //        PathFindingResult pathFindingResultForPickup = FindPathFindingWithTimeline(Map, robot.Location, robot.PickupLocation, robot.RobotId, Robots, timeline);
496
        //        if (pathFindingResultForPickup != null && pathFindingResultForPickup.Path.Any())
497
        //        {
498
        //            //Move robot
499
        //            pathFindingResult = pathFindingResultForPickup;
500
        //            //currentRobotLocation = pathFindingResultForPickup.Path.Last();
501
        //        }
502
        //        //robotAction.RobotPickupEndingLocation = currentRobotLocation;
503
        //        //robot.Location = currentRobotLocation;
504
        //    }
505
        //    return pathFindingResult;
506
        //}
507

508
        //public TimeLine RunRobots()
509
        //{
510
        //    TimeLine timeline = new TimeLine();
511

512
        //    //Create a dictonary to track robot turn progress over time
513
        //    foreach (Robot robot in Robots)
514
        //    {
515
        //        _RobotProgress.Add(robot.RobotId, 0);
516
        //    }
517

518
        //    //Need to loop through all unsorted pieces until they are sorted
519
        //    while (UnsortedPieces.Count > 0)
520
        //    {
521
        //        //Sort the progress list to find the robot with the least number of turns - this is the robot who should pick up next
522
        //        List<KeyValuePair<int, int>> orderedRobotProgress = _RobotProgress.OrderBy(x => x.Value).ToList();
523
        //        //For each robot
524
        //        foreach (Robot robot in Robots)
525
        //        {
526
        //            //Find the robot with the least progress, and then break
527
        //            if (robot.Piece == null && orderedRobotProgress[0].Key == robot.RobotId)
528
        //            {
529
        //                RobotAction robotAction = new RobotAction(robot.RobotId);
530
        //                Piece piece = null;
531
        //                //See if the robot needs to move to the pickup zone
532
        //                if (robot.Location != robot.PickupLocation)
533
        //                {
534
        //                    robot.RobotStatus = RobotStatus.RobotStatusEnum.MovingToPickupLocation;
535
        //                    //Move the robot to the pickup zone - By doing this first we ensure we don't pick up a piece until we are there.
536
        //                    Vector2 currentRobotLocation = robot.Location;
537
        //                    Vector2 pickupLocation = robot.PickupLocation;
538

539
        //                    // Move to unsorted pile
540
        //                    robotAction.RobotPickupStartingLocation = currentRobotLocation;
541
        //                    if (currentRobotLocation != pickupLocation)
542
        //                    {
543
        //                        PathFindingResult pathFindingResultForPickup = FindPathFindingWithTimeline(Map, currentRobotLocation, pickupLocation, robot.RobotId, Robots, timeline);
544
        //                        if (pathFindingResultForPickup != null && pathFindingResultForPickup.Path.Any())
545
        //                        {
546
        //                            //Move robot
547
        //                            robotAction.PathToPickup = pathFindingResultForPickup;
548
        //                            currentRobotLocation = pathFindingResultForPickup.Path.Last();
549
        //                        }
550
        //                        else
551
        //                        {
552
        //                            int g = 0;
553
        //                        }
554
        //                    }
555
        //                    robotAction.RobotPickupEndingLocation = currentRobotLocation;
556
        //                    robot.Location = currentRobotLocation;
557
        //                }
558
        //                //Else do the pickup, dropoff and delivery
559
        //                else if (robot.Piece == null && UnsortedPieces.Count > 0)
560
        //                {
561
        //                    piece = UnsortedPieces.Dequeue();
562
        //                    robotAction = GetRobotAction(robot, piece, timeline);
563
        //                }
564
        //                ////Robot is holding the piece
565
        //                //else if (robot.Piece != null)
566
        //                //{
567
        //                //    robotAction = GetRobotAction(robot, robot.Piece);
568
        //                //    if (robot.Location != robotAction.RobotDropoffEndingLocation)
569
        //                //    {
570
        //                //        //need to find a dropoff path
571
        //                //    }
572
        //                //    else
573
        //                //    {
574
        //                //        //is at the dropoff point
575
        //                //    }
576
        //                //}
577

578
        //                //process the robot action
579
        //                if (robotAction != null)
580
        //                {
581
        //                    int turn = _RobotProgress[robot.RobotId];
582
        //                    int turnsNeeded = 0;
583

584
        //                    //move to pickup
585
        //                    if (robotAction.PathToPickup != null)
586
        //                    {
587
        //                        turnsNeeded += robotAction.PathToPickup.Path.Count;
588
        //                    }
589
        //                    //pickup piece
590
        //                    if (robotAction.PickupAction != null)
591
        //                    {
592
        //                        turnsNeeded++;
593
        //                    }
594
        //                    //move to drop off
595
        //                    if (robotAction.PathToDropoff != null)
596
        //                    {
597
        //                        turnsNeeded += robotAction.PathToDropoff.Path.Count;
598
        //                    }
599
        //                    //drop off piece
600
        //                    if (robotAction.DropoffAction != null)
601
        //                    {
602
        //                        turnsNeeded++;
603
        //                    }
604
        //                    //Initialize the turns needed for this robot to complete it's turn
605
        //                    for (int j = turn; j < turn + turnsNeeded; j++)
606
        //                    {
607
        //                        if (timeline.Turns.Any(t => t.TurnNumber == j + 1) == false)
608
        //                        {
609
        //                            timeline.Turns.Add(new Turn(j + 1));
610
        //                        }
611
        //                    }
612

613
        //                    //Now populate the turns with the pickup path
614
        //                    int pickupCounter = 0;
615
        //                    if (robotAction.PathToPickup != null &&
616
        //                        robotAction.PathToPickup.Path != null &&
617
        //                        robotAction.PathToPickup.Path.Count > 0)
618
        //                    {
619
        //                        Robot robotPathRemaining = GetRobot(robotAction.RobotId);
620
        //                        if (robotPathRemaining != null)
621
        //                        {
622
        //                            robotPathRemaining.RobotPath = new Queue<Vector2>(robotAction.PathToPickup.Path);
623
        //                        }
624
        //                        pickupCounter++;
625
        //                        timeline.Turns[turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToPickupLocation, null)
626
        //                        {
627
        //                            Movement = new List<Vector2>() { robotAction.RobotPickupStartingLocation, robotAction.PathToPickup.Path[0] },
628
        //                            PathRemaining = robotPathRemaining.RobotPath.ToList()
629
        //                        });
630
        //                        robotPathRemaining.RobotPath.Dequeue();
631
        //                        for (int j = 1; j <= robotAction.PathToPickup.Path.Count - 1; j++)
632
        //                        {
633
        //                            pickupCounter++;
634
        //                            timeline.Turns[turn + j].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToPickupLocation, null)
635
        //                            {
636
        //                                Movement = new List<Vector2>() { robotAction.PathToPickup.Path[j - 1], robotAction.PathToPickup.Path[j] },
637
        //                                PathRemaining = robotPathRemaining.RobotPath.ToList()
638
        //                            });
639
        //                            robotPathRemaining.RobotPath.Dequeue();
640
        //                        }
641
        //                    }
642

643
        //                    if (robotAction.PickupAction != null)
644
        //                    {
645
        //                        timeline.Turns[pickupCounter + turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.PickingUpPackage, piece.Id)
646
        //                        {
647
        //                            PickupAction = robotAction.PickupAction
648
        //                        });
649
        //                        pickupCounter++;
650
        //                        robot.Location = robotAction.RobotPickupEndingLocation;
651
        //                    }
652

653
        //                    //Now populate the turns with the dropoff path
654
        //                    int dropoffCounter = 0;
655
        //                    if (robotAction.PathToDropoff != null &&
656
        //                        robotAction.PathToDropoff.Path != null &&
657
        //                        robotAction.PathToDropoff.Path.Count > 0)
658
        //                    {
659
        //                        Robot robotPathRemaining = GetRobot(robotAction.RobotId);
660
        //                        if (robotPathRemaining != null)
661
        //                        {
662
        //                            robotPathRemaining.RobotPath = new Queue<Vector2>(robotAction.PathToDropoff.Path);
663
        //                        }
664
        //                        dropoffCounter++;
665
        //                        timeline.Turns[pickupCounter + turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToDeliveryLocation, piece.Id)
666
        //                        {
667
        //                            Movement = new List<Vector2>() { robotAction.RobotDropoffStartingLocation, robotAction.PathToDropoff.Path[0] },
668
        //                            PathRemaining = robotPathRemaining.RobotPath.ToList()
669
        //                        });
670
        //                        robotPathRemaining.RobotPath.Dequeue();
671
        //                        for (int j = 1; j <= robotAction.PathToDropoff.Path.Count - 1; j++)
672
        //                        {
673
        //                            dropoffCounter++;
674
        //                            timeline.Turns[pickupCounter + turn + j].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToDeliveryLocation, piece.Id)
675
        //                            {
676
        //                                Movement = new List<Vector2>() { robotAction.PathToDropoff.Path[j - 1], robotAction.PathToDropoff.Path[j] },
677
        //                                PathRemaining = robotPathRemaining.RobotPath.ToList()
678
        //                            });
679
        //                            robotPathRemaining.RobotPath.Dequeue();
680
        //                        }
681
        //                    }
682

683
        //                    if (robotAction.DropoffAction != null)
684
        //                    {
685
        //                        robotAction.DropoffAction.DestinationPieceCount = GetPieceCount(robotAction.DropoffAction.Location);
686
        //                        timeline.Turns[pickupCounter + dropoffCounter + turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.DeliveringPackage, piece.Id)
687
        //                        {
688
        //                            DropoffAction = robotAction.DropoffAction
689
        //                        });
690
        //                        dropoffCounter++;
691
        //                        robot.Location = robotAction.RobotDropoffEndingLocation;
692
        //                    }
693
        //                    _RobotProgress[robot.RobotId] += pickupCounter + dropoffCounter;
694
        //                }
695
        //                break;
696
        //            }
697
        //            //else if (robot.Piece != null)
698
        //            //{
699
        //            //    RobotAction robotAction = new RobotAction(robot.RobotId);
700
        //            //    robotAction = GetRobotAction(robot, robot.Piece, timeline);
701

702
        //            //    //Run the dropoff routine again
703
        //            //    if (robotAction.PathToDropoff != null &&
704
        //            //            robotAction.PathToDropoff.Path != null &&
705
        //            //            robotAction.PathToDropoff.Path.Count > 0)
706
        //            //    {
707
        //            //        Robot robotPathRemaining = GetRobot(robotAction.RobotId);
708
        //            //        if (robotPathRemaining != null)
709
        //            //        {
710
        //            //            robotPathRemaining.RobotPath = new Queue<Vector2>(robotAction.PathToDropoff.Path);
711
        //            //        }
712
        //            //        dropoffCounter++;
713
        //            //        timeline.Turns[pickupCounter + turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToDeliveryLocation, piece.Id)
714
        //            //        {
715
        //            //            Movement = new List<Vector2>() { robotAction.RobotDropoffStartingLocation, robotAction.PathToDropoff.Path[0] },
716
        //            //            PathRemaining = robotPathRemaining.RobotPath.ToList()
717
        //            //        });
718
        //            //        robotPathRemaining.RobotPath.Dequeue();
719
        //            //        for (int j = 1; j <= robotAction.PathToDropoff.Path.Count - 1; j++)
720
        //            //        {
721
        //            //            dropoffCounter++;
722
        //            //            timeline.Turns[pickupCounter + turn + j].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToDeliveryLocation, piece.Id)
723
        //            //            {
724
        //            //                Movement = new List<Vector2>() { robotAction.PathToDropoff.Path[j - 1], robotAction.PathToDropoff.Path[j] },
725
        //            //                PathRemaining = robotPathRemaining.RobotPath.ToList()
726
        //            //            });
727
        //            //            robotPathRemaining.RobotPath.Dequeue();
728
        //            //        }
729
        //            //    }
730

731
        //            //    if (robotAction.DropoffAction != null)
732
        //            //    {
733
        //            //        robotAction.DropoffAction.DestinationPieceCount = GetPieceCount(robotAction.DropoffAction.Location);
734
        //            //        timeline.Turns[pickupCounter + dropoffCounter + turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.DeliveringPackage, piece.Id)
735
        //            //        {
736
        //            //            DropoffAction = robotAction.DropoffAction
737
        //            //        });
738
        //            //        dropoffCounter++;
739
        //            //        robot.Location = robotAction.RobotDropoffEndingLocation;
740
        //            //    }
741
        //            //    _RobotProgress[robot.RobotId] += pickupCounter + dropoffCounter;
742
        //            //}
743
        //        }
744
        //    }
745

746
        //    //Move the robots back to the start location
747
        //    foreach (Robot robot in Robots)
748
        //    {
749
        //        if (robot.Location != robot.PickupLocation)
750
        //        {
751
        //            RobotAction robotAction = new RobotAction(robot.RobotId);
752
        //            //Move the robot to the pickup zone - By doing this first we ensure we don't pick up a piece until we are there.
753
        //            Vector2 currentRobotLocation = robot.Location;
754
        //            Vector2 pickupLocation = robot.PickupLocation;
755

756
        //            // Move to unsorted pile
757
        //            robotAction.RobotPickupStartingLocation = currentRobotLocation;
758
        //            if (currentRobotLocation != pickupLocation)
759
        //            {
760
        //                PathFindingResult pathFindingResultForPickup = FindPathFindingWithTimeline(Map, currentRobotLocation, pickupLocation, robot.RobotId, Robots, timeline);
761
        //                if (pathFindingResultForPickup != null && pathFindingResultForPickup.Path.Any())
762
        //                {
763
        //                    //Move robot
764
        //                    robotAction.PathToPickup = pathFindingResultForPickup;
765
        //                    currentRobotLocation = pathFindingResultForPickup.Path.Last();
766
        //                }
767
        //                else
768
        //                {
769
        //                    int g = 0;
770
        //                }
771
        //            }
772
        //            robotAction.RobotPickupEndingLocation = currentRobotLocation;
773
        //            robot.Location = currentRobotLocation;
774

775
        //            //process the robot action
776
        //            if (robotAction != null)
777
        //            {
778
        //                int turn = _RobotProgress[robot.RobotId];
779
        //                int turnsNeeded = 0;
780

781
        //                //move to pickup
782
        //                if (robotAction.PathToPickup != null)
783
        //                {
784
        //                    turnsNeeded += robotAction.PathToPickup.Path.Count;
785
        //                }
786
        //                //Initialize the turns needed for this robot to complete it's turn
787
        //                for (int j = turn; j < turn + turnsNeeded; j++)
788
        //                {
789
        //                    if (timeline.Turns.Any(t => t.TurnNumber == j + 1) == false)
790
        //                    {
791
        //                        timeline.Turns.Add(new Turn(j + 1));
792
        //                    }
793
        //                }
794

795
        //                //Now populate the turns with the pickup path
796
        //                int pickupCounter = 0;
797
        //                if (robotAction.PathToPickup != null &&
798
        //                    robotAction.PathToPickup.Path != null &&
799
        //                    robotAction.PathToPickup.Path.Count > 0)
800
        //                {
801
        //                    Robot robotPathRemaining = GetRobot(robotAction.RobotId);
802
        //                    if (robotPathRemaining != null)
803
        //                    {
804
        //                        robotPathRemaining.RobotPath = new Queue<Vector2>(robotAction.PathToPickup.Path);
805
        //                    }
806
        //                    pickupCounter++;
807
        //                    timeline.Turns[turn].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToPickupLocation, null)
808
        //                    {
809
        //                        Movement = new List<Vector2>() { robotAction.RobotPickupStartingLocation, robotAction.PathToPickup.Path[0] },
810
        //                        PathRemaining = robotPathRemaining.RobotPath.ToList()
811
        //                    });
812
        //                    robotPathRemaining.RobotPath.Dequeue();
813
        //                    for (int j = 1; j <= robotAction.PathToPickup.Path.Count - 1; j++)
814
        //                    {
815
        //                        pickupCounter++;
816
        //                        timeline.Turns[turn + j].RobotActions.Add(new RobotTurnAction(robot.RobotId, RobotStatus.RobotStatusEnum.MovingToPickupLocation, null)
817
        //                        {
818
        //                            Movement = new List<Vector2>() { robotAction.PathToPickup.Path[j - 1], robotAction.PathToPickup.Path[j] },
819
        //                            PathRemaining = robotPathRemaining.RobotPath.ToList()
820
        //                        });
821
        //                        robotPathRemaining.RobotPath.Dequeue();
822
        //                    }
823
        //                }
824
        //                _RobotProgress[robot.RobotId] += pickupCounter;
825
        //            }
826
        //        }
827
        //    }
828

829
        //    return timeline;
830
        //}
831

832
        private Robot GetRobot(int robotId)
833
        {
189✔
834
            Robot result = null;
189✔
835
            foreach (Robot robot in Robots)
1,004✔
836
            {
313✔
837
                if (robot.RobotId == robotId)
313✔
838
                {
189✔
839
                    result = robot;
189✔
840
                    break;
189✔
841
                }
842
            }
124✔
843
            return result;
189✔
844
        }
189✔
845

846
        public int GetPieceCount(Vector2 dropOfflocation)
847
        {
150✔
848
            int pieceCount = 0;
150✔
849
            foreach (SortedDropZone sortedDropZone in SortedDropZones)
1,340✔
850
            {
520✔
851
                if (sortedDropZone.Location == dropOfflocation)
520✔
852
                {
150✔
853
                    pieceCount = sortedDropZone.Count;
150✔
854
                    break;
150✔
855
                }
856
            }
370✔
857
            return pieceCount;
150✔
858
        }
150✔
859

860
        private Vector2? GetAdjacentLocation(Vector2 destinationLocation, string[,] map, List<SortedDropZone> sortedDropZones)
861
        {
106✔
862
            Vector2? adjacentLocation = null;
106✔
863
            if (destinationLocation != null)
106✔
864
            {
106✔
865
                if (destinationLocation.X == 0)
106✔
866
                {
80✔
867
                    //it's a right location drop-off
868
                    adjacentLocation = new Vector2((int)destinationLocation.X + 1, (int)destinationLocation.Y);
80✔
869
                }
80✔
870
                else if (destinationLocation.X == map.GetUpperBound(0))
26✔
871
                {
1✔
872
                    //it's a left location drop-off
873
                    adjacentLocation = new Vector2((int)destinationLocation.X - 1, (int)destinationLocation.Y);
1✔
874
                }
1✔
875
                else if (destinationLocation.Y == 0)
25✔
876
                {
15✔
877
                    //it's a top location drop-off
878
                    adjacentLocation = new Vector2((int)destinationLocation.X, (int)destinationLocation.Y + 1);
15✔
879
                }
15✔
880
                else if (destinationLocation.Y == map.GetUpperBound(1))
10✔
881
                {
10✔
882
                    //it's a bottom location drop-off
883
                    adjacentLocation = new Vector2((int)destinationLocation.X, (int)destinationLocation.Y - 1);
10✔
884
                }
10✔
885
            }
106✔
886
            return adjacentLocation;
106✔
887
        }
106✔
888

889
        private RobotAction GetRobotAction(Robot robot, Piece piece, TimeLine timeline)
890
        {
×
891
            RobotAction robotAction = new RobotAction(robot.RobotId);
×
892

893
            Vector2 currentRobotLocation = robot.Location;
×
894
            Vector2 pickupLocation = robot.PickupLocation;
×
895

896
            // Move to unsorted pile
897
            robotAction.RobotPickupStartingLocation = currentRobotLocation;
×
898
            if (currentRobotLocation != pickupLocation)
×
899
            {
×
900
                robot.RobotStatus = RobotStatus.RobotStatusEnum.MovingToPickupLocation;
×
901
                PathFindingResult pathFindingResultForPickup = FindPathFindingWithTimeline(Map, currentRobotLocation, pickupLocation, robot.RobotId, Robots, timeline);
×
902
                if (pathFindingResultForPickup != null && pathFindingResultForPickup.Path.Any())
×
903
                {
×
904
                    //Move robot
905
                    robotAction.PathToPickup = pathFindingResultForPickup;
×
906
                    currentRobotLocation = pathFindingResultForPickup.Path.Last();
×
907
                }
×
908
                else
909
                {
×
910
                    int g = 0;
×
911
                }
×
912
            }
×
913
            robotAction.RobotPickupEndingLocation = currentRobotLocation;
×
914

915
            // Pickup an unsorted piece from the unsorted pile
916
            if (robot.Piece != null)
×
917
            {
×
918
                throw new System.Exception("Piece " + robot.Piece.Id + " was not delivered");
×
919
            }
920
            robot.RobotStatus = RobotStatus.RobotStatusEnum.PickingUpPackage;
×
921
            robot.Piece = piece;
×
922
            robotAction.PieceId = piece.Id;
×
923
            robotAction.PickupAction = new ObjectInteraction()
×
924
            {
×
925
                Location = piece.Location
×
926
            };
×
927

928
            // Process the unsorted piece to work out where it goes
929
            Vector2? destinationLocation = null;
×
930
            foreach (SortedDropZone sortedDropZone in SortedDropZones)
×
931
            {
×
932
                if (sortedDropZone.Color == robot.Piece.ImageStats.TopColorGroupColor)
×
933
                {
×
934
                    destinationLocation = sortedDropZone.Location;
×
935
                    break;
×
936
                }
937
            }
×
938
            if (destinationLocation == null)
×
939
            {
×
940
                throw new System.Exception("Destination not found for piece " + piece.Id);
×
941
            }
942

943
            //Get the best adjacent location to the destination
944
            Vector2? pathDestinationLocation = destinationLocation;
×
945
            if (destinationLocation != null)
×
946
            {
×
947
                Vector2? adjacentLocation = GetAdjacentLocation((Vector2)destinationLocation, Map, SortedDropZones);
×
948
                if (adjacentLocation != null)
×
949
                {
×
950
                    pathDestinationLocation = (Vector2)adjacentLocation;
×
951
                }
×
952
            }
×
953

954
            // Move the sorted piece to the correct pile
955
            robotAction.RobotDropoffStartingLocation = currentRobotLocation;
×
956
            if (destinationLocation != null && pathDestinationLocation != null)
×
957
            {
×
958
                robot.RobotStatus = RobotStatus.RobotStatusEnum.MovingToDeliveryLocation;
×
959
                //now find the path
960
                PathFindingResult pathFindingResultForDropoff = FindPathFindingWithTimeline(Map, currentRobotLocation, (Vector2)pathDestinationLocation, robot.RobotId, Robots, timeline);
×
961
                if (pathFindingResultForDropoff != null && pathFindingResultForDropoff.Path.Count >= 0)
×
962
                {
×
963
                    //Move robot
964
                    robotAction.PathToDropoff = pathFindingResultForDropoff;
×
965
                    if ((Vector2)pathDestinationLocation == pathFindingResultForDropoff.Path.LastOrDefault())
×
966
                    {
×
967
                        robotAction.DropoffAction = new ObjectInteraction()
×
968
                        {
×
969
                            Location = (Vector2)destinationLocation
×
970
                        };
×
971
                        //Move the piece from the robot to the sorted pile
972
                        robot.RobotStatus = RobotStatus.RobotStatusEnum.DeliveringPackage;
×
973
                        robot.Piece.Location = robotAction.DropoffAction.Location;
×
974
                        SortedPieces.Add(robot.Piece);
×
975
                        foreach (SortedDropZone sortedDropZone in SortedDropZones)
×
976
                        {
×
977
                            if (sortedDropZone.Location == destinationLocation)
×
978
                            {
×
979
                                sortedDropZone.Count++;
×
980
                                break;
×
981
                            }
982
                        }
×
983
                        robot.Piece = null;
×
984
                        robotAction.DropoffPieceCount = GetPieceCount(robotAction.DropoffAction.Location);
×
985
                        if (pathFindingResultForDropoff.Path.Count > 0)
×
986
                        {
×
987
                            currentRobotLocation = pathFindingResultForDropoff.Path.Last();
×
988
                        }
×
989
                    }
×
990
                }
×
991
            }
×
992
            robot.RobotStatus = RobotStatus.RobotStatusEnum.LookingForJob;
×
993
            robotAction.RobotDropoffEndingLocation = currentRobotLocation;
×
994

995
            return robotAction;
×
996
        }
×
997
    }
998
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc