Find Chess960 starting position identifier: Difference between revisions

Content added Content deleted
Line 599: Line 599:
}
}
List<Integer> rookKing = List.of(aPosition.indexOf('R'), aPosition.indexOf('K'), aPosition.lastIndexOf('R'));
List<Integer> rookAndKing =
if ( ! ( rookKing.get(0) < rookKing.get(1) && rookKing.get(1) < rookKing.get(2) ) ) {
List.of(aPosition.indexOf('R'), aPosition.indexOf('K'), aPosition.lastIndexOf('R'));
if ( ! ( rookAndKing.get(0) < rookAndKing.get(1) && rookAndKing.get(1) < rookAndKing.get(2) ) ) {
throw new AssertionError("The king must be between the two rooks.");
throw new AssertionError("The king must be between the two rooks.");
}
}
Line 622: Line 621:
private static String retainIf(String aText, Predicate<Character> aPredicate) {
private static String retainIf(String aText, Predicate<Character> aPredicate) {
return aText.chars().mapToObj( i -> (char) i ).filter(aPredicate)
return aText.chars()
.mapToObj( i -> (char) i )
.map(String::valueOf).reduce("", String::concat);
.filter(aPredicate)
.map(String::valueOf)
.reduce("", String::concat);
}
}