2022-03-30 03:40:19 +00:00
|
|
|
using MultiversalDiplomacy.Adjudicate;
|
|
|
|
using MultiversalDiplomacy.Adjudicate.Decision;
|
|
|
|
using MultiversalDiplomacy.Model;
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace MultiversalDiplomacyTests;
|
|
|
|
|
|
|
|
public class TimeTravelTest
|
|
|
|
{
|
|
|
|
[Test]
|
2022-04-22 20:33:17 +00:00
|
|
|
public void MDATC_3_A_1_MoveIntoOwnPastForksTimeline()
|
2022-03-30 03:40:19 +00:00
|
|
|
{
|
2022-03-30 15:04:44 +00:00
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
2022-03-30 03:40:19 +00:00
|
|
|
|
2022-03-30 04:01:15 +00:00
|
|
|
// Hold to move into the future, then move back into the past.
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 0)]
|
2022-03-30 03:40:19 +00:00
|
|
|
.GetReference(out Season s0)
|
|
|
|
["Germany"]
|
2022-03-30 04:01:15 +00:00
|
|
|
.Army("Mun").Holds().GetReference(out var mun0)
|
2022-03-30 15:04:44 +00:00
|
|
|
.Execute()
|
2024-08-12 16:28:56 +00:00
|
|
|
[("a", 1)]
|
2022-03-30 03:40:19 +00:00
|
|
|
.GetReference(out Season s1)
|
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").MovesTo("Tyr", season: s0).GetReference(out var mun1);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.ValidateOrders();
|
2022-03-30 03:40:19 +00:00
|
|
|
Assert.That(mun1, Is.Valid);
|
2022-03-30 15:04:44 +00:00
|
|
|
setup.AdjudicateOrders();
|
2022-03-30 03:40:19 +00:00
|
|
|
Assert.That(mun1, Is.Victorious);
|
|
|
|
|
2022-03-30 15:04:44 +00:00
|
|
|
World world = setup.UpdateWorld();
|
2022-03-30 03:40:19 +00:00
|
|
|
|
2022-04-10 04:10:44 +00:00
|
|
|
// Confirm that there are now four seasons: three in the main timeline and one in a fork.
|
|
|
|
Assert.That(
|
2024-08-15 20:51:41 +00:00
|
|
|
world.Timelines.Pasts.Keys.Select(key => new Season(key)).Where(s => s.Timeline == s0.Timeline).Count(),
|
2022-04-10 04:10:44 +00:00
|
|
|
Is.EqualTo(3),
|
|
|
|
"Failed to advance main timeline after last unit left");
|
|
|
|
Assert.That(
|
2024-08-15 20:51:41 +00:00
|
|
|
world.Timelines.Pasts.Keys.Select(key => new Season(key)).Where(s => s.Timeline != s0.Timeline).Count(),
|
2022-04-10 04:10:44 +00:00
|
|
|
Is.EqualTo(1),
|
|
|
|
"Failed to fork timeline when unit moved in");
|
2022-03-30 03:40:19 +00:00
|
|
|
|
2024-08-12 16:28:56 +00:00
|
|
|
// Confirm that there is a unit in Tyr b1 originating from Mun a1
|
2024-08-15 20:51:41 +00:00
|
|
|
Season fork = new("b1");
|
2024-08-13 23:24:43 +00:00
|
|
|
Unit originalUnit = world.GetUnitAt("Mun", s0);
|
|
|
|
Unit aMun0 = world.GetUnitAt("Mun", s1);
|
|
|
|
Unit aTyr = world.GetUnitAt("Tyr", fork);
|
2024-08-15 13:52:08 +00:00
|
|
|
Assert.That(aTyr.Past, Is.EqualTo(mun1.Order.Unit.Key));
|
|
|
|
Assert.That(world.GetUnitByKey(aTyr.Past!).Past, Is.EqualTo(mun0.Order.Unit.Key));
|
2022-03-30 03:40:19 +00:00
|
|
|
|
2024-08-12 16:28:56 +00:00
|
|
|
// Confirm that there is a unit in Mun b1 originating from Mun a0
|
2024-08-13 23:24:43 +00:00
|
|
|
Unit aMun1 = world.GetUnitAt("Mun", fork);
|
2024-08-15 13:52:08 +00:00
|
|
|
Assert.That(aMun1.Past, Is.EqualTo(originalUnit.Key));
|
2022-03-30 03:40:19 +00:00
|
|
|
}
|
2022-03-30 20:00:51 +00:00
|
|
|
|
|
|
|
[Test]
|
2022-04-22 20:33:17 +00:00
|
|
|
public void MDATC_3_A_2_SupportToRepelledPastMoveForksTimeline()
|
2022-03-30 20:00:51 +00:00
|
|
|
{
|
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
|
|
|
|
|
|
|
// Fail to dislodge on the first turn, then support the move so it succeeds.
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 0)]
|
2022-03-30 20:00:51 +00:00
|
|
|
.GetReference(out Season s0)
|
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").MovesTo("Tyr").GetReference(out var mun0)
|
|
|
|
["Austria"]
|
|
|
|
.Army("Tyr").Holds().GetReference(out var tyr0);
|
|
|
|
|
|
|
|
setup.ValidateOrders();
|
|
|
|
Assert.That(mun0, Is.Valid);
|
|
|
|
Assert.That(tyr0, Is.Valid);
|
|
|
|
setup.AdjudicateOrders();
|
|
|
|
Assert.That(mun0, Is.Repelled);
|
|
|
|
Assert.That(tyr0, Is.NotDislodged);
|
|
|
|
setup.UpdateWorld();
|
|
|
|
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 1)]
|
2022-03-30 20:00:51 +00:00
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").Supports.Army("Mun", season: s0).MoveTo("Tyr").GetReference(out var mun1)
|
|
|
|
["Austria"]
|
|
|
|
.Army("Tyr").Holds();
|
|
|
|
|
|
|
|
// Confirm that history is changed.
|
|
|
|
setup.ValidateOrders();
|
|
|
|
Assert.That(mun1, Is.Valid);
|
|
|
|
setup.AdjudicateOrders();
|
|
|
|
Assert.That(mun1, Is.NotCut);
|
|
|
|
Assert.That(mun0, Is.Victorious);
|
|
|
|
Assert.That(tyr0, Is.Dislodged);
|
|
|
|
|
|
|
|
// Confirm that an alternate future is created.
|
|
|
|
World world = setup.UpdateWorld();
|
2024-08-15 20:51:41 +00:00
|
|
|
Season fork = new("b1");
|
2024-08-13 23:24:43 +00:00
|
|
|
Unit tyr1 = world.GetUnitAt("Tyr", fork);
|
2022-03-30 20:00:51 +00:00
|
|
|
Assert.That(
|
|
|
|
tyr1.Past,
|
2024-08-15 13:52:08 +00:00
|
|
|
Is.EqualTo(mun0.Order.Unit.Key),
|
2024-08-12 16:28:56 +00:00
|
|
|
"Expected A Mun a0 to advance to Tyr b1");
|
2022-03-30 20:00:51 +00:00
|
|
|
Assert.That(
|
|
|
|
world.RetreatingUnits.Count,
|
|
|
|
Is.EqualTo(1),
|
2024-08-12 16:28:56 +00:00
|
|
|
"Expected A Tyr a0 to be in retreat");
|
2022-03-30 20:00:51 +00:00
|
|
|
Assert.That(world.RetreatingUnits.First().Unit, Is.EqualTo(tyr0.Order.Unit));
|
|
|
|
}
|
2022-04-10 04:10:44 +00:00
|
|
|
|
|
|
|
[Test]
|
2022-04-22 20:33:17 +00:00
|
|
|
public void MDATC_3_A_3_FailedMoveDoesNotForkTimeline()
|
2022-04-10 04:10:44 +00:00
|
|
|
{
|
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
|
|
|
|
|
|
|
// Hold to create a future, then attempt to attack in the past.
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 0)]
|
2022-04-10 04:10:44 +00:00
|
|
|
.GetReference(out Season s0)
|
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").Holds()
|
|
|
|
["Austria"]
|
|
|
|
.Army("Tyr").Holds().GetReference(out var tyr0)
|
|
|
|
.Execute()
|
2024-08-12 16:28:56 +00:00
|
|
|
[("a", 1)]
|
2022-04-10 04:10:44 +00:00
|
|
|
.GetReference(out Season s1)
|
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").MovesTo("Tyr", season: s0).GetReference(out var mun1)
|
|
|
|
["Austria"]
|
|
|
|
.Army("Tyr").Holds();
|
|
|
|
|
|
|
|
setup.ValidateOrders();
|
|
|
|
Assert.That(mun1, Is.Valid);
|
|
|
|
setup.AdjudicateOrders();
|
|
|
|
Assert.That(mun1, Is.Repelled);
|
2024-08-12 16:28:56 +00:00
|
|
|
// The order to Tyr a0 should have been pulled into the adjudication set, so the reference
|
2022-04-10 04:10:44 +00:00
|
|
|
// should not throw when accessing it.
|
|
|
|
Assert.That(tyr0, Is.NotDislodged);
|
|
|
|
|
|
|
|
// There should only be three seasons, all in the main timeline, since the move failed to
|
|
|
|
// change the past and therefore did not create a new timeline.
|
|
|
|
World world = setup.UpdateWorld();
|
|
|
|
Assert.That(
|
2024-08-15 20:51:41 +00:00
|
|
|
world.Timelines.GetFutures(s0).Count(),
|
2022-04-10 04:10:44 +00:00
|
|
|
Is.EqualTo(1),
|
|
|
|
"A failed move incorrectly forked the timeline");
|
2024-08-15 20:51:41 +00:00
|
|
|
Assert.That(world.Timelines.GetFutures(s1).Count(), Is.EqualTo(1));
|
|
|
|
Season s2 = new(s1.Timeline, s1.Turn + 1);
|
|
|
|
Assert.That(world.Timelines.GetFutures(s2).Count(), Is.EqualTo(0));
|
2022-04-10 04:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-04-22 20:33:17 +00:00
|
|
|
public void MDATC_3_A_4_SuperfluousSupportDoesNotForkTimeline()
|
2022-04-10 04:10:44 +00:00
|
|
|
{
|
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
|
|
|
|
|
|
|
// Move, then support the past move even though it succeeded already.
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 0)]
|
2022-04-10 04:10:44 +00:00
|
|
|
.GetReference(out Season s0)
|
|
|
|
["Germany"]
|
|
|
|
.Army("Mun").MovesTo("Tyr").GetReference(out var mun0)
|
|
|
|
.Army("Boh").Holds();
|
|
|
|
|
|
|
|
setup.ValidateOrders();
|
|
|
|
Assert.That(mun0, Is.Valid);
|
|
|
|
setup.AdjudicateOrders();
|
|
|
|
Assert.That(mun0, Is.Victorious);
|
|
|
|
setup.UpdateWorld();
|
|
|
|
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 1)]
|
2022-04-10 04:10:44 +00:00
|
|
|
.GetReference(out Season s1)
|
|
|
|
["Germany"]
|
|
|
|
.Army("Tyr").Holds()
|
|
|
|
.Army("Boh").Supports.Army("Mun", season: s0).MoveTo("Tyr").GetReference(out var boh1);
|
|
|
|
|
|
|
|
// The support does work and the move does succeed, but...
|
|
|
|
setup.ValidateOrders();
|
|
|
|
Assert.That(boh1, Is.Valid);
|
|
|
|
setup.AdjudicateOrders();
|
|
|
|
Assert.That(boh1, Is.NotCut);
|
|
|
|
Assert.That(mun0, Is.Victorious);
|
|
|
|
|
|
|
|
// ...since it succeeded anyway, no fork is created.
|
|
|
|
World world = setup.UpdateWorld();
|
|
|
|
Assert.That(
|
2024-08-15 20:51:41 +00:00
|
|
|
world.Timelines.GetFutures(s0).Count(),
|
2022-04-10 04:10:44 +00:00
|
|
|
Is.EqualTo(1),
|
|
|
|
"A superfluous support incorrectly forked the timeline");
|
2024-08-15 20:51:41 +00:00
|
|
|
Assert.That(world.Timelines.GetFutures(s1).Count(), Is.EqualTo(1));
|
|
|
|
Season s2 = new(s1.Timeline, s1.Turn + 1);
|
|
|
|
Assert.That(world.Timelines.GetFutures(s2).Count(), Is.EqualTo(0));
|
2022-04-10 04:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-04-22 20:33:17 +00:00
|
|
|
public void MDATC_3_A_5_CrossTimelineSupportDoesNotForkHead()
|
2022-04-10 04:10:44 +00:00
|
|
|
{
|
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
|
|
|
|
|
|
|
// London creates two timelines by moving into the past.
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 0)]
|
|
|
|
.GetReference(out var a0)
|
2022-04-10 04:10:44 +00:00
|
|
|
["England"].Army("Lon").Holds()
|
2022-11-06 22:43:45 +00:00
|
|
|
["Austria"].Army("Tyr").Holds()
|
2022-04-10 04:10:44 +00:00
|
|
|
["Germany"].Army("Mun").Holds()
|
|
|
|
.Execute()
|
2024-08-12 16:28:56 +00:00
|
|
|
[("a", 1)]
|
|
|
|
["England"].Army("Lon").MovesTo("Yor", a0)
|
2022-04-10 04:10:44 +00:00
|
|
|
.Execute()
|
2024-08-12 16:28:56 +00:00
|
|
|
// Head seasons: a2 b1
|
2022-04-10 04:10:44 +00:00
|
|
|
// Both contain copies of the armies in Mun and Tyr.
|
|
|
|
// Now Germany dislodges Austria in Tyr by supporting the move across timelines.
|
2024-08-12 16:28:56 +00:00
|
|
|
[("a", 2)]
|
|
|
|
.GetReference(out var a2)
|
|
|
|
["Germany"].Army("Mun").MovesTo("Tyr").GetReference(out var mun_a2)
|
|
|
|
["Austria"].Army("Tyr").Holds().GetReference(out var tyr_a2)
|
|
|
|
[("b", 1)]
|
|
|
|
.GetReference(out var b1)
|
|
|
|
["Germany"].Army("Mun").Supports.Army("Mun", a2).MoveTo("Tyr").GetReference(out var mun_b1)
|
2022-04-10 04:10:44 +00:00
|
|
|
["Austria"].Army("Tyr").Holds();
|
|
|
|
|
2024-08-12 16:28:56 +00:00
|
|
|
// The attack against Tyr a2 succeeds.
|
2022-04-10 04:10:44 +00:00
|
|
|
setup.ValidateOrders();
|
2024-08-12 16:28:56 +00:00
|
|
|
Assert.That(mun_a2, Is.Valid);
|
|
|
|
Assert.That(tyr_a2, Is.Valid);
|
|
|
|
Assert.That(mun_b1, Is.Valid);
|
2022-04-10 04:10:44 +00:00
|
|
|
setup.AdjudicateOrders();
|
2024-08-12 16:28:56 +00:00
|
|
|
Assert.That(mun_a2, Is.Victorious);
|
|
|
|
Assert.That(tyr_a2, Is.Dislodged);
|
|
|
|
Assert.That(mun_b1, Is.NotCut);
|
2022-04-10 04:10:44 +00:00
|
|
|
|
|
|
|
// Since both seasons were at the head of their timelines, there should be no forking.
|
|
|
|
World world = setup.UpdateWorld();
|
|
|
|
Assert.That(
|
2024-08-15 20:51:41 +00:00
|
|
|
world.Timelines.GetFutures(a2).Count(),
|
2022-04-10 04:10:44 +00:00
|
|
|
Is.EqualTo(1),
|
|
|
|
"A cross-timeline support incorrectly forked the head of the timeline");
|
|
|
|
Assert.That(
|
2024-08-15 20:51:41 +00:00
|
|
|
world.Timelines.GetFutures(b1).Count(),
|
2022-04-10 04:10:44 +00:00
|
|
|
Is.EqualTo(1),
|
|
|
|
"A cross-timeline support incorrectly forked the head of the timeline");
|
2024-08-15 20:51:41 +00:00
|
|
|
Season a3 = new(a2.Timeline, a2.Turn + 1);
|
|
|
|
Assert.That(world.Timelines.GetFutures(a3).Count(), Is.EqualTo(0));
|
|
|
|
Season b2 = new(b1.Timeline, b1.Turn + 1);
|
|
|
|
Assert.That(world.Timelines.GetFutures(b2).Count(), Is.EqualTo(0));
|
2022-04-10 04:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2022-04-22 20:33:17 +00:00
|
|
|
public void MDATC_3_A_6_CuttingCrossTimelineSupportDoesNotFork()
|
2022-04-10 04:10:44 +00:00
|
|
|
{
|
|
|
|
TestCaseBuilder setup = new(World.WithStandardMap(), MovementPhaseAdjudicator.Instance);
|
|
|
|
|
|
|
|
// As above, only now London creates three timelines.
|
2024-08-12 16:28:56 +00:00
|
|
|
setup[("a", 0)]
|
|
|
|
.GetReference(out var a0)
|
2022-04-10 04:10:44 +00:00
|
|
|
["England"].Army("Lon").Holds()
|
|
|
|
["Austria"].Army("Boh").Holds()
|
|
|
|
["Germany"].Army("Mun").Holds()
|
|
|
|
.Execute()
|
2024-08-12 16:28:56 +00:00
|
|
|
[("a", 1)]
|
|
|
|
["England"].Army("Lon").MovesTo("Yor", a0)
|
2022-04-10 04:10:44 +00:00
|
|
|
.Execute()
|
2024-08-12 16:28:56 +00:00
|
|
|
// Head seasons: a2, b1
|
|
|
|
[("a", 2)]
|
|
|
|
[("b", 1)]
|
|
|
|
["England"].Army("Yor").MovesTo("Edi", a0)
|
2022-04-10 04:10:44 +00:00
|
|
|
.Execute()
|
2024-08-12 16:28:56 +00:00
|
|
|
// Head seasons: a3, b2, c1
|
2022-04-10 04:10:44 +00:00
|
|
|
// All three of these contain copies of the armies in Mun and Tyr.
|
2024-08-12 16:28:56 +00:00
|
|
|
// As above, Germany dislodges Austria in Tyr a3 by supporting the move from b2.
|
|
|
|
[("a", 3)]
|
|
|
|
.GetReference(out var a3)
|
2022-04-10 04:10:44 +00:00
|
|
|
["Germany"].Army("Mun").MovesTo("Tyr")
|
|
|
|
["Austria"].Army("Tyr").Holds()
|
2024-08-12 16:28:56 +00:00
|
|
|
[("b", 2)]
|
|
|
|
.GetReference(out Season b2)
|
|
|
|
["Germany"].Army("Mun").Supports.Army("Mun", a3).MoveTo("Tyr").GetReference(out var mun_b2)
|
2022-04-10 04:10:44 +00:00
|
|
|
["Austria"].Army("Tyr").Holds()
|
2024-08-12 16:28:56 +00:00
|
|
|
[("c", 1)]
|
2022-04-10 04:10:44 +00:00
|
|
|
["Germany"].Army("Mun").Holds()
|
|
|
|
["Austria"].Army("Tyr").Holds()
|
|
|
|
.Execute()
|
2024-08-12 16:28:56 +00:00
|
|
|
// Head seasons: a4, b3, c2
|
|
|
|
// Now Austria cuts the support in b2 by attacking from c2.
|
|
|
|
[("a", 4)]
|
2022-04-10 04:10:44 +00:00
|
|
|
["Germany"].Army("Tyr").Holds()
|
2024-08-12 16:28:56 +00:00
|
|
|
[("b", 3)]
|
2022-04-10 04:10:44 +00:00
|
|
|
["Germany"].Army("Mun").Holds()
|
|
|
|
["Austria"].Army("Tyr").Holds()
|
2024-08-12 16:28:56 +00:00
|
|
|
[("c", 2)]
|
2022-04-10 04:10:44 +00:00
|
|
|
["Germany"].Army("Mun").Holds()
|
2024-08-12 16:28:56 +00:00
|
|
|
["Austria"].Army("Tyr").MovesTo("Mun", b2).GetReference(out var tyr_c2);
|
2022-04-10 04:10:44 +00:00
|
|
|
|
2024-08-12 16:28:56 +00:00
|
|
|
// The attack on Mun b2 is repelled, but the support is cut.
|
2022-04-10 04:10:44 +00:00
|
|
|
setup.ValidateOrders();
|
2024-08-12 16:28:56 +00:00
|
|
|
Assert.That(tyr_c2, Is.Valid);
|
2022-04-10 04:10:44 +00:00
|
|
|
setup.AdjudicateOrders();
|
2024-08-12 16:28:56 +00:00
|
|
|
Assert.That(tyr_c2, Is.Repelled);
|
|
|
|
Assert.That(mun_b2, Is.NotDislodged);
|
|
|
|
Assert.That(mun_b2, Is.Cut);
|
2022-04-10 04:10:44 +00:00
|
|
|
|
|
|
|
// Though the support was cut, the timeline doesn't fork because the outcome of a battle
|
|
|
|
// wasn't changed in this timeline.
|
|
|
|
World world = setup.UpdateWorld();
|
|
|
|
Assert.That(
|
2024-08-15 20:51:41 +00:00
|
|
|
world.Timelines.GetFutures(a3).Count(),
|
2022-04-10 04:10:44 +00:00
|
|
|
Is.EqualTo(1),
|
|
|
|
"A cross-timeline support cut incorrectly forked the timeline");
|
|
|
|
Assert.That(
|
2024-08-15 20:51:41 +00:00
|
|
|
world.Timelines.GetFutures(b2).Count(),
|
2022-04-10 04:10:44 +00:00
|
|
|
Is.EqualTo(1),
|
|
|
|
"A cross-timeline support cut incorrectly forked the timeline");
|
|
|
|
}
|
2022-03-30 03:40:19 +00:00
|
|
|
}
|