资源简介
用QT写的五子棋AI,进攻和防守势力都不错,单机AI,界面美观。
代码片段和文件信息
#include “analysis.h“
int Analysis::Five(int(*grid)[15]){
int count = 0;
for(int i = 0; i < 15; i++) //横向
for(int j = 0; j < 11; j++)
if(grid[i][j] + grid[i][j+1] + grid[i][j+2] + grid[i][j+3] + grid[i][j+4] == 5)
count++;
for(int i = 0; i < 11; i++) //纵向
for(int j = 0; j < 15; j++)
if(grid[i][j] + grid[i+1][j] + grid[i+2][j] + grid[i+3][j] + grid[i+4][j] == 5)
count++;
for(int i = 0; i < 11; i++) //-45°
for(int j = 0; j < 11; j++)
if(grid[i][j] + grid[i+1][j+1] + grid[i+2][j+2] + grid[i+3][j+3] + grid[i+4][j+4] == 5)
count++;
for(int i = 4; i < 15; i++) //+45°
for(int j = 0; j < 11; j++)
if(grid[i][j] + grid[i-1][j+1] + grid[i-2][j+2] + grid[i-3][j+3] + grid[i-4][j+4] == 5)
count++;
return count;
}
int Analysis::Four(int(*grid)[15]){
int count = 0;
for(int i = 0; i < 15; i++) //横向四连
for(int j = 1; j < 11; j++)
if(grid[i][j] == 1 && grid[i][j-1] == 0 && grid[i][j+4] == 0)
if(grid[i][j] + grid[i][j+1] + grid[i][j+2] + grid[i][j+3] == 4)
count++;
for(int i = 1; i < 11; i++) //纵向四连
for(int j = 0; j < 15; j++)
if(grid[i][j] == 1 && grid[i-1][j] == 0 && grid[i+4][j] == 0)
if(grid[i][j] + grid[i+1][j] + grid[i+2][j] + grid[i+3][j] == 4)
count++;
for(int i = 1; i < 11; i++) //-45°四连
for(int j = 1; j < 11; j++)
if(grid[i][j] == 1 && grid[i-1][j-1] == 0 && grid[i+4][j+4] == 0)
if(grid[i][j] + grid[i+1][j+1] + grid[i+2][j+2] + grid[i+3][j+3] == 4)
count++;
for(int i = 4; i < 14; i++) //+45°四连
for(int j = 1; j < 11; j++)
if(grid[i][j] == 1 && grid[i+1][j-1] == 0 && grid[i-4][j+4] == 0)
if(grid[i][j] + grid[i-1][j+1] + grid[i-2][j+2] + grid[i-3][j+3] == 4)
count++;
return count;
}
int Analysis::ChongFour(int(*grid)[15]){
int count = 0;
for(int i = 0; i < 15; i++) //横向冲四
for(int j = 1; j < 10; j++)
if(grid[i][j] == 1)
if( ((-grid[i][j-1] == grid[i][j]) || (-grid[i][j+5] == grid[i][j] && grid[i][j+4]))
&& (grid[i][j] + grid[i][j+1] + grid[i][j+2] + grid[i][j+3] + grid[i][j+4] == 4))
count++;
for(int i = 0; i < 15; i++){
if(grid[i][0] && grid[i][0] + grid[i][1] + grid[i][2] + grid[i][3] + grid[i][4] == 4)
count++;
if(grid[i][14] && grid[i][10] + grid[i][11] + grid[i][12] + grid[i][13] + grid[i][14] == 4)
count++;
}
for(int i = 0; i < 15; i++)
for(int j = 1; j < 11; j++)
if(grid[i][j] == 1)
if((-g
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 33017 2011-01-22 14:22 FiveChess\analysis.cpp
文件 684 2010-11-03 03:18 FiveChess\analysis.h
文件 3853 2011-01-23 19:18 FiveChess\chess.cpp
文件 1039 2010-10-30 17:37 FiveChess\chess.h
文件 538 2011-01-23 21:01 FiveChess\chess.qrc
文件 490 2011-01-23 19:47 FiveChess\FiveChess.pro
文件 13581 2011-01-26 15:50 FiveChess\FiveChess.pro.user
文件 16257 2011-01-26 15:36 FiveChess\form.cpp
文件 1312 2011-01-25 01:19 FiveChess\form.h
文件 9691 2011-01-23 21:00 FiveChess\form.ui
文件 4865 2008-08-17 04:32 FiveChess\images\black.png
文件 3356 2008-07-09 19:56 FiveChess\images\blackchess.bmp
文件 1659 2010-10-22 15:15 FiveChess\images\blue.png
文件 966654 2008-06-22 16:45 FiveChess\images\board.bmp
文件 55130 2011-01-23 20:06 FiveChess\images\board.jpg
文件 1359 2010-10-22 15:15 FiveChess\images\circle.png
文件 1731 2010-10-22 15:15 FiveChess\images\exit.png
文件 1121 2010-10-22 15:15 FiveChess\images\fileclose.png
文件 1824054 2011-01-23 20:57 FiveChess\images\Game-bg.bmp
文件 90322 2011-01-23 19:57 FiveChess\images\Game-bg.jpg
文件 1824044 2011-01-21 21:14 FiveChess\images\Game-bg.tga
文件 93 2008-02-19 18:34 FiveChess\images\icons\background.png
文件 1659 2008-02-19 18:34 FiveChess\images\icons\blue.png
文件 1359 2008-02-19 18:34 FiveChess\images\icons\circle.png
文件 1731 2008-02-19 18:34 FiveChess\images\icons\exit.png
文件 1121 2008-02-19 18:34 FiveChess\images\icons\fileclose.png
文件 1266 2008-02-19 18:34 FiveChess\images\icons\filenew.png
文件 1771 2008-02-19 18:34 FiveChess\images\icons\fileopen.png
文件 1022 2008-02-19 18:34 FiveChess\images\icons\filesave.png
文件 1766 2008-02-19 18:34 FiveChess\images\icons\green.png
............此处省略32个文件信息
- 上一篇:编译好的VS2012使用的gdal库
- 下一篇:12864液晶设计指导及程序集
评论
共有 条评论