@@ -37,7 +37,8 @@ int winState[9][3] = {
3737 {1 , 4 , 7 },
3838 {2 , 5 , 8 },
3939 {0 , 4 , 8 },
40- {2 , 4 , 6 }};
40+ {2 , 4 , 6 }
41+ };
4142
4243//! ALL MAIN FUNCTIONS SEE DOWN BELOW
4344void drew (void );
@@ -51,30 +52,35 @@ void validate();
5152char * winner ;
5253int main ()
5354{
54- validate ();
55- printf ("%s" );
55+ validate ();
5656}
5757
58+
5859//! IMPORTANT FUNCTION
5960void validate ()
6061{
61- winner = " " ;
62+ winner = "\0 " ;
6263 resetArea ();
6364 do
6465 {
6566 drew ();
6667 userInput ();
6768 autoPlayer ();
69+
6870 for (int i = 0 ; i < 9 ; i ++ )
6971 {
70- if (gameArea [winState [i ][0 ]] == mainPlayer && gameArea [winState [i ][1 ]] == mainPlayer && gameArea [winState [i ][2 ]] == mainPlayer )
72+ printf ("%d,%s,%s,%s" ,i ,gameArea [winState [i ][0 ]],gameArea [winState [i ][1 ]],gameArea [winState [i ][2 ]]);
73+ if (gameArea [winState [i ][0 ]] == mainPlayer & gameArea [winState [i ][1 ]] == mainPlayer & gameArea [winState [i ][2 ]] == mainPlayer )
7174 {
72- // printf("%s", gameArea[i]);
7375 winner = mainPlayer ;
76+
77+ break ;
7478 }
7579 else if (gameArea [winState [i ][0 ]] == computer && gameArea [winState [i ][1 ]] == computer && gameArea [winState [i ][2 ]] == computer )
7680 {
7781 winner = computer ;
82+ break ;
83+
7884 }else {
7985 winner = " " ;
8086 }
@@ -90,30 +96,30 @@ void validate()
9096//? DREWING THE LINES
9197void drew ()
9298{
93- system ("clear" );
99+ // system("clear");
94100 printf (GRN BOLD "\n\t|\t|\t" RESET );
95- printf (GRN BOLD "\n %s| %s| %s" RESET , gameArea [0 ], gameArea [1 ], gameArea [2 ]);
96- printf (GRN BOLD "\n--------|-------|-------" RESET );
101+ printf (GRN BOLD "\n %s| %s| %s" RESET , gameArea [0 ], gameArea [1 ], gameArea [2 ]);
102+ printf (GRN BOLD "\n--------|-------|-------" RESET Underlined BOLD "\t\e[1;98mwww.github.com/DSDmark" RESET );
97103 printf (GRN BOLD "\n\t|\t|\t" RESET );
98- printf (GRN BOLD "\n%s|%s|%s " RESET , gameArea [3 ], gameArea [4 ], gameArea [5 ]);
104+ printf (GRN BOLD "\n %s| %s| %s" RESET BOLD "\t\e[7;77m\e[1;92m\e[5;77mUnder The work:) " RESET , gameArea [3 ], gameArea [4 ], gameArea [5 ]);
99105 printf (GRN BOLD "\n--------|-------|-------" RESET );
100106 printf (GRN BOLD "\n\t|\t|\t" RESET );
101- printf (GRN BOLD "\n %s| %s|%s\n\n" RESET , gameArea [6 ], gameArea [7 ], gameArea [8 ]);
107+ printf (GRN BOLD "\n %s| %s| %s\n\n" RESET , gameArea [6 ], gameArea [7 ], gameArea [8 ]);
102108}
103109
104110//? RESET THE AREA FOR NEW GAME
105111void resetArea ()
106112{
107- int i , j ;
108- for (i = 0 ; i < 9 ; i ++ )
113+ int i ;
114+ for (i = 0 ; i <= 9 ; i ++ )
109115 gameArea [i ] = checkSpace ;
110116}
111117
112118//? CHECK ALL field FILLED OR NOT
113119int checkField ()
114120{
115121 int field = 9 ;
116- int i , j ;
122+ int i ;
117123 for (i = 0 ; i < 9 ; i ++ )
118124 {
119125 if (gameArea [i ] != checkSpace )
@@ -147,12 +153,12 @@ void userInput()
147153 int x ;
148154 do
149155 {
150- printf (BLU BOLD Underlined "What your N0.#(1-9)❔:" RESET );
156+ printf (BLU BOLD Underlined "What your lucky N0.#(1-9)❔:" RESET );
151157 scanf ("%d" , & x );
152158 x -- ;
153159
154160 // TODO VALIDET THE INPUT FIELD
155- if (0 > x )
161+ if (0 >= x )
156162 {
157163 printf (Strikethrough gRED GRN "\n🤠 Hey boy, Enter a valid input ❕" RESET );
158164 }
@@ -165,12 +171,13 @@ void userInput()
165171 else
166172 {
167173 gameArea [x ] = mainPlayer ;
174+ x = '\0' ;
168175 break ;
169176 }
170177 } while (gameArea [x ] != checkSpace );
171178}
172179
173- //? AUTO PLAYER FOR 0
180+ //? AUTO PLAYER FOR 0
174181void autoPlayer ()
175182{
176183 int x , y ;
@@ -180,9 +187,9 @@ void autoPlayer()
180187 {
181188 do
182189 {
183- x = (rand () % 9 ) + 1 ;
190+ x = (rand () % 8 ) + 1 ;
184191 } while (gameArea [x ] != checkSpace );
185192 gameArea [x ] = computer ;
186193 drew ();
187194 }
188- }
195+ }
0 commit comments