Question: Define a p solve method which uses the random piece method above to randomly pick puzzle pieces and see if they go together, following the

Define a p solve method which uses the random piece method above to randomly pick puzzle pieces and see if they go together, following the description in the introduction. First generate a puzzle piece to start with, and from then on generate a new puzzle piece and see if it fits or not. If it doesnt, it gets thrown back to possibly get picked up again later (to keep things simple, its ok if the same piece gets picked up multiple times in a row). Eventually, you build outward from one piece to put all the pieces together. You should return the list of pieces you successfully put together *in the order that you put them together*. Needless to say, this list should include all the puzzle pieces. You should also print the number of times you had to pick a random piece. Needless to say, this number might be fairly large since you will likely pick up a lot of pieces that dont fit at first. Oh, and I almost forgot: for full credit this method must be written recursively! If you find this confusing, you might want to first write it non-recursively and then see if you can convert it to being recursive. Also, let me emphasize that this method should only check individual puzzle pieces to see if they are connected using the connected pieces attribute of the PuzzlePiece class. You should NOT use the secret id attribute or the puzzle grid or any other outside knowledge to determine if two pieces go together or not.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!