亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 編程 > C++ > 正文

基于C語言實現五子棋游戲完整實例代碼

2020-05-23 14:23:28
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了基于C語言實現五子棋游戲完整實例代碼,相信對于學習游戲開發的朋友會有一定的幫助與借鑒價值,需要的朋友可以參考下
 
 

本文實例講述了基于C語言實現五子棋游戲的方法,代碼備有比較完整的注釋,可以幫助讀者更好的加以理解。

五子棋游戲代碼如下:

/* * 使用鍵盤的上下左右鍵移動棋盤,空格鍵表示下棋,ESC鍵退出程序 */#include <stdio.h>#include <stdlib.h>#include <bios.h>#include <graphics.h>#include<malloc.h>/* * 對應鍵盤鍵的十六進制數字 */#define ESC 0x11b#define UP 0x4800#define DOWN 0x5000#define LEFT 0x4b00#define RIGHT 0x4d00#define BLANK 0x3920#define PLAYER1 1#define PLAYER2 2#define COMPUTER 2#define LENGTH 15#define SEARCH_DEEP 2/* * 用來在函數can_expand()查找可以擴展的節點步長 */#define STEP 1/************全局變量定義***************/int       x1 = 240,        y1 = 240,        oldx = 240,        oldy = 240;int       key_mode;int       key_net;int       step_sum = 0;int       chessman[LENGTH][LENGTH];int       depth = 2; /* 搜索的深度 */int       a = 0,        b = 0;int       flag_run;int       win_flag = 0;typedef struct five_chess *point;struct five_chess {  int       x;  int       y;  int       layer;  double     value;  double     score;  int       chess[LENGTH][LENGTH];  int       record[LENGTH][LENGTH];} A;int       stack_deep0 = 0;point      stack_c[10];point      close[600];voidpush(point s0){  if (stack_deep0 < 10) stack_c[stack_deep0++] = s0;}pointtop(){  if (stack_deep0 > 0) return stack_c[stack_deep0 - 1];  /*else return 一個什么樣的東西?*/}voidpop(){  if (stack_deep0 > 0) stack_deep0--;}intis_empty(){  if (stack_deep0 != 0) return 1;  else return 0;} /************函數的聲明**************/void      five();void      show();int       win_or_not(int x0, int y0, int who,   int chessman[LENGTH][LENGTH], int a);void      set_chessman();void      print_result();/************評價函數部分************/double     score_row(int i, int j, int chessman[LENGTH][LENGTH]);double     score_col(int i, int j, int chessman[LENGTH][LENGTH]);double     score_diag_45(int i, int j, int chessman[LENGTH][LENGTH]);double     score_diag_135(int i, int j, int chessman[LENGTH][LENGTH]);double     total_score(int who_running, int chessman[LENGTH][LENGTH]);double     score(int chessman[LENGTH][LENGTH]);int       rowdt(int i, int j, int chessman[LENGTH][LENGTH]);int       coldt(int i, int j, int chessman[LENGTH][LENGTH]);int       diadt(int i, int j, int chessman[LENGTH][LENGTH]);int       vdiadt(int i, int j, int chessman[LENGTH][LENGTH]);int       can_expand(int i, int j, int chessman[LENGTH][LENGTH]);void     copy(point s1, point s0);intPOW(int s, int t){  int       sum = s,          i;  if (t <= 0) return 1;  for (i = 0; i < t; i++) sum *= sum;  return sum;}/* * 定義computer先手 */pointexpand(point s0){  int       flag;  int       i,          j;  point      new_chess = (point) malloc(sizeof(struct five_chess));/*************************這里出錯***********************************/  for (i = 0; i < LENGTH; i++) for (j = 0; j < LENGTH; j++)   new_chess->chess[i][j] = s0->chess[i][j];  for (i = 0; i < LENGTH; i++) for (j = 0; j < LENGTH; j++)   new_chess->record[i][j] = s0->chess[i][j];/*************************這里出錯***********************************/  if (s0->layer % 2 == 0) flag = COMPUTER;  else flag = PLAYER1;  for (i = 0; i < LENGTH; i++) for (j = 0; j < LENGTH; j++) {   if (s0->record[i][j])             /*如果有棋子*/ continue;   if (can_expand(i, j, s0->chess) == 0)  /*如果有棋子,而且沿水平,樹直,左上—右下,右上—左下,四個方向可以擴展*/ continue;   s0->record[i][j] = flag;   new_chess->chess[i][j] = flag;   new_chess->layer = s0->layer + 1;   new_chess->x = i;   new_chess->y = j;   new_chess->record[i][j] = flag;   return new_chess; }  /*   * for(i=5;i<10;i++) for(j=5;j<10;j++){ if(s0->record[i][j]) continue;   * if(can_expand(i,j,s0->chess)==0) continue; s0->record[i][j]=flag;   * new_chess->x=i; new_chess->y=j; new_chess->record[i][j]=flag;   * new_chess->layer=s0->layer+1; new_chess->chess[i][j]=flag ; return   * new_chess; } for(i=2;i<12;i++) for(j=2;j<12;j++){   * if(i>4&&i<10&&j>4&&j<10) continue; if(s0->record[i][j]) continue;   * if(can_expand(i,j,s0->chess)==0) continue; s0->record[i][j]=flag;   * new_chess->x=i; new_chess->y=j; new_chess->record[i][j]=flag;   * new_chess->layer=s0->layer+1; new_chess->chess[i][j]=flag; return   * new_chess;   *    * } for(i=0;i<LENGTH;i++) for(j=0;j<LENGTH;j++){   * if(i>1&&i<12&&j>1&&j<12) continue; if(s0->record[i][j]) continue;   * if(can_expand(i,j,s0->chess)==0) continue; s0->record[i][j]=flag;   * new_chess->chess[i][j]=flag; new_chess->layer=s0->layer+1;   * new_chess->x=i; new_chess->y=j; new_chess->record[i][j]=flag; return    * new_chess; }    */  new_chess->layer = -1;  return new_chess;} voidcomputer(){  int       i,          j,          k,          num = 0;  int       break_now = 0;  int       break_then = 0;  int       go_on = 0;  point     s0 = NULL,          s1 = NULL,          s2 = NULL,          max_chess = NULL;  point     temps = NULL,          s01;  /*   * 堆棧的初始化   */  stack_deep0 = 0;  s0 = malloc(sizeof(struct five_chess));  for (i = 0; i < 600; i++)              /*為什么是600*/ close[i] = NULL;                 /*close是一個point 數組*/  close[num++] = s0;  for (i = 0; i < LENGTH; i++) for (j = 0; j < LENGTH; j++) {   s0->chess[i][j] = chessman[i][j];   s0->record[i][j] = chessman[i][j]; }  s0->layer = 0;  s0->value = -3000000;  s0->score = -3000000;  push(s0);  while (is_empty() != 0) {        /*看是棧否為空*/ s01 = top();                  /*如果不是空*/ s1 = expand(s01);             /*從棧頂開始展開*/ close[num++] = s1; if (s1->layer == -1) {   pop();   continue; } go_on =   win_or_not((s1->x + 1) * 30, (s1->y + 1) * 30, 2, s1->chess,     1); if (go_on == 2) {   a = (s1->x + 1) * 30;   b = (s1->y + 1) * 30;   break_then = 1;   break; } go_on =   win_or_not((s1->x + 1) * 30, (s1->y + 1) * 30, 1, s1->chess,     1); if (go_on == 1) {   a = (s1->x + 1) * 30;   b = (s1->y + 1) * 30;   break_then = 1;   break; } s1->value = 30000; push(s1); while (1) {   s1 = top();   s2 = expand(s1);   if (s2->layer == -1) { pop(); if (s1->value > top()->value) {   top()->value = s1->value;   max_chess = s1; } free(s2); break;   }/*end of if*/   s2->score = score(s2->chess);   temps = top();   if (s2->score < temps->value) temps->value = s2->score;   free(s2); }/*end of whiile(1) */  }  if (break_then == 0) { for (i = 0; i < LENGTH; i++) {   for (j = 0; j < LENGTH; j++) if (max_chess->chess[i][j] != chessman[i][j]) {   a = i * 30 + 30;   b = j * 30 + 30;   break_now = 1;   break; }   if (break_now == 1) break; }  }  for (i = 0; i < 600; i++) { if (close[i] == NULL)   continue; free(close[i]);  }}/**********************************************************/voidmain(){  int       key;  int       play_with_who = 1;  printf("1.Play with human/n2.Play with computer/nPlease choice: ");  scanf("%d", &play_with_who);   five();              /*顯示棋盤*/  show();  if (play_with_who == 1) {   /*人與人玩*/ while (1) {  /*設置人與人玩的界面*/   settextstyle(0, 0, 2);   if ((step_sum + 1) % 2) { setcolor(1); outtextxy(500, 180, "Player2"); setcolor(4); outtextxy(500, 180, "Player1");   } else { setcolor(1); outtextxy(500, 180, "Player1"); setcolor(10); outtextxy(500, 180, "Player2");   }   if (bioskey(1)) /*  * 按了一次鍵盤那么就true,執行下面代碼,這是bios。h  */   { key = bioskey(0); /*  * 返回一個鍵盤值,如沒有按鍵,則一直等待  */ switch (key) { case ESC:   exit(0); case LEFT:   if (x1 > 30) {  x1 -= 30;  show();   /*顯示方框*/   }   break; case UP:   if (y1 > 30) {  y1 -= 30;  show();   }   break; case RIGHT:   if (x1 < 450) {  x1 += 30;  show();   }   break; case DOWN:   if (y1 < 450) {  y1 += 30;  show();   }   break; case BLANK:         /*按下空格鍵后放置棋子*/   {  if (chessman[x1 / 30][y1 / 30])    break;       /*如果當前位置有棋子,不能放置,退出*/  step_sum++;    /*如果沒有棋子,下一步誰走加1*/  /*  * P1 設置棋子  */  if (step_sum % 2) {    setcolor(15);  /*畫棋子*/    setfillstyle(SOLID_FILL, 15); /* 封閉圖形,進行實體填充*/    circle(x1, y1, 10);      /*畫圓*/    floodfill(x1, y1, 15);    /*填充圓*/    chessman[x1 / 30][y1 / 30] = PLAYER1;        /*設置棋盤狀態*/    win_flag = win_or_not(x1, y1, 1, chessman, 0);   /*分析游戲是否結束,誰勝誰敗*/    if (win_flag == 1)  outtextxy(480, 240, "P1 Win");    else if (win_flag == 3)  outtextxy(480, 240, "DOGFALL");    if (win_flag != 0) {           /*如果沒人勝,游戲繼續*/  while (bioskey(1) == 0);  closegraph();            /*what this mean?*/    }  } else { /* P2 設置棋子 */    setcolor(12);                setfillstyle(SOLID_FILL, 12);    circle(x1, y1, 10);    floodfill(x1, y1, 12);    chessman[x1 / 30][y1 / 30] = PLAYER2;    win_flag = win_or_not(x1, y1, 2, chessman, 0);    if (win_flag == 2)  outtextxy(480, 240, "P2 Win");    else if (win_flag == 3)  outtextxy(480, 240, "DOGFALL");    if (win_flag != 0) {  while (bioskey(1) == 0);  closegraph();    }  }    }   break; }   } }  } else { chessman[7][7] = COMPUTER;       /*人和電腦玩,電腦先走一步*/       setcolor(12); setfillstyle(SOLID_FILL, 12); circle(240, 240, 10); floodfill(240, 240, 12); flag_run = 0;          /*有什么用?*/ step_sum++;          /*下一步誰走?*/ while (1) {   while (1) { if (flag_run == 1)   break; if (bioskey(1)) {   key = bioskey(0);   /*    * 返回一個鍵盤值,如沒有按鍵,則一直等待    */   switch (key) {   case ESC:  exit(0);   case LEFT:  if (x1 > 30) {    x1 -= 30;    show();  }  break;   case UP:  if (y1 > 30) {    y1 -= 30;    show();  }  break;   case RIGHT:  if (x1 < 450) {    x1 += 30;    show();  }  break;   case DOWN:  if (y1 < 450) {    y1 += 30;    show();  }  break;   case BLANK:  {    if (chessman[x1 / 30 - 1][y1 / 30 - 1])  break;                             /*有棋子了不走*/    setcolor(15);    setfillstyle(SOLID_FILL, 15); /* 封閉圖形,進行實體填充      */    circle(x1, y1, 10);    floodfill(x1, y1, 15);               /*畫棋子*/    chessman[x1 / 30 - 1][y1 / 30 - 1] = PLAYER1;    flag_run = 1;                 /*有什么用?*/    step_sum++;                 /*下一步誰走*/    win_flag = win_or_not(x1, y1, 1, chessman, 0);  /*誰勝誰負*/    if (win_flag == 1)  outtextxy(480, 240, "P1 Win");    else if (win_flag == 3)  outtextxy(480, 240, "DOGFALL");    if (win_flag != 0) {  while (bioskey(1) == 0);                 /*沒有人勝則繼續等待下棋*/  closegraph();    }  }   } /* switch */ }   }   computer();                      /*調用智能體*/   /*   * a,b存放的是現在電腦準備下的位置   * 返回一個a,b的結構體不是更好,用全局變量不爽啊   * struct {   *     int a;   *     int b;   * }   */   setcolor(12);   setfillstyle(SOLID_FILL, 12);   circle(a, b, 10);   floodfill(a, b, 12);   chessman[a / 30 - 1][b / 30 - 1] = COMPUTER;   flag_run = 0;   step_sum++;   win_flag = win_or_not(a, b, 2, chessman, 0);   if (win_flag == 2) outtextxy(480, 240, "ComputerWin");   else if (win_flag == 3) outtextxy(480, 240, "DOGFALL");   if (win_flag != 0) { while (bioskey(1) == 0); closegraph();   }   }  }}voidfive(){  int       i,          j;  /*   * 畫棋盤的過程   */  int       gdriver = DETECT,          gmode;  registerbgidriver(EGAVGA_driver);  initgraph(&gdriver, &gmode, " ");  /*   * 對顯示適配器進行配置   */  setbkcolor(1);  for (i = 0; i < 30; i++) { setcolor((i >= 2) ? 9 : i); rectangle(i, i, 479 - i, 479 - i); /* 畫矩形邊框 */  }  /*   * 畫棋盤   */  for (i = 1; i < 14; i++) for (j = 1; j < 14; j++) {   setcolor(14);   line(30 + 30 * i, 30, 30 + 30 * i, 449);   line(30, 30 + 30 * i, 449, 30 + 30 * i); }  /*   * 畫整個圖的邊框   */  for (i = 0; i < 15; i++) { setcolor(i); rectangle(i, i, 640 - i, 480 - i); line(480 - i, 15, 480 - i, 465);  }  /*   * 輸出屏幕右側的信息   */  setcolor(4);  settextstyle(0, 0, 2);  outtextxy(500, 45, "GOBANG");  setcolor(10);  settextstyle(0, 0, 1);  outtextxy(500, 90, "Designed By");  outtextxy(514, 118, "Ye Binbin");  outtextxy(480, 140, "from class A of CS");}/* * 移動光標 */voidshow(){  setcolor(1);  if (oldx < 450) { if (oldy > 30)   line(oldx + 7, oldy - 15, oldx + 15, oldy - 15); if (oldy > 30)   line(oldx + 15, oldy - 15, oldx + 15, oldy - 7); if (oldy < 450)   line(oldx + 15, oldy + 7, oldx + 15, oldy + 15); if (oldy < 450)   line(oldx + 15, oldy + 15, oldx + 7, oldy + 15);  }  if (oldx > 30) { if (oldy < 450)   line(oldx - 7, oldy + 15, oldx - 15, oldy + 15); if (oldy < 450)   line(oldx - 15, oldy + 15, oldx - 15, oldy + 7); if (oldy > 30)   line(oldx - 15, oldy - 7, oldx - 15, oldy - 15); if (oldy > 30)   line(oldx - 15, oldy - 15, oldx - 7, oldy - 15);  }  setcolor(12);  if (x1 < 450) { if (y1 > 30)   line(x1 + 7, y1 - 15, x1 + 15, y1 - 15); if (y1 > 30)   line(x1 + 15, y1 - 15, x1 + 15, y1 - 7); if (y1 < 450)   line(x1 + 15, y1 + 7, x1 + 15, y1 + 15); if (y1 < 450)   line(x1 + 15, y1 + 15, x1 + 7, y1 + 15);  }  if (x1 > 30) { if (y1 < 450)   line(x1 - 7, y1 + 15, x1 - 15, y1 + 15); if (y1 < 450)   line(x1 - 15, y1 + 15, x1 - 15, y1 + 7); if (y1 > 30)   line(x1 - 15, y1 - 7, x1 - 15, y1 - 15); if (y1 > 30)   line(x1 - 15, y1 - 15, x1 - 7, y1 - 15);  }  oldx = x1;  oldy = y1;} voidset_chessman(){  /*   * 棋子有三種狀態,0是未初始狀態,1是控制方棋子,2是對方棋子    */  int       i,          j;  for (i = 0; i < 15; i++) for (j = 0; j < 15; j++)   chessman[i][j] = 0;}/* * 0表示沒有贏,1表示p1勝利,2表示p2勝利,3表示平局 */intwin_or_not(int x0, int y0, int who, int chessman[LENGTH][LENGTH], int a){  int       i = x0 / 30 - 1,          j = y0 / 30 - 1;  int       who_run = who;  int       line_sum = -1;  int       tmp_i = i,          tmp_j = j;  int       c;  if (a == 1) { /* * 測試第一層擴展是否滿足贏的條件 */ c = chessman[i][j]; chessman[i][j] = who_run;  }  while (1) {  /* 查找共行的棋子是否連接了五個 */ while (tmp_i >= 0 && line_sum != 4) {   if (chessman[tmp_i--][j] == who_run) line_sum++;   else break; } if (line_sum == 4)   line_sum++; tmp_i = i; while (tmp_i <= 15 && line_sum != 5) {   if (chessman[tmp_i++][j] == who_run) line_sum++;   else break; } if (line_sum == 5) {   if (a == 1) chessman[i][j] = c;   return who_run; } line_sum = -1; tmp_i = i; break;  }  while (1) {  /* 查找共列的棋子是否連接了五個 */ while (tmp_j >= 0 && line_sum != 4) {   if (chessman[i][tmp_j--] == who_run) line_sum++;   else break; } if (line_sum == 4)   line_sum++; tmp_j = j; while (tmp_j <= 15 && line_sum != 5) {   if (chessman[i][tmp_j++] == who_run) line_sum++;   else break; } if (line_sum == 5) {   if (a == 1) chessman[i][j] = c;   return who_run; } line_sum = -1; tmp_j = j; break;  }  while (1) {  /* 查找上對角線上是否連接了五個 */ while (line_sum != 4 && tmp_i <= 15 && tmp_j >= 0) {   if (chessman[tmp_i++][tmp_j--] == who_run) line_sum++;   else break; } tmp_i = i; tmp_j = j; if (line_sum == 4)   line_sum++; while (line_sum != 5 && tmp_i >= 0 && tmp_j <= 15) {   if (chessman[tmp_i--][tmp_j++] == who_run) line_sum++;   else break; } if (line_sum == 5) {   if (a == 1) chessman[i][j] = c;   return who_run; } tmp_i = i; tmp_j = j; line_sum = -1; break;  }  while (1) {  /* 查找下對角線上是否連接了五個 */ while (line_sum != 4 && tmp_i >= 0 && tmp_j >= 0) {   if (chessman[tmp_i--][tmp_j--] == who_run) line_sum++;   else break; } tmp_i = i; tmp_j = j; if (line_sum == 4)   line_sum++; while (line_sum != 5 && tmp_i <= 15 && tmp_j <= 15) {   if (chessman[tmp_i++][tmp_j++] == who_run) line_sum++;   else break; } if (line_sum == 5) {   if (a == 1) chessman[i][j] = c;   return who_run; } break;  }  if (step_sum == 225) { if (a == 1)   chessman[i][j] = c; return 3;  }  if (a == 1) chessman[i][j] = c;  return 0;} doublescore_row(int i, int j, int chessman[LENGTH][LENGTH]){  int       sum_chessmen = 0;  double     score = 0;  int       mid_j;  int       who_running = chessman[i][j];  if (j == LENGTH) { while (chessman[i][j] == who_running) {   j--;   sum_chessmen++; } if (sum_chessmen >= 5)   score = 200000; else {   if (chessman[i][j] == 0) /* 沒有下子,活的情況 */ score = 2000 / POW(10, 4 - sum_chessmen);   else score = 0; /* 死的情況 */ }  } else { while (chessman[i][j] == who_running && j != LENGTH) {   j++;   sum_chessmen++; } mid_j = j; j = j - sum_chessmen - 1; while (chessman[i][j] == who_running && j != -1) {   j--;   sum_chessmen++; } if (j >= 0 && mid_j < LENGTH) {   if (chessman[i][j] == 0 && chessman[i][mid_j] == 0) score = 18000 / POW(50, 4 - sum_chessmen);   else if ((chessman[i][j] != 0 && chessman[i][mid_j] == 0)    || (chessman[i][j] == 0 && chessman[i][mid_j] != 0)) score = 2000 / POW(10, 4 - sum_chessmen);   else score = 0; } if (j < 0 && mid_j < LENGTH) {   if (chessman[i][mid_j] == 0) score = 2000 / POW(10, 4 - sum_chessmen);   else score = 0; } if (j >= 0 && mid_j >= LENGTH) {   if (chessman[i][j] == 0) score = 2000 / POW(10, 4 - sum_chessmen);   else score = 0; } if (j < 0 && mid_j >= LENGTH)   score = 0;  }  return score;}doublescore_col(int i, int j, int chessman[LENGTH][LENGTH]){  int       sum_chessmen = 0,          mid_i;  double     score = 0;  int       who_running = chessman[i][j];  if (i == LENGTH) { while (chessman[i][j] == who_running) {   i--;   sum_chessmen++; } if (sum_chessmen >= 5)   score = 200000; if (chessman[i][j] == 0)   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;  } else { while (chessman[i][j] == who_running) {   i++;   sum_chessmen++; } mid_i = i; if (i == LENGTH || chessman[i][j] != who_running) {   i = i - sum_chessmen;   while (chessman[i - 1][j] == who_running) { i--; sum_chessmen++;   }   if (i >= 0) { if (chessman[i][j] == 0 && chessman[mid_i][j] == 0)   score = 18000 / POW(50, 4 - sum_chessmen); else if ((chessman[i][j] != 0 && chessman[mid_i][j]) == 0  || (chessman[i][j] == 0    && chessman[mid_i][j] != 0))   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   }   if (i < 0 && mid_i < LENGTH) { if (chessman[mid_i][j] == 0)   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   }   if (i < 0 && mid_i < LENGTH) { if (chessman[mid_i][j] == 0)   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   }   if (i >= 0 && mid_i >= LENGTH) { if (chessman[i][j] == 0)   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   } }  }  return score;}doublescore_diag_45(int i, int j, int chessman[LENGTH][LENGTH]){  int       sum_chessmen = 0;  double     score = 0;  int       mid_i,          mid_j;  int       who_running = chessman[i][j];  if (i == LENGTH || j == LENGTH) { while (chessman[i][j] == who_running && i > 1 && j > 1) {   i--;   j--;   sum_chessmen++; } if (sum_chessmen >= 5)   score = 200000; else {   if (chessman[i][j] == 0) score = 2000 / POW(10, 4 - sum_chessmen);   else score = 0; }  } else { while (chessman[i][j] == who_running && i <= LENGTH && j <= LENGTH) {   i++;   j++;   sum_chessmen++; } mid_i = i; mid_j = j; i = i - sum_chessmen; j = j - sum_chessmen; while (chessman[i - 1][j - 1] == who_running) {   i--;   j--;   sum_chessmen++; } if (sum_chessmen >= 5)   score = 200000; if (i >= 0 && j >= 0 && mid_i < LENGTH && mid_j < LENGTH) {   if (chessman[mid_i][mid_j] == 0 && chessman[i][j] == 0) score = 18000 / POW(50, 4 - sum_chessmen);   else if ((chessman[mid_i][mid_j] == 0 && chessman[i][j] != 0)    || (chessman[mid_i][mid_j] != 0  && chessman[i][j] == 0)) score = 2000 / POW(10, 4 - sum_chessmen);   else score = 0; } else {   if (i >= 0 && j >= 0) { if (chessman[i][j] == 0)   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   } else if (mid_i < LENGTH && mid_j < LENGTH) { if (chessman[mid_i][mid_j] == 0)   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   } else score = 0; }  }  return score;}doublescore_diag_135(int i, int j, int chessman[LENGTH][LENGTH]){  int       sum_chessmen = 0;  double     score = 0;  int       mid_i,          mid_j;  int       who_running = chessman[i][j];  while (chessman[i][j] == who_running && j != -1 && i < LENGTH) { i++; j--; sum_chessmen++;  }  mid_i = i;  mid_j = j;  j += sum_chessmen;  i -= sum_chessmen;  j++;  i--;  while (chessman[i][j] == who_running && j != LENGTH) { i--; j++; sum_chessmen++;  }  if (sum_chessmen >= 5) score = 200000;  else { if (i >= 0 && j < LENGTH && mid_j >= 0 && mid_i < LENGTH) {   if (chessman[i][j] == 0 && chessman[mid_i][mid_j] == 0) score = 18000 / POW(50, 4 - sum_chessmen);   else { if ((chessman[i][j] == 0 && chessman[mid_i][mid_j] != 0)   || (chessman[i][j] != 0  && chessman[mid_i][mid_j] == 0))   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   } } else {   if (i >= 0 && j < LENGTH) { if (chessman[i][j] == 0)   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   }   if (mid_j >= 0 && mid_i < LENGTH) { if (chessman[mid_i][mid_j] == 0)   score = 2000 / POW(10, 4 - sum_chessmen); else   score = 0;   } }  }  return score;}doubletotal_score(int who_running, int chessman[LENGTH][LENGTH]){  /*   * 統計出在該點上的得分,who_running=1表示人的棋子,2為電腦的棋子   */  int       i,          j;  double     score = 0;  for (i = 0; i < LENGTH; i++) for (j = 0; j < LENGTH; j++) {   if (chessman[i][j] == who_running) { score += score_row(i, j, chessman); score += score_col(i, j, chessman); score += score_diag_45(i, j, chessman); score += score_diag_135(i, j, chessman);   } }  return score;}doublescore(int chessman[LENGTH][LENGTH]){  /*   * 計算最終的得分數,分別考慮了在這個位置放對方棋子跟自己棋子的綜合   */  double     sum1,            sum2;  sum1 = total_score(COMPUTER, chessman);  sum2 = total_score(PLAYER1, chessman);  return sum1 - sum2;}/* * 擴展-----剪枝過程 */introwdt(int i, int j, int chessman[LENGTH][LENGTH])  /*在樹直方向*/{  int       k;  int       midjl = j - STEP,         /*當前棋子的上方*/          midjr = j + STEP + 1;     /*當前棋子的下方棋子的下方??????*/  if (midjl < 0)                    midjl = 0;            if (midjr > LENGTH) midjr = LENGTH;  for (k = midjl; k < midjr; k++)       /**/  if (chessman[i][k] != 0)         /*如果有棋子*/   return 1;  return 0;}intcoldt(int i, int j, int chessman[LENGTH][LENGTH])     /*水平方向*/{  int       k;  int       midil = i + STEP + 1,         /*當前的右邊棋子的右一個*/          midiu = i - STEP;            /*當前棋子的左一個*/  if (midiu < 0) midiu = 0;  if (midil > LENGTH) midil = LENGTH;  for (k = midiu; k < midil; k++) if (chessman[k][j] != 0)   return 1;  return 0;}intdiadt(int i, int j, int chessman[LENGTH][LENGTH])   /*右上到左下方向*/{  int       k,          midi,          midj;  midi = i;  midj = j;  for (k = 0; k < STEP; k++) { midi++; midj--; if (midj < 0 || midi >= LENGTH)   break; if (chessman[midi][midj] != 0)   return 1;  }  for (k = 0; k < STEP; k++) { i--; j++; if (i < 0 || j >= LENGTH)   break; if (chessman[i][j] != 0)   return 1;  }  return 0;}intvdiadt(int i, int j, int chessman[LENGTH][LENGTH])  /*左上到右下方向*/{  int       k,          midi,          midj;  midi = i;  midj = j;  for (k = 0; k < STEP; k++) { midi--; midj--; if (midi < 0 || midj < 0)   break; if (chessman[midi][midj] != 0)   return 1;  }  for (k = 0; k < STEP; k++) { i++; j++; if (j >= LENGTH || i >= LENGTH)   break; if (chessman[i][j] != 0)   return 1;  }  return 0;}intcan_expand(int i, int j, int chessman[LENGTH][LENGTH]){  if (rowdt(i, j, chessman)) return 1;  if (coldt(i, j, chessman)) return 1;  if (diadt(i, j, chessman)) return 1;  if (vdiadt(i, j, chessman)) return 1;  /*   * 如果不能擴展,返回0   */  return 0;}/************************************************************/

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
成人黄色免费片| 日韩有码在线电影| 欧美性猛交xxxx免费看漫画| 欧美成年人网站| 欧洲永久精品大片ww免费漫画| 国产在线拍揄自揄视频不卡99| **欧美日韩vr在线| 欧美一级片在线播放| 亚洲精品97久久| 久久天天躁狠狠躁夜夜躁2014| 欧美在线视频免费| 色悠悠国产精品| 亚洲精品视频网上网址在线观看| 久久这里只有精品视频首页| 国产精品久久久久久久久久尿| 日本免费久久高清视频| 国产精品99久久99久久久二8| 成人黄色av网| 亚洲欧美国产一本综合首页| 国产精品av免费在线观看| 久久国产精品偷| 久久理论片午夜琪琪电影网| 国产精品极品在线| 欧美不卡视频一区发布| 国产精品xxx视频| 久久久久久免费精品| 日韩av电影中文字幕| 日韩在线观看高清| 国产精品亚洲视频在线观看| 国产一区二区三区日韩欧美| 国产69精品久久久久9| 中文字幕亚洲欧美日韩2019| 亚洲free性xxxx护士白浆| 91av视频在线播放| 欧美精品久久一区二区| 亚洲xxx大片| 久久久亚洲精品视频| 成人午夜黄色影院| 日韩欧美极品在线观看| 国产精品日韩在线观看| 国产亚洲精品日韩| 777精品视频| 久久精品国产一区二区电影| 久久久精品视频在线观看| 亚洲人成电影在线播放| 久久久久久成人| 欧美精品手机在线| 91av在线不卡| 国产精品久久久久久久9999| 国内精品视频一区| 久久久久久久久久久av| 精品亚洲一区二区三区在线观看| 91老司机精品视频| 国产精品视频99| 欧美亚洲一区在线| 亚洲影影院av| 亚洲精品国产精品乱码不99按摩| 亚洲人成在线电影| 久久香蕉国产线看观看网| 精品亚洲精品福利线在观看| 欧美中文字幕在线观看| 亚洲欧洲一区二区三区在线观看| 色综合久久悠悠| 57pao成人永久免费视频| 成人午夜小视频| 黄网动漫久久久| 亚洲精品成人网| 伊人久久久久久久久久久| 午夜精品久久久久久久久久久久久| 国产丝袜精品第一页| 国产精品入口日韩视频大尺度| 亚洲国语精品自产拍在线观看| 欧美日韩一区二区三区在线免费观看| 欧美色videos| 亚洲小视频在线| 日本一区二区在线免费播放| 中文国产成人精品| 久久综合九色九九| 国产精品福利在线| 国产福利视频一区二区| 日韩美女在线观看| 国产日本欧美一区二区三区在线| 成人黄色片网站| 91香蕉电影院| 日韩高清电影免费观看完整版| 清纯唯美日韩制服另类| 91色琪琪电影亚洲精品久久| 亚洲码在线观看| 久久久久久久久久久av| 欧美富婆性猛交| 97国产真实伦对白精彩视频8| 国产成人精品视频在线观看| 亚洲日韩中文字幕在线播放| 草民午夜欧美限制a级福利片| 国产98色在线| 91久久国产婷婷一区二区| 日本亚洲欧洲色α| 国产精品久久国产精品99gif| 美女久久久久久久| 久久久久久国产免费| 日本aⅴ大伊香蕉精品视频| 国产精品久久久av| 国产日韩综合一区二区性色av| 久久精品国产一区二区电影| 欧美电影免费观看大全| 国产日韩视频在线观看| 一本大道香蕉久在线播放29| 欧美在线视频免费| 一本色道久久88综合亚洲精品ⅰ| 国产精品∨欧美精品v日韩精品| 欧美一区二三区| 国产成人精品免高潮在线观看| 在线电影欧美日韩一区二区私密| 综合网日日天干夜夜久久| 九九热精品视频国产| 精品久久久久久久久久| 国产精品久久一| 国产欧美日韩精品丝袜高跟鞋| 66m—66摸成人免费视频| 精品久久久久久久久久久久久久| 国产成人福利夜色影视| 国产狼人综合免费视频| 日韩精品中文字幕有码专区| 亚洲电影天堂av| 国产精品一区二区三区毛片淫片| 亚洲成人a级网| 国产欧美精品日韩精品| 日韩在线免费视频| 日韩av在线影视| 亚洲午夜国产成人av电影男同| 正在播放欧美视频| 久久深夜福利免费观看| 欧美激情视频免费观看| 国产成人精品一区二区在线| 最新69国产成人精品视频免费| 亚洲欧美成人一区二区在线电影| 美女精品视频一区| 国产精品444| 久久综合久中文字幕青草| 亚洲精品wwww| 精品福利一区二区| 欧美大片大片在线播放| 成人黄色大片在线免费观看| 久久久91精品国产| 九九久久综合网站| 国产精品久久不能| 日韩免费不卡av| 欧美日韩在线影院| 国语自产在线不卡| 日韩电影免费观看在线观看| 国产亚洲精品美女久久久久| 欧美黄色三级网站| 日韩成人激情影院| 中文字幕亚洲欧美在线| 久久久精品一区二区三区| 美日韩精品免费观看视频| 亚洲色图25p| 亚洲黄色成人网| 国产精品午夜一区二区欲梦| 国产91在线高潮白浆在线观看| 国内精品久久久久影院 日本资源| 亚洲视频自拍偷拍| 中文字幕精品一区久久久久| 日韩中文理论片|