Examples of BlockadeMove


Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

                                          ParameterArray weights, List<BlockadeMove> moves) {
        int value = 0;
        // @@ we should provide the value here since we have all the path info.
        // we do not want to compute the path info again by calling findPlayerPathLengths.
        // The value will change based on how much we shorten our paths while lengthening the opponents.
        BlockadeMove m =
               BlockadeMove.createMove(ourmove.getFromLocation(),
                                       ourmove.getToLocation(),
                                       value, ourmove.getPiece(), wall);
        // for the time being just call worth directly. Its less efficient, but simpler.
        board.makeMove(m);
        PlayerPathLengths pathLengths = board.findPlayerPathLengths();
        board.undoMove();

        if (pathLengths.isValid()) {
            m.setValue(pathLengths.determineWorth(SearchStrategy.WINNING_VALUE, weights));
            moves.add(m);
        }
        else {
            GameContext.log(2, "Did not add "+ m+ " because it was invalid.");
        }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

            // 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());
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

     * return the SGF (4) representation of the move
     * SGF stands for Smart Game Format and is commonly used for Go
     */
    @Override
    protected String getSgfForMove(Move move) {
        BlockadeMove m = (BlockadeMove) move;
        // passes are not represented in SGF - so just skip it if the piece is null.
        if (m.getPiece() == null)
             return "[]";
        StringBuilder buf = new StringBuilder("");
        String player = "P2";
        if ( m.getPiece().isOwnedByPlayer1() )
        {
            player = "P1";
        }
        buf.append( ';' );
        buf.append( player );
         buf.append( '[' );
        buf.append( (char) ('a' + m.getFromCol() - 1) );
        buf.append( (char) ('a' + m.getFromRow() - 1) );
        buf.append( ']' );
        buf.append( '[' );
        buf.append( (char) ('a' + m.getToCol() - 1) );
        buf.append( (char) ('a' + m.getToRow() - 1) );
        buf.append( ']' );
        // also print the wall placement if there is one
        if (m.getWall() != null) {
            buf.append("wall");
            for (BlockadeBoardPosition pos : m.getWall().getPositions()) {
                serializePosition(pos.getLocation(), buf);
            }
        }
        else {
            buf.append("nowall");
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

                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());
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

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

        BlockadeMove m = null;
        while ( it.hasNext() && !found ) {
            m = (BlockadeMove) it.next();
            if ( (m.getToRow() == destpos.getRow()) && (m.getToCol() == destpos.getCol()) )
                found = true;
        }

        if ( !found ) {
            return null; // it was not valid
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

     *   A big negative value means a good move for p2.
     */
    @Override
    public int worth( TwoPlayerMove lastMove, ParameterArray weights ) {
        getProfiler().startCalcWorth();
        BlockadeMove m = (BlockadeMove)lastMove;
        // if its a winning move then return the winning value
        boolean player1Moved = m.isPlayer1();

        if (checkForWin(player1Moved)) {
            GameContext.log(1, "FOUND WIN!!!");
            return player1Moved ? SearchStrategy.WINNING_VALUE : -SearchStrategy.WINNING_VALUE;
        }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

     * @return true if the move was made successfully
     */
    @Override
    protected boolean makeInternalMove( Move move ) {
        getProfiler().startMakeMove();
        BlockadeMove m = (BlockadeMove) move;
        BlockadeBoardPosition toPos = getPosition(m.getToLocation());
        // in the rare event that we capture an opponent on his base, remember it so it can be undone.
        if (toPos.isOccupiedHomeBase(!m.isPlayer1())) {
            m.capturedOpponentPawn = toPos.getPiece();
        }
        toPos.setPiece(m.getPiece());

        // we also need to place a wall.
        if (m.getWall() != null) {
            addWall(m.getWall());
        }
        getPosition(m.getFromRow(), m.getFromCol()).clear();
        getProfiler().stopMakeMove();
        return true;
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

     * It can only happen on the final winning move.
     */
    @Override
    protected void undoInternalMove( Move move ) {
        getProfiler().startUndoMove();
        BlockadeMove m = (BlockadeMove) move;
        BoardPosition startPos = getPosition(m.getFromRow(), m.getFromCol());
        startPos.setPiece( m.getPiece() );
        BlockadeBoardPosition toPos = getPosition(m.getToLocation());
        toPos.clear();
        if (m.capturedOpponentPawn != null) {
            toPos.setPiece(m.capturedOpponentPawn);
            m.capturedOpponentPawn = null;
        }

        // remove the wall that was placed by this move.
        if (m.getWall() != null) {
            removeWall(m.getWall());
        }
        getProfiler().stopUndoMove();
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

        Iterator it = path.iterator();
        int len = path.getLength() + 1;
        int x[] = new int[len];
        int y[] = new int[len];
        int ct = 0;
        BlockadeMove m = null;
        float offset = 0;
        while (it.hasNext()) {
            m = (BlockadeMove)it.next();
            offset = (m.isPlayer1() ?  PLAYER1_PATH_OFFSET :  PLAYER2_PATH_OFFSET) ;
            x[ct] = calcPosition(m.getFromCol(), offset, cellSize);
            y[ct] = calcPosition(m.getFromRow(), offset, cellSize);
            ct++;
        }
        if (m != null) {
            x[ct] = calcPosition(m.getToCol(), offset, cellSize);
            y[ct] = calcPosition(m.getToRow(), offset, cellSize);
            ct++;
            g2.drawPolyline(x, y , ct);
            int diameter = (int)(cellSize * POINT_WIDTH_RATIO);
            int radius = diameter / 2;
            for (int i=0; i < ct; i++) {
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.