;================================================================
; mahjong/mahjong_play 麻将游戏 实际业务逻辑
; mahjong_run_round.erb 进行整场游戏（ba）
;================================================================


;;;初始化整场麻将游戏
;;;@return 没有返回值
@MahjongInitRoom
    CALL PrintLine
    SELECTCASE MJ_GAME_RULE
        CASE 0  ; 四人东
            VARSET MJ_PLAYER_POINTS, 25000
            MJ_ROUND_INDEX = 1
            MJ_HONBA_COUNT = 0
            MJ_RIICHI_COUNT = 0
            MJ_ROUND_WIND = MJ_STARTING_WIND
            MJ_PLAYER_SEAT = RAND:4
            ; TODO debug 每次都是东家
            MJ_PLAYER_SEAT = 0
        CASEELSE
            ; PASS
    ENDSELECT
    CALL PrintLog(@"已初始化麻将游戏房间，当前规则为{MJ_PLAYER_COUNT}人%MJ_ENUM_SEAT:MJ_STARTING_WIND%。")
    RETURN


;;;开始一场完整的麻将游戏
;;;@return 没有返回值
@MahjongStartGame
    CALL MahjongInitRoom
    WHILE 1
        CALL MahjongInitGame
        CALL MahjongMainLoop
        CALL MahjongSettleGame
        SIF MINARRAY(MJ_PLAYER_POINTS) <= 0 || (MJ_ROUND_WIND >= 1 && MAXARRAY(MJ_PLAYER_POINTS) >= 35000)
            BREAK
    WEND
    RETURN
