以判断竖行为例我的代码如下publicbooleancheckCol(intwho,BoardCellstartCell){intstartX=startCell.x;intcounter=1;startX++;while(board[startX][startCell.y]==who){counter++;st...
以判断竖行为例 我的代码如下
public boolean checkCol(int who, BoardCell startCell){
int startX = startCell.x;
int counter = 1;
startX++;
while(board[startX][startCell.y] == who){
counter++;
startX++;
if(startX == boardSize)
break;
}
startX = startCell.x;
startX--;
while(board[startX][startCell.y] == who){
counter++;
startX--;
if(startX == -1)
break;
}
System.out.println(counter);
return counter == COUNT;
}
之后我做了一个测试
b = new Board(10);
cell = new BoardCell();
cell.set(3, 2); b.addPiece(1, cell);
cell.set(4, 2); b.addPiece(1, cell);
cell.set(5, 2); b.addPiece(1, cell);
cell.set(6, 2); b.addPiece(1, cell);
cell.set(7, 2); b.addPiece(1, cell);
b.printBoard();
System.out.println(b.isFiveConnected(1, cell) ? "yes 5":"not 5");
cell.set(4, 2); b.addPiece(2, cell);
b.printBoard();
System.out.println(b.isFiveConnected(1, cell) ? "yes 5":"not 5");
输出结果为
0 1 2 3 4 5 6 7 8 9
0 . . . . . . . . . .
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . x . . . . . . .
4 . . x . . . . . . .
5 . . x . . . . . . .
6 . . x . . . . . . .
7 . . x . . . . . . .
8 . . . . . . . . . .
9 . . . . . . . . . .
1
5
yes 5
0 1 2 3 4 5 6 7 8 9
0 . . . . . . . . . .
1 . . . . . . . . . .
2 . . . . . . . . . .
3 . . x . . . . . . .
4 . . o . . . . . . .
5 . . x . . . . . . .
6 . . x . . . . . . .
7 . . x . . . . . . .
8 . . . . . . . . . .
9 . . . . . . . . . .
1
5
yes 5
求教这个逻辑有什么问题么?
展开