Enhance family and roster management in school simulation by implementing support for incomplete families, ensuring proper handling of absent parents while maintaining surname consistency. Update family creation logic to account for single-parent households and revise child identification to prevent ID conflicts. Introduce seat shuffling to prevent siblings from being placed in the same class, improving the realism of student distribution. Update related tests to validate these new functionalities and ensure robustness in family and roster handling.
This commit is contained in:
@@ -3,12 +3,31 @@ namespace HSchool.People;
|
||||
internal readonly record struct FamilyPlan(int FamilyIndex, IReadOnlyList<PupilSeat> Seats);
|
||||
|
||||
/// <summary>
|
||||
/// Walks seats in order and groups them into families of 1–3. A short remainder becomes
|
||||
/// singleton families rather than shrinking an earlier family's intended size, so a longer
|
||||
/// seat list only appends families.
|
||||
/// Walks seats in order and groups them into families of 1–3, taking a run of consecutive seats
|
||||
/// per family. Callers hand in a shuffled seat list — a run of *adjacent* seats is one classroom,
|
||||
/// which would put every sibling in the same class.
|
||||
///
|
||||
/// A family whose intended size does not fit the remainder takes one seat instead of shrinking,
|
||||
/// so growing the seat list only disturbs the tail.
|
||||
/// </summary>
|
||||
internal static class FamilyPlanner
|
||||
{
|
||||
/// <summary>
|
||||
/// One child per family. Used by the yearly intake: every seat there is a first-year seat, so
|
||||
/// grouping would hand a family two or three same-age children at once. An arriving pupil who
|
||||
/// does have an older sibling gets attached to that family instead.
|
||||
/// </summary>
|
||||
public static IReadOnlyList<FamilyPlan> Singletons(IReadOnlyList<PupilSeat> seats, int startIndex)
|
||||
{
|
||||
var plans = new FamilyPlan[seats.Count];
|
||||
for (var i = 0; i < seats.Count; i++)
|
||||
{
|
||||
plans[i] = new FamilyPlan(startIndex + i, [seats[i]]);
|
||||
}
|
||||
|
||||
return plans;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<FamilyPlan> Plan(int schoolSeed, IReadOnlyList<PupilSeat> seats, int startIndex = 0)
|
||||
{
|
||||
var plans = new List<FamilyPlan>();
|
||||
|
||||
Reference in New Issue
Block a user