# src/core/round.gd
class_name Round
extends RefCounted

var active_player_idx: int = 0
var pass_count: int = 0
var table: Array = []
var action_seq: int = 0
var is_cleared: bool = false

func can_pass() -> bool:
    return not table.is_empty()

func add_play(play: HandEvaluator.EvaluatedPlay, player_idx: int) -> void:
    table.append(play)
    if play.type == -1:
        pass_count += 1
    else:
        pass_count = 0
    if pass_count >= 3:
        is_cleared = true
    else:
        is_cleared = false

func next_player() -> int:
    return (active_player_idx + 1) % 4

func last_non_pass_player() -> int:
    for i in range(table.size() - 1, -1, -1):
        if table[i].type != -1:
            return i % 4
    return -1

func next_seq() -> int:
    action_seq += 1
    return action_seq

func reset_for_new_round() -> void:
    table.clear()
    pass_count = 0
    is_cleared = false
