Package com.barrybecker4.game.twoplayer.common

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


        GamePlugin plugin = PluginManager.getInstance().getPlugin(gameName);
        GameContext.loadResources(gameName);

        // for now, also create a corresponding viewer. The server should really not have knowledge of a UI component.
        // fix this by doing plugin.getModelInstance, then getting the controller from that.
        GamePanel panel  = plugin.getPanelInstance();
        panel.init(null);
        GameBoardViewer viewer = panel.getViewer();

        controller_ = viewer.getController();
    }
View Full Code Here


        // for now, also create a corresponding viewer. The server should really not have knowledge of a UI component.
        // fix this by doing plugin.getModelInstance, then getting the controller from that.
        GamePanel panel  = plugin.getPanelInstance();
        panel.init(null);
        GameBoardViewer viewer = panel.getViewer();

        controller_ = viewer.getController();
    }
View Full Code Here

    void ok() {
        GameContext.setDebugMode( dbgLevelField_.getIntValue() );
        GameContext.setProfiling( profileCheckbox_.isSelected() );
        GameContext.getLogger().setDestination( logDestination_ );

        GameBoardViewer v = ((GameBoardViewer)controller_.getViewer());
        v.setBackground( boardColorButton_.getBackground() );
        v.setGridColor( gridColorButton_.getBackground() );

        LocaleType[] locales = LocaleType.values();
        GameContext.setLocale(locales[localeComboBox_.getSelectedIndex()]);

        // game specific options
View Full Code Here

    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

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

    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

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

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

    @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

            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

TOP

Related Classes of com.barrybecker4.game.twoplayer.common.TwoPlayerMove

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.