j'ai inseré un if vers la fin de mon code pour choisir entre noir ou blanc:
main.c
puis showboard.c
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <stdio.h> #include <stdlib.h> int c=0; int i,j; unsigned char p[19][19]; /* go board */ unsigned char l[19][19]; /* liberty of current color */ unsigned char ma[19][19]; /* working matrix for marking */ unsigned char ml[19][19]; /* working matrix for marking */ char ans[2]; int p1move, p2move; /* p1 color, p2 color */ int lib; /* current stone liberty */ int p1ik, p1jk; /* location of p1 stone captured */ int p2ik, p2jk; /* location of p2 stone captured */ int p1k, p2k; /* no. of stones captured by p1 and p2 */ int new=0; void showboard(int c); int main(int argc,char *argv[]){ while ((c!=1)&&(c!=2)&&(c!=3)&&(c!=4)&&(c!=5)){ printf ("Taille du Goban:\n\t1) 5x5\n\t2) 7x7\n\t3) 9x9\n\t4) 13x13\n\t5) 19x19\n\nVotre choix:"); scanf("%d",&c); } if ((c==1)) { /* init board */ for (i = 0; i < 5; i++) for (j = 0; j < 5; j++) p[i][j] = 0; } if ((c==2)) { /* init board */ for (i = 0; i < 7; i++) for (j = 0; j < 7; j++) p[i][j] = 0; } if ((c==3)) { /* init board */ for (i = 0; i < 9; i++) for (j = 0; j < 9; j++) p[i][j] = 0; } if ((c==4)) { /* init board */ for (i = 0; i < 13; i++) for (j = 0; j < 13; j++) p[i][j] = 0; } if ((c==5)) { /* init board */ for (i = 0; i < 19; i++) for (j = 0; j < 19; j++) p[i][j] = 0; } if (!new) /* new game */ { /* choose color */ printf("\nChoose side(b or w)? "); scanf("%c",ans); if (ans[0] == 'b') { p1move = 1; /* P1 white */ p2move = 2; /* P2 black */ } else { p1move = 2; /* P1 black */ p2move = 1; /* P2 white */ } } showboard(c); /* main loop * tant que pas capturer de pierres * lit mouvement joueur1 * enleve pierre * lit mouvement joueur2 * enleve pierre * */ return 0; }
mais une fois compilé je ne peux pas choisir entre black or white.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <stdio.h> #include <stdlib.h> extern unsigned char p[19][19]; extern int p1move, p2move; /* p1 color, p2 color */ extern int lib; /* current stone liberty */ extern int p1ik, p1jk; /* location of p1 stone captured */ extern int p2ik, p2jk; /* location of p2 stone captured */ extern int p1k, p2k; /* no. of stones captured by p1 and p2 */ int ii=0; int i=0; int j=0; void showboard(int c){ if (c==1){ /*goban 5x5*/ printf(" A B C D E\n"); for (i = 0; i < 5; i++){ ii = 5 - i; printf("%2d",ii); for (j = 0; j < 5; j++) if (p[i][j] == 0) printf(" -"); else if (p[i][j] == 1) printf(" O"); else printf(" X"); printf("%2d",ii); printf("\n"); } printf(" A B C D E\n"); } if (c==2){ /*goban 7x7*/ printf(" A B C D E F G\n"); for (i = 0; i < 7; i++){ ii = 7 - i; printf("%2d",ii); for (j = 0; j < 7; j++) if (p[i][j] == 0) printf(" -"); else if (p[i][j] == 1) printf(" O"); else printf(" X"); printf("%2d",ii); printf("\n"); } printf(" A B C D E F G\n"); } if (c==3){ /*goban 9x9*/ printf(" A B C D E F G H J\n"); for (i = 0; i < 9; i++){ ii = 9 - i; printf("%2d",ii); for (j = 0; j < 9; j++) if (p[i][j] == 0) printf(" -"); else if (p[i][j] == 1) printf(" O"); else printf(" X"); printf("%2d",ii); printf("\n"); } printf(" A B C D E F G H J\n"); } if (c==4){ /*goban 13x13*/ printf(" A B C D E F G H J K L M N\n"); for (i = 0; i < 13; i++){ ii = 13 - i; printf("%2d",ii); for (j = 0; j < 13; j++) if (p[i][j] == 0) printf(" -"); else if (p[i][j] == 1) printf(" O"); else printf(" X"); printf("%2d",ii); printf("\n"); } printf(" A B C D E F G H J K L M N\n"); } if (c==5){ /*goban19x19*/ printf(" A B C D E F G H J K L M N O P Q R S T\n"); for (i = 0; i < 19; i++){ ii = 19 - i; printf("%2d",ii); for (j = 0; j < 19; j++) if (p[i][j] == 0) printf(" -"); else if (p[i][j] == 1) printf(" O"); else printf(" X"); printf("%2d",ii); printf("\n"); } printf(" A B C D E F G H J K L M N O P Q R S T\n"); } if (p2move == 1) printf(" Your color: White O\n"); else if (p2move == 2) printf(" Your color: Black X\n"); else printf("\n"); if (p1move == 1) printf(" My color: White O\n"); else if (p1move == 2) printf(" My color: Black X\n"); else printf("\n"); }
J'y arrive quand j'utilise scanf(%d,&s) avec int mais pas avec char.
Je ne sais pas de ou viens mon probleme.
merci de votre aide
Partager