// ChangeStatus(ptempboard); pi=i; pj=j; while(SearchBlank(i,j,ptempboard)) {//进行第二不查找 ptempboard[i][j]=3;//标记已被查找 ptemp=GiveScore(0,i,j); if(pscore>ptemp)//此时为玩家下子,运用极小极大法时应选取最小值 pscore=ptemp; } for(m=0;m<n;m++) {//恢复玩家信息 ptable[pi][pj][temp1[m]]=true; win[0][temp1[m]]=temp2[m]; } //ctemp+pscore为实际估价函数 if(ctemp+pscore>cscore) //此时为计算机下子,运用极小极大法时应选取最最大值 { cscore=ctemp+pscore; bestx=pi; besty=pj; } } } board[bestx][besty]=1; if(m_pclastpos.x!=-1&&m_pclastpos.y!=-1) {//画前一棋子 if(!m_bwfirst) DrawBlackChess(m_pclastpos.x,m_pclastpos.y); else DrawWhiteChess(m_pclastpos.x,m_pclastpos.y); } if(!m_bwfirst) DrawNowBlack(bestx,besty); else DrawNowWhite(bestx,besty); m_pclastpos.x=bestx; m_pclastpos.y=besty; for(i=0;i<572;i++) {//修改计算机下子后,棋盘的变化状况 if(ctable[bestx][besty][i]&&win[1][i]!=7) win[1][i]++; if(ptable[bestx][besty][i]) { ptable[bestx][besty][i]=false; win[0][i]=7; } } computer=false; player=true; } (8) 玩家下棋:(其中坐标(9) 加减目的是调整图片的位置和棋盘对齐) void CMyChessDlg::OnLButtonDown(UINT nFlags, CPoint point) { int x,y,tx,ty; // TODO: Add your message handler code here and/or call default if(player&&point.x<=535&&point.y<=535)//判断是否在有效区域 { tx=x=point.x-24; ty=y=point.y-25; while(tx>=36) tx-=36; while(ty>=36) ty-=36; tx+=x/36; ty+=y/36; if(tx>18) x=x/36+1; else x=x/36; if(ty>18) y=y/36+1; else y=y/36; if(board[x][y]==2) { board[x][y]=0;//设为玩家的棋子 if(m_pplastpos.x!=-1&&m_pplastpos.y!=-1) { if(!m_bwfirst) DrawWhiteChess(m_pplastpos.x,m_pplastpos.y); else DrawBlackChess(m_pplastpos.x,m_pplastpos.y); } if(!m_bwfirst) DrawNowWhite(x,y); else DrawNowBlack(x,y); m_pplastpos.x=x; m_pplastpos.y=y; for(int i=0;i<572;i++)//修改玩家下子后棋盘状态的变化 { if(i==80) i=80; if(ptable[x][y][i]&&win[0][i]!=7) win[0][i]++; if(ctable[x][y][i]) { ctable[x][y][i]=false; win[1][i]=7; } } player=false; computer=true; } } CDialog::OnLButtonDown(nFlags, point); }

评论