public static class TransitionHarness
{
    private static void SetBoard(HoldemGame game, int flop0, int flop1, int flop2, int turn, int river)
    {
        VrcRuntimeFake.SetPrivate(game, "flop0", flop0);
        VrcRuntimeFake.SetPrivate(game, "flop1", flop1);
        VrcRuntimeFake.SetPrivate(game, "flop2", flop2);
        VrcRuntimeFake.SetPrivate(game, "turn", turn);
        VrcRuntimeFake.SetPrivate(game, "river", river);
    }

    private static int Board(HoldemGame game, string field)
    {
        return (int)VrcRuntimeFake.GetPrivate(game, field);
    }

    // [0] tableState .. [22] callOnlyMask, or null when nothing serializable changed.
    public static object[] CalculateTransition(HoldemGame game,
            int tableState, int lastTransitionMillis, int bettingRound, int actingSeat, int dealerSeat,
            int currentBet, int minimumRaise, bool headsUp, bool wonByFold,
            int[] playerState, int[] stacks, int[] roundContribution, int[] potContribution,
            int flop0, int flop1, int flop2, int turn, int river,
            int[] holeCards0, int[] holeCards1,
            int aggressorSeat, int winnerMask,
            int nowMillis, int bigBlind,
            int winnerTimeoutSecs, int readyTimeoutSecs,
            int actionTimeoutSecs, int headsUpTimeoutSecs,
            bool[] playerIsSeated, bool[] playerIsReady, bool bReceivedBalanceUpdate,
            int actingPlayerBet, bool actingPlayerCommited,
            int[] deck)
    {
        game.tableState = tableState;
        game.lastTransitionMillis = lastTransitionMillis;
        game.bettingRound = bettingRound;
        game.actingSeat = actingSeat;
        game.dealerSeat = dealerSeat;
        game.currentBet = currentBet;
        game.minimumRaise = minimumRaise;
        game.headsUp = headsUp;
        game.wonByFold = wonByFold;
        game.playerState = playerState;
        game.stacks = stacks;
        game.roundContribution = roundContribution;
        game.potContribution = potContribution;
        SetBoard(game, flop0, flop1, flop2, turn, river);
        game.holeCards0 = holeCards0;
        game.holeCards1 = holeCards1;
        game.aggressorSeat = aggressorSeat;
        game.winnerMask = winnerMask;
        game.bigBlind = bigBlind;
        game.winnerTimeoutSecs = winnerTimeoutSecs;
        game.readyTimeoutSecs = readyTimeoutSecs;
        game.actionTimeoutSecs = actionTimeoutSecs;
        VrcRuntimeFake.SetPrivate(game, "headsUpTimeoutSecs", headsUpTimeoutSecs);

        if (!game.Advance(nowMillis, playerIsSeated, playerIsReady, bReceivedBalanceUpdate,
                actingPlayerBet, actingPlayerCommited, deck)) return null;

        return new object[]
        {
            game.tableState, game.lastTransitionMillis, game.bettingRound, game.actingSeat, game.dealerSeat,
            game.currentBet, game.minimumRaise, game.headsUp, game.wonByFold,
            game.playerState, game.stacks, game.roundContribution, game.potContribution,
            Board(game, "flop0"), Board(game, "flop1"), Board(game, "flop2"), Board(game, "turn"), Board(game, "river"),
            game.holeCards0, game.holeCards1,
            game.aggressorSeat, game.winnerMask, game.callOnlyMask
        };
    }

    // [0] bettingRound .. [11] callOnlyMask, or null while waiting on the acting seat.
    public static object[] CalculateGameTransition(HoldemGame game,
            int lastTransitionMillis, int bettingRound, int actingSeat,
            int currentBet, int minimumRaise, bool headsUp,
            int[] currentPlayerState,
            int[] stacks, int[] roundContribution, int[] potContribution,
            int nowMillis,
            int actTimeoutSecs, int headsUpTimeoutSecs, int bigBlind, int dealerSeat, bool actingPlayerSeated,
            int actingPlayerBet, bool actingPlayerCommitted,
            int aggressorSeat, int callOnlyMask)
    {
        game.lastTransitionMillis = lastTransitionMillis;
        game.bettingRound = bettingRound;
        game.actingSeat = actingSeat;
        game.currentBet = currentBet;
        game.minimumRaise = minimumRaise;
        game.headsUp = headsUp;
        game.playerState = currentPlayerState;
        game.stacks = stacks;
        game.roundContribution = roundContribution;
        game.potContribution = potContribution;
        game.actionTimeoutSecs = actTimeoutSecs;
        VrcRuntimeFake.SetPrivate(game, "headsUpTimeoutSecs", headsUpTimeoutSecs);
        game.bigBlind = bigBlind;
        game.dealerSeat = dealerSeat;
        game.aggressorSeat = aggressorSeat;
        game.callOnlyMask = callOnlyMask;

        if (!game.AdvanceBetting(nowMillis, actingPlayerSeated, actingPlayerBet, actingPlayerCommitted)) return null;

        return new object[]
        {
            game.bettingRound, game.actingSeat, game.currentBet, game.minimumRaise, game.headsUp, game.wonByFold,
            game.playerState, game.stacks, game.roundContribution, game.potContribution,
            game.aggressorSeat, game.callOnlyMask
        };
    }

    public static int CalculateTableTransition(HoldemGame game,
            int currentTableState, int lastTransitionMillis,
            int nowMillis, int bettingRound, bool wonByFold, int bigBlind,
            int winnerTimeoutSecs, int readyTimeoutSecs,
            bool[] playerIsSeated, bool[] playerIsReady, int[] stacks)
    {
        game.tableState = currentTableState;
        game.lastTransitionMillis = lastTransitionMillis;
        game.bettingRound = bettingRound;
        game.wonByFold = wonByFold;
        game.bigBlind = bigBlind;
        game.winnerTimeoutSecs = winnerTimeoutSecs;
        game.readyTimeoutSecs = readyTimeoutSecs;
        game.stacks = stacks;
        return game.NextTableState(nowMillis, playerIsSeated, playerIsReady);
    }
}
