smallboard.java

来自「基于Java的五子棋的源代码」· Java 代码 · 共 51 行

JAVA
51
字号
package net.sourceforge.gomoku;/** * @author <a href="mailto:anton.safonov@gmail.com">Anton Safonov</a> */public final class SmallBoard extends Board {  private final byte[] pieces;  private final byte rows;  private final byte cols;  SmallBoard(final int rows, final int cols) {    this.rows = (byte) rows;    this.cols = (byte) cols;    this.pieces = new byte[rows * cols];  }  int getRows() {    return this.rows;  }  int getCols() {    return this.cols;  }  Board copy() {    SmallBoard newBoard = new SmallBoard(getRows(), getCols());    System.arraycopy(this.pieces, 0, newBoard.pieces, 0, pieces.length);    return newBoard;  }  byte getPiece(final int row, final int col) {    try {      return pieces[toPosition(row, col)];    } catch (ArrayIndexOutOfBoundsException e) {      return NO_PIECE;    }  }  void setPiece(final int row, final int col, final byte piece) {    pieces[toPosition(row, col)] = piece;  }  void clear() {    for (int i = 0, max = pieces.length; i < max; ++i) {      pieces[i] = NO_PIECE;    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?