Search in sources :

Example 1 with Group

use of suite.weiqi.GroupAnalysis.Group in project suite by stupidsing.

the class Board method killIfDead1.

private boolean killIfDead1(GroupAnalysis ga, Coordinate c) {
    Group group = ga.getGroup(c);
    boolean isKilled = group.breathes.isEmpty();
    if (isKilled)
        for (Coordinate c1 : group.coords) set(c1, Occupation.EMPTY);
    return isKilled;
}
Also used : Group(suite.weiqi.GroupAnalysis.Group)

Example 2 with Group

use of suite.weiqi.GroupAnalysis.Group 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 3 with Group

use of suite.weiqi.GroupAnalysis.Group in project suite by stupidsing.

the class Judge method checkGroupsLiveness.

public static void checkGroupsLiveness(Board board, Array<Boolean> alives) {
    GroupAnalysis ga = new GroupAnalysis(board);
    // judge which groups are eyes, i.e. surrounded by only one colour
    Map<Group, Boolean> groupIsEye = new HashMap<>();
    for (Group group : ga.getGroups()) if (group.color == Occupation.EMPTY) {
        Set<Occupation> colors = new HashSet<>();
        for (Group neighborGroup : group.touches) {
            Occupation color = neighborGroup.color;
            if (color != Occupation.EMPTY)
                colors.add(color);
        }
        // has two colours
        groupIsEye.put(group, colors.size() <= 1);
    }
}
Also used : Group(suite.weiqi.GroupAnalysis.Group) Occupation(suite.weiqi.Weiqi.Occupation) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap)

Example 4 with Group

use of suite.weiqi.GroupAnalysis.Group in project suite by stupidsing.

the class BoardTest method testGroupAnalysis.

@Test
public void testGroupAnalysis() {
    Board board = blackBoard();
    board.set(Coordinate.c(3, 3), Occupation.EMPTY);
    board.set(Coordinate.c(3, 4), Occupation.EMPTY);
    board.set(Coordinate.c(7, 3), Occupation.EMPTY);
    board.set(Coordinate.c(18, 0), Occupation.EMPTY);
    board.set(Coordinate.c(17, 1), Occupation.EMPTY);
    board.set(Coordinate.c(17, 0), Occupation.WHITE);
    board.set(Coordinate.c(18, 1), Occupation.WHITE);
    GroupAnalysis ga = new GroupAnalysis(board);
    Group blackGroup = ga.getGroup(Coordinate.c(15, 15));
    Group whiteGroup = ga.getGroup(Coordinate.c(17, 0));
    assertEquals(361 - 7, blackGroup.coords.size());
    assertEquals(3, whiteGroup.touches.size());
    assertTrue(blackGroup.touches.contains(whiteGroup));
    assertTrue(whiteGroup.touches.contains(blackGroup));
    assertEquals(4, blackGroup.breathes.size());
}
Also used : Group(suite.weiqi.GroupAnalysis.Group) Test(org.junit.Test)

Aggregations

Group (suite.weiqi.GroupAnalysis.Group)4 HashSet (java.util.HashSet)2 Occupation (suite.weiqi.Weiqi.Occupation)2 HashMap (java.util.HashMap)1 Set (java.util.Set)1 Test (org.junit.Test)1