Remove Season.Past so all lookups go through World

This commit is contained in:
Tim Van Baak 2024-08-12 14:51:07 -07:00
parent 81c9aa4859
commit 5e5483367d
4 changed files with 16 additions and 21 deletions

View File

@ -114,17 +114,17 @@ public static class PathFinder
List<Season> adjacents = []; List<Season> adjacents = [];
// The immediate past and all immediate futures are adjacent. // The immediate past and all immediate futures are adjacent.
if (season.Past != null) adjacents.Add(season.Past); if (season.PastId != null) adjacents.Add(world.GetSeason(season.PastId));
adjacents.AddRange(season.Futures); adjacents.AddRange(season.Futures);
// Find all adjacent timelines by finding all timelines that branched off of this season's // Find all adjacent timelines by finding all timelines that branched off of this season's
// timeline, i.e. all futures of this season's past that have different timelines. Also // timeline, i.e. all futures of this season's past that have different timelines. Also
// include any timelines that branched off of the timeline this timeline branched off from. // include any timelines that branched off of the timeline this timeline branched off from.
List<Season> adjacentTimelineRoots = new(); List<Season> adjacentTimelineRoots = [];
Season? current; Season? current;
for (current = season; for (current = season;
current?.Past?.Timeline != null && current.Past.Timeline == current.Timeline; current?.PastId != null && world.GetSeason(current.PastId).Timeline == current.Timeline;
current = current.Past) current = world.GetSeason(current.PastId))
{ {
adjacentTimelineRoots.AddRange( adjacentTimelineRoots.AddRange(
current.Futures.Where(s => s.Timeline != current.Timeline)); current.Futures.Where(s => s.Timeline != current.Timeline));
@ -135,10 +135,10 @@ public static class PathFinder
// then current is the branch timeline's root season (current.past.timeline != // then current is the branch timeline's root season (current.past.timeline !=
// current.timeline). There are co-branches if this season is in a branched timeline, since // current.timeline). There are co-branches if this season is in a branched timeline, since
// the first timeline by definition cannot have co-branches. // the first timeline by definition cannot have co-branches.
if (current?.Past != null) if (current?.PastId != null && world.GetSeason(current.PastId) is Season past)
{ {
IEnumerable<Season> cobranchRoots = current.Past.Futures IEnumerable<Season> cobranchRoots = past.Futures
.Where(s => s.Timeline != current.Timeline && s.Timeline != current.Past.Timeline); .Where(s => s.Timeline != current.Timeline && s.Timeline != past.Timeline);
adjacentTimelineRoots.AddRange(cobranchRoots); adjacentTimelineRoots.AddRange(cobranchRoots);
} }

View File

@ -10,13 +10,6 @@ public class Season
/// </summary> /// </summary>
public const int FIRST_TURN = 0; public const int FIRST_TURN = 0;
/// <summary>
/// The season immediately preceding this season.
/// If this season is an alternate timeline root, the past is from the origin timeline.
/// The initial season does not have a past.
/// </summary>
public Season? Past { get; }
/// <summary> /// <summary>
/// The designation of the season immediately preceding this season. /// The designation of the season immediately preceding this season.
/// If this season is an alternate timeline root, the past is from the origin timeline. /// If this season is an alternate timeline root, the past is from the origin timeline.
@ -54,7 +47,6 @@ public class Season
private Season(Season? past, int turn, string timeline, TimelineFactory factory) private Season(Season? past, int turn, string timeline, TimelineFactory factory)
{ {
this.Past = past;
this.PastId = past?.ToString(); this.PastId = past?.ToString();
this.Turn = turn; this.Turn = turn;
this.Timeline = timeline; this.Timeline = timeline;

View File

@ -245,9 +245,12 @@ public class World
/// </summary> /// </summary>
public Season GetTimelineRoot(Season season) public Season GetTimelineRoot(Season season)
{ {
Season? past = season.Past; if (season.PastId is null) {
return past != null && season.Timeline == past.Timeline return season;
? GetTimelineRoot(season.Past!) }
Season past = SeasonLookup[season.PastId];
return season.Timeline == past.Timeline
? GetTimelineRoot(past)
: season; : season;
} }

View File

@ -171,7 +171,7 @@ public class MovementAdjudicatorTest
// Confirm the future was created // Confirm the future was created
Assert.That(updated.Seasons.Count, Is.EqualTo(2)); Assert.That(updated.Seasons.Count, Is.EqualTo(2));
Season future = updated.Seasons.Single(s => s != updated.RootSeason); Season future = updated.Seasons.Single(s => s != updated.RootSeason);
Assert.That(future.Past, Is.EqualTo(updated.RootSeason)); Assert.That(future.PastId, Is.EqualTo(updated.RootSeason.ToString()));
Assert.That(future.Futures, Is.Empty); Assert.That(future.Futures, Is.Empty);
Assert.That(future.Timeline, Is.EqualTo(updated.RootSeason.Timeline)); Assert.That(future.Timeline, Is.EqualTo(updated.RootSeason.Timeline));
Assert.That(future.Turn, Is.EqualTo(Season.FIRST_TURN + 1)); Assert.That(future.Turn, Is.EqualTo(Season.FIRST_TURN + 1));
@ -200,7 +200,7 @@ public class MovementAdjudicatorTest
// Confirm the future was created // Confirm the future was created
Season s2 = updated.GetSeason("a", 1); Season s2 = updated.GetSeason("a", 1);
Assert.That(s2.Past, Is.EqualTo(s1)); Assert.That(s2.PastId, Is.EqualTo(s1.ToString()));
Assert.That(s2.Futures, Is.Empty); Assert.That(s2.Futures, Is.Empty);
Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline)); Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline));
Assert.That(s2.Turn, Is.EqualTo(s1.Turn + 1)); Assert.That(s2.Turn, Is.EqualTo(s1.Turn + 1));
@ -250,7 +250,7 @@ public class MovementAdjudicatorTest
// Confirm the future was created // Confirm the future was created
Season s2 = updated.GetSeason(s1.Timeline, s1.Turn + 1); Season s2 = updated.GetSeason(s1.Timeline, s1.Turn + 1);
Assert.That(s2.Past, Is.EqualTo(s1)); Assert.That(s2.PastId, Is.EqualTo(s1.ToString()));
Assert.That(s2.Futures, Is.Empty); Assert.That(s2.Futures, Is.Empty);
Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline)); Assert.That(s2.Timeline, Is.EqualTo(s1.Timeline));
Assert.That(s2.Turn, Is.EqualTo(s1.Turn + 1)); Assert.That(s2.Turn, Is.EqualTo(s1.Turn + 1));