Examples of BlockadeBoardPosition


Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

            // do a breadth first search until you have spanned/visited all opponent homes.
            while (homeSet.size() < Homes.NUM_HOMES && !queue.isEmpty()) {
                // pop the next move from the head of the queue.
                DefaultMutableTreeNode node = queue.remove(0);
                BlockadeMove nodeMove = (BlockadeMove)node.getUserObject();
                BlockadeBoardPosition toPosition =
                        board.getPosition(nodeMove.getToRow(), nodeMove.getToCol());
                if (!toPosition.isVisited()) {
                    toPosition.setVisited(true);
                    MutableTreeNode parentNode = (MutableTreeNode)node.getParent();
                    node.setParent(null);
                    parentNode.insert(node, parentNode.getChildCount());
                    if (toPosition.isHomeBase(opponentIsPlayer1)) {
                        homeSet.add(node);
                    }
                    List<DefaultMutableTreeNode> children = findPathChildren(toPosition, node, opponentIsPlayer1);
                    queue.addAll(children);
                }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

     * @return either the top/north or the left/west board position
     *  depending on whether this is a vertical or horizontal wall, respectively.
     */
    public BlockadeBoardPosition getFirstPosition() {
        Iterator<BlockadeBoardPosition> it = positions_.iterator();
        BlockadeBoardPosition pos1 = it.next();
        BlockadeBoardPosition pos2 = it.next();
        if (isVertical_) {
            return (pos1.getRow() < pos2.getRow())? pos1 : pos2;
        }
        else {
            return (pos1.getCol() < pos2.getCol())? pos1 : pos2;
        }
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

        int numShortestPaths = Homes.NUM_HOMES * Homes.NUM_HOMES;
        PathList opponentPaths = new PathList();
        Set<BlockadeBoardPosition> hsPawns = new LinkedHashSet<BlockadeBoardPosition>();
        for ( int row = 1; row <= board.getNumRows(); row++ ) {
            for ( int col = 1; col <= board.getNumCols(); col++ ) {
                BlockadeBoardPosition pos = board.getPosition( row, col );
                if ( pos.isOccupied() && pos.getPiece().isOwnedByPlayer1() != player1 ) {
                    hsPawns.add(pos);
                    assert (hsPawns.size() <= Homes.NUM_HOMES) : "Error: too many opponent pieces: " + hsPawns ;
                    PathList paths = findShortestPaths(pos);
                    GameContext.log(2, "about to add " + paths.size() + " more paths to "
                            + opponentPaths.size() + " maxAllowed=" + numShortestPaths);
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

    public PlayerPathLengths findPlayerPathLengths() {
        PlayerPathLengths playerPaths = new PlayerPathLengths();

        for ( int row = 1; row <= board.getNumRows(); row++ ) {
            for ( int col = 1; col <= board.getNumCols(); col++ ) {
                BlockadeBoardPosition pos = board.getPosition( row, col );
                if ( pos.isOccupied() ) {
                    GamePiece piece = pos.getPiece();

                    // should reuse cached path if still valid.
                    PathList paths = board.findShortestPaths(pos);

                    playerPaths.getPathLengthsForPlayer(piece.isOwnedByPlayer1()).updatePathLengths(paths);
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

     */
    BlockadeWallList checkWallsForEast(BlockadeBoardPosition eastPos, BlockadeBoardPosition pos) {
        BlockadeWallList wallsToCheck = new BlockadeWallList();
        if (eastPos!=null && !pos.isEastBlocked())  {

            BlockadeBoardPosition northPos = pos.getNeighbor(Direction.NORTH, board);
            BlockadeBoardPosition southPos = pos.getNeighbor(Direction.SOUTH, board);
            BlockadeBoardPosition northEastPos = pos.getNeighbor(Direction.NORTH_EAST, board);
            if (northPos != null && !northPos.isEastBlocked()
                 && !(northPos.isSouthBlocked() && northPos.getSouthWall() == northEastPos.getSouthWall())) {
                wallsToCheck.add( new BlockadeWall(pos, northPos) );
            }
            if (southPos != null && !southPos.isEastBlocked()
                && !(pos.isSouthBlocked() && pos.getSouthWall() == eastPos.getSouthWall())) {
                wallsToCheck.add( new BlockadeWall( pos, southPos) );
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

     * Add valid wall placements to the west.
     */
    BlockadeWallList checkWallsForWest(BlockadeBoardPosition westPos, BlockadeBoardPosition pos) {
        BlockadeWallList wallsToCheck = new BlockadeWallList();
        if (westPos!=null && !westPos.isEastBlocked())  {
            BlockadeBoardPosition northPos = pos.getNeighbor(Direction.NORTH, board);
            BlockadeBoardPosition southPos = pos.getNeighbor(Direction.SOUTH, board);
            BlockadeBoardPosition northWestPos = pos.getNeighbor(Direction.NORTH_WEST, board);
            if (northPos !=  null && !northWestPos.isEastBlocked()
                && !(northWestPos.isSouthBlocked() && northWestPos.getSouthWall() == northPos.getSouthWall())) {
                wallsToCheck.add( new BlockadeWall(westPos, northWestPos) );
            }
            BlockadeBoardPosition southWestPos = pos.getNeighbor(Direction.SOUTH_WEST, board);
            if (southPos != null && !southWestPos.isEastBlocked()
                && !(westPos.isSouthBlocked() && westPos.getSouthWall() == pos.getSouthWall())) {
                wallsToCheck.add( new BlockadeWall(westPos, southWestPos) );
            }
        }
        return wallsToCheck;
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

     * Add valid wall placements to the north.
     */
    BlockadeWallList checkWallsForNorth(BlockadeBoardPosition northPos, BlockadeBoardPosition pos) {
        BlockadeWallList wallsToCheck = new BlockadeWallList();
        if (northPos!=null && !northPos.isSouthBlocked())  {
            BlockadeBoardPosition westPos = pos.getNeighbor(Direction.WEST, board);
            BlockadeBoardPosition northWestPos = pos.getNeighbor(Direction.NORTH_WEST, board);
            if (westPos != null && !northWestPos.isSouthBlocked()
                && !(westPos.isEastBlocked() && westPos.getEastWall() == northWestPos.getEastWall())) {
                wallsToCheck.add( new BlockadeWall( northPos, northWestPos) );
            }
            BlockadeBoardPosition northEastPos = pos.getNeighbor(Direction.NORTH_EAST, board);
            if (northEastPos != null && !northEastPos.isSouthBlocked()
                && !(pos.isEastBlocked() && pos.getEastWall() == northPos.getEastWall())) {
                wallsToCheck.add( new BlockadeWall(northPos, northEastPos) );
            }
        }
        return wallsToCheck;
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

     * Add valid wall placements to the south.
     */
    BlockadeWallList checkWallsForSouth(BlockadeBoardPosition southPos, BlockadeBoardPosition pos) {
        BlockadeWallList wallsToCheck = new BlockadeWallList();
        if (southPos != null && !pos.isSouthBlocked()) {
            BlockadeBoardPosition westPos = pos.getNeighbor(Direction.WEST, board);
            BlockadeBoardPosition eastPos = pos.getNeighbor(Direction.EAST, board);
            if (eastPos != null && !eastPos.isSouthBlocked()
                && !(pos.isEastBlocked() && pos.getEastWall() == southPos.getEastWall())) {
                wallsToCheck.add( new BlockadeWall(pos, eastPos) );
            }
            BlockadeBoardPosition southWestPos = pos.getNeighbor(Direction.SOUTH_WEST, board);
            if (westPos != null && !westPos.isSouthBlocked()
                && !(westPos.isEastBlocked() && westPos.getEastWall() == southWestPos.getEastWall())) {
                wallsToCheck.add( new BlockadeWall(pos, westPos) );
            }
        }
        return wallsToCheck;
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

    private boolean checkSouthOptions(boolean eastOpen, boolean southOpen) {
        if (southPos != null ) {
             Location toLocation = fromLocation.incrementOnCopy(2, 0);
             addIf2HopLegal(southOpen, southPos.isSouthBlocked(), toLocation);                  // SS

             BlockadeBoardPosition southEastPos = position.getNeighbor(Direction.SOUTH_EAST, board);
             addIfDiagonalLegal(southEastPos, eastOpen && !eastPos.isSouthBlocked(),
                                southOpen && !southPos.isEastBlocked());                        // SE
        }

        boolean westOpen = false;
        if (westPos != null)  {
            BlockadeBoardPosition southWestPos = position.getNeighbor(Direction.SOUTH_WEST, board);
            westOpen = (!westPos.isEastBlocked());                                                // W
            addIf1HopNeeded(westOpen, westPos, 0, -1);

            addIfDiagonalLegal(southWestPos, westOpen && !westPos.isSouthBlocked(),
                               southOpen && !southWestPos.isEastBlocked());                      // SW
        }
        return westOpen;
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

        }
        return westOpen;
    }

    private void checkWest(boolean westOpen) {
        BlockadeBoardPosition westWestPos = position.getNeighbor(Direction.WEST_WEST, board);
        if (westWestPos != null) {
           Location toLocation = fromLocation.incrementOnCopy(0, -2);
           addIf2HopLegal(westOpen, westWestPos.isEastBlocked(), toLocation);                    // WW
        }
    }
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.