program.c
//Implementations
//Inintializes the computer's boards, including placement of it's ships
Implementations
Inintializes the computer's boards, including placement of it's ships
Implementations Inintializes the computer ' s boards including placement of it ' s ships
void computerInit(char (*board)[BOARDSIZE], char (*shots)[BOARDSIZE], ship *ships){
  int good, dir = 0, row, col;
  for(int i = 0; i < 3; i++) { 
    ships[i] = makeShip(i + 1); 
	good = 0;
	while(good == 0){
	  good = 1;
      dir = rand() % 2;
	  if(dir) {
	    row = rand() % ((BOARDSIZE - ships[i].size) + 1);
		col = rand() % BOARDSIZE;
	  } else {
		row = rand() % BOARDSIZE;
		col = rand() % ((BOARDSIZE - ships[i].size) + 1);
	  }
      for(int k = 0; k < ships[i].size; ++k) {
        if(dir) {
		  if(board[row + k][col] == BOAT){ 
		    good = 0;
		  }
        } else {
		if(board[row][col + k] == BOAT){ 
		  good = 0;
		}
        }
      }
	}
	for(int k = 0; k < ships[i].size; ++k) {
      if(dir) {
		board[row + k][col] = BOAT;
        ships[i].spaces[k] = &board[row + k][col];
      } else {
	    board[row][col + k] = BOAT;
        ships[i].spaces[k] = &board[row][col + k];
      }
    }
  }
}
void computerInit ( char ( * board ) [ BOARDSIZE ] , char ( * shots ) [ BOARDSIZE ] , ship * ships ) { int good , dir = 0 , row , col ; for ( int i = 0 ; i < 3 ; i ++ ) { ships [ i ] = makeShip ( i + 1 ) ; good = 0 ; while ( good == 0 ) { good = 1 ; dir = rand ( ) % 2 ; if ( dir ) { row = rand ( ) % ( ( BOARDSIZE - ships [ i ] . size ) + 1 ) ; col = rand ( ) % BOARDSIZE ; } else { row = rand ( ) % BOARDSIZE ; col = rand ( ) % ( ( BOARDSIZE - ships [ i ] . size ) + 1 ) ; } for ( int k = 0 ; k < ships [ i ] . size ; ++ k ) { if ( dir ) { if ( board [ row + k ] [ col ] == BOAT ) { good = 0 ; } } else { if ( board [ row ] [ col + k ] == BOAT ) { good = 0 ; } } } } for ( int k = 0 ; k < ships [ i ] . size ; ++ k ) { if ( dir ) { board [ row + k ] [ col ] = BOAT ; ships [ i ] . spaces [ k ] = & board [ row + k ] [ col ] ; } else { board [ row ] [ col + k ] = BOAT ; ships [ i ] . spaces [ k ] = & board [ row ] [ col + k ] ; } } } }
Implementations
Inintializes the computer's boards, including placement of it's ships
Implementations Inintializes the computer ' s boards including placement of it ' s ships
//this *should* work //this works //from here down works