mancala/apps/backend/src/main/java/app/playmancala/model/Series.java

25 lines
744 B
Java
Raw Normal View History

package app.playmancala.model;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
// The series a live game belongs to: its id and the games played before this one, oldest first. A game that is not a
// rematch starts a series of its own (docs/specs/rematch).
public record Series(String id, List<SeriesGame> games) {
public Series {
games = List.copyOf(games);
}
public static Series start() {
return new Series(UUID.randomUUID().toString(), List.of());
}
// The same series with `finished` played.
public Series next(SeriesGame finished) {
List<SeriesGame> played = new ArrayList<>(games);
played.add(finished);
return new Series(id, played);
}
}