getBeEatenList method
获取要被吃的子,无根,或者吃子者权重低, 不含老将
Implementation
List<ChessItem> getBeEatenList(int team) {
List<ChessItem> items = [];
List<ChessItem> pieces = fen.getAll();
int eTeam = team == 0 ? 1 : 0;
for (var item in pieces) {
if (item.team == team && !['K', 'k'].contains(item.code)) {
int rc = rootCount(item.position, team);
int erc = rootCount(item.position, eTeam);
if (rc == 0 && erc > 0) {
items.add(item);
} else {
List<ChessItem> canEatMe = getBeEatList(item.position);
for (ChessItem eItem in canEatMe) {
if (chessWeight[eItem.code.toLowerCase()]! <
chessWeight[item.code.toLowerCase()]!) {
items.add(item);
break;
}
}
}
}
}
items.sort(
(a, b) => chessWeight[b.code.toLowerCase()]!
.compareTo(chessWeight[a.code.toLowerCase()]!),
);
return items;
}