Package com.barrybecker4.game.twoplayer.common

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


     * Initialize the board based on the SGF game.
     */
    @Override
    protected void parseSGFGameInfo( SGFGame game) {

        TwoPlayerController gc = (TwoPlayerController) controller_;

        Enumeration e = game.getInfoTokens();
        int numRows = 15; // default unless specified
        int numCols = 12; // default unless specified
        while (e.hasMoreElements()) {
            InfoToken token = (InfoToken) e.nextElement();
            if (token instanceof Size2Token) {
                Size2Token sizeToken = (Size2Token)token;
                GameContext.log(2, "info token columns =" + sizeToken.getNumColumns() +" rows=" + sizeToken.getNumRows());
                numRows = sizeToken.getNumRows();
                numCols = sizeToken.getNumColumns();
            }
            else if (token instanceof Player2NameToken) {
                Player2NameToken nameToken = (Player2NameToken) token;
                gc.getPlayers().getPlayer2().setName(nameToken.getName());
            }
            else if (token instanceof Player1NameToken) {
                Player1NameToken nameToken = (Player1NameToken) token;
                gc.getPlayers().getPlayer1().setName(nameToken.getName());
            }
        }
        ((IRectangularBoard)gc.getBoard()).setSize(numRows, numCols);
    }
View Full Code Here


        return new PlayerAssignmentPanel(get2PlayerController(), parent_);
    }

    @Override
    protected void ok() {
        TwoPlayerController c = get2PlayerController();
        IRectangularBoard board = (IRectangularBoard) board_;

        if (board != null && gridParamPanel_!= null) {
            board.setSize(gridParamPanel_.getRowSize(), gridParamPanel_.getColSize());
        }

        PlayerList players = c.getPlayers();
        if (optimizationCheckbox_.isSelected())
        {
            players.getPlayer1().setHuman(false);
            players.getPlayer2().setHuman(false);
            c.getTwoPlayerOptions().setAutoOptimize(true);
        }
        else {
            playersPanel_.ok();
        }
        if (board != null && gridParamPanel_ != null) {
View Full Code Here

     * Initialize the board based on the SGF game.
     */
    @Override
    protected void parseSGFGameInfo( SGFGame game) {

        TwoPlayerController gc = (TwoPlayerController) controller_;
        PlayerList players = gc.getPlayers();

        Enumeration e = game.getInfoTokens();
        int size = 13; // default unless specified
        while (e.hasMoreElements()) {
            InfoToken token = (InfoToken) e.nextElement();
            if (token instanceof SizeToken) {
                SizeToken sizeToken = (SizeToken)token;
                size = sizeToken.getSize();
            }
            else if (token instanceof KomiToken) {
                KomiToken komiToken = (KomiToken) token;
                ((GoOptions)gc.getOptions()).setKomi(komiToken.getKomi());
            }
            // so we don't guess wrong on where the handicap positions are
            // we will rely on their being an AB (add black) command to specifically tell where the handicap stones are
            /*else if (token instanceof HandicapToken) {
                HandicapToken handicapToken = (HandicapToken) token;
                GameContext.log(2,"***handicap ="+handicapToken.getHandicap());
                this.setHandicap(handicapToken.getHandicap());
            }*/
            else if (token instanceof WhiteNameToken) {
                WhiteNameToken nameToken = (WhiteNameToken) token;
                players.getPlayer2().setName(nameToken.getName());
            }
            else if (token instanceof BlackNameToken) {
                BlackNameToken nameToken = (BlackNameToken) token;
                players.getPlayer1().setName(nameToken.getName());
            }
            else if (token instanceof RuleSetToken) {
                //RuleSetToken ruleToken = (RuleSetToken) token;
                //this.setRuleSet(ruleToken.getKomi());
            }
            else {
                GameContext.log(1, "Ignoring  token =" + token.getClass().getName() + " while parsing.");
            }
        }
        ((IRectangularBoard)gc.getBoard()).setSize(size, size);
    }
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.common.TwoPlayerController

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.