-
Notifications
You must be signed in to change notification settings - Fork 4
/
structure.txt
102 lines (82 loc) · 3.94 KB
/
structure.txt
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# **************************************************************************** #
# #
# ::: :::::::: #
# structure.txt :+: :+: :+: #
# +:+ +:+ +:+ #
# By: cschulle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/02/02 19:35:09 by cschulle #+# #+# #
# Updated: 2019/02/22 20:43:59 by cschulle ### ########.fr #
# #
# **************************************************************************** #
--- ---
FILLIT PROGRAM STRUCTURE
--- ---
• MAIN()
Starting input point for the program.
Calls parser() to return list of pieces (& determine if valid file).
Calls solver() to solve puzzle.
Calls map_printer() to print solved puzzle.
Calls free_map() to free map.
Calls free_pieces() to free piece list.
Input: arguments from stdin
Output: -
• PARSER()
Calls open() on filestring to get an fd.
Calls piecemaker() in a loop to read through file and return pieces.
Appends each new piece to the piece list.
Closes fd.
Returns error if invalid file.
Input: filename as a string
Output: t_list pointer to head of piece list
• PIECEMAKER()
Reads through a given section of the buffer to create a t_piece struct.
Uses size limits and calls valid_checker() as it reads to check if valid file.
Input: char * beginning of piece, char * end of piece
Output: t_piece pointer to new piece
• VALID_CHECKER()
Checks if the file is valid.
A file is invalid if ([x] indicates already checked in parser):
[x] Fewer than 21 bytes
- Piece chunk does not contain 4 '#' characters
- adjacency_counter() return isn't 6 or 8
- Lines are more than 4 chars long (excluding '\n')
- Piece blocks are more than 4 lines long
- Contains chars other than '.', '#', and '\n'
- Contains invalid pieces
[x] Greater than 544 bytes
• ADJACENCY_COUNTER()
Checks if piece has a valid number of adjacencies.
Valid tetrominos will contain either 6 or 8 (8 if little square) adjacencies.
• SOLVER()
Calls mapper() to create a blank map.
Calls fitter() in a loop to start recursive backtracking implementation.
While fitter() fails, increments size of blank map.
Returns solved mapp when fitter() succeeds.
Input: piece list head (t_list pointer)
Output: solved map as a 2-D array
• FITTER()
>> RECURSIVE BACKTRACKING TIME! <<
While the piece doesn't hit either edge, call placer() to add the piece to the map.
If placer() is unsuccessful, move piece 1 space forward within map.
If placer() is successful, call fitter() on the next piece
If placer() is unusscessful for ALL placements of next piece, backtrack to previous piece, & move 1 space forward.
Repeat until valid map is found.
Return solved map.
• PLACER()
Checks if current position of piece is valid (no intersections with other pieces).
If not, return (0).
If yes, places piece, calls letterer() to replace '#' characters with letter corresponding to piece number.
-- keep track of how many pieces, as letterer() must fill with a different letter for each!
Input: Tetris piece struct pointer, map pointer, x coordinate, y coordinate.
Output: Integer (success or failure flag)
• LETTERER()
Replaces given tetromino's '#' characters with the given letter.
Input: Tetris piece struct pointer, character
Output: Tetris piece struct pointer
• MAP_PRINTER()
Prints solved map.
• FREE_MAP()
Frees malloc'd 2D map array.
• FREE_PIECES()
Frees malloc'd list of pieces.