Package com.barrybecker4.game.twoplayer.blockade.board

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


     * 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

    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

        }
        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

    }

    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

     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

      * 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

                   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

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

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

TOP

Related Classes of com.barrybecker4.game.twoplayer.blockade.board.BlockadeBoardPosition

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.