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

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


     * 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

        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

        ParameterArray initialGuess = new TantrixPath(board);
        assert(initialGuess.size() > 0) : "The random path should have some tiles!";
        long startTime = System.currentTimeMillis();

        Optimizer optimizer = new Optimizer(this);
        optimizer.setListener(this);

        ParameterArray solution =
            optimizer.doOptimization(strategy, initialGuess, SOLVED_THRESH);

        solution_ =
            new TantrixBoard(((TantrixPath)solution).getTilePlacements(), board.getPrimaryColor());

        TilePlacementList moves;
View Full Code Here

     * @return list of moves to a solution.
     */
    @Override
    public TilePlacementList solve()  {

        ParameterArray initialGuess = new TantrixPath(board);
        assert(initialGuess.size() > 0) : "The random path should have some tiles!";
        long startTime = System.currentTimeMillis();

        Optimizer optimizer = new Optimizer(this);
        optimizer.setListener(this);

        ParameterArray solution =
            optimizer.doOptimization(strategy, initialGuess, SOLVED_THRESH);

        solution_ =
            new TantrixBoard(((TantrixPath)solution).getTilePlacements(), board.getPrimaryColor());

View Full Code Here

     * Draw one of the tile paths which takes one of three forms.
     */
    public void drawPath(Graphics2D g2, int pathNumber, TilePlacement tilePlacement,
                         Point position, double size) {

        HexTile tile = tilePlacement.getTile();
        int pathStartIndex = getPathStartIndex(tile, pathNumber);

        int i = pathStartIndex + 1;

        PathColor pathColor = tile.getEdgeColor(pathStartIndex);
        while (pathColor != tile.getEdgeColor(i++)) {
            assert(i<6): "Should never exceed 6";
        }

        int pathEndIndex = i-1;
        int diff = pathEndIndex - pathStartIndex;
View Full Code Here

        this.numTiles = numTiles;
    }

    public TantrixBoard initialPosition() {
        //MathUtil.RANDOM.setSeed(1);
        return new TantrixBoard(new HexTiles().createRandomList(numTiles));
    }
View Full Code Here

    public boolean isGoal(TantrixBoard position) {
        return position.isSolved();
    }

    public TilePlacementList legalMoves(TantrixBoard position) {
        return new MoveGenerator(position).generateMoves();
    }
View Full Code Here

        HexTile tile = tilePlacement.getTile();
        int pathStartIndex = getPathStartIndex(tile, pathNumber);

        int i = pathStartIndex + 1;

        PathColor pathColor = tile.getEdgeColor(pathStartIndex);
        while (pathColor != tile.getEdgeColor(i++)) {
            assert(i<6): "Should never exceed 6";
        }

        int pathEndIndex = i-1;
View Full Code Here

     */
    private int getPathStartIndex(HexTile tile, int pathNumber) {
        Set<PathColor> set = new HashSet<PathColor>();
        int i = 0;
        do {
            PathColor c = tile.getEdgeColor(i++);
            set.add(c);
        } while (set.size() <= pathNumber);
        return i-1;
    }
View Full Code Here

TOP

Related Classes of com.barrybecker4.game.twoplayer.blockade.board.move.BlockadeMove

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.