安卓欢乐五子棋人机大战报告
实 验 报 告
课程名称实验名称安卓五子棋人机大战实验时间 月 (系)专 业
一、实验目的
在棋盘上任意落下一颗子,计算机调用AI算法,能判断出最佳的落子位置并落子。
程序能判断出输赢,结束游戏,停止落子。
二、实验环境(实验设备)
Eclipse ADT
AI难点解析
赢法数组:记录五子棋所有的赢法,三维数组
每一种赢法的统计数组,一维数组
如何判断胜负
计算机落子规则四、实验结果
开局前:
比赛一 游戏结束:
比赛二 游戏结束:
五、实验内容
1.创建安卓项目工程:B002_五子棋人机对战
2.创建一个类WuziqiPanel 继承系统的View类
public class WuziqiPanel extends View { }
3.在activity_main.xml文件中添加WuziqiPanel控件,并设置游戏背景界面
设置背景图片
android:background="@drawable/bg"
添加WuziqiPanel控件
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
4.定义相关数据
private int mPanelWidth;
private float mLineHeight;
private int MAX_LINE = 10;
private Paint mPaint = new Paint();
private Bitmap mWhitePiece;
private Bitmap mBlackPiece;
private float radioPieceOfLineHeight = 3 * 1.0f/4;
//白棋先下,当前轮到白棋
private boolean mIsWhite = true;
private List mWhiteArray = new ArrayList();
private List mBlackArray = new ArrayList();
//赢法数组
int[][][] wins= new int[10][10][200];
//赢法统计数组
int[] myWin = new int[200];
int[] computerWin = new int[200];
private int count;
//游戏是否结束over
private boolean over = false;
//棋盘上两方棋子的标志 0 无子 ; 1 我方 ; 2 电脑
private int[][] chessBoard = new int[10][10];
//保存最高得分的i,j值
int u=0;
int v=0;
5.测量棋盘大小
//截取屏幕大小为正方形
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int width = Math.min(widthSize, heightSize);
if(widthMode == MeasureSpec.UNSPECIFIED ){
width = heightSize;
}else if(heightMode == MeasureSpec.UNSPECIFIED){
width = widthSize;
如果觉得《android五子棋赢法数组 安卓欢乐五子棋人机大战报告.doc》对你有帮助,请点赞、收藏,并留下你的观点哦!