-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_updated_board_game.c
120 lines (109 loc) · 2.16 KB
/
print_updated_board_game.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
/*
** printf_board_game_in_a_pretty_fram.c for a in /home/soucan_d/soucan_d/Bootstrap/CPE_2015_allum1_bootstrap
**
** Made by Dimitri
** Login <[email protected]>
**
** Started on Tue Feb 9 11:12:35 2016 Dimitri
** Last update Fri Feb 26 18:23:59 2016 Dimitri
*/
#include <stdio.h>
#include <stdlib.h>
#include "get_next_line.h"
int matches_norme(int matches, char **str)
{
int line;
char *tmp;
my_putstr("Matches: ");
if ((tmp = get_next_line(0)) == NULL)
return (-1);
else if ((matches = my_atoi(tmp)) == -1)
{
my_putstr("Error: invalid input (positive number expected)\n");
if ((line = get_line(str)) != 0)
get_matches(line, str);
return (42);
}
else
return (matches);
}
int nb_of_space(int line)
{
int a;
if (line == 1)
return (3);
else if (line == 2)
return (2);
else if (line == 3)
return (1);
else if (line == 4)
return (0);
}
char **print_updated_board_game(int line, int matches, char **str, int d)
{
int a;
int ligne;
int new_pipe;
int space;
ligne = 0;
a = 0;
my_putchar(10);
while (str[++ligne] != 0)
{
if (ligne == line)
{
new_pipe = d - matches;
space = nb_of_space(line);
while (space-- != 0)
str[line][a++] = ' ';
while (new_pipe-- != 0)
str[line][a++] = '|';
while (str[line][a] != 0)
str[line][a++] = ' ';
printf_board_game_in_a_pretty_fram(str[line]);
}
else
printf_board_game_in_a_pretty_fram(str[ligne]);
}
}
int main2(char **map, int a)
{
int choice_line;
while (42)
{
if ((make_human_and_ai_play_a_round(a)) != 2)
{
if ((choice_line = get_line(map)) == 0
|| get_matches(choice_line, map, 0) == 0)
return (0);
}
else
{
choice_line = 0;
if (get_matches(choice_line, map, 2) == 0)
return (0);
}
}
}
int main()
{
char **map;
int a;
int line;
int choice_line;
choice_line = 0;
line = 1;
a = 1;
if ((map = malloc(sizeof(char *) * 7)) == 0)
return (0);
while (a <= 7)
{
map[line] = display_map(a);
printf_board_game_in_a_pretty_fram(map[line]);
line = line + 1;
a = a + 2;
}
my_putchar(10);
main2(map, 0);
free(map);
}