Browse Source

done with checkers

Iman Anwarzai 1 year ago
parent
commit
eb5ca9f34d
2 changed files with 25 additions and 14 deletions
  1. BIN
      boggle
  2. 25 14
      game_server.c

BIN
boggle


+ 25 - 14
game_server.c

@@ -37,23 +37,31 @@ char dice[16][6] = {
 
 //word checker
 int exists = 0;
-void isaword_helper(char arr[4][4], int ** passed, int i, int j, char * str, char * goal){
-        passed[i][j] = 1;
-        str[strlen(str)] = arr[i][j];
+void isaword_helper(int ** passed, int i, int j, char * str, char * goal){
+        //printf("strlength: %d\n", (int)strlen(str));
+	passed[i][j] = 1;
+        str[strlen(str)] = board[i][j];
+	//printf("strlength: %d\n", (int)strlen(str));
+	//printf("here: %s\n", str);
         if(strcmp(str, goal) == 0){
-                exists = 1;
+          //      printf("exists!\n");
+		exists = 1;
 		            return;
         }
         for (int r = i-1; r <= i+1 && r < 4; r++)
                 for (int c = j-1; c <= j+1 && c < 4; c++)
                         if (r >=0 && c >=0 && !passed[r][c])
-                                if(goal[strlen(str)] == arr[r][c])
-                                        isaword_helper(arr, passed, r, c, str, goal);
+                                if(goal[strlen(str)] == board[r][c]){
+            //                    	printf("indside!\n");
+	//			        printf("strlength: %d\n", (int)strlen(str));
+					isaword_helper(passed, r, c, str, goal);	
+				}
         str[strlen(str) - 1] = '\0';
         passed[i][j] = 0;
 }
-int isaword(char arr[4][4], char * goal){
-        int ** temp = malloc(sizeof(int*) * 4);
+int isaword(char * goal){
+       // printf("the word is: %s\n", goal);
+	int ** temp = malloc(sizeof(int*) * 4);
         for(int i = 0; i < 4; i ++)
                 temp[i] = malloc(sizeof(int) * 4);
         for(int x = 0; x < 4; x++)
@@ -63,7 +71,7 @@ int isaword(char arr[4][4], char * goal){
         char * string = calloc(1, 1024);
         for(int i = 0; i < 4; i++)
                 for(int j = 0; j < 4; j++)
-                        isaword_helper(arr, temp, i, j, string, goal);
+                        isaword_helper(temp, i, j, string, goal);
         for(int i = 0; i < 4; i++)
 		free(temp[i]);
 	free(temp);
@@ -512,10 +520,13 @@ int do_command(struct client * p, int cmd_argc, char **cmd_argv) {
 			sendclient(p, str);
     		}
     		sendclient(p, "\r\n");
-  	}	
+  	Player* curr = find_player(p->name, player_list);
+	curr->total_games = curr->total_games + 1;
+	}	
     }else {
-	/*char * word = cmd_argv[0];								//word and dictionary checker
-	if(isaword(board, word)){
+	char * word = cmd_argv[0];								//word and dictionary checker
+	capitalize(word);
+	if(isaword(word)){
 		if(isInDictionary(word)){
 				Player *player = find_player(p->name, player_list);
 				char str [BUFFER_SIZE - 10];
@@ -532,8 +543,8 @@ int do_command(struct client * p, int cmd_argc, char **cmd_argv) {
 	}
 	else{ 
         	sendclient(p, "Word is not in board\r\n");
-	}*/
-    		sendclient(p, "Invalid syntax\r\n");
+	}
+    	//	sendclient(p, "Invalid syntax\r\n");
 	}
 
 	//sendclient(p, "thank you for playing. goodbye!\n");