-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiller.c
192 lines (175 loc) · 5.1 KB
/
filler.c
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* filler.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ydeineha <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/23 12:20:53 by ydeineha #+# #+# */
/* Updated: 2018/05/23 12:20:59 by ydeineha ### ########.fr */
/* */
/* ************************************************************************** */
#include "filler.h"
#include <fcntl.h>//del
t_brd *create_board(char *line)
{
int i;
t_brd *board;
i = -1;
board = (t_brd *)malloc(sizeof(t_brd));
board->i = ft_atoi(ft_strchr(line, ' '));
board->j = ft_atoi(ft_strrchr(line, ' '));
board->brd = (char **)malloc(sizeof(char *) * (board->i + 1));
if (!board->brd)
return (NULL);
board->brd[board->i] = NULL;
while (++i < board->i)
board->brd[i] = ft_strnew(board->j);
return (board);
}
void fill_board(char **board, char *line, int *type)
{
static int i = 0;
if (*type == BOARD)
board[i] = ft_strcpy(board[i], &ft_strchr(line, ' ')[1]);
else
board[i] = ft_strcpy(board[i], line);
*type = board[i + 1] ? *type : 0;
i = board[i + 1] ? i + 1 : 0;
}
int main(void)
{
char *line;
t_brd *board;
t_brd *piece;
int type;
int player;
int fd;//del
board = NULL;
piece = NULL;
type = 0;
fd = open("shit.txt", O_CREAT | O_WRONLY | O_APPEND);
while (get_next_line(0, &line))//дозаписывать в файл
{
ft_putstr_fd(line, fd);
ft_putstr_fd("\n", fd);
if (type == BOARD)
fill_board(board->brd, line, &type);
if (type == PIECE)
fill_board(piece->brd, line, &type);
type = type > BOARD ? type - 1 : type;
type = ft_strstr(line, "Piece") ? PIECE : type;
type = ft_strstr(line, "Plateau") ? BOARD + 1 : type;
board = !board && ft_strstr(line, "Plateau") ? create_board(line) : board;
piece = !piece && ft_strstr(line, "Piece") ? create_board(line) : piece;
player = ft_strstr(line, "ydeineha") && ft_strstr(line, "exec") ?
ft_atoi(&ft_strchr(line, 'p')[1]) : player;
!type && board && piece ? put_piece(board, &piece, player) : 0;
ft_strdel(&line);
}
}
/*DELETE!
int i;
//ft_printf("\nplayer = %d\n", p);
if (type == 0 && board)
{
i = 0;
while (board->brd[i])
{
if (i == 0)
ft_printf("\n");
ft_printf(" %s\n", board->brd[i]);
i++;
}
}
if (type == 0 && piece)
{
i = 0;
while (piece->brd[i])
{
if (i == 0)
ft_printf("\n");
ft_printf("%s\n", piece->brd[i]);
i++;
}
}
//TILL HERE*/
/*
exec p2 ydeineha
Piece 5 3:
.*.
.*.
.*.
.*.
...
Plateau 14 30:
012345678901234567890123456789
000 ..............................
001 ..............................
002 ..............................
003 .....X.......................X
004 ..............................
005 ..............................
006 ..............................
007 ..............................
008 ..............................
009 ..............................
010 ......................O.......
011 ..............................
012 ..............................
013 .............................X
Plateau 14 30:
012345678901234567890123456789
000 ..............................
001 ..............................
002 ..............................
003 .....X........................
004 ..............................
005 ..............................
006 ..............................
007 ..............................
008 ..............................
009 ......................o.......
010 ......................O.......
011 ..............................
012 ..............................
013 ..............................
Plateau 14 30:
012345678901234567890123456789
000 ..............................
001 ..............................
002 ..............................
003 .....X........................
004 ..............................
005 ..............................
006 ..............................
007 ..............................
008 ..............................
009 ......................O.......
010 ......................O.......
011 ..............................
012 ..............................
013 .........................o....
exec p2 ydeineha
Piece 4 3:
123
123
123
123
Plateau 14 30:
012345678901234567890123456789
000 ..............................
001 ..............................
002 ..............................
003 .....X........................
004 ..............................
005 ..............................
006 ..............................
007 ..............................
008 ..............................
009 ..............................
010 ..............................
011 ..............................
012 ..............................
013 .......................ooo....
*/