⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 initboard.c

📁 linux下编的黑白棋 棋盘格4x4 人机对战 gcc编译
💻 C
字号:
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define DIM 4
#define NOSPC 'x'
#define FREESPC ' '
#define BLACKPC '*'
#define WHITEPC 'o'
char board[DIM + 2][DIM + 2];
int pcnum[3] = { 2, 2, 12 }; /* records the number of pieces for
                                 each player and the number of
                                 free spaces.  0 = computer
                                               1 = human
                                               2 = free spaces    */

int depth;  /* holds the current depth during move calculation */

void
clear( void )
{
   if (system("clear"))
   {
      printf("An error occured clearing the screen.\n");
      exit(0);
   }
}

void
center( int spaces )
{
   int i;

   for( i = 0; i < (80 - spaces) / 2; i++ )
      printf(" ");
}



void
printboard( void )
{
   int i, j, c = DIM * 4 + 17;
   char  comp[10] = "Computer",
         humn[10] = "Human   ",
        *pstr[2]  = {comp, humn};

   clear();

   /* print column numbers */

   center( c );
   printf("  ");
   for( i = 0; i < DIM; i++ )
      printf("  %d ", i + 1);
   printf("\n");

   /* Print row of board */
   for ( i = 0; i < DIM; i++ )
   {

      /* Prints a divider line between rows */

      center( c );
      printf("  +");
      for (j = 0; j < DIM; j++)
         printf("---+");
      printf("\n");

      /* Prints the corresponding row, and the values for that row */

      center( c );
      printf("%c | %c", 'A' + i, board[i+1][1] );
      for (j = 1; j < DIM; j++)
         printf(" | %c", board[i+1][j+1]);
      printf(" | %c", 'A' + i);

      if (i < 2)  /* print score */
         printf("   %s: %d", pstr[i], pcnum[i] );

      printf("\n");

   }

   /* Another divider line */
   center( c );
   printf("  +");
   for (j = 0; j < DIM; j++)
      printf("---+");

   printf("\n");

   /* print column numbers again at the bottom */

   center( c );
   printf("  ");
   for( i = 0; i < DIM; i++ )
      printf("  %d ", i + 1);
   printf("\n\n");
}
int main(void)
{	
	int i, j;

   /*  For loops used to place the borders and valid places on *
    *  the board                                               *
    */

   for( i = 0; i < DIM + 2; i++ )
      for( j = 0; j < DIM + 2; j++ )
         if (i * j == 0 || i == DIM + 1 || j == DIM + 1)
            board[i][j] = NOSPC;
         else
            board[i][j] = FREESPC;

   /*  Place the initial four pieces on the board */

   board[ DIM/2    ][ DIM/2    ] = BLACKPC;
   board[ DIM/2    ][ DIM/2 + 1] = WHITEPC;
   board[ DIM/2 + 1][ DIM/2    ] = WHITEPC;
   board[ DIM/2 + 1][ DIM/2 + 1] = BLACKPC;
void printboard( void );
return (0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -