#include<string>voidcalcScore(ChessData* data){if(!data)return;//統(tǒng)計(jì)玩家或AI連子int personNum =0;//玩家int botNum =0;//AIint emptyNum =0;//各方向空白位數(shù)//清空評(píng)分?jǐn)?shù)組memset(data->scoreMap,0,sizeof(data->scoreMap));for(int row =0; row < BOARD_GRAD_SIZE; row++){for(int col =0; col < BOARD_GRAD_SIZE; col++){//空白點(diǎn)計(jì)算if(row >=0&& col >=0&& data->chessMap[row][col]==0){//遍歷四個(gè)方向,然后分別計(jì)算正反四個(gè)方向int directs[4][2]={{1,0},{1,1},{0,1},{-1,1}};for(int k =0; k <4; k++){int x = directs[k][0];int y = directs[k][1];//重置personNum =0;botNum =0;emptyNum =0;//對(duì)黑棋評(píng)分(正向)for(int i =1; i <=4; i++){if(row + i * y >=0&& row + i * y < BOARD_GRAD_SIZE && col + i * x >=0&& col + i * x < BOARD_GRAD_SIZE && data->chessMap[row + i * y][col + i * x]==1){//玩家的子personNum++;}elseif(row + i * y >=0&& row + i * y < BOARD_GRAD_SIZE &&col + i * x >=0&& col + i * x < BOARD_GRAD_SIZE && data->chessMap[row + i * y][col + i * x]==0){//空白位emptyNum++;break;//遇到空白位置停止該方向搜索}else{break;//出邊界或遇到白棋停止搜索}}//對(duì)黑棋評(píng)分(反向)for(int i =1; i<=4; i++){if(row - i * y >=0&& row - i * y < BOARD_GRAD_SIZE && col - i * x >=0&& col - i * x <BOARD_GRAD_SIZE && data->chessMap[row - i * y][col - i * x]==1){personNum++;}elseif(row - i * y >=0&& row - i * y <BOARD_GRAD_SIZE && col - i * x >=0&& col - i * x < BOARD_GRAD_SIZE &&data->chessMap[row -i * y][col - i * x]==0){emptyNum++;break;}else{break;}}if(personNum ==1){data->scoreMap[row][col]+=10;}elseif(personNum ==2){if(emptyNum ==1){//死3data->scoreMap[row][col]+=30;}elseif(emptyNum ==2){//活3data->scoreMap[row][col]+=40;}}elseif(personNum ==3){if(empty ==1){//死4data->scoreMap[row][col]+=60;}elseif(emptyNum ==2){//活4data->scoreMap[row][col]+=200;}}elseif(personNum ==4){data->scoreMap[row][col]+=20000;}emptyNum =0;//清空//對(duì)白棋評(píng)分(正向)for(int i =1; i <=4; i++){if(row + i * y >0&& row + i * y < BOARD_GRAD_SIZE && col + i * x >0&& col + i * x < BOARD_GARD_SIZE &&data->chessMap[row + i * y][col + i * x ==-1]){botNum++;}elseif(row + i * y >0&& row + i * y < BOARD_GRAD_SIZE && col + i * x >0&& col + i * x < BOARD_GRAD_SIZE && data->chessMap[row + i * y][col + i *x]==0){emptyNum++;break;}else{break;}}//白棋評(píng)分(反向)for(int i =1; i <=4; i++){if(row - i * y >0&& row - i * y <BOARD_GRAD_SIZE && col - i * x >0&& col - i * x < BOARD_GRAD_SIZE && data->chessMap[row - i * y][col -i * x]==-1){botNum++;}elseif(row - i * y >0&& row - i * y < BOARD_GRAD_SIZE &&col - i * x >0&& col - i * x < BOARD_GRAD_SIZE &&data->chessMap[row - i * y][col - i * x]==0){emptyNum++;break;}else{break;//出邊界}}if(botNum ==0){//連1data->scoreMap[row][col]+=5;}elseif(botNum ==1){//活2data->scoreMap[row][col]+=10;}elseif(botNum ==2){if(emptyNum ==1){//死3data->scoreMap[row][col]+=25;}elseif(emptyNum ==2){//活3data->scoreMap[row][col]+=50;}}elseif(botNum ==3){if(emptyNum ==1){//死4data->scoreMap[row][col]+=55;}elseif(botNum ==2){//活4data->scoreMap[row][col]+=300;}}elseif(botNum >=4){//活5data->scoreMap[row][col]+=30000;}}}}}}