voidcalcScore(ChessData* data){if(!data)return;//统计玩家或AI连子int personNum =0;//玩家int botNum =0;//AIint emptyNum =0;//各方向空白位数//清空评分数组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++){//空白点计算if(row >=0&& col >=0&& data->chessMap[row][col]==0){//遍历四个方向,然后分别计算正反四个方向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;//对黑棋评分(正向)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;//出边界或遇到白棋停止搜索}}//对黑棋评分(反向)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){//死3
data->scoreMap[row][col]+=30;}elseif(emptyNum ==2){//活3
data->scoreMap[row][col]+=40;}}elseif(personNum ==3){if(empty ==1){//死4
data->scoreMap[row][col]+=60;}elseif(emptyNum ==2){//活4
data->scoreMap[row][col]+=200;}}elseif(personNum ==4){
data->scoreMap[row][col]+=20000;}
emptyNum =0;//清空//对白棋评分(正向)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;}}//白棋评分(反向)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){//连1
data->scoreMap[row][col]+=5;}elseif(botNum ==1){//活2
data->scoreMap[row][col]+=10;}elseif(botNum ==2){if(emptyNum ==1){//死3
data->scoreMap[row][col]+=25;}elseif(emptyNum ==2){//活3
data->scoreMap[row][col]+=50;}}elseif(botNum ==3){if(emptyNum ==1){//死4
data->scoreMap[row][col]+=55;}elseif(botNum ==2){//活4
data->scoreMap[row][col]+=300;}}elseif(botNum >=4){//活5
data->scoreMap[row][col]+=30000;}}}}}}