Skip to content

Commit

Permalink
Allowing seeded layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
merschformann committed Jul 17, 2024
1 parent 70cd507 commit cfd2b7c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 61 deletions.
4 changes: 4 additions & 0 deletions RAWSimO.Core/Configurations/LayoutConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public class LayoutConfiguration

#region member variables

/// <summary>
/// The seed used to initialize the RNG.
/// </summary>
public int Seed = 0;
/// <summary>
/// The number of tiers to generate.
/// </summary>
Expand Down
64 changes: 31 additions & 33 deletions RAWSimO.Core/Generator/InstanceGenerator.cs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions RAWSimO.Core/Generator/LayoutGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal static void DebugPrintLayout(Tile[,] tiles, bool showRows = false, bool
Console.Write((
showRows ? i.ToString().PadLeft(maxRowIndexLength) :
showCols ? j.ToString().PadLeft(maxColIndexLength) :
(tiles[i, j] != null ? tiles[i, j].directionAsString() : " ")) +
(tiles[i, j] != null ? tiles[i, j].directionAsString() : " ")) +
(j == tiles.GetLength(1) - 1 ? "" : " "));
Console.WriteLine();
}
Expand All @@ -179,7 +179,6 @@ internal static void DebugPrintLayout(Tile[,] tiles, bool showRows = false, bool

public LayoutGenerator(
LayoutConfiguration layoutConfiguration,
IRandomizer rand,
SettingConfiguration baseConfiguration,
ControlConfiguration controlConfiguration,
Action<string> logAction = null)
Expand All @@ -202,7 +201,7 @@ public LayoutGenerator(
throw new ArgumentException("ControlConfiguration is not valid. " + errorMessage);
}

this.rand = rand;
this.rand = new RandomizerSimple(layoutConfiguration.Seed);
this.baseConfiguration = baseConfiguration;
elevatorPositions = new Dictionary<Tuple<double, double>, Elevator>();
elevatorWaypoints = new Dictionary<Elevator, List<Waypoint>>();
Expand Down
2 changes: 1 addition & 1 deletion RAWSimO.Core/IO/InstanceIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static Instance ReadInstance(
layoutConfig.ApplyOverrideConfig(settingConfig.OverrideConfig);
// Generate instance
logAction?.Invoke("Generating instance...");
instance = InstanceGenerator.GenerateLayout(layoutConfig, new RandomizerSimple(0), settingConfig, controlConfig, logAction);
instance = InstanceGenerator.GenerateLayout(layoutConfig, settingConfig, controlConfig, logAction);
}
else
{
Expand Down
37 changes: 15 additions & 22 deletions RAWSimO.Playground/Generators/InstanceGenerators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,23 @@ class InstanceGenerators
{
public static void GenerateMaTiInstances()
{
// Generate MaTi instances
RandomizerSimple random = new RandomizerSimple(0);
// Generate original MaTi set
Instance tiny = InstanceGenerator.GenerateMaTiLayoutTiny(random, new SettingConfiguration(), new ControlConfiguration());
Instance small = InstanceGenerator.GenerateMaTiLayoutSmall(random, new SettingConfiguration(), new ControlConfiguration());
Instance medium = InstanceGenerator.GenerateMaTiLayoutMedium(random, new SettingConfiguration(), new ControlConfiguration());
Instance large = InstanceGenerator.GenerateMaTiLayoutLarge(random, new SettingConfiguration(), new ControlConfiguration());
Instance huge = InstanceGenerator.GenerateMaTiLayoutHuge(random, new SettingConfiguration(), new ControlConfiguration());
InstanceIO.WriteInstance("MaTiTiny.xinst", tiny);
InstanceIO.WriteInstance("MaTiSmall.xinst", small);
InstanceIO.WriteInstance("MaTiMedium.xinst", medium);
InstanceIO.WriteInstance("MaTiLarge.xinst", large);
InstanceIO.WriteInstance("MaTiHuge.xinst", huge);
InstanceIO.WriteInstance("MaTiTiny.xinst", InstanceGenerator.GenerateMaTiLayoutTiny(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiSmall.xinst", InstanceGenerator.GenerateMaTiLayoutSmall(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiMedium.xinst", InstanceGenerator.GenerateMaTiLayoutMedium(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiLarge.xinst", InstanceGenerator.GenerateMaTiLayoutLarge(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiHuge.xinst", InstanceGenerator.GenerateMaTiLayoutHuge(new SettingConfiguration(), new ControlConfiguration()));
// Generate alternative MaTi set
InstanceIO.WriteInstance("MaTiPico.xinst", InstanceGenerator.GenerateMaTiLayoutPico(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiNano.xinst", InstanceGenerator.GenerateMaTiLayoutNano(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiMicro.xinst", InstanceGenerator.GenerateMaTiLayoutMicro(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiMilli.xinst", InstanceGenerator.GenerateMaTiLayoutMilli(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiCenti.xinst", InstanceGenerator.GenerateMaTiLayoutCenti(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiDeca.xinst", InstanceGenerator.GenerateMaTiLayoutDeca(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiHecto.xinst", InstanceGenerator.GenerateMaTiLayoutHecto(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiKilo.xinst", InstanceGenerator.GenerateMaTiLayoutKilo(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiMega.xinst", InstanceGenerator.GenerateMaTiLayoutMega(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiGiga.xinst", InstanceGenerator.GenerateMaTiLayoutGiga(random, new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiPico.xinst", InstanceGenerator.GenerateMaTiLayoutPico(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiNano.xinst", InstanceGenerator.GenerateMaTiLayoutNano(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiMicro.xinst", InstanceGenerator.GenerateMaTiLayoutMicro(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiMilli.xinst", InstanceGenerator.GenerateMaTiLayoutMilli(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiCenti.xinst", InstanceGenerator.GenerateMaTiLayoutCenti(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiDeca.xinst", InstanceGenerator.GenerateMaTiLayoutDeca(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiHecto.xinst", InstanceGenerator.GenerateMaTiLayoutHecto(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiKilo.xinst", InstanceGenerator.GenerateMaTiLayoutKilo(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiMega.xinst", InstanceGenerator.GenerateMaTiLayoutMega(new SettingConfiguration(), new ControlConfiguration()));
InstanceIO.WriteInstance("MaTiGiga.xinst", InstanceGenerator.GenerateMaTiLayoutGiga(new SettingConfiguration(), new ControlConfiguration()));
}
}
}
3 changes: 1 addition & 2 deletions RAWSimO.Visualization/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,7 @@ private void ButtonGenerateInstance_Click(object sender, RoutedEventArgs e)
_baseConfiguration.VisualizationAttached = true;

// Generate
IRandomizer rand = new RandomizerSimple(0);
_instance = InstanceGenerator.GenerateLayout(_layoutConfig, rand, _baseConfiguration, _controlConfiguration);
_instance = InstanceGenerator.GenerateLayout(_layoutConfig, _baseConfiguration, _controlConfiguration);
_instanceInvalidated = false;
_instance.Name = _instance.GetMetaInfoBasedInstanceName();

Expand Down

0 comments on commit cfd2b7c

Please sign in to comment.