示例#1
0
//prints out all sides of the cube
void
print_cube(void){
	int i;

	for(i = 0; i < 6; i++){
		
		print_side(this_cube->full_cube[i].side, SIDE_WIDTH);
		printf("\n");

	}

}
示例#2
0
void print_board(int black_pieces[], int white_pieces[])
{
  /* prints current state of board to screen */

  /* counters */
  int i, j, k;
  
  /* get number of board lines */
  int limit = get_lines_length(get_maximum_piece(black_pieces, white_pieces));

  /* write top of board */
  print_side("top");
  
  /* write every line */
  for(i = 0; i < limit; i++) {
    /* write left part of board (it is not a location)*/
    printf("||||");
    
    /* i know, one variable is enough, but it is more aesthetic */
    for(j = 12, k = 13; j > 0; j--, k++) {
      /* print spaces for ( B W B...)*/
      printf("%3s", "");
      
      /*
       * first_condition || second_condition
       *
       * pieces[k] -> number of pieces in k location
       * i -> line number
       *
       * first_condition is for top board (locations from 13 to 24)
       * - it is not difficult to understand.
       * - if number of pieces in k location is greater than line number,
       * then write B (or W).
       * - ex. let k is 13 and pieces[k] = 5, it will print five times B (or W)
       * for i = 0, 1, 2, 3, 4. as you can see, there must be 5 pieces.
       *
       * second_condition is for bottom board (locations from 12 to 1)
       * - it is a little bit hard to understand, but solution is very practical.
       * - if number of pieces in k location plus line number is greater than or
       * equal to limit, then write B (or W).
       * - ex. (IMPORTANT) let k is 12, pieces[k] = 5 and limit = 14, it will
       * print five times B (or W) for i = 9 (5 + 9 >= 14, then print),
       * i = 10 (5 + 10 >= 14, then print) ... i = 14 (5 + 14 >= 14, then print)
       * as you can see, i = 8 (8 + 5 >= 14, it is not true, do not print)
       */

      if(black_pieces[k] > i || black_pieces[j] + i >= limit)
	printf("B");
      else if(white_pieces[k] > i || white_pieces[j] + i >= limit)
	printf("W");
      else
	printf(" ");

      /* print |||| middle of board row and right of board row */
      if(k == 18 || k == 24 || j == 7 || j == 1)
	printf("%3s||||", "");
    }
    
    /* new line */
    printf("\n");
  }

  /* write bottom of board */
  print_side("bottom");
}