《Android应用程序开发》大作业题目:五子棋游戏的设计与实现专业:网络工程学号:*********学生姓名:***指导教师:***完成日期:2015-11-25目录1开发背景 (1)2.需求分析 (1)2.1功能需求 (1)2.2性能需求软件环境: (1)3.概要设计 (1)4.棋盘、棋子的绘制 (1)5.游戏核心设计 (2)5.1手机选择落子位置 (2)5.2判断游戏的输赢 (2)6.运行截图 (2)7.核心代码 (5)7.1首界面 (5)7.2棋盘、棋子的初始化等 (6)7.3 判断输赢 (8)7.4手机落子算法 (10)1开发背景每个人手机上都有手机游戏,上下班以及无聊闲暇时,游戏是人们娱乐的一种方式。
Android 平台下的手机游戏更是受到顾客的青睐,手机游戏不仅玩起来比较方便,还有助于开发我们的思维,使大家在娱乐的同时也增长了见识,拓展了思维。
五子棋对思维及协调能力有益,能使我们注意力集中,耐心也有明显的提升,培养我们的逻辑思维能力,对智力及记忆力都很有帮助。
2.需求分析2.1功能需求1.适合不同阶段的玩家(新手和熟手)2.玩家和手机对弈2.2性能需求软件环境:1.硬件环境:PC机2Windows XP、Android 2.1 以上3.概要设计五子棋分三个模块:开始游戏、设置、退出。
1.开始游戏:点击进入游戏2.游戏设置:音效设置:开启/关闭背景音乐、开启/关闭音效难度设置:简单,中等,较难3.退出游戏关闭游戏4.棋盘、棋子的绘制本设计中棋盘的设置采用drawLine(float startX,float startY,float stopX,float stopY,Paint paint)画线,参数一起始点的X轴位置,参数二起始点的Y轴位置,参数三终点的水平位置,参数四垂直位置,最后的一个参数为Paint画刷对象。
本设计中棋子是用drawCircle在坐标上绘制一个经典几何图形。
先判断是否有棋,是黑子还是白子,然后判断是那个坐标,然后调用drawCircle绘制棋子canvas.drawCircle(float,float,float,Paint)方法用于画圆,前两个参数代表圆心坐标,第三个参数为圆半径,第四个参数是画笔。
5.游戏核心设计5.1手机选择落子位置评估当前棋局中,某个位置的得分。
五子棋要赢,必然要有五个棋子在一起成线,那么我们就可以计算棋盘中每一个五格相连的线,一下称之为五元组。
一般情况(包括专业五子棋)下棋盘是15*15的。
那么应该是572个五元组。
同时,针对五元组中黑子和白子的数量(可以不考虑相对位置)的不同,给该五元组评不同的分。
然后每一个位置的得分就是包含这个位置的所有五元组的得分之和。
说明:当五元组为空,分数为7,不为零的原因是,还有跟糟的情况:五元组中既有黑子又有白子,五元组也就是无效了,这时才给0分。
根据得到的评分,手机选出最佳位置,进行落子。
5.2判断游戏的输赢在判断输赢时,用到的一个巧妙的方法。
从所周知,无论谁下棋赢了以后总会成五子连线,而成五子连线时,第五颗棋总是会着落在棋盘上,所以我们在判断是否有五子连线时,并不是全盘扫描,而是在每着落一子后就扫描该棋子左右、上下、以及斜着的四个方向。
如果扫描出来了那个方向上的棋子首先到达五子,就返回给上级调用,由上级调用者作出相应判断。
如果是其它子,如果某个方向上成了六子或六子以上时,不能算作它赢得了棋,而必是五子才能赢得了棋。
如果是五子以下的棋子时,将要根局相应棋子成子情况,作出相应反应,如加权、减权等操作。
6.运行截图首界面:开始游戏:设置:判断输赢:7.核心代码7.1首界面public class StartActivity extends Activity{@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);this.setContentView(yout.activity_start);Button button1 = (Button) findViewById(R.id.button1);button1.setOnClickListener(new View.OnClickListener(){ @Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubIntent intent1 = new Intent();intent1.setClass(StartActivity.this,MainActivity.class);startActivity(intent1);StartActivity.this.finish();}});Button button2 = (Button) findViewById(R.id.button2);button2.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View v) {// TODO Auto-generated method stubIntent intent2 = new Intent();intent2.setClass(StartActivity.this, settingActivity.class);startActivity(intent2);StartActivity.this.finish();}});Button button3 = (Button) findViewById(R.id.button3);button3.setOnClickListener(new View.OnClickListener() { @Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubStartActivity.this.finish();}});}}7.2棋盘、棋子的初始化等private ChessType[][] chessMap = new ChessType[ROWS][COLS];private static float PADDING = ((float) (screenWidth) / (COLS - 1)) / 2;private static float PADDING_LEFT = ((float) (screenWidth) / (COLS - 1)) / 2;private static float PADDING_TOP = ((float) (screenHeight) / (ROWS - 1)) / 2;private static float ROW_MARGIN= (screenHeight- PADDING* 2) / (ROWS - 1);private static float COL_MARGIN = (screenWidth - PADDING * 2)/ (COLS - 1);private static float MARGIN;public GameView(Context context) {super(context);this.context = context;this.setBackgroundResource(R.drawable.bg);PADDING_LEFT = ((screenWidth) / (COLS - 1)) / 2;PADDING_TOP = ((screenHeight) / (ROWS - 1)) / 2;PADDING = PADDING_LEFT < PADDING_TOP ? PADDING_LEFT : PADDING_TOP;ROW_MARGIN = ((screenHeight - PADDING * 2)) / (ROWS - 1);COL_MARGIN = ((screenWidth - PADDING * 2)) / (COLS - 1);MARGIN= ROW_MARGIN< COL_MARGIN? ROW_MARGIN: COL_MARGIN;PADDING_LEFT = (screenWidth - (COLS - 1) * MARGIN) / 2;PADDING_TOP = (screenHeight - (ROWS - 1) * MARGIN) / 2;// 对棋子进行初始化initChess();// System.out.println(PADDING_LEFT + " " + PADDING_TOP);}//对棋子进行初始化public void initChess() {for (int i = 0; i < ROWS; i++) {for (int j = 0; j < COLS; j++) {chessMap[i][j] = ChessType.NONE;}}invalidate();}//画棋盘@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);Paint paint = new Paint();paint.setColor(Color.WHITE);// 打印行for (int i = 0; i < ROWS; i++) {canvas.drawLine(PADDING_LEFT, i * MARGIN+ PADDING_TOP, (COLS - 1)* MARGIN+ PADDING_LEFT, i * MARGIN+ PADDING_TOP, paint);}// 打印列for (int i = 0; i < COLS; i++) {canvas.drawLine(PADDING_LEFT+ i * MARGIN, PADDING_TOP,PADDING_LEFT + i * MARGIN, MARGIN * (ROWS - 1)+ PADDING_TOP, paint);}for (int r = 0; r < ROWS; r++) {for (int c = 0; c < COLS; c++) {// System.out.print(chessMap[r][c] + " ");if (chessMap[r][c] == ChessType.NONE)continue;if (chessMap[r][c] == ChessType.BLACK) {paint.setColor(Color.BLACK);canvas.drawCircle(r * MARGIN + PADDING_LEFT, c * MARGIN+ PADDING_TOP, MARGIN / 2, paint);} else if (chessMap[r][c] == ChessType.WHITE) {paint.setColor(Color.WHITE);canvas.drawCircle(r * MARGIN + PADDING_LEFT, c * MARGIN+ PADDING_TOP, MARGIN / 2, paint);}}// System.out.println();}}7.3 判断输赢public boolean hasWin(int r, int c) {ChessType chessType = chessMap[r][c];System.out.println(chessType);int count = 1;// 纵向搜索for (int i = r + 1; i < r + 5; i++) {if (i >= GameView.ROWS)break;if (chessMap[i][c] == chessType) {count++;} elsebreak;}for (int i = r - 1; i > r - 5; i--) {if (i < 0)break;if (chessMap[i][c] == chessType)count++;elsebreak;}// System.out.println(count +" "+"1");if (count >= 5)return true;// 横向搜索count = 1;for (int i = c + 1; i < c + 5; i++) {if (i >= GameView.COLS)break;if (chessMap[r][i] == chessType)count++;elsebreak;}for (int i = c - 1; i > c - 5; i--) {if (i < 0)break;if (chessMap[r][i] == chessType)count++;elsebreak;}// System.out.println(count +" " +"2");if (count >= 5)return true;// 斜向"\"count = 1;for (int i = r + 1, j = c + 1; i < r + 5; i++, j++) { if (i >= GameView.ROWS || j >= GameView.COLS) { break;}if (chessMap[i][j] == chessType)count++;elsebreak;}for (int i = r - 1, j = c - 1; i > r - 5; i--, j--) { if (i < 0 || j < 0)break;if (chessMap[i][j] == chessType)count++;elsebreak;}// System.out.println(count +" " +"3");if (count >= 5)return true;// 斜向"/"count = 1;for (int i = r + 1, j = c - 1; i < r + 5; i++, j--) { if (i >= GameView.ROWS || j < 0)break;if (chessMap[i][j] == chessType)count++;elsebreak;}for (int i = r - 1, j = c + 1; i > r - 5; i--, j++) { if (i < 0 || j >= GameView.COLS)break;if (chessMap[i][j] == chessType)count++;elsebreak;}// System.out.println(count +" " +"4");if (count >= 5)return true;return false;}7.4手机落子算法/* 得到最优点** @return得到最优的点*/private Point getBestPoint() {initValue();for (int r = 0; r < GameView.ROWS; r++) {for (int c = 0; c < GameView.COLS; c++) {if (chessMap[r][c] == ChessType.NONE) {puterMap[r][c] = getValue(r, c, puterType);this.playerMap[r][c] = getValue(r, c,this.playerType);}}}int pcMax = 0, playerMax = 0;Random rd = new Random();Point pcPoint = new Point(-1, -1);Point playerPoint = new Point();// 分别选出pc估分和玩家估分的最大值for (int r = 0; r < GameView.ROWS; r++) {for (int c = 0; c < GameView.COLS; c++) {// 选出电脑估分的最大值if (pcMax == computerMap[r][c]) {if (rd.nextInt(10) % 2 == 0) {pcMax = computerMap[r][c];pcPoint.x = r;pcPoint.y = c;}} else if (pcMax < computerMap[r][c]) {pcMax = computerMap[r][c];pcPoint.x = r;pcPoint.y = c;}// 选出玩家估分的最大值if (playerMax == playerMap[r][c]) {if (rd.nextInt(10) % 2 == 0) {playerMax = playerMap[r][c];playerPoint.x = r;playerPoint.y = c;}} else if (playerMax < playerMap[r][c]) {playerMax = playerMap[r][c];playerPoint.x = r;playerPoint.y = c;}}}// 两者都在90~100分之间,优先选择PCif(pcMax >= 90 && pcMax < 100 && playerMax >= 90 && playerMax < 100) {return pcPoint;} else {return playerMax > pcMax ? playerPoint : pcPoint;}}/* 得到该位置的分数** @param r* 该棋子所在的行数* @param c* 该棋子所在的列数* @param chessType* 棋子的类型* @return得到的分数*/private int getValue(int r, int c, ChessType chessType) { int[] dir = new int[4];dir[0] = this.getHorCount(r, c, chessType);dir[1] = this.getVerCount(r, c, chessType);dir[2] = this.getSloRCount(r, c, chessType);dir[3] = this.getSloLCount(r, c, chessType);// 成五for (int i = 0; i < dir.length; i++) {if (dir[i] >= 5)return ScoreTable.FIVE;}int temp = 0;// 双活四for (int i = 0; i < dir.length; i++) {if (dir[i] == 4 && chessStatus[i] != ChessStatus.DIED) temp++;if (temp == 2)return ScoreTable.DOUBLE_ALIVE_FOUR;}int t1 = 0, t2 = 0;// 活四死四for (int i = 0; i < dir.length; i++) {if(dir[i] == 4 && chessStatus[i] == ChessStatus.ALIVE) t1 = 1;if (dir[i] == 4 && chessStatus[i] != ChessStatus.DIED) t2 = 1;if (t1 == 1 && t2 == 1)return ScoreTable.ALIVE_FOUR_AND_DEAD_FOUR;}// 活四活三t1 = 0;t2 = 0;for (int i = 0; i < dir.length; i++) {if (dir[i] == 4 && chessStatus[i] != ChessStatus.DIED) t1 = 1;if(dir[i] == 3 && chessStatus[i] == ChessStatus.ALIVE) t2 = 1;if (t1 == 1 && t2 == 1)return ScoreTable.ALIVE_FOUR_AND_ALIVE_THREE;}// 活四死三t1 = 0;t2 = 0;for (int i = 0; i < dir.length; i++) {if (dir[i] == 4 && chessStatus[i] != ChessStatus.DIED) t1 = 1;if (dir[i] == 3 && chessStatus[i] != ChessStatus.DIED) t2 = 1;if (t1 == 1 && t2 == 1) {return ScoreTable.ALIVE_FOUR_AND_DEAD_THREE;}}// 活四活二t1 = 0;t2 = 0;for (int i = 0; i < dir.length; i++) {if (dir[i] == 4 && chessStatus[i] != ChessStatus.DIED) t1 = 1;if(dir[i] == 2 && chessStatus[i] != ChessStatus.ALIVE) t2 = 1;if (t1 == 1 && t2 == 1)return ScoreTable.ALIVE_FOUR_AND_ALIVE_TWO;}// 活四for (int i = 0; i < dir.length; i++) {if(dir[i] == 4 && chessStatus[i] == ChessStatus.ALIVE) {return ScoreTable.ALIVE_FOUR;}}// 双死四temp = 0;for (int i = 0; i < dir.length; i++) {if (dir[i] == 4 && chessStatus[i] == ChessStatus.DIED)temp++;if (temp == 2)return ScoreTable.DOUBLE_DEAD_FOUR;}// 死四活3t1 = 0;t2 = 0;for (int i = 0; i < dir.length; i++) {if (dir[i] == 4 && chessStatus[i] == ChessStatus.DIED) t1 = 1;if (dir[i] == 3 && chessStatus[i] != ChessStatus.DIED) t2 = 1;if (t1 == 1 && t2 == 1) {return ScoreTable.DEAD_FOUR_AND_ALIVE_THREE;}}// 死四活2t1 = 0;t2 = 0;for (int i = 0; i < dir.length; i++) {if (dir[i] == 4 && chessStatus[i] == ChessStatus.DIED) t1 = 1;if (dir[i] == 2 && chessStatus[i] != ChessStatus.DIED) t2 = 1;if (t1 == 1 && t2 == 1)return ScoreTable.DEAD_FOUR_AND_ALIVE_TWO;}// 双活三temp = 0;for (int i = 0; i < dir.length; i++) {if (dir[i] == 3 && chessStatus[i] != ChessStatus.DIED) temp++;if (temp == 2)return ScoreTable.DOUBLE_ALIVE_THREE;}// 活死三t1 = 0;t2 = 0;for (int i = 0; i < dir.length; i++) {if(dir[i] == 3 && chessStatus[i] == ChessStatus.ALIVE) t1 = 1;if (dir[i] == 3 && chessStatus[i] == ChessStatus.DIED) t2 = 1;if (t1 == 1 && t2 == 1)return ScoreTable.ALIVE_THREE_AND_DEAD_THREE;}// 活三for (int i = 0; i < dir.length; i++) {if(dir[i] == 3 && chessStatus[i] == ChessStatus.ALIVE) return ScoreTable.ALIVE_THREE;}// 死四for (int i = 0; i < dir.length; i++) {if (dir[i] == 4 && chessStatus[i] == ChessStatus.DIED) return ScoreTable.DEAD_FOUR;}// 半活死3t1 = 0;t2 = 0;for (int i = 0; i < 4; i++) {if (dir[i] == 3 && chessStatus[i] == ChessStatus.DIED) t1 = 1;if (dir[i] == 3 && chessStatus[i] ==ChessStatus.HALFALIVE)t2 = 1;if (t1 == 1 && t2 == 1)return ScoreTable.ALIVE_THREE_AND_DEAD_THREE;}// 双活2temp = 0;for (int i = 0; i < 4; i++) {if(dir[i] == 2 && chessStatus[i] == ChessStatus.ALIVE) temp++;if (temp == 2)return ScoreTable.DOUBLE_ALIVE_TWO;}// 死3for (int i = 0; i < 4; i++)if (dir[i] == 3 && chessStatus[i] == ChessStatus.DIED) return ScoreTable.DEAD_THREE;// 活2for (int i = 0; i < 4; i++)if(dir[i] == 2 && chessStatus[i] == ChessStatus.ALIVE) return ScoreTable.ALIVE_TWO;// 死2for (int i = 0; i < 4; i++)if (dir[i] == 2 && chessStatus[i] == ChessStatus.DIED) return ScoreTable.DEAD_TWO;return 0;}/* 横向搜索** @param r* 该棋子所在的行数* @param c* 该棋子所在的列数* @param chessType* 棋子的类型* @return得到的个数*/private int getHorCount(int r, int c, ChessType chessType) { int count = 1;int t1 = c + 1;int t2 = c - 1;for (int j = c + 1; j < c + 5; j++) {if (j >= GameView.COLS) {chessStatus[0] = ChessStatus.DIED;break;}if (chessMap[r][j] == chessType) {count++;if (count >= 5)return count;} else {chessStatus[0] = (chessMap[r][j] == ChessType.NONE) ? ChessStatus.ALIVE: ChessStatus.DIED;t1 = j;break;}}for (int j = c - 1; j > c - 5; j--) {if (j < 0) {if(chessStatus[0] == ChessStatus.DIED&& count < 5) {return 0;}chessStatus[0] = ChessStatus.DIED;break;}if (chessMap[r][j] == chessType) {count++;if (count >= 5)return count;} else {if (chessStatus[0] == ChessStatus.DIED) {if(count < 5 && chessMap[r][j] != ChessType.NONE) {return 0;}} else {chessStatus[0] = (chessMap[r][j]) == ChessType.NONE ? ChessStatus.ALIVE: ChessStatus.DIED;t2 = j;// 记录遇到的空格// 当两端都活的时候,看是否可以延伸if (chessStatus[0] == ChessStatus.ALIVE) {int tempCount1 = count, tempCount2 = count;boolean isAlive1 = false, isAlive2 = false;for (int i = t1 + 1; i < t1 + 5; i++) {if (i >= GameView.ROWS)break;if (chessMap[r][i] == chessType) {tempCount1++;} else {isAlive1 = (chessMap[r][i] == ChessType.NONE) ? true: false;break;}}for (int i = t2 - 1; i > t2 - 5; i--) {if (i < 0)break;if (chessMap[r][i] == chessType) {tempCount2++;} else {isAlive2 = (chessMap[r][i] == ChessType.NONE) ? true: false;break;}}// 如果两头都是空,直接跳出if(tempCount1 == count && tempCount2 == count)break;if (tempCount1 == tempCount2) {count = tempCount1;chessStatus[0] = (isAlive1 && isAlive2) ? ChessStatus.HALFALIVE: ChessStatus.DIED;} else {count = (tempCount1 > tempCount2) ? tempCount1: tempCount2;if (count >= 5)return 0;if (tempCount1 > tempCount2)chessStatus[0] = (isAlive1) ? ChessStatus.HALFALIVE: ChessStatus.DIED;elsechessStatus[0] = (isAlive2) ? ChessStatus.HALFALIVE: ChessStatus.DIED;}}}break;}}return count;}/* 纵向搜索** @param chessType* 要搜索的棋子类型* @param r* 棋子所在的行* @param c* 棋子所在的列* @return*/private int getVerCount(int r, int c, ChessType chessType) { int t1 = r + 1;int t2 = r - 1;int count = 1;for (int i = r + 1; i < r + 5; i++) {if (i >= GameView.ROWS) {chessStatus[1] = ChessStatus.DIED;break;}if (chessMap[i][c] == chessType) {count++;if (count >= 5) {return count;}} else {chessStatus[1] = (chessMap[i][c] == ChessType.NONE) ? ChessStatus.ALIVE: ChessStatus.DIED;t1 = i;break;}}for (int i = r - 1; i > r - 5; i--) {if (i < 0) {if(chessStatus[1] == ChessStatus.DIED&& count < 5) {return 0;}chessStatus[1] = ChessStatus.DIED;break;}if (chessMap[i][c] == chessType) {count++;if (count >= 5) {return count;}} else {if (chessStatus[1] == ChessStatus.DIED) {if(chessMap[i][c] != ChessType.NONE&& count < 5) {return 0;}} else {chessStatus[1] = chessMap[i][c] == ChessType.NONE ? ChessStatus.ALIVE: ChessStatus.DIED;t2 = i;// 如果两头都活,看是否还可以延伸if (chessStatus[1] == ChessStatus.ALIVE) {int tempCount1 = count, tempCount2 = count;boolean isAlive1 = false, isAlive2 = false;for (int j = t1 + 1; j < t1 + 5; j++) {if (j >= GameView.ROWS) {// chessStatus[1] = ChessStatus.DIED;break;}if (chessMap[j][c] == chessType) {tempCount1++;} else {isAlive1 = (chessMap[j][c] == ChessType.NONE) ? true: false;break;}}for (int j = t2 - 1; j > t2 - 5; j--) {if (j < 0) {break;}if (chessMap[j][c] == chessType) {tempCount2++;} else {isAlive2 = (chessMap[j][c] == ChessType.NONE) ? true: false;break;}}if(tempCount1 == count && tempCount2 == count) {break;}if (tempCount1 == tempCount2) {count = tempCount1;chessStatus[1] = (isAlive1 && isAlive2) ? ChessStatus.HALFALIVE: ChessStatus.DIED;} else {count = (tempCount1 > tempCount2) ? tempCount1: tempCount2;if (count >= 5)return 0;if (tempCount1 > tempCount2) {chessStatus[1] = isAlive1 ? ChessStatus.HALFALIVE: ChessStatus.DIED;} else {chessStatus[1] = isAlive2 ? ChessStatus.HALFALIVE: ChessStatus.DIED;}}}break;}}}return count;}/* 斜向"\"*/private int getSloRCount(int r, int c, ChessType chessType) { int count = 1;int tr1 = r + 1;int tc1 = c + 1;int tr2 = r - 1;int tc2 = c - 1;for (int i = r + 1, j = c + 1; i < r + 5; i++, j++) { if (i >= GameView.ROWS || j >= GameView.COLS) {chessStatus[2] = ChessStatus.DIED;break;}if (chessMap[i][j] == chessType) {count++;if (count >= 5)return count;} else {chessStatus[2] = (chessMap[i][j] == ChessType.NONE) ? ChessStatus.ALIVE: ChessStatus.DIED;tr1 = i;tc1 = j;break;}}for (int i = r - 1, j = c - 1; i > r - 5; i--, j--) { if (i < 0 || j < 0) {if(chessStatus[2] == ChessStatus.DIED&& count < 5) {return 0;}chessStatus[2] = ChessStatus.DIED;break;}if (chessMap[i][j] == chessType) {count++;if (count >= 5) {return count;}} else {if (chessStatus[2] == ChessStatus.DIED) {if(count < 5 && chessMap[i][j] != ChessType.NONE)return 0;} else {chessStatus[2] = chessMap[i][j] == ChessType.NONE ? ChessStatus.ALIVE: ChessStatus.DIED;tr2 = i;tc2 = j;// 两头都活看是否可以延伸if (chessStatus[2] == ChessStatus.ALIVE) {int tempCount1 = count, tempCount2 = count;boolean isAlive1 = false, isAlive2 = false;for (int p = tr1 + 1, q = tc1 + 1; p < tr1 + 5; p++, q++) {if(p >= GameView.ROWS|| q >= GameView.COLS) {break;}if (chessMap[p][q] == chessType) {tempCount1++;} else {isAlive1 = (chessMap[p][q] == ChessType.NONE) ? true: false;break;}}for (int p = tr2 - 1, q = tc2 - 1; p > tr2 - 5; p--, q--) {if (p < 0 || q < 0)break;if (chessMap[p][q] == chessType) {tempCount2++;} else {isAlive2 = (chessMap[p][q] == ChessType.NONE) ? true: false;break;}}if(tempCount1 == count && tempCount2 == count) {break;}if (tempCount1 == tempCount2) {count = tempCount1;chessStatus[2] = (isAlive1 && isAlive2) ? ChessStatus.HALFALIVE: ChessStatus.DIED;} else {count = (tempCount1 > tempCount2) ? tempCount1: tempCount2;if (count >= 5)return 0;if (tempCount1 > tempCount2) {chessStatus[2] = isAlive1 ? ChessStatus.HALFALIVE: ChessStatus.DIED;} else {chessStatus[2] = isAlive2 ? ChessStatus.HALFALIVE: ChessStatus.DIED;}}}}break;}}return count;}/* 斜向"/"*/private int getSloLCount(int r, int c, ChessType chessType) { int count = 1;int tr1 = r + 1;int tc1 = c + 1;int tr2 = r - 1;int tc2 = c - 1;for (int i = r + 1, j = c - 1; i < r + 5; i++, j--) { if (i >= GameView.ROWS || j < 0) {chessStatus[3] = ChessStatus.DIED;break;}if (chessMap[i][j] == chessType) {count++;if (count >= 5)return count;} else {chessStatus[3] = (chessMap[i][j] == ChessType.NONE) ? ChessStatus.ALIVE: ChessStatus.DIED;tr1 = i;tc1 = j;break;}}for (int i = r - 1, j = c + 1; i > r - 5; i--, j++) { if (i < 0 || j >= GameView.COLS) {if(chessStatus[3] == ChessStatus.DIED&& count < 5) return 0;chessStatus[3] = ChessStatus.DIED;break;}if (chessMap[i][j] == chessType) {count++;if (count >= 5)return count;} else {if (chessStatus[3] == ChessStatus.DIED) {if(count < 5 && chessMap[i][j] != ChessType.NONE) {return 0;}} else {chessStatus[3] = (chessMap[i][j] == ChessType.NONE) ? ChessStatus.ALIVE: ChessStatus.DIED;tr2 = i;tc2 = j;if (chessStatus[3] == ChessStatus.ALIVE) {int tempCount1 = count, tempCount2 = count;boolean isAlive1 = false, isAlive2 = false;for (int p = tr1 + 1, q = tc1 - 1; p < tr1 + 5; p++, q++) {if (p >= GameView.ROWS || q < 0) {break;}if (chessMap[p][q] == chessType) {tempCount1++;} else {isAlive1 = chessMap[p][q] == ChessType.NONE ? true: false;break;}}for (int p = tr2 - 1, q = tc1 + 1; p > tr2 - 5; p--, q++) {if (p < 0 || q >= GameView.COLS) {break;}if (chessMap[p][q] == chessType) {tempCount2++;} else {isAlive2 = chessMap[p][q] ==ChessType.NONE ? true: false;break;}}if(tempCount1 == count && tempCount2 == count) {break;}if (tempCount1 == tempCount2) {count = tempCount1;chessStatus[3] = (isAlive1 && isAlive2) ? ChessStatus.HALFALIVE: ChessStatus.DIED;} else {count = (tempCount1 > tempCount2) ? tempCount1: tempCount2;if (count >= 5)return 0;if (tempCount1 > tempCount2) {chessStatus[3] = isAlive1 ? ChessStatus.HALFALIVE: ChessStatus.DIED;} else {chessStatus[3] = isAlive2 ? ChessStatus.HALFALIVE: ChessStatus.DIED;}}}}break;}}return count;}。