Skip to content

Commit b1e4d95

Browse files
committed
fix stream crash
1 parent 561ec13 commit b1e4d95

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

Motely/MotelySingleSearchContext.Jokers.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public MotelySingleItemSet GetNextBuffoonPackContents(ref MotelySingleJokerStrea
137137

138138
public MotelySingleItemSet GetNextBuffoonPackContents(ref MotelySingleJokerStream jokerStream, int size)
139139
{
140+
Debug.Assert(!jokerStream.RarityPrngStream.IsInvalid, "Joker stream must have valid rarity PRNG");
140141
Debug.Assert(size <= MotelySingleItemSet.MaxLength);
141142

142143
MotelySingleItemSet pack = new();

Motely/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static int Main(string[] args)
5050

5151
var cutoffOption = app.Option<string>(
5252
"--cutoff <SCORE>",
53-
"Minimum TotalScore threshold (1-10 for fixed, 0 for auto-cutoff)",
53+
"Minimum TotalScore threshold (0+ for fixed, 'auto' for auto-cutoff)",
5454
CommandOptionType.SingleValue);
5555
cutoffOption.DefaultValue = "0";
5656

@@ -149,9 +149,9 @@ static int Main(string[] args)
149149
var batchSize = batchSizeOption.ParsedValue;
150150
var enableDebug = debugOption.HasValue();
151151
var cutoffStr = cutoffOption.Value() ?? "0";
152-
int cutoffValue = int.TryParse(cutoffStr, out var c) ? c : 0;
153-
bool autoCutoff = cutoffValue == 0; // 0 means auto-cutoff
154-
int cutoff = autoCutoff ? 1 : cutoffValue; // Start at 1 for auto-cutoff
152+
bool autoCutoff = cutoffStr.ToLowerInvariant() == "auto";
153+
int cutoffValue = autoCutoff ? 1 : (int.TryParse(cutoffStr, out var c) ? c : 0);
154+
int cutoff = cutoffValue; // Use the parsed value or 1 for auto
155155

156156
// Validate batch ranges based on search space
157157
ulong maxBatches = (ulong)Math.Pow(35, 8 - batchSize); // 35^(8-batchSize)

Motely/filters/MotelyJson/MotelyJsonFilterDesc.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,32 +234,35 @@ private VectorMask FilterJokers(ref MotelyVectorSearchContext ctx)
234234
if (clauses.Count == 1 && clauses[0].ItemTypeEnum == MotelyFilterItemType.SoulJoker &&
235235
clauses[0].JokerEnum == MotelyJoker.Perkeo)
236236
{
237+
// Capture clause to avoid closure issues
238+
var perkeoClause = clauses[0];
239+
var effectiveAntes = perkeoClause.EffectiveAntes ?? new[] { 1, 2, 3, 4, 5, 6, 7, 8 };
237240
return ctx.SearchIndividualSeeds((ref MotelySingleSearchContext singleCtx) =>
238241
{
239242
// Fast path for Perkeo check
240-
foreach (var ante in clauses[0].EffectiveAntes)
243+
foreach (var ante in effectiveAntes)
241244
{
242-
var packStream = singleCtx.CreateBoosterPackStream(ante, ante != 1, false);
245+
var packStream = singleCtx.CreateBoosterPackStream(ante, ante != 1, isCached: true);
243246
for (int i = 0; i < 4; i++) // Check first 4 packs
244247
{
245248
var pack = singleCtx.GetNextBoosterPack(ref packStream);
246249

247250
if (pack.GetPackType() == MotelyBoosterPackType.Arcana)
248251
{
249-
var tarotStream = singleCtx.CreateArcanaPackTarotStream(ante, true);
252+
var tarotStream = singleCtx.CreateArcanaPackTarotStream(ante, soulOnly: true, isCached: true);
250253
if (singleCtx.GetNextArcanaPackHasTheSoul(ref tarotStream, pack.GetPackSize()))
251254
{
252-
var soulStream = singleCtx.CreateSoulJokerStream(ante);
255+
var soulStream = singleCtx.CreateSoulJokerStream(ante, isCached: true);
253256
if (singleCtx.GetNextJoker(ref soulStream).Type == MotelyItemType.Perkeo)
254257
return true;
255258
}
256259
}
257260
else if (pack.GetPackType() == MotelyBoosterPackType.Spectral)
258261
{
259-
var spectralStream = singleCtx.CreateSpectralPackSpectralStream(ante, true);
262+
var spectralStream = singleCtx.CreateSpectralPackSpectralStream(ante, soulOnly: true, isCached: true);
260263
if (singleCtx.GetNextSpectralPackHasTheSoul(ref spectralStream, pack.GetPackSize()))
261264
{
262-
var soulStream = singleCtx.CreateSoulJokerStream(ante);
265+
var soulStream = singleCtx.CreateSoulJokerStream(ante, isCached: true);
263266
if (singleCtx.GetNextJoker(ref soulStream).Type == MotelyItemType.Perkeo)
264267
return true;
265268
}

Motely/filters/MotelyJson/MotelyJsonScoring.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ public static int CountJokerOccurrences(ref MotelySingleSearchContext ctx, Motel
324324
if (clause.Sources?.PackSlots?.Length > 0)
325325
{
326326
var buffoonStream = ctx.CreateBuffoonPackJokerStream(ante);
327+
Debug.Assert(!buffoonStream.RarityPrngStream.IsInvalid, $"BuffoonStream RarityPrng should be valid for ante {ante}");
327328
var packSlots = clause.Sources.PackSlots;
328329
int maxPackSlot = clause.MaxPackSlot ?? (packSlots.Length > 0 ? packSlots.Max() : 0);
329330
for (int i = 0; i <= maxPackSlot; i++)

0 commit comments

Comments
 (0)