Examples of BoardPosition


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

        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

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

        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

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

    @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

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

        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

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

        if ( getRenderer().getDraggedPiece() == null )
            return; // nothing being dragged

        Board board = (Board)controller.getBoard();
        // get the original position.
        BoardPosition position = board.getPosition( getRenderer().getDraggedPiece().getLocation());

        // valid or not, we won't show the dragged piece after releasing the mouse
        getRenderer().setDraggedPiece(null);

        BoardPosition destp = board.getPosition( loc );
        if (customCheckFails(position, destp)) {
            invalidMove();
            return;
        }

        List possibleMoveList = getPossibleMoveList(position);

        // verify that the move is valid before allowing it to be made
        Iterator it = possibleMoveList.iterator();
        boolean found = false;

        TwoPlayerMove move = null;
        while ( it.hasNext() && !found ) {
            move = (TwoPlayerMove) it.next();
            if ( (move.getToRow() == destp.getRow()) && (move.getToCol() == destp.getCol()) )
                found = true;
        }

        if ( !found ) {
            invalidMove();
View Full Code Here

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

        int row, col;
        ChessBoard b = (ChessBoard)controller_.getBoard();
        boolean checked = false;
        for ( row = 1; row <= b.getNumRows(); row++ ) {
            for ( col = 1; col <= b.getNumCols(); col++ ) {
                BoardPosition pos = b.getPosition( row, col );
                assert (pos != null) : "pos at row="+row+" col="+col +" is null";
                if ( pos.isOccupied() && pos.getPiece().isOwnedByPlayer1() == m.isPlayer1() ) {
                    // @@ second arg is not technically correct. it should be last move, but I don't think it matters.
                    checked = b.isKingCheckedByPosition(pos, m);
                }
                if (checked) {
                    JOptionPane.showMessageDialog( this,
View Full Code Here

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

    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( loc );
            sb.append("<br>");
            sb.append(space.toString());
        }
        sb.append( "</font></html>" );
        return sb.toString();
    }
View Full Code Here

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

        assert (move.getPiece() != null) : "piece for next move is null: " + move;

        g2.setColor(getPieceColor(move.getPiece()));

        BoardPosition position = b.getPosition(move.getToRow(), move.getToCol());
        int pieceSize = (int)(NEXT_MOVE_SIZE_FRAC * getPieceSize(cellSize, move.getPiece()));
        Point pos = getPosition(position, cellSize, pieceSize, margin);
        g2.setFont(BASE_FONT);
        g2.fillOval( pos.x, pos.y, pieceSize, pieceSize );
        g2.setColor(move.isUrgent() ? URGENT_COLOR : Color.DARK_GRAY);
View Full Code Here

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

    @Override
    protected boolean makeInternalMove( Move move ) {

        TwoPlayerMove m = (TwoPlayerMove)move;
        if ( !m.isPassOrResignation() ) {
            BoardPosition pos = getPosition(m.getToLocation());
            assert(m.getPiece() != null) : "move's piece was null :" + m;
            pos.setPiece(m.getPiece());
            GamePiece piece = pos.getPiece();
            assert (piece != null):
                    "The piece was " + piece + ". Moved to " + m.getToRow() + ", " + m.getToCol();
            if ( GameContext.getDebugMode() > 0 ) {
                piece.setAnnotation( Integer.toString(getMoveList().getNumMoves()) );
            }
View Full Code Here

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

        TwoPlayerMove m = (TwoPlayerMove) getMoveList().getLastMove();

        for ( int i = 1; i <= nRows; i++ )   {
            boolean followingLastMove = false;
            for ( int j = 1; j <= nCols; j++ ) {
                BoardPosition pos = this.getPosition(i,j);
                if (pos.isOccupied()) {
                    if (pos.getLocation().equals(m.getToLocation())) {
                        bldr.append("[").append(pos.getPiece()).append("]");
                        followingLastMove = true;
                    }
                    else  {
                        bldr.append(followingLastMove?"":" ").append(pos.getPiece());
                        followingLastMove = false;
                    }
                }
                else {
                    bldr.append(followingLastMove?"":" " + "_");
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.