#Puzzle pieces processing confusing

1 messages · Page 1 of 1 (latest)

junior snowBOT
#

<@&987246399047479336> please have a look, thanks.

junior snowBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

wild chasm
#

PS. I am not looking for someone to do my work, I want to do this and learn for the future. I am just struggling and need a little help.

Thanks again.

clever hawk
#

i think this is the wrong community for what ur looking for

#

we don't do dm help

wild chasm
#

OK thats fine, I can't send my code here though.

#

Here is more information:

Problem 1: Jigsaw Puzzles (Again!)
When a puzzle is produced, we need to check that all the pieces are in order and correct. The challenge
is that the pieces may need to be rotated if they are not in the correct orientation.
Write the body of the program called Problem1 that reads in a sequence of puzzle pieces and ensures that
they are in the correct order. Your solution MUST include a Piece class to store each puzzle piece.
Input
The first part of the input consists of two positive integers, denoting width (W) and height (H) of the
puzzle. I.e., the puzzle contains H rows and W columns with a total of W x H pieces. This is followed by
W x H pieces in row order. I.e., the first W pieces correspond to row 0, the next W pieces correspond to
row 1, and so on. The first piece in the input is the top left corner of the puzzles and the last piece is the
bottom right corner of the puzzle. Each piece is represented by a word and four integers:
Word Top Right Bottom Left
where
• Word is the word in the puzzle piece;
•Top is the integer representing the top side of the piece;
•Right is the integer representing the right side of the piece;
•Bottom is the integer representing the bottom side of the piece; and
•Left is the integer representing the left side of the piece.
The Piece Class
As part of your solution, implement a Piece class that has the following public interface:
Constructor / Method Description
Piece(String word, int [] tabs) Constructor: stores the word on the puzzle piece and the shape of the four tabs, represented by inte-
gers, stored in the tabs array.
void rotate() Rotates the piece clockwise 90 degrees. I.e., all the
tabs are shifted to the right and the last tab is moved
to the front. String getWord() Returns the word on the puzzle piece.
boolean matches(Piece piece, int side) Returns true if the piece matches to the specified side of the piece on which this method is called.
side is 0, 1, 2, or 3, and has the following meaning:

#
  1. Match to top side
  2. Match to right side
  3. Match to bottom side
  4. Match to left side
    E.g., if side == 0 and the bottom tab of piece matches
    the top tab of the piece on which this method is
    called, return true.
    String toString() Returns a string representing the Piece object in the
    format:
    [word,T,R,B,L]
    where T, R, B, and L are the top, right, bottom, and
    left tab values of the piece.
    Processing
    The program must determine if the puzzle is ordered. An ordered puzzle satisfies the following conditions:
    • Pieces adjacent to each other fit together. Two adjacent pieces fit together if the integers repre-
    senting the adjacent sides sum to -1.
    • Each row contains W pieces and there are H rows.
    • All pieces are used.
    • The puzzle is checked in the order the pieces are read in. I.e., first row, then second row, etc.
    Output
    If the puzzle is ordered, output the resulting string from the puzzle pieces, one row per line. If the puzzle
    is not ordered, output
    Wrong piece [word,T,R,B,L] at (x,y).
    where the piece output is the same as the toString() method of Piece() class and x and y are the coordi-
    nates of the piece. Note: (1,1) is the top-left corner and (W,H) is the bottom-right corner.
#

Sorry if it's long. This is literally in the beginner java course too.

#

Check 4 failed
Output:
Wrong piece [I,-5,-2,0,-4] at (2,1).
Expected:
JIGSAW
PUZZLE
MANIAS
AREFUN
Feedback:
Input:

6 4
J 0 0 1 -3
I -5 -2 0 -4
G 9 -8 3 0
S 0 11 12 -10
A -12 0 -24 -42
W 25 23 0 0
P 5 14 0 2
U 4 -7 16 -6
Z 6 7 -14 -19
Z -22 13 -13 20
L -25 27 -21 41
E 0 -27 24 -26
M -15 -16 -43 0
A -17 -18 -39 15
N 18 -20 -37 17
I 19 21 22 -36
A -34 -23 -28 29
S 0 31 -30 26
A 42 39 0 0
R -40 38 -38 0
E 0 37 36 34
F -33 0 -35 35
U 33 -31 0 32
N 0 30 -32 0

#

Ok, so I have Piece.JAVA done and a lot of the code done. Its just the rotation aspect I think.

#

The example I just provided hopefully will show

#

Sorry again for the long crap

void maple
#

Can you format your question? It's difficult to read and understand. I'm not sure where the actual question is embedded.

stone whale
#

yea that was a crazy verbose reading comprehension problem lol, the relevant parts appear to be

This is followed by
W x H pieces in row order. I.e., the first W pieces correspond to row 0, the next W pieces correspond to
row 1, and so on. The first piece in the input is the top left corner of the puzzles and the last piece is the
bottom right corner of the puzzle. Each piece is represented by a word and four integers:

Each piece is represented by a word and four integers:
Word Top Right Bottom Left

• Pieces adjacent to each other fit together. Two adjacent pieces fit together if the integers representing the adjacent sides sum to -1.

void maple
#

what is the question though

wild chasm
#

Sorry, I'll summarize it.

#

Background:

This assignment aims to strengthen your understanding of object-based programming, 2D arrays, and problem-solving using objects, classes, and nested loops. It consists of three problems of increasing complexity.

The assignment revolves around two-dimensional jigsaw puzzles. Each puzzle piece has a word representing its content and four integers representing the shape of its sides. Puzzle pieces can fit together if the sum of the integers representing the adjacent sides is -1. The edge side of edge pieces is denoted by 0.

Puzzle pieces can be rotated to four different orientations, and the assignment involves solving puzzles with rotated pieces.

In summary, you need to write code that solves 2D jigsaw puzzles by considering the shapes of the puzzle pieces and their orientations. The assignment is divided into three problems, with each problem being more complex than the previous one.

#

Problem 1:

The program is about solving jigsaw puzzles by checking if the pieces are in the correct order and orientation. It requires implementing a Piece class to store each puzzle piece.

The input consists of the width (W) and height (H) of the puzzle, followed by the puzzle pieces in row order. Each piece is represented by a word and four integers: top, right, bottom, and left.

The Piece class has a constructor to store the word and the shape of the four tabs. It also has methods to rotate the piece, get the word, and check if it matches with another piece on a specific side.

The program checks if the puzzle is ordered by ensuring that adjacent pieces fit together, all rows have the correct number of pieces, all pieces are used, and the puzzle is checked in the order they are read.

The output is either the resulting string from the puzzle pieces if the puzzle is ordered, or an error message indicating the wrong piece at a specific coordinate if the puzzle is not ordered. The coordinates start from (1,1) as the top-left corner and (W,H) as the bottom-right corner.

#

Example:

stone whale
#

Where are you stuck?

wild chasm
#

Rotation example:

#

I'm stuck at the rotation of the pieces / the part where it outputs

stone whale
#

what you want is this, and Each piece is represented by a word and four integers: Word Top Right Bottom Left , and you have Piece(String word, int [] tabs), so just figure out how to create a new tabs array and cyclically rotate it 1 step to the right

wild chasm
#

Could you dm me so I could send you my code?

#

I dont want to risk academic integrity by sending it out in public

#

if not its fine

stone whale
#
jshell> int[] s = {1,2,3,4};
s ==> int[4] { 1, 2, 3, 4 }

jshell> var t = new ArrayList<>(Arrays.stream(s).boxed().toList());
t ==> [1, 2, 3, 4]

jshell> Collections.rotate(t, 1)

jshell> t
t ==> [4, 1, 2, 3]
junior snowBOT
stone whale
#

here's one way you could do the rotation, for example

wild chasm