3D Puzzle

11
3 3 D D Puzzle Puzzle Assignment #1 Programming Language, Spring 2003

description

3D Puzzle. Assignment #1 Programming Language, Spring 2003. 3D Puzzle. Characteristics Consist of 4ⅹ4ⅹ4 frame Contains 63 small cells of equal size 1 empty position that was the same size as a small cell A unique number of integer was printed on each small cell - PowerPoint PPT Presentation

Transcript of 3D Puzzle

Page 1: 3D Puzzle

33DD Puzzle PuzzleAssignment #1

Programming Language, Spring 2003

Page 2: 3D Puzzle

3D Puzzle

• Characteristics – Consist of

• 4ⅹ4ⅹ4 frame

– Contains • 63 small cells of equal size • 1 empty position that was the same size as a small cell• A unique number of integer was printed on each small cell

– Empty position is marked with ‘$’

Page 3: 3D Puzzle

Making out a Puzzle

• Puzzle– Solving a puzzle

• Make the frame display the numbers in order

– Operation • Small cell can be moved into empty position • If it were immediately to the right, to the left, in the front, in the

rear, above, or below the empty position

Page 4: 3D Puzzle

Assignment

• Objectives– Slide cells into the empty position so that the frame displays

the numbers in order

• Requirements – Input initial puzzle from file– Show current frame status

• Can slide cell into the empty position – by command line input– by sliding-sequence file

• Can output complete solution of sliding-sequence into file

Page 5: 3D Puzzle

Input Convention

• Command– Sliding operations

• 1 : The square above the empty position moves• 2 : The square below the empty position moves• 3 : The square to the left of the empty position moves• 4 : The square to the right of the empty position moves• 5 : The square in the front of the empty position moves• 6 : The square in the rear of the empty position moves

Page 6: 3D Puzzle

Source Code

• puzzle.c– Input initial puzzle file

• Get file name by program argument• $>./puzzle puzzle.in

– Show current frame status• Command line input

– Input ‘1~6’ command to slide cell

• File input– Input ‘1~6’ command from sliding-sequence file – Each line contains maximum 10 command

• Output complete solution – Output complete sliding-sequence solution into file– puzzle.out

Page 7: 3D Puzzle

Initial Puzzle

• puzzle.in– 4ⅹ4ⅹ4 matrix

• Consist of 1st, 2nd, 3rd,and 4th planes(4ⅹ4 matrix)• Total 16 lines

– Example• 5 6 7 8• 21 22 23 24• 13 $ 15 16• 17 18 19 20• …• 30 33 41 60

Page 8: 3D Puzzle

Input Command

• Command Line– Input

• sliding command – 1~6

• Input sequence file name– $>in [filename]

• Output sequence file name– $>out [filename]

– Example• $>1• $>6• $>in seq.in• $>out seq.out• $>3

Page 9: 3D Puzzle

Sliding-Sequence File

• In File– Contain lines of cell sliding-sequence

• Each line contains maximum 10 operations

– Example• 1364524351• 2625342516• 53…

Page 10: 3D Puzzle

Output Puzzle

• Command Line– Current puzzle status

• Consist of 1st, 2nd, 3rd,and 4th planes(4ⅹ4 matrix) • Example

– 5 6 7 8 | 25 26 27 28 | 33 40 41 43 | 44 45 46 47– 21 22 23 24 | 1 2 3 4 | 34 39 42 48 | 53 54 55 56– 9 10 11 12 | 29 30 31 32 | 35 38 49 50 | 57 58 59 60– 13 $ 15 16 | 17 18 19 20 | 36 37 51 52 | 61 62 63 14

Page 11: 3D Puzzle

Spec.

• Assignment Spec.– System

• Unix (junebug.snu.ac.kr)– Language

• C/C++– Compile

• Use Makefile• $>make

– Execution• $>./puzzle puzzle.in