Examples of BlockadeBoardPosition


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

    }

    private void checkNorthOptions(boolean eastOpen, boolean westOpen) {
        boolean northOpen = false;
        if (northPos != null) {
            BlockadeBoardPosition northEastPos = position.getNeighbor(Direction.NORTH_EAST, board);
            northOpen = (!northPos.isSouthBlocked()) ;                                             // N
            addIf1HopNeeded(northOpen, northPos, -1, 0);
            addIfDiagonalLegal(northEastPos, eastOpen && !northEastPos.isSouthBlocked(),
                                northOpen && !northPos.isEastBlocked());                          // NE
        }

        BlockadeBoardPosition northNorthPos = position.getNeighbor(Direction.NORTH_NORTH, board);
        if (northNorthPos != null) {
            Location toLocation = fromLocation.incrementOnCopy(-2, 0);
            addIf2HopLegal(northOpen, northNorthPos.isSouthBlocked(), toLocation);                 // NN
        }

        BlockadeBoardPosition northWestPos = position.getNeighbor(Direction.NORTH_WEST, board);
        if (northWestPos != null) {
            addIfDiagonalLegal(northWestPos, westOpen && !northWestPos.isSouthBlocked(),
                              northOpen && !northWestPos.isEastBlocked());                      // NW
        }
    }
View Full Code Here

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

     private void addIf1HopNeeded(boolean directionOpen, BlockadeBoardPosition dirPosition,
                                  int rowOffset, int colOffset) {

         int fromRow = fromLocation.getRow();
         int fromCol = fromLocation.getCol();
         BlockadeBoardPosition dirDirPosition =
                 board.getPosition(fromRow + 2 * rowOffset, fromCol + 2 * colOffset);
         // if either the players own pawn or that of the opponent is blocking the path, then true
         boolean pawnBlockingPath =
                 (dirDirPosition!=null && dirDirPosition.getPiece()!=null );
         if (directionOpen && !dirPosition.isVisited() &&
                  (pawnBlockingPath || dirPosition.isHomeBase(opponentPlayer1))) {
              possibleMoveList.add(
                      BlockadeMove.createMove(new ByteLocation(fromRow, fromCol),
                              new ByteLocation(fromRow + rowOffset, fromCol + colOffset),
View Full Code Here

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

      * Check for 2 space moves (4 cases).
      */
     private void addIf2HopLegal(boolean directionOpen, boolean blocked,
                                 Location toLocation) {

         BlockadeBoardPosition dirDirPosition = board.getPosition(toLocation);
         if (directionOpen && (dirDirPosition != null) && !blocked
              && (dirDirPosition.isUnoccupied() || dirDirPosition.isHomeBase(opponentPlayer1))
              && !dirDirPosition.isVisited()) { //DD
               possibleMoveList.add(
                       BlockadeMove.createMove(fromLocation, toLocation, 0, position.getPiece(), null));
         }
     }
View Full Code Here

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

                   BlockadeMove.createMove(fromLocation, diagonalPos.getLocation(), 0, position.getPiece(), null));
          }
          else if (diagonalPos.isOccupied()) {
              // if the diagonal position that we want to move to is occupied, we try to add the 1 space moves

              BlockadeBoardPosition horzPos =
                      board.getPosition(fromLocation.getRow(), diagonalPos.getCol());
              BlockadeBoardPosition vertPos =
                      board.getPosition(diagonalPos.getRow(), fromLocation.getCol());

              if (horizontalPathOpen && horzPos.isUnoccupied() && !horzPos.isVisited()) {
                   possibleMoveList.add(
                          BlockadeMove.createMove(fromLocation, horzPos.getLocation(), 0, position.getPiece(), null));
              }
              if (verticalPathOpen && vertPos.isUnoccupied() && !vertPos.isVisited()) {
                   possibleMoveList.add(
                          BlockadeMove.createMove(fromLocation, vertPos.getLocation(), 0, position.getPiece(), null));
              }
          }
     }
View Full Code Here

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

     */
    BlockadeWallList checkAddWallsForDirection(BlockadeBoardPosition pos, PathList paths,
                                                         Direction direction) {
        BlockadeBoard b = board;
        BlockadeWallList wallsToCheck = new BlockadeWallList();
        BlockadeBoardPosition westPos = pos.getNeighbor(Direction.WEST, b);
        BlockadeBoardPosition eastPos = pos.getNeighbor(Direction.EAST, b);
        BlockadeBoardPosition northPos = pos.getNeighbor(Direction.NORTH, b);
        BlockadeBoardPosition southPos = pos.getNeighbor(Direction.SOUTH, b);
        StraightWallChecker straightChecker = new StraightWallChecker(b);
        DiagonalWallChecker diagonalChecker = new DiagonalWallChecker(b);

        switch (direction) {
            case EAST :
                wallsToCheck = straightChecker.checkWallsForEast(eastPos, pos);
                break;
            case WEST :
                wallsToCheck = straightChecker.checkWallsForWest(westPos, pos);
                break;
            case NORTH :
                wallsToCheck = straightChecker.checkWallsForNorth(northPos, pos);
                break;
            case SOUTH :
                wallsToCheck = straightChecker.checkWallsForSouth(southPos, pos);
                break;
            // There are 4 basic cases for all the diagonals.
            case NORTH_WEST :
                 BlockadeBoardPosition northWestPos = pos.getNeighbor(Direction.NORTH_WEST, b);
                 wallsToCheck = diagonalChecker.checkWalls(northWestPos, northPos, westPos);
                 break;
            case NORTH_EAST :
                 BlockadeBoardPosition northEastPos = pos.getNeighbor(Direction.NORTH_EAST, b);
                 wallsToCheck = diagonalChecker.checkWalls(northPos, northEastPos, pos);
                 break;
            case SOUTH_WEST :
                 BlockadeBoardPosition southWestPos = pos.getNeighbor(Direction.SOUTH_WEST, b);
                 wallsToCheck = diagonalChecker.checkWalls(westPos, pos, southWestPos);
                 break;
            case SOUTH_EAST :
                 wallsToCheck = diagonalChecker.checkWalls(pos, eastPos, southPos);
                 break;
View Full Code Here

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

        // 12 cases
        int fromRow = move.getFromRow();
        int fromCol = move.getFromCol();
        BlockadeBoard b = board_;
        BlockadeBoardPosition origPos = board_.getPosition(fromRow, fromCol);
        BlockadeBoardPosition westPos = origPos.getNeighbor(Direction.WEST, b);
        BlockadeBoardPosition eastPos = origPos.getNeighbor(Direction.EAST, b);
        BlockadeBoardPosition northPos = origPos.getNeighbor(Direction.NORTH, b);
        BlockadeBoardPosition southPos = origPos.getNeighbor(Direction.SOUTH, b);
        switch (move.getDirection()) {
            case EAST_EAST :
                accumulator.checkAddWallsForDirection(eastPos, friendlyPaths, Direction.EAST);
            case EAST :
                accumulator.checkAddWallsForDirection(origPos, friendlyPaths, Direction.EAST);
View Full Code Here

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

     * @param pos one of the 3 base positions
     * @return list of accumulated walls to check.
     */
    private BlockadeWallList handleDirectionCase(BlockadeBoardPosition pos, int rowOffset, int colOffset,
                                                          BlockadeWallList wallsToCheck) {
        BlockadeBoardPosition offsetPos =
                    board.getPosition(pos.getRow() + rowOffset, pos.getCol() + colOffset);
        boolean isVertical = (rowOffset != 0);

        if (offsetPos != null) {
            boolean dirOpen = isVertical? offsetPos.isEastOpen() : offsetPos.isSouthOpen();
            if (dirOpen) {
                wallsToCheck.add( new BlockadeWall(pos, offsetPos));
            }
        }
        return wallsToCheck;
View Full Code Here

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

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

        BlockadeBoardPosition space = ((BlockadeBoard)controller_.getBoard()).getPosition( loc );
        if ( space != null && GameContext.getDebugMode() > 0 ) {
            sb.append(space.toString());
            sb.append(space.isVisited()?":Visited":"");
            sb.append((space.isHomeBase()?(space.isHomeBase(true)?" P1 Home":"p2 Home"):""));
        }
        sb.append( "</font></html>" );
        return sb.toString();
    }
View Full Code Here

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

         BlockadeMoveToken mvToken = (BlockadeMoveToken) token;

         boolean player1 = token instanceof Player1BlockadeMoveToken;
         BlockadeWall wall = null;
         if (mvToken.hasWall())
             wall = new BlockadeWall(new BlockadeBoardPosition(mvToken.getWallPoint1().y, mvToken.getWallPoint1().x),
                                                       new BlockadeBoardPosition(mvToken.getWallPoint2().y, mvToken.getWallPoint2().x));

         return BlockadeMove.createMove(new ByteLocation(mvToken.getFromY(), mvToken.getFromX()),
                 new ByteLocation(mvToken.getToY(), mvToken.getToX()),
                 0, new GamePiece(player1), wall);
    }
View Full Code Here

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

        }

        BlockadeController controller = (BlockadeController)viewer_.getController();
        BlockadeBoard board = (BlockadeBoard) controller.getBoard();
        // get the original position.
        BlockadeBoardPosition position =
                board.getPosition(getRenderer().getDraggedPiece().getLocation());

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

        BlockadeMove m = checkAndGetValidMove(position, loc);
        if (m == null) {
            return false;
        }

        // make sure that the piece shows while we decide where to place the wall.
        currentMove = m;
        GameContext.log(1, "legal human move :" + m.toString());
        position.getPiece().setTransparency((short) 0);
        boolean isPlayer1 = position.getPiece().isOwnedByPlayer1();
        BlockadeBoardPosition newPosition =
                board.getPosition(currentMove.getToRow(), currentMove.getToCol());
        newPosition.setPiece(position.getPiece());
        position.setPiece(null);
        viewer_.refresh();

        if (newPosition.isHomeBase( !isPlayer1 )) {
            hasWon = true;
            assert(isPlayer1 == (controller.getCurrentPlayer() == controller.getPlayers().getFirstPlayer()));
            controller.getCurrentPlayer().setWon(true);
        }
        else {
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.