示例#1
0
  @Override
  public MoveResult makeMove(HantoPieceType pieceType, HantoCoordinate from, HantoCoordinate to)
      throws HantoException {
    final HexCoordinate src = HexCoordinate.extractHexCoordinate(from);
    final HexCoordinate dest = HexCoordinate.extractHexCoordinate(to);

    // Verify the source piece is valid, if provided.
    rules.doPreMoveChecks(pieceType, src, dest);

    // Now that we know we can make the move, do it for realsies.
    rules.actuallyMakeMove(pieceType, src, dest);

    // Make sure that move we just did was valid
    // (We're assuming that just throwing an exception is okay here,
    // the incorrect move is applied and NOT changed for now.)
    rules.doPostMoveChecks(dest);

    // Finish move
    completeMove();

    // Return the result of the move
    return rules.evaluateMoveResult();
  }
示例#2
0
  /**
   * Add a coordinate to the board
   *
   * <p>TODO: Move this to the test harness
   *
   * @param color color of new piece
   * @param type type of new piece
   * @param c location of new piece
   */
  public void addToBoard(HantoPlayerColor color, HantoPieceType type, HantoCoordinate c) {
    final HexCoordinate hc = HexCoordinate.extractHexCoordinate(c);
    final HantoPiece p = new HantoPiece(color, type, hc);

    state.board.addPieceAt(p, hc);
  }
示例#3
0
  /**
   * @return true if a piece exists on the board
   * @param c coordinate to check for a piece
   *     <p>TODO: Move this to the test harness?
   *     <p>NOTE: this name makes sense to me. I don't understand how the suggestions in CodePro's
   *     audit rule could make more sense here.
   */
  public boolean doesPieceExistAt(HantoCoordinate c) {
    final HexCoordinate h = HexCoordinate.extractHexCoordinate(c);

    return state.getBoard().getPieceAt(h) != null;
  }