Package com.barrybecker4.game.common.board

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


     * @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

       // 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

    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

     */
    @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

     */
    @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

        int row, col;
        boolean checked = false;
        for ( row = 1; row <= getNumRows(); row++ ) {
            for ( col = 1; col <= getNumCols(); col++ ) {
                BoardPosition pos = getPosition( row, col );
                if ( pos.isOccupied() && pos.getPiece().isOwnedByPlayer1() == !m.isPlayer1() ) {
                    checked = isKingCheckedByPosition(pos, m);
                }
                if (checked) {
                    undoMove();
                    return checked;
View Full Code Here

        for (int i = 0; i < getNumPlanets(); i++)
        {
            // find a random position
            int randRow;
            int randCol;
            BoardPosition position;
            // find an unoccupied position to place the new planet
            do {
                randRow = (int)(Math.random() * getNumRows())+1;
                randCol = (int)(Math.random() * getNumCols())+1;
                position = this.getPosition(randRow, randCol);
            } while (position.isOccupied());

            // initial ships and production factor
            int production = (int)( 1 + Math.max(0, GameContext.random().nextGaussian()) * options.getPlanetProductionRate());
            int initialFleet = (int)( 1 + Math.max(0, GameContext.random().nextGaussian()) * options.getInitialFleetSize());
            Planet planet = new Planet(PLANET_NAMES[i], initialFleet,
                                       production, position.getLocation());
            position.setPiece(planet);

            // substitute in the players home planets that have already been created.
            for (Player p : players) {
                GalacticPlayer newVar = (GalacticPlayer) p;
                if (planet.getName() == newVar.getHomePlanet().getName()) {
                    Planet home = newVar.getHomePlanet();
                    position.setPiece(home);    // replace
                    home.setLocation(position.getLocation());
                }
            }
            // add the planet to our list
            planets_.add((Planet)position.getPiece());

            hmPlanets_.put(planet.getName(), (Planet)position.getPiece());
        }
    }
View Full Code Here

    @Override
    public String getToolTipText( MouseEvent e ) {
        Location loc = getBoardRenderer().createLocation(e);
        StringBuilder sb = new StringBuilder( "<html><font=-3>" );

        BoardPosition space = ((IRectangularBoard)controller_.getBoard()).getPosition( loc );
        if ( space != null && space.isOccupied() && GameContext.getDebugMode() >= 0 ) {
            sb.append(((Planet)space.getPiece()).toHtml());
            sb.append("<br>");
            sb.append( loc );
        }
        sb.append( "</font></html>" );
        return sb.toString();
View Full Code Here

        if (controller.isProcessing())
            return;
        Location loc = getRenderer().createLocation(e);

        Board board = (Board)controller.getBoard();
        BoardPosition position = board.getPosition( loc );
        // if there is no piece or out of bounds, then return without doing anything
        if ( (position == null) || (position.isUnoccupied()) ) {
            return;
        }
        GamePiece piece = position.getPiece();
        if ( controller.isPlayer1sTurn() != piece.isOwnedByPlayer1() )
            return; // wrong players piece

        getRenderer().setDraggedPiece(position);
    }
View Full Code Here

TOP

Related Classes of com.barrybecker4.game.common.board.BoardPosition

Copyright © 2018 www.massapicom. 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.