Examples of TwoPlayerMove


Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

    public boolean done( TwoPlayerMove move, boolean recordWin ) {

        if (move == null)  {
            // for checkers this means that the other player won.
            if (recordWin)  {
                TwoPlayerMove lastMove = (TwoPlayerMove) getMoveList().getLastMove();
                recordPlayerWin(lastMove.isPlayer1());
            }
            return true;
        }

        boolean won = (Math.abs( move.getValue() ) >= SearchStrategy.WINNING_VALUE);
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

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

        TwoPlayerMove move = null;
        while ( it.hasNext() && !found ) {
            move = (TwoPlayerMove) it.next();
            if ( (move.getToRow() == destp.getRow()) && (move.getToCol() == destp.getCol()) )
                found = true;
        }

        if ( !found ) {
            invalidMove();
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

    protected List getPossibleMoveList(BoardPosition position) {

        CheckersBoardViewer viewer = (CheckersBoardViewer)viewer_;
        CheckersController controller = (CheckersController)viewer.getController();

        TwoPlayerMove lastMove = (TwoPlayerMove)controller.getLastMove();
        MoveGenerator generator =
                new MoveGenerator((CheckersSearchable)controller.getSearchable(),
                                  controller.getComputerWeights().getDefaultWeights());

        MoveList possibleMoveList = new MoveList();
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

     * @param moveSequence the sequence of consecutive moves to play on the board.
     */
    private synchronized void performMoveSequence(List moveSequence) {
        int firstFuture = 0;
        for ( int i = 0; i < moveSequence.size(); i++ ) {
            TwoPlayerMove m =  (TwoPlayerMove) moveSequence.get( i );
            if (m.isFuture()) {
                if (firstFuture == 0) {
                    firstFuture = i;
                }
                m.getPiece().setAnnotation(Integer.toString(i - firstFuture + 1));
                m.getPiece().setTransparency(FUTURE_MOVE_TRANSP);
            }
            controller_.makeMove(m);
        }
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

    /**
     * Draw a line/arc connecting a parent and child node.
     */
    private synchronized void drawArc( SearchTreeNode parent, SearchTreeNode child,
                                       int depth, int offset1, int offset2, Graphics2D g2) {
        TwoPlayerMove m = (TwoPlayerMove)child.getUserObject();
        boolean highlighted = m.isSelected() && ((TwoPlayerMove)parent.getUserObject()).isSelected();
        if (highlighted)
            g2.setStroke(HIGHLIGHT_STROKE);
        g2.setColor( colormap_.getColorForValue(m.getInheritedValue()));
        g2.drawLine(MARGIN + (int) (width_*(offset1 + parent.getSpaceAllocation() / 2.0) / totalAtLevel_[depth]),
                    MARGIN + depth*levelHeight_,
                    MARGIN + (int) (width_*(offset2 + child.getSpaceAllocation() / 2.0) / totalAtLevel_[depth+1]),
                    MARGIN + (depth+1)*levelHeight_);
        if (highlighted) {
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

    @Override
    protected TwoPlayerMove findBestMove(TwoPlayerMove lastMove, int depth, MoveList list,
                                         SearchWindow window, SearchTreeNode parent) {
        int i = 0;
        int newBeta = window.beta;
        TwoPlayerMove selectedMove;
        TwoPlayerMove bestMove = (TwoPlayerMove)list.getFirstMove();

        while ( !list.isEmpty() ) {
            TwoPlayerMove theMove = getNextMove(list);
            if (pauseInterrupted())
                return lastMove;
            updatePercentDone(depth, list);

            searchable.makeInternalMove( theMove );
            SearchTreeNode child = addNodeToTree(parent, theMove, window );

            // search with minimal search window
            selectedMove = searchInternal( theMove, depth-1, new SearchWindow(-newBeta, -window.alpha), child);
            searchable.undoInternalMove( theMove );

            if (selectedMove != null) {

                int selectedValue = -selectedMove.getInheritedValue();
                theMove.setInheritedValue( selectedValue );

                if (selectedValue > window.alpha) {
                    window.alpha = selectedValue;
                }
                if (window.alpha >= window.beta) {      // beta cut-off
                    //System.out.println(getIndent(depth) + "beta cut-off1 because a=" + window.alpha + " >= " + window.beta);
                    theMove.setInheritedValue(window.alpha);
                    bestMove = theMove;
                    break;
                }
                if (window.alpha >= newBeta) {
                    // re-search with narrower window (typical alpha beta search).
                    searchable.makeInternalMove( theMove );
                    selectedMove = searchInternal( theMove, depth-1, window.negateAndSwap(), child );
                    if (selectedMove != null)  {
                        searchable.undoInternalMove( theMove );

                        selectedValue = -selectedMove.getInheritedValue();
                        theMove.setInheritedValue(selectedValue);
                        bestMove = theMove;

                        if (window.alpha >= window.beta) {
                            showPrunedNodesInTree(list, parent, i, selectedValue, window);
                            break;
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

            return entry.bestMove;

        boolean done = searchable.done( lastMove, false);
        if ( depth <= 0 || done ) {
            if (doQuiescentSearch(depth, done, lastMove))  {
                TwoPlayerMove qMove = quiescentSearch(lastMove, depth, window, parent);
                if (qMove != null)  {
                    entry = new Entry(qMove, qMove.getInheritedValue());
                    lookupTable.put(key, entry);
                    return qMove;
                }
            }
            int sign = fromPlayer1sPerspective(lastMove) ? 1 : -1;
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

    @Override
    protected TwoPlayerMove findBestMove(TwoPlayerMove lastMove,int depth,  MoveList list,
                                         SearchWindow window, SearchTreeNode parent) {
        int i = 0;
        int newBeta = window.beta;
        TwoPlayerMove selectedMove;

        TwoPlayerMove bestMove = (TwoPlayerMove) list.get(0);
        Entry entry = new Entry(bestMove, depth, window);

        while ( !list.isEmpty() ) {
            TwoPlayerMove theMove = getNextMove(list);
            if (pauseInterrupted())
                return lastMove;
            updatePercentDone(depth, list);

            searchable.makeInternalMove( theMove );
            SearchTreeNode child = addNodeToTree(parent, theMove, window );

            // search with minimal search window
            selectedMove = searchInternal( theMove, depth-1, new SearchWindow(-newBeta, -window.alpha), child );

            searchable.undoInternalMove( theMove );
            if (selectedMove != null) {

                int selectedValue = -selectedMove.getInheritedValue();
                theMove.setInheritedValue( selectedValue );

                if (selectedValue > window.alpha) {
                    window.alpha = selectedValue;
                }
                if (window.alpha >= window.beta) {
                    theMove.setInheritedValue(window.alpha);
                    bestMove = theMove;
                    break;
                }
                if (window.alpha >= newBeta) {
                    // re-search with narrower window (typical alpha beta search).
                    searchable.makeInternalMove( theMove );
                    selectedMove = searchInternal( theMove, depth-1, window.negateAndSwap(), child );
                    searchable.undoInternalMove( theMove );

                    selectedValue = -selectedMove.getInheritedValue();
                    theMove.setInheritedValue(selectedValue);
                    bestMove = theMove;

                    if (window.alpha >= window.beta) {
                        break;
                    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

        entry = new Entry(lastMove, depth, new SearchWindow(-INFINITY, INFINITY));

        boolean done = searchable.done( lastMove, false);
        if ( depth <= 0 || done ) {
            if (doQuiescentSearch(depth, done, lastMove))  {
                TwoPlayerMove qMove = quiescentSearch(lastMove, depth, window, parent);
                if (qMove != null)  {
                    entry = new Entry(qMove, qMove.getInheritedValue());
                    lookupTable.put(key, entry);
                    return qMove;
                }
            }
            int sign = fromPlayer1sPerspective(lastMove) ? 1 : -1;
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

    @Override
    protected TwoPlayerMove findBestMove(TwoPlayerMove lastMove, int depth, MoveList list,
                                         SearchWindow window, SearchTreeNode parent) {
        int i = 0;
        int bestInheritedValue = -INFINITY;
        TwoPlayerMove selectedMove;

        TwoPlayerMove bestMove = (TwoPlayerMove)list.get(0);
        Entry entry = new Entry(bestMove, depth, window);

        while ( !list.isEmpty() ) {
            TwoPlayerMove theMove = getNextMove(list);
            if (pauseInterrupted())
                return lastMove;
            updatePercentDone(depth, list);

            searchable.makeInternalMove( theMove );
            SearchTreeNode child = addNodeToTree(parent, theMove, window); i++;

            selectedMove = searchInternal( theMove, depth-1, window.negateAndSwap(), child );

            searchable.undoInternalMove( theMove );

            if (selectedMove != null) {

                int selectedValue = -selectedMove.getInheritedValue();
                theMove.setInheritedValue( selectedValue );

                if ( selectedValue > bestInheritedValue ) {
                    bestMove = theMove;
                    entry.bestMove = theMove;
                    bestInheritedValue = selectedValue;
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.