Search in sources :

Example 11 with Occupation

use of suite.weiqi.Weiqi.Occupation 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 12 with Occupation

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

the class UserInterface method importBoard.

public static Board importBoard(String s) {
    Board board = new Board();
    String[] rows = s.split("\n");
    for (int x = 0; x < Weiqi.size; x++) {
        String[] cols = rows[x].split(" ");
        for (int y = 0; y < Weiqi.size; y++) {
            Occupation occupation = Occupation.EMPTY;
            for (Occupation o : Occupation.values()) if (String_.equals(cols[y], o.display()))
                occupation = o;
            board.set(Coordinate.c(x, y), occupation);
        }
    }
    return board;
}
Also used : Occupation(suite.weiqi.Weiqi.Occupation)

Example 13 with Occupation

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

the class UctTest method evaluateRandomOutcome.

private String evaluateRandomOutcome(Coordinate move) {
    Occupation player = Occupation.WHITE;
    int nWins = 0, nTotal = 1000;
    for (int i = 0; i < nTotal; i++) {
        GameSet gameSet = new GameSet(new Board(), player);
        UctVisitor<Coordinate> visitor = UctWeiqi.newVisitor(gameSet);
        visitor.playMove(move);
        nWins += visitor.evaluateRandomOutcome() ? 0 : 1;
    }
    return nWins + "/" + nTotal;
}
Also used : Occupation(suite.weiqi.Weiqi.Occupation)

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