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

samsmithnz / PuzzleSolver / 4098923822

pending completion
4098923822

Pull #31

github

GitHub
Merge 47620c5b6 into 8d442730a
Pull Request #31: Setup board and goals

825 of 876 branches covered (94.18%)

Branch coverage included in aggregate %.

93 of 93 new or added lines in 7 files covered. (100.0%)

1258 of 1281 relevant lines covered (98.2%)

1179183.07 hits per line

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

82.67
/src/PuzzleSolver/Board.cs
1
using PuzzleSolver.Images;
2
using PuzzleSolver.Map;
3
using SixLabors.ImageSharp;
4
using SixLabors.ImageSharp.PixelFormats;
5
using System.Collections.Generic;
6
using System.Linq;
7
using System.Numerics;
8

9
namespace PuzzleSolver
10
{
11
    public class Board
12
    {
13
        private Vector2 PickUpLocation = new Vector2(2, 1);
2✔
14
        public string[,] Map { get; set; }
7✔
15

16
        //Pieces
17
        public Vector2 UnsortedPiecesLocation { get; set; }
3✔
18
        public Queue<Rgb24> UnsortedPieces { get; set; }
13✔
19
        public Dictionary<Rgb24, SortedPiece> SortedPieces { get; set; }
8✔
20
        public int SortedPiecesCount { get; set; }
12✔
21
        public int UnsortedPiecesCount
22
        {
23
            get
24
            {
7✔
25
                return UnsortedPieces.Count;
7✔
26
            }
7✔
27
        }
28

29
        //Characters
30
        public Robot Robot { get; set; }
20✔
31

32

33
        public Board() { }
6✔
34

35
        //public Board(int width, int height, Vector2 unsortedPileLocation, List<Rgb24> colorPalette)
36
        //{
37
        //    Map = new string[width, height];
38
        //    UnsortedPiecesLocation = unsortedPileLocation;
39
        //    SortedPiecesLocations = new Dictionary<Vector2, Rgb24>();
40
        //    //int i = 0;
41
        //    //foreach (Rgb24 color in colorPalette)
42
        //    //{
43
        //    //    SortedPileLocations.Add(new Vector2(i, 0), color);
44
        //    //    i++;
45
        //    //}
46
        //}
47

48
        public Queue<RobotAction> RunRobot()
49
        {
1✔
50
            Queue<RobotAction> results = new Queue<RobotAction>();
1✔
51

52
            ImageColorGroups imageProcessing = new ImageColorGroups(ColorPalettes.Get3ColorPalette());
1✔
53

54
            while (UnsortedPiecesCount > 0)
5✔
55
            {
4✔
56
                RobotAction robotAction = new RobotAction();
4✔
57
                
58
                // Move to unsorted pile
59
                if (Robot.Location != PickUpLocation)
4!
60
                {
×
61
                    PathFindingResult pathFindingResultForPickup = PathFinding.FindPath(Map, Robot.Location, PickUpLocation);
×
62
                    if (pathFindingResultForPickup != null && pathFindingResultForPickup.Path.Any())
×
63
                    {
×
64
                        //Move robot
65
                        robotAction.PathToPickup = pathFindingResultForPickup;
×
66
                    }
×
67
                }
×
68

69
                // Pickup an unsorted piece
70
                Robot.Piece = UnsortedPieces.Dequeue();
4✔
71
                robotAction.PickupAction = new ObjectInteraction()
4✔
72
                {
4✔
73
                    Location = PickUpLocation
4✔
74
                };
4✔
75

76
                // Process the unsorted piece to work out where it goes
77
                Image<Rgb24> image = ImageCropping.CreateImage(Robot.Piece);
4✔
78
                ImageStats imageStats = imageProcessing.ProcessStatsForImage(null, image);
4✔
79
                Vector2? destinationLocation = null;
4✔
80
                foreach (KeyValuePair<Rgb24, SortedPiece> sortedPiece in SortedPieces)
44✔
81
                {
16✔
82
                    if (sortedPiece.Key == imageStats.TopColorGroupColor)
16✔
83
                    {
4✔
84
                        destinationLocation = sortedPiece.Value.Location;
4✔
85
                    }
4✔
86
                }
16✔
87

88
                // Move the sorted piece to the correct pile
89
                if (destinationLocation != null)
4✔
90
                {
4✔
91
                    PathFindingResult pathFindingResultForDropoff = PathFinding.FindPath(Map, Robot.Location, (Vector2)destinationLocation);
4✔
92
                    if (pathFindingResultForDropoff != null && pathFindingResultForDropoff.Path.Any())
4!
93
                    {
4✔
94
                        //Move robot
95
                        robotAction.PathToDropoff = pathFindingResultForDropoff;
4✔
96
                        robotAction.DropoffAction = new ObjectInteraction()
4✔
97
                        {
4✔
98
                            Location = (Vector2)destinationLocation
4✔
99
                        };
4✔
100
                    }
4✔
101
                }
4✔
102

103
                SortedPiecesCount++;
4✔
104

105
                // Add to queue
106
                results.Enqueue(robotAction);
4✔
107
            }
4✔
108

109
            return results;
1✔
110
        }
1✔
111
    }
112
}
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

© 2026 Coveralls, Inc