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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations