Browse Source

board generator error

Akarsh Balaji 1 year ago
parent
commit
bfb2deec60
8 changed files with 21 additions and 16 deletions
  1. BIN
      boggle
  2. 15 13
      game.c
  3. BIN
      game.o
  4. 4 1
      game_server.c
  5. 1 1
      game_server.h
  6. BIN
      game_server.o
  7. BIN
      players.o
  8. 1 1
      utils.h

BIN
boggle


+ 15 - 13
game.c

@@ -13,6 +13,7 @@ int score;
 int word_score;
 int old_score;
 int skip;
+extern char board[4][4];
 
 char dice[16][6] = {
   {'R', 'I', 'F', 'O', 'B', 'X'},
@@ -41,19 +42,20 @@ void swap(int* i, int* j) {
   *j = temp;
 }
 
-void generate_board() {
-  srand(time(0));
-  int order[16];
-  int i;
-  for (i = 0; i < 16; i++) {
-    order[i] = i;
-  }
-  for (i = 0; i < 16; i++) {
-    swap(order + i, order + (rand() % (16-i)) + i);
-  }
-  for (i = 0; i < 16; i++) {
-    board[i] = dice[order[i]][rand() % 6];
-  }
+void generate_board(char ** arr){
+	srand(time(0));
+	int filled[16];
+	for(int i = 0; i < 16; i++)
+		filled[i] = 0;
+
+        for(int i = 0; i < 4; i++)
+                for(int j = 0; j < 4; j++){
+			int dicenumber = rand() % 16;
+			while(filled[dicenumber] == 1)
+				dicenumber = rand() % 16;
+                        arr[i][j] = dice[dicenumber][rand() % 6];
+			filled[dicenumber] = 1;
+		}
 }
 
 /*void refresh_screen(int score, int bonus, char* prev) {

BIN
game.o


+ 4 - 1
game_server.c

@@ -7,6 +7,8 @@ Client *client_list = NULL;
 
 short port = -1;
 
+extern char board[4][4];
+
 int main(int argc, char* argv[]) {
    // struct client *p;
 	if (argc > 1)
@@ -329,10 +331,11 @@ int do_command(struct client * p, int cmd_argc, char **cmd_argv) {
         sendclient(p, str);
     } else if (strcmp(cmd_argv[0], "new_game") == 0 && cmd_argc == 1) {
         //TODO -- transmit current board to be presented as a 2D array of chars
+	sendclient(p, "\r\n");
 	for (int i = 0; i < 4; i++) {
     		for (int j = 0; j < 4; j++) {
 			char str[2];
-      			sprintf(str, "%c ", board[4*i+j]);
+      			sprintf(str, "%c ", board[i][j]);
 			sendclient(p, str);
     		}
     		sendclient(p, "\r\n");

+ 1 - 1
game_server.h

@@ -25,7 +25,7 @@
 
 #define BUFFER_SIZE 1024
 
-int board[16];
+extern char board[4][4];
 
 //Node for the linked list which stores currently connected clients
 typedef struct client {

BIN
game_server.o


BIN
players.o


+ 1 - 1
utils.h

@@ -11,7 +11,7 @@ typedef struct user {
   struct user * next;
 } User;
 
-int board[16];
+//extern xh board[16];
 
 int login();
 int verify_word(char* word);