Examples of BoardPosition


Examples of com.barrybecker4.game.common.board.BoardPosition

     * fill a row with pieces during setup.
     */
    private void fillRow( int row, int odd, boolean player1 ) {

        for ( int j = 1; j <= SIZE/2; j++ )
            setPosition(new BoardPosition(row, (TWO * j - odd),
                                          new CheckersPiece(player1, CheckersPiece.REGULAR_PIECE)));
    }
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

     */
    @Override
    protected void undoInternalMove( Move move ) {

        CheckersMove m = (CheckersMove) move;
        BoardPosition startPos = getPosition(m.getFromRow(), m.getFromCol());

        startPos.setPiece( m.getPiece().copy() );
        if ( m.kinged ) {
            // then it was just kinged and we need to undo it
            startPos.setPiece(new CheckersPiece(m.isPlayer1(), CheckersPiece.REGULAR_PIECE));
        }
        // restore the captured pieces to the board
        m.restoreCaptures( this );

        getPosition(m.getToRow(), m.getToCol()).clear();
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

        // add all the moves that it can make.
        for ( row = 1; row <= CheckersBoard.SIZE; row++ ) {
            int odd = row % 2;
            for ( j = 1; j <= CheckersBoard.SIZE/2; j++ ) {
                col = 2 * j - odd;
                BoardPosition p = board_.getPosition( row, col );
                if ( p.isOccupied() && p.getPiece().isOwnedByPlayer1() == player1 ) {
                    addMoves(p, lastMove, moveList);
                }
            }
        }
        return moveList;
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

     * @param pos the piece to check
     * @return the number of moves added
     */
    private int addMovesForDirection( BoardPosition pos,
                                      int rowInc, int colInc, TwoPlayerMove lastMove, MoveList moveList) {
        BoardPosition next = board_.getPosition( pos.getRow() + rowInc, pos.getCol() + colInc );
        if (next!=null)
        {
            if (next.isUnoccupied()) {
                addSimpleMove(pos, rowInc, colInc, lastMove, moveList);
                // only one move added
                return 1;
            }
            // if just a simple move was not possible, we check for jump(s)
            BoardPosition beyondNext = board_.getPosition( pos.getRow() + 2 * rowInc, pos.getCol() + 2 * colInc );
            if (next.isOccupied() &&
                (next.getPiece().isOwnedByPlayer1() != pos.getPiece().isOwnedByPlayer1()) &&
                 beyondNext!=null && beyondNext.isUnoccupied()) {
                return addJumpMoves(pos, rowInc, lastMove, next, beyondNext, moveList);
            }
        }
        return 0; // no moves added
    }
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

        double score = 0;

        // evaluate the board after the move has been made
        for ( row = 1; row <= CheckersBoard.SIZE; row++ ) {
            for ( col = 1; col <= CheckersBoard.SIZE; col++ ) {
                BoardPosition pos = getBoard().getPosition( row, col );
                if ( pos.isOccupied() ) {
                    ChessPiece piece = (ChessPiece)pos.getPiece();
                    int side = piece.isOwnedByPlayer1() ? 1 : -1;
                    int advancement =
                            (piece.isOwnedByPlayer1() ? pos.getRow()-1 : (CheckersBoard.SIZE - pos.getRow()-1));
                    score += piece.getWeightedScore(side, pos, weights, advancement);
                }
            }
        }
        return (int)score;
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

     * @return number of additional jump moves added.
     */
    private int checkJumpMove( BoardPosition current,
                               CheckersMove m, int rowInc, int colInc,
                               List<CheckersMove> jumpMoves, ParameterArray weights ) {
        BoardPosition next = board_.getPosition( current.getRow() + rowInc, current.getCol() + colInc );
        BoardPosition beyondNext = board_.getPosition( current.getRow() + 2 * rowInc, current.getCol() + 2 * colInc );
        // if the adjacent square is an opponent's piece, and the space beyond it
        // is empty, and we have not already capture this piece, then take another jump.
        boolean opponentAdjacent =
                next!=null && next.isOccupied() && (next.getPiece().isOwnedByPlayer1() != m.isPlayer1());
        if ( opponentAdjacent
              && beyondNext!=null && beyondNext.isUnoccupied()
              && (m.captureList != null) && (!m.captureList.alreadyCaptured( next )) ) {
            // then there is another jump. We must take it.
            CheckersMove mm = m.copy()// base it on the original jump
            mm.setToLocation(new ByteLocation(beyondNext.getLocation().getRow(), beyondNext.getLocation().getCol()));
            mm.captureList.add( next.copy() );
            // next.setPiece(null); ?

            boolean justKinged = false;   // ?? may be superfluous
            GameContext.log( 2, "calling findJumpMoves on " +
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

       // scan through the board positions. For each each piece of the current player's,
       // add all the moves that it can make.
       for ( row = 1; row <= CheckersBoard.SIZE; row++ ) {
           for ( col = 1; col <= CheckersBoard.SIZE; col++ ) {
               BoardPosition pos = getBoard().getPosition(row, col);
               if ( pos.isOccupied() && pos.getPiece().isOwnedByPlayer1() == player1 ) {
                   addMoves( pos, moveList, lastMove, weights);
               }
           }
       }
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

    private void setupPlayerPieces(boolean isPlayer1) {
        int numRows = getNumRows();
        int pawnRow = isPlayer1 ? 2 : numRows - 1;
        int kingRow = isPlayer1 ? 1 : numRows;
        for ( int j = 1; j <= getNumCols(); j++ ) {
            setPosition(new BoardPosition( kingRow, j, new ChessPiece(isPlayer1, PIECE_ARRANGEMENT[j-1])));
            setPosition(new BoardPosition( pawnRow, j, new ChessPiece(isPlayer1, ChessPieceType.PAWN)));
        }
    }
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

     */
    @Override
    protected boolean makeInternalMove( Move move )
    {
        ChessMove m = (ChessMove) move;
        BoardPosition oldPos = getPosition(m.getFromRow(), m.getFromCol());
        BoardPosition newPos = getPosition(m.getToRow(), m.getToCol());

        // remove the captures before we place the moved piece since it may be underneath.
        removeCaptures( m.captureList );

        if (oldPos.getPiece() != null) {
            m.setFirstTimeMoved(((ChessPiece)oldPos.getPiece()).isFirstTimeMoved());
            newPos.setPiece(m.getPiece());

            // once its been moved its no longer the first time its been moved
            ((ChessPiece)newPos.getPiece()).setFirstTimeMoved(false);

            getPosition(m.getFromRow(), m.getFromCol()).clear();
        }
        return true;
    }
View Full Code Here

Examples of com.barrybecker4.game.common.board.BoardPosition

     */
    @Override
    protected void undoInternalMove( Move move )
    {
        ChessMove m = (ChessMove) move;
        BoardPosition start = getPosition(m.getFromRow(), m.getFromCol());
        start.setPiece(m.getPiece());

        getPosition(m.getToRow(), m.getToCol()).clear();
        // restore the firstTimeMoved status of the piece since we
        // may be moving it back to its original position.
        ((ChessPiece)start.getPiece()).setFirstTimeMoved(m.isFirstTimeMoved());

        // restore the captured pieces to the board
        restoreCaptures( m.captureList );
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.