文章标题
2015-11-03 22:38
369 查看
2015.11.1
1、熟悉人机模式的基本函数
2、百度搜索到了一个人机模式的估分函数,是用5*5的五子棋来举例说明的,不过考虑到我要实现的是15*15的人机五子棋,这个方法就有点麻烦了,因此只是看了下里面的思路,并没有选择这个方法。
3、http://www.bccn.net/Article/kfyy/cyy/jszl/200707/4610.html
2015.11.2
1、今天尝试着编写了人机的代码
2、用的是自己的思路:通过判断下子点的八个方向上的棋子的数量。
`void MainWindow::selectAiMode()
{
// for(int i = 0 ;i < LATERAL ;i++)
// {
// for(int j = 0 ;j < AXIS ;j++)
// {
// if(blackcount[i][j]==maxblackcount)
// {
// maxblackX = i; //黑子最大值的横坐标(逻辑)
// maxblackY = j; //黑子最大值的纵坐标(逻辑)
// break;
// }
// if(whitecount[i][j]==maxwhitecount)
// {
// maxwhiteX = i; //白子最大值的横坐标(逻辑)
// maxwhiteY = j; //白子最大值的横坐标(逻辑)
// break;
// qDebug()<<”Maxwhitecount[“<
1、熟悉人机模式的基本函数
2、百度搜索到了一个人机模式的估分函数,是用5*5的五子棋来举例说明的,不过考虑到我要实现的是15*15的人机五子棋,这个方法就有点麻烦了,因此只是看了下里面的思路,并没有选择这个方法。
3、http://www.bccn.net/Article/kfyy/cyy/jszl/200707/4610.html
2015.11.2
1、今天尝试着编写了人机的代码
2、用的是自己的思路:通过判断下子点的八个方向上的棋子的数量。
`void MainWindow::selectAiMode()
{
for(int x = 0 ;x < LATERAL ;x++) { for(int y = 0 ;y < AXIS ;y++) { if(chessboard[x][y]==ORIGIN) { //左扫 if( x-1 > 0 &&chessboard[x-1][y]==BLACK) blackcount[x][y]++; if( x-1 > 0 &&chessboard[x-1][y]==WHITE) whitecount[x][y]++; if( x-2 > 0 &&chessboard[x-2][y]==BLACK) blackcount[x][y]++; if( x-2 > 0 &&chessboard[x-2][y]==WHITE) whitecount[x][y]++; if( x-3 > 0 &&chessboard[x-3][y]==BLACK) blackcount[x][y]++; if( x-3 > 0 &&chessboard[x-3][y]==WHITE) whitecount[x][y]++; if( x-4 > 0 &&chessboard[x-4][y]==BLACK) blackcount[x][y]++; if( x-4 > 0 &&chessboard[x-4][y]==WHITE) whitecount[x][y]++; //右扫 if( x+1 < 15 &&chessboard[x+1][y]==BLACK) blackcount[x][y]++; if( x+1 < 15 &&chessboard[x+1][y]==WHITE) whitecount[x][y]++; if( x+2 < 15 &&chessboard[x+2][y]==BLACK) blackcount[x][y]++; if( x+2 < 15 &&chessboard[x+2][y]==WHITE) whitecount[x][y]++; if( x+3 < 15 &&chessboard[x+3][y]==BLACK) blackcount[x][y]++; if( x+3 < 15 &&chessboard[x+3][y]==WHITE) whitecount[x][y]++; if( x+4 < 15 &&chessboard[x+4][y]==BLACK) blackcount[x][y]++; if( x+4 < 15 &&chessboard[x+4][y]==WHITE) whitecount[x][y]++; //上扫 if( y+1 < 15 &&chessboard[x][y+1]==BLACK) blackcount[x][y]++; if( y+1 < 15 &&chessboard[x][y+1]==WHITE) whitecount[x][y]++; if( y+2 < 15 &&chessboard[x][y+2]==BLACK) blackcount[x][y]++; if( y+2 < 15 &&chessboard[x][y+2]==WHITE) whitecount[x][y]++; if( y+3 < 15 &&chessboard[x][y+3]==BLACK) blackcount[x][y]++; if( y+3 < 15 &&chessboard[x][y+3]==WHITE) whitecount[x][y]++; if( y+4 < 15 &&chessboard[x][y+4]==BLACK) blackcount[x][y]++; if( y+4 < 15 &&chessboard[x][y+4]==WHITE) whitecount[x][y]++; //下扫 if( y-1 > 0 &&chessboard[x][y-1]==BLACK) blackcount[x][y]++; if( y-1 > 0 &&chessboard[x][y-1]==WHITE) whitecount[x][y]++; if( y-2 > 0 &&chessboard[x][y-2]==BLACK) blackcount[x][y]++; if( y-2 > 0 &&chessboard[x][y-2]==WHITE) whitecount[x][y]++; if( y-3 > 0 &&chessboard[x][y-3]==BLACK) blackcount[x][y]++; if( y-3 > 0 &&chessboard[x][y-3]==WHITE) whitecount[x][y]++; if( y-4 > 0 &&chessboard[x][y-4]==BLACK) blackcount[x][y]++; if( y-4 > 0 &&chessboard[x][y-4]==WHITE) whitecount[x][y]++; //左上扫 if( x-1 > 0 && y-1 > 0 &&chessboard[x-1][y-1]==BLACK) blackcount[x][y]++; if( x-1 > 0 && y-1 > 0 &&chessboard[x-1][y-1]==WHITE)whitecount[x][y]++; if( x-2 > 0 && y-2 > 0 &&chessboard[x-2][y-2]==BLACK) blackcount[x][y]++; if( x-2 > 0 && y-2 > 0 &&chessboard[x-2][y-2]==WHITE) whitecount[x][y]++; if( x-3 > 0 && y-3 > 0 &&chessboard[x-3][y-3]==BLACK) blackcount[x][y]++; if( x-3 > 0 && y-3 > 0 &&chessboard[x-3][y-3]==WHITE) whitecount[x][y]++; if( x-4 > 0 && y-4 > 0 &&chessboard[x-4][y-4]==BLACK) blackcount[x][y]++; if( x-4 > 0 && y-4 > 0 &&chessboard[x-4][y-4]==WHITE) whitecount[x][y]++; //右上扫 if( x+1 < 15 && y-1 > 0 &&chessboard[x+1][y-1]==BLACK) blackcount[x][y]++; if( x+1 < 15 && y-1 > 0 &&chessboard[x+1][y-1]==WHITE) whitecount[x][y]++; if( x+2 < 15 && y-2 > 0 &&chessboard[x+2][y-2]==BLACK) blackcount[x][y]++; if( x+2 < 15 && y-2 > 0 &&chessboard[x+2][y-2]==WHITE) whitecount[x][y]++; if( x+3 < 15 && y-3 > 0 &&chessboard[x+3][y-3]==BLACK) blackcount[x][y]++; if( x+3 < 15 && y-3 > 0 &&chessboard[x+3][y-3]==WHITE) whitecount[x][y]++; if( x+4 < 15 && y-4 > 0 &&chessboard[x+4][y-4]==BLACK) blackcount[x][y]++; if( x+4 < 15 && y-4 > 0 &&chessboard[x+4][y-4]==WHITE) whitecount[x][y]++; //左下扫 if( x-1 > 0 && y+1 < 15 &&chessboard[x-1][y+1]==BLACK) blackcount[x][y]++; if( x-1 > 0 && y+1 < 15 &&chessboard[x-1][y+1]==WHITE) whitecount[x][y]++; if( x-2 > 0 && y+2 < 15 &&chessboard[x-2][y+2]==BLACK) blackcount[x][y]++; if( x-2 > 0 && y+2 < 15 &&chessboard[x-2][y+2]==WHITE) whitecount[x][y]++; if( x-3 > 0 && y+3 < 15 &&chessboard[x-3][y+3]==BLACK) blackcount[x][y]++; if( x-3 > 0 && y+3 < 15 &&chessboard[x-3][y+3]==WHITE) whitecount[x][y]++; if( x-4 > 0 && y+4 < 15 &&chessboard[x-4][y+4]==BLACK) blackcount[x][y]++; if( x-4 > 0 && y+4 < 15 &&chessboard[x-4][y+4]==WHITE) whitecount[x][y]++; //右下扫 if( x+1 < 15 && y+1 < 15 &&chessboard[x+1][y+1]==BLACK) blackcount[x][y]++; if( x+1 < 15 && y+1 < 15 &&chessboard[x+1][y+1]==WHITE) whitecount[x][y]++; if( x+2 < 15 && y+2 < 15 &&chessboard[x+2][y+2]==BLACK) blackcount[x][y]++; if( x+2 < 15 && y+2 < 15 &&chessboard[x+2][y+2]==WHITE) whitecount[x][y]++; if( x+3 < 15 && y+3 < 15 &&chessboard[x+3][y+3]==BLACK) blackcount[x][y]++; if( x+3 < 15 && y+3 < 15 &&chessboard[x+3][y+3]==WHITE) whitecount[x][y]++; if( x+4 < 15 && y+4 < 15 &&chessboard[x+4][y+4]==BLACK) blackcount[x][y]++; if( x+4 < 15 && y+4 < 15 &&chessboard[x+4][y+4]==WHITE) whitecount[x][y]++; qDebug()<<"whitecount["<<x<<"]["<<y<<"] = "<<whitecount[x][y]; } } } //判断最大的值 int maxblackX = 0,maxblackY = 0,maxwhiteX = 0,maxwhiteY = 0,maxblackcount,maxwhitecount; maxblackcount = blackcount[maxblackX][maxblackY]; maxwhitecount = whitecount[maxwhiteX][maxwhiteY]; for(int i = 0 ;i < LATERAL ;i++) { for(int j = 0 ;j < AXIS ;j++) { if(blackcount[i][j] > maxblackcount) { maxblackcount = blackcount[i][j]; maxblackX = i; //黑子最大值的横坐标(逻辑) maxblackY = j; //黑子最大值的纵坐标(逻辑) } if(whitecount[i][j] > maxwhitecount) { maxwhitecount = whitecount[i][j]; maxwhiteX = i; //白子最大值的横坐标(逻辑) maxwhiteY = j; //白子最大值的横坐标(逻辑) } } } qDebug()<<"maxblackcount = "<<maxblackcount; qDebug()<<"maxwhitecount = "<<maxwhitecount; //找出最大值所在的各个逻辑坐标
// for(int i = 0 ;i < LATERAL ;i++)
// {
// for(int j = 0 ;j < AXIS ;j++)
// {
// if(blackcount[i][j]==maxblackcount)
// {
// maxblackX = i; //黑子最大值的横坐标(逻辑)
// maxblackY = j; //黑子最大值的纵坐标(逻辑)
// break;
// }
// if(whitecount[i][j]==maxwhitecount)
// {
// maxwhiteX = i; //白子最大值的横坐标(逻辑)
// maxwhiteY = j; //白子最大值的横坐标(逻辑)
// break;
// qDebug()<<”Maxwhitecount[“<