-- Cycle the turns during setup to allow players purchasing their initial stocks.
-- @author Eric Pietrocupo
-- @date March 21st, 2026
-- @license GNU GPL 3.0
--



-- increment active player, or reset to the first player
-- The select case simulate a modulus operator
UPDATE game
SET fk_active_player = (
    SELECT CASE
        WHEN fk_active_player < (SELECT MAX(pk) FROM player)
        THEN fk_active_player + 1
        ELSE 1
    END
);

-- Increment game turn when it returns back to player 1 to play
UPDATE game
SET turn_number = turn_number + 1
WHERE fk_active_player = 1;


