-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpseudocode
26 lines (24 loc) · 1.66 KB
/
pseudocode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
I. Read from one and only one file given as argument. If there is not exactly 1 argument, display program usage.
A. Ensure correct format
a. If tetrimino is not four lines long, exit program with error message.
b. If tetrimino is not four characters on each line, exit program with error message.
c. If there is a character that is not '#' or '\n' or '.' then exit program with error message.
d. Each block must be touching another block on at least one side.
e. If there is more than ONE newline in a row, exit program with error.
d. If there are more than 26 tetriminos in a file, exit with error.
B. The order of the tetriminos must be retained
a. Change the '#' to the letter that corresponds with order. (ie. the first tetrimino would change '#' to 'A')
C. Store the tetriminos in a 2D array.
II. Create map for solution.
A. Find the minimum initial dimensions for map to place all tetriminos,
B. Initialize map to minimum initial dimensions
a. malloc size for string and initialize empty values to '.' and include new line chars.
b. str[(width + 1) * width] = '/0'
III. Fill Map
A. Place first piece in the top-left corner.
B. Attempt to place next piece in the first viable spot,
and continue this pattern until a solution is reached or a piece doesn’t fit (in the case of the latter, move to step C)
C. When a piece doesn't fit, move the PREVIOUS piece right to the next viable spot. Then repeat B.
D. Continue pattern above until a solution is reached,
or until the first piece has been moved to the end of the map and no solution has been reached.
E. If first piece has exhausted all possible positions, increment size of map and go back to step A.