feat(battle-node): CountHiddenDraws — hidden shared-RNG draw tally for real spin
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,41 @@ internal static class KnownListBuilder
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Count hidden, non-reproduced shared-RNG draws implied by an orderList: <c>move</c> ops
|
||||
/// from Deck(0) to Hand(10) for a non-played, unrevealed card (a random fetch the opponent can't
|
||||
/// reproduce — it can't enumerate the active player's deck). Each such moved card = one crank the
|
||||
/// receiver must apply (<c>spin += 1</c>). Skips: the played card's own move (<c>idx == playIdx</c>);
|
||||
/// any idx in <paramref name="revealed"/> (its identity is already on the wire — a revealed uList
|
||||
/// fetch); and lot-based randoms (a <c>move</c> op carrying a <c>rand</c> array — the receiver
|
||||
/// reproduces those by re-rolling, so counting would double-crank). An ordinary card DRAW also
|
||||
/// surfaces as a hidden <c>move(0→10)</c> but is a deterministic top-of-deck pop (no shared-stream
|
||||
/// roll) and must NOT be counted — distinguishing it from a random fetch on the wire is the open
|
||||
/// capture (real-spin design §3.1; the spec's Task 0). Base 0; see the real-spin design doc.</summary>
|
||||
public static int CountHiddenDraws(object? orderList, int playIdx, IReadOnlySet<int> revealed)
|
||||
{
|
||||
if (orderList is not IEnumerable<object?> ops) return 0;
|
||||
var count = 0;
|
||||
foreach (var op in ops)
|
||||
{
|
||||
if (op is not IDictionary<string, object?> opDict) continue;
|
||||
if (!opDict.TryGetValue("move", out var moveRaw) || moveRaw is not IDictionary<string, object?> move) continue;
|
||||
|
||||
if (move.ContainsKey("rand")) continue; // lot random → receiver re-rolls
|
||||
if (!move.TryGetValue("from", out var fromRaw) || (int)AsLong(fromRaw) != 0) continue; // not from Deck
|
||||
if (!move.TryGetValue("to", out var toRaw) || (int)AsLong(toRaw) != 10) continue; // not to Hand
|
||||
if (!move.TryGetValue("idx", out var idxRaw) || idxRaw is not IEnumerable<object?> idxList) continue;
|
||||
|
||||
foreach (var i in idxList)
|
||||
{
|
||||
var idx = (int)AsLong(i);
|
||||
if (idx == playIdx) continue; // the played card's own move
|
||||
if (revealed.Contains(idx)) continue; // opponent already knows this card's identity
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/// <summary>Mine generated-token identities from a sender's <c>add</c> ops: yields
|
||||
/// <c>(idx, cardId, isSelf)</c> for every idx in each <c>{add:{idx:[...], isSelf, card:{cardId}}}</c>
|
||||
/// op. <c>isSelf</c> is surfaced verbatim (the sender's perspective tag on <c>CardObj.IsPlayer</c>,
|
||||
|
||||
@@ -20,6 +20,78 @@ public class KnownListBuilderTests
|
||||
}
|
||||
};
|
||||
|
||||
// A move op dict allowing extra keys (e.g. "rand") for CountHiddenDraws fixtures.
|
||||
private static Dictionary<string, object?> MoveOp(long[] idxs, int from, int to,
|
||||
IDictionary<string, object?>? extra = null)
|
||||
{
|
||||
var move = new Dictionary<string, object?>
|
||||
{
|
||||
["idx"] = idxs.Select(i => (object?)i).ToList(),
|
||||
["isSelf"] = 1L, ["from"] = (long)from, ["to"] = (long)to,
|
||||
};
|
||||
if (extra is not null) foreach (var kv in extra) move[kv.Key] = kv.Value;
|
||||
return new Dictionary<string, object?> { ["move"] = move };
|
||||
}
|
||||
|
||||
private static readonly IReadOnlySet<int> NoneRevealed = new HashSet<int>();
|
||||
|
||||
[Test]
|
||||
public void CountHiddenDraws_counts_a_hidden_deck_to_hand_fetch()
|
||||
{
|
||||
// Hoverboard-shaped: move(0->10) for a non-played, unrevealed token idx.
|
||||
var orderList = new List<object?> { MoveOp(new[] { 31L }, from: 0, to: 10) };
|
||||
Assert.That(KnownListBuilder.CountHiddenDraws(orderList, playIdx: 3, NoneRevealed), Is.EqualTo(1));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountHiddenDraws_ignores_the_played_cards_own_move()
|
||||
{
|
||||
// The played card moving hand(10)->field(20) is not a draw.
|
||||
var orderList = new List<object?> { MoveOp(new[] { 3L }, from: 10, to: 20) };
|
||||
Assert.That(KnownListBuilder.CountHiddenDraws(orderList, playIdx: 3, NoneRevealed), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountHiddenDraws_ignores_a_visible_destroy()
|
||||
{
|
||||
// A visible field(20)->cemetery(30) destroy is reproduced by the receiver → 0.
|
||||
var orderList = new List<object?> { MoveOp(new[] { 8L }, from: 20, to: 30) };
|
||||
Assert.That(KnownListBuilder.CountHiddenDraws(orderList, playIdx: 3, NoneRevealed), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountHiddenDraws_ignores_a_revealed_fetch()
|
||||
{
|
||||
// The fetched idx's identity was revealed to the opponent (in `revealed`) → 0.
|
||||
var orderList = new List<object?> { MoveOp(new[] { 31L }, from: 0, to: 10) };
|
||||
var revealed = new HashSet<int> { 31 };
|
||||
Assert.That(KnownListBuilder.CountHiddenDraws(orderList, playIdx: 3, revealed), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountHiddenDraws_ignores_a_lot_based_random()
|
||||
{
|
||||
// A move op carrying a `rand` array is reproduced (re-rolled) by the receiver → 0.
|
||||
var rand = new Dictionary<string, object?> { ["rand"] = new List<object?> { 0.5d } };
|
||||
var orderList = new List<object?> { MoveOp(new[] { 31L }, from: 0, to: 10, extra: rand) };
|
||||
Assert.That(KnownListBuilder.CountHiddenDraws(orderList, playIdx: 3, NoneRevealed), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountHiddenDraws_counts_each_hidden_card_in_a_multi_fetch()
|
||||
{
|
||||
var orderList = new List<object?> { MoveOp(new[] { 31L, 32L }, from: 0, to: 10) };
|
||||
Assert.That(KnownListBuilder.CountHiddenDraws(orderList, playIdx: 3, NoneRevealed), Is.EqualTo(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountHiddenDraws_returns_zero_for_a_vanilla_play()
|
||||
{
|
||||
var orderList = new List<object?> { MoveOp(new[] { 3L }, from: 10, to: 20) };
|
||||
Assert.That(KnownListBuilder.CountHiddenDraws(orderList, playIdx: 3, NoneRevealed), Is.EqualTo(0));
|
||||
Assert.That(KnownListBuilder.CountHiddenDraws(null, playIdx: 3, NoneRevealed), Is.EqualTo(0));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExtractMoveTo_returns_to_for_matching_idx()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user