Package com.barrybecker4.game.twoplayer.go.board.elements.position

Examples of com.barrybecker4.game.twoplayer.go.board.elements.position.GoBoardPosition


                                      boolean friendPlayer1, boolean sameSideOnly,
                                      GoBoardPositionList stack ) {
        if ( !board_.inBounds( r + rowOffset, c + colOffset )) {
            return 0;
        }
        GoBoardPosition nbr = (GoBoardPosition) board_.getPosition(r + rowOffset, c + colOffset);
        // don't add it if it is in atari
        //if (nbr.isInAtari(board_)) {
        //    return 0;
        //}

        if ( nbr.isOccupied() &&
            (!sameSideOnly || nbr.getPiece().isOwnedByPlayer1() == friendPlayer1) && !nbr.isVisited() ) {

            BoardPosition intermediate1, intermediate2;
            if ( Math.abs( rowOffset ) == 2 ) {
                int rr = r + (rowOffset >> 1);
                intermediate1 = board_.getPosition(rr, c);
View Full Code Here


        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);
                    }
                }
            }
        }
        return strings;
View Full Code Here

     * Gets rid of everything we know about the board. Careful.
     */
    private void clearEyes() {
         for ( int i = 1; i <= board_.getNumRows(); i++ ) {
            for ( int j = 1; j <= board_.getNumCols(); j++ ) {
                GoBoardPosition pos = (GoBoardPosition) board_.getPosition( i, j );
                pos.setEye(null);
                pos.setString(null);
                pos.setVisited(false);
                //pos.clear();
            }
        }
    }
View Full Code Here

        assert box.contains(stone.getLocation()) : "stone " +  stone + " not in " + box;

        assert ( !stone.isVisited() ): "stone="+stone;
        stack.add( 0, stone );
        while ( !stack.isEmpty() ) {
            GoBoardPosition s = stack.pop();
            if ( !s.isVisited() ) {
                s.setVisited( true );
                stones.add( s );
                pushStringNeighbors(s, friendOwnedByP1, stack, true, type,  box);
            }
        }
        if ( returnToUnvisitedState ) {
View Full Code Here

    private int checkNeighbor( int r, int c, int rowOffset, int colOffset,
                               boolean friendOwnedByPlayer1, GoBoardPositionList stack,
                               boolean samePlayerOnly, NeighborType type,
                               Box bbox )  {

        GoBoardPosition nbr = (GoBoardPosition) board_.getPosition(r + rowOffset, c + colOffset);
        if (bbox.contains(nbr.getLocation())) {
            return checkNeighbor( r, c, rowOffset, colOffset, friendOwnedByPlayer1, stack, samePlayerOnly, type );
        }
        else {
            return 0;
        }
View Full Code Here

     */
    private int checkNeighbor( int r, int c, int rowOffset, int colOffset,
                                    boolean friendOwnedByPlayer1, GoBoardPositionList stack,
                                    boolean samePlayerOnly, NeighborType type) {

        GoBoardPosition nbr = (GoBoardPosition) board_.getPosition(r + rowOffset, c + colOffset);

        switch (type) {
            case FRIEND:
            case OCCUPIED:
                 if ( !nbr.isVisited() && nbr.isOccupied() &&
                     (!samePlayerOnly || nbr.getPiece().isOwnedByPlayer1() == friendOwnedByPlayer1)) {
                     stack.push( nbr );
                     return 1;
                 }
                 break;
            case UNOCCUPIED:
                 if ( !nbr.isVisited() && nbr.isUnoccupied() ) {
                     stack.push( nbr );
                     return 1;
                 }
                 break;
            case NOT_FRIEND:
                 if ( !nbr.isVisited() &&
                    ( nbr.isUnoccupied() ||
                       ( nbr.isOccupied() && (nbr.getPiece().isOwnedByPlayer1() != friendOwnedByPlayer1))
                    ))  {
                     stack.push( nbr );
                     return 1;
                 }
                break;
View Full Code Here

        Map<GoBoardPosition, GoBoardPositionList> nbrMap = new HashMap<GoBoardPosition, GoBoardPositionList>();
        // we should probably be able to assume that the eye spaces_ are unvisited, but apparently not. assert instead?
        eye_.setVisited(false);

        GoBoardPositionList queue = new GoBoardPositionList();
        GoBoardPosition firstPos = eye_.getMembers().iterator().next();
        firstPos.setVisited(true);
        queue.add(firstPos);

        int count = processSearchQueue(queue, nbrMap);

        if (count != eye_.getMembers().size()) {
View Full Code Here

     * @return the number of element that were searched.
     */
    private int processSearchQueue(GoBoardPositionList queue, Map<GoBoardPosition, GoBoardPositionList> nbrMap) {
        int count = 0;
        while (!queue.isEmpty()) {
            GoBoardPosition current = queue.remove(0);
            GoBoardPositionList nbrs = getEyeNobiNeighbors(current);
            nbrMap.put(current, nbrs);
            count++;
            for (GoBoardPosition space : nbrs)  {
                if (!space.isVisited()) {
View Full Code Here

     */
    private double findProportionWithEnemyNbrs(GoBoardPositionSet groupStones) {

        int numWithEnemyNbrs = 0;
        for (Object p : groupStones) {
            GoBoardPosition stone = (GoBoardPosition)p;
            if (stone.isVisited()) {
                numWithEnemyNbrs++;
                stone.setVisited(false); // clear the visited state.
            }
        }
        return(double)numWithEnemyNbrs / ((double)groupStones.size() + 2);
    }
View Full Code Here

     */
    private void clearScores() {

        for ( int i = 1; i <= board_.getNumRows(); i++ )  {
           for ( int j = 1; j <= board_.getNumCols(); j++ ) {
               GoBoardPosition pos = (GoBoardPosition)board_.getPosition(i, j);
               pos.setScoreContribution(0);

               if (pos.isOccupied()) {
                   GoStone stone = ((GoStone)pos.getPiece());
                   stone.setHealth(0);
               }
           }
        }
    }
View Full Code Here

TOP

Related Classes of com.barrybecker4.game.twoplayer.go.board.elements.position.GoBoardPosition

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.