Examples of GoStringSet


Examples of com.barrybecker4.game.twoplayer.go.board.elements.string.GoStringSet

        GoBoardPosition pos = (GoBoardPosition)board.getPosition( getToRow(), getToCol() );
        NeighborAnalyzer na = new NeighborAnalyzer(board);
        GoBoardPositionSet enemyNbrs = na.getNobiNeighbors( pos, NeighborType.ENEMY );
        Iterator it = enemyNbrs.iterator();
        int numInAtari = 0;
        GoStringSet stringSet = new GoStringSet();
        while ( it.hasNext() ) {
            GoBoardPosition s = (GoBoardPosition) it.next();
            IGoString atariedString = s.getString();
            if (!stringSet.contains(atariedString) && atariedString.getNumLiberties(board) == 1 ) {
                numInAtari += atariedString.size();
            }
            stringSet.add(atariedString); // once its in the set we won't check it again.
        }
        return numInAtari;
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.go.board.elements.string.GoStringSet

        profiler_.startFindCaptures();
        assert ( stone != null );
        GoBoardPositionSet nbrs = nbrAnalyzer_.getNobiNeighbors( stone, NeighborType.ENEMY );
        GoCaptureList captureList = new GoCaptureList();
        // keep track of the strings captured so we don't capture the same one twice
        GoStringSet capturedStrings = new GoStringSet();

        for (GoBoardPosition enbr : nbrs) {

            assert (enbr.isOccupied()): "enbr=" + enbr;

            IGoString str = enbr.getString();
            assert ( str.isOwnedByPlayer1() != stone.getPiece().isOwnedByPlayer1()):
                    "The "+str+" is not an enemy of "+stone;
            assert ( str.size() > 0 ) : "Sting has 0 stones:" + str;

            if ( str.getNumLiberties(getBoard()) == 0 && !capturedStrings.contains(str) ) {
                capturedStrings.add( str );
                // we need to add copies so that when the original stones on the board are
                // changed we don't change the captures.
                captureList.addCaptures(str.getMembers());
            }
        }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.go.board.elements.string.GoStringSet

     * @param liberty either occupied or not depending on if we are placing the stone or removing it.
     */
    public void adjustLiberties(GoBoardPosition liberty) {

         NeighborAnalyzer na = new NeighborAnalyzer(this);
         GoStringSet stringNbrs = na.findStringNeighbors( liberty );
         for (IGoString sn : stringNbrs) {
            ((GoString)sn).changedLiberty(liberty);
         }
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.go.board.elements.string.GoStringSet

    /**
     * Must be ordered (i.e. LinkedHashSet
     */
    @Override
    protected void initializeMembers() {
        members_ = new GoStringSet();
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.go.board.elements.string.GoStringSet

    /**
     * @param stone stone to find string neighbors for.
     * @return list of string neighbors of specified position.
     */
    GoStringSet findStringNeighbors(GoBoardPosition stone) {
        GoStringSet stringNbrs = new GoStringSet();
        GoBoardPositionList nobiNbrs = new GoBoardPositionList();

        pushStringNeighbors(stone, true, nobiNbrs, false);

        // add strings only once
        for (GoBoardPosition nbr : nobiNbrs) {
            stringNbrs.add(nbr.getString());
        }
        return stringNbrs;
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.go.board.elements.string.GoStringSet

     * @return all the strings on the board
     */
    public GoStringSet determineAllStringsOnBoard() {

        clearEyes();
        GoStringSet strings = new GoStringSet();
        for ( int i = 1; i <= board_.getNumRows(); i++ )  {
            for ( int j = 1; j <= board_.getNumCols(); j++ ) {
                GoBoardPosition pos = (GoBoardPosition)board_.getPosition(i, j);
                if (pos.isOccupied()) {
                    IGoString existingString = strings.findStringContainingPosition(pos);
                    if (existingString == null) {
                        GoString str = new GoString(findStringFromInitialPosition(pos, true), board_);
                        strings.add(str);
                        pos.setString(str);
                    }
                    else {
                        pos.setString(existingString);
                    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.go.board.elements.string.GoStringSet

    /**
     * @return true if any of the candidateStrings are unconditionally alive (i.e. pass alive).
     */
    private boolean determineUnconditionalLife() {

        GoStringSet livingStrings = findPassAliveStrings();
        return !livingStrings.isEmpty();
    }
View Full Code Here

Examples of com.barrybecker4.game.twoplayer.go.board.elements.string.GoStringSet

    /**
     * @return the set of strings in the group that are unconditionally alive.
     */
    private GoStringSet findPassAliveStrings() {

        GoStringSet candidateStrings = new GoStringSet(group_.getMembers());
        boolean done;

        do {
            initializeEyeLife();
            Iterator<IGoString> it = candidateStrings.iterator();

            done = true;
            while (it.hasNext()) {

                IGoString str = it.next();
                int numLivingAdjacentEyes = findNumLivingAdjacentEyes(str);
                if (numLivingAdjacentEyes < 2) {
                    str.setUnconditionallyAlive(false);
                    it.remove();
                    done = false; // something changed
                }
            }

        }  while ( !(done || candidateStrings.isEmpty()));
        return candidateStrings;
    }
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.