Search in sources :

Example 6 with Occupation

use of suite.weiqi.Weiqi.Occupation in project suite by stupidsing.

the class Board method findGroup.

public Set<Coordinate> findGroup(Coordinate c) {
    Set<Coordinate> group = new HashSet<>();
    Occupation color = get(c);
    group.add(c);
    Stack<Coordinate> unexplored = new Stack<>();
    unexplored.push(c);
    while (!unexplored.isEmpty()) for (Coordinate c1 : unexplored.pop().neighbors) if (get(c1) == color && group.add(c1))
        unexplored.push(c1);
    return group;
}
Also used : Occupation(suite.weiqi.Weiqi.Occupation) HashSet(java.util.HashSet) Stack(java.util.Stack)

Example 7 with Occupation

use of suite.weiqi.Weiqi.Occupation in project suite by stupidsing.

the class Board method hasBreath.

private boolean hasBreath(Coordinate c) {
    Set<Coordinate> group = new HashSet<>();
    Occupation color = get(c);
    group.add(c);
    Stack<Coordinate> unexplored = new Stack<>();
    unexplored.push(c);
    while (!unexplored.isEmpty()) for (Coordinate c1 : unexplored.pop().neighbors) {
        Occupation color1 = get(c1);
        if (color1 == color) {
            if (group.add(c1))
                unexplored.push(c1);
        } else if (color1 == Occupation.EMPTY)
            return true;
    }
    return false;
}
Also used : Occupation(suite.weiqi.Weiqi.Occupation) HashSet(java.util.HashSet) Stack(java.util.Stack)

Example 8 with Occupation

use of suite.weiqi.Weiqi.Occupation in project suite by stupidsing.

the class Evaluator method evaluate.

public static int evaluate(Occupation player, Board board) {
    int score = 0;
    Occupation opponent = player.opponent();
    // count territories by counting groups
    GroupAnalysis ga = new GroupAnalysis(board);
    for (Group group : ga.getGroups()) {
        Occupation color = group.color;
        Set<Occupation> colors = new HashSet<>();
        boolean us = false, theirs = false;
        // count pieces
        if (color == player)
            score += pieceScore * group.coords.size();
        else if (color == opponent)
            score -= pieceScore * group.coords.size();
        // count territory
        if (color == Occupation.EMPTY) {
            for (Group neighborGroup : group.touches) colors.add(neighborGroup.color);
            us = colors.contains(player);
            theirs = colors.contains(opponent);
        } else if (color == player)
            us = true;
        else
            theirs = true;
        if (!us || !theirs) {
            // do not count when it is nearby both colours
            int scoreDelta = territoryScore * group.coords.size();
            score += !theirs ? scoreDelta : -scoreDelta;
        }
    }
    return score;
}
Also used : Occupation(suite.weiqi.Weiqi.Occupation) Group(suite.weiqi.GroupAnalysis.Group) HashSet(java.util.HashSet)

Example 9 with Occupation

use of suite.weiqi.Weiqi.Occupation in project suite by stupidsing.

the class GameSet method unplay_.

private void unplay_(Move move) {
    Occupation opponent = nextPlayer.opponent();
    if (move.type == MoveType.CAPTURE) {
        int i = 0;
        for (Coordinate c1 : move.position.neighbors) if (move.neighborColors[i++] != board.get(c1))
            for (Coordinate c2 : board.findGroup(c1)) board.set(c2, opponent);
    }
    board.set(move.position, Occupation.EMPTY);
}
Also used : Occupation(suite.weiqi.Weiqi.Occupation)

Example 10 with Occupation

use of suite.weiqi.Weiqi.Occupation in project suite by stupidsing.

the class Judge method checkByOccupationExistence.

public static Occupation checkByOccupationExistence(Board board) {
    int nPiecesCount = 0;
    Set<Occupation> players = new HashSet<>();
    for (Coordinate c : Coordinate.all()) {
        Occupation color = board.get(c);
        players.add(color);
        nPiecesCount += color != Occupation.EMPTY ? 1 : 0;
    }
    if (1 < nPiecesCount)
        for (Occupation player : Weiqi.players) if (players.contains(player) && !players.contains(player.opponent()))
            return player;
    return null;
}
Also used : Occupation(suite.weiqi.Weiqi.Occupation) HashSet(java.util.HashSet)

Aggregations

Occupation (suite.weiqi.Weiqi.Occupation)13 HashSet (java.util.HashSet)5 Stack (java.util.Stack)2 Group (suite.weiqi.GroupAnalysis.Group)2 DecimalFormat (java.text.DecimalFormat)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 Set (java.util.Set)1 Test (org.junit.Test)1 Profiler (suite.sample.Profiler)1 UctSearch (suite.uct.UctSearch)1