package lyj.chess.main; /** * 五子棋判断输赢类 * * @author LYJ * */ public class GameContorler { private static int HOW_MANY = 5; /** * 判断棋子横线是否五连珠 * * @param row * 横坐标 * @param column * 纵坐标 * @param chessType * @return */ public boolean acrossLine(int[][] chess, int row, int column, int chessType, int howMany) { int count = 0; int origalX = row, origalY = column; while (column >= 0 && chess[column][row] == chessType) { count++; column--; if (count == HOW_MANY) return true; } column = origalY + 1; while (column < chess[0].length && chess[column][row] == chessType) { count++; column++; if (count == HOW_MANY) return true; } row = origalX; column = origalY; return false; } /** * 判断纵线是否五连珠 * * @param chess * @param row * @param column * @param chessType * @return */ public boolean upRightLine(int[][] chess, int row, int column, int chessType, int howMany) { int count = 0; // 往上 int origalX = row, origalY = column; while (row >= 0 && chess[column][row] == chessType) { count++; row--; if (count == HOW_MANY) return true; } row = origalX + 1; // 往下 while (row < chess.length && chess[column][row] == chessType) { count++; row++; if (count == HOW_MANY) return true; } row = origalX; column = origalY; return false; } /** * 判断左斜 * * @param chess * @param row * @param column * @param chessType * @return */ public boolean leftBais(int[][] chess, int row, int column, int chessType, int howMany) { int count = 0; int origalX = row, origalY = column; while (row >= 0 && column <= chess[0].length - 1 && chess[column][row] == chessType) { count++; column++; row--; if (count == HOW_MANY) return true; } row = origalX + 1; column = origalY - 1; while (row <= chess.length - 1 && column >= 0 && chess[column][row] == chessType) { count++; row++; column--; if (count == HOW_MANY) return true; } row = origalX; column = origalY; return false; } /** * 判断右斜 * * @param chess * @param row * @param column * @param chessType * @return */ public boolean rightBias(int[][] chess, int row, int column, int chessType, int howMany) { int count = 0; int origalX = row, origalY = column; while (row <= 14 && column <= 14 && chess[column][row] == chessType) { row++; column++; count++; if (count == HOW_MANY) return true; } row = origalX - 1; column = origalY - 1; while (row >= 0 && column >= 0 && chess[column][row] == chessType) { row--; column--; count++; if (count == HOW_MANY) return true; } row = origalX; column = origalY; return false; } public boolean isGameOver(int[][] chess, int row, int column, int chessType, int howMany){ boolean one=acrossLine(chess, row, column, chessType, howMany); boolean two=upRightLine(chess, row, column, chessType, howMany); boolean three=leftBais(chess, row, column, chessType, howMany); boolean four=rightBias(chess, row, column, chessType, howMany); if(one||two||three||four) return true; return false; } }

gzryue LV6
2023年4月23日
刘鹏yyds LV10
2022年12月20日
123aa21a LV5
2021年6月23日
蔡 LV10
2021年6月12日
小小鹿lu LV1
2021年5月19日
ds0420 LV4
2021年1月4日
Care269031877 LV4
2020年12月18日
lxp66666 LV1
2020年12月6日
3159792465 LV10
2020年10月14日
dengge123 LV14
2020年9月2日

yzhsnjdn LV1
2024年12月17日
20201202038
2024年3月27日
暂无贡献等级
周俊杰 LV1
2023年12月25日
46562026
2023年12月22日
暂无贡献等级
2386136609 LV1
2023年12月17日
qq1434100519 LV1
2023年11月1日
wangjialiang1 LV17
2023年8月20日
2385649653 LV7
2023年6月26日
陈小灏 LV18
2023年6月5日
gzryue LV6
2023年4月23日