system "Trojan's Square v2"
{
*************************************
*          System by Trojan
*         on the VIP Lounge
*       Roulette Extreme Code
*              by Moch
*           00-compatible
*************************************


}
method "main" begin
    // start up
    while starting new session begin
        Clear all records
        call "Init"
        call "WheelType"
        exit
    end

    // count spins
    add 1 record"TotalSpins" data

    copy last number record"LastN"layout

    if record"LastN"layout = number 0 or record"LastN"layout = number 00 begin
        subtract 1 record"TotalSpins" data
        exit
    end

    if record"TotalSpins" data = 1 and flag "Ready2Bet" false and record"ChooseLayout"data = 2 begin
        call"LayNumbersOnSquare"
    end

    if flag "Ready2Bet" false begin
        call "CrossOffNumbers"
    end

    // act on a loss
    if net < 0 begin
        if record"BetType"data < 5 begin
            add 1 record"Progression"data index
            if record"Progression"data index > record"MaxSteps"data begin
                put 1 record"Progression"data index
                call "Reset"
                set flag "qualified" false
            end
        end
    end

    // act on a win
    if net > 0 begin // Bankroll
        if record"BetType"data = 5 begin
            if bankroll > record"HighBankroll"data begin
                put 100% bankroll record"HighBankroll"data
            end
        end
        else begin
            put 1 record"Progression"data index
        end
        call "Reset"
        set flag "qualified" false
    end

    // act when not qualified
    if flag "qualified" false begin
        if flag "Ready2Bet" true begin
            set flag "qualified" true
        end
    end

    // act when  qualified
    if flag "qualified" true begin
        if record"BetType"data = 5 begin
            call "CalculateNextBet"
        end
        put 100% record"Progression"data record"BetLayout"layout list
    end
end

// Methods
method "Init" begin
     call "Reset"
    // defaults
    put 0 record"TotalSpins"data
    // Input
    group begin
        display "System Trojan's Square"
        display "by Trojan on the VIP Lounge"
        display "coded by Moch"
        display "00-compatible"
        input dropdown "Wheel Type ?
            1:= Single Wheel
            2:= Double Wheel" record"Wheel"data
        input dropdown "Choose Layout
            1:= Start with 6, or
            2:= Start with 1st number of the session" record"ChooseLayout"data
        input dropdown "Progression
            1:= 3 steps
            2:= 4
            3:= 5
            4:= 6
            5:= Profit on a win" record"BetType"data
    end
    // flags
    set flag "qualified" false
    set flag "Ready2Bet" false
    // assign
    put 100% bankroll record"HighBankroll"data
    put 100% bankroll record"LowBankroll"data

    if record"ChooseLayout"data = 1 begin
        if record"Wheel"data = 1 begin
            copy list [ 6,27,13,36,11,30] record"Row1"layout
            copy list [ 8,23,10, 5,24,16] record"Row2"layout
            copy list [33, 1,20,14,31, 9] record"Row3"layout
            copy list [22,18,29, 7,28,12] record"Row4"layout
            copy list [35, 3,26,32,15,19] record"Row5"layout
            copy list [ 4,21, 2,25,17,34] record"Row6"layout
        end
        else begin
            copy list [ 6,21,33,16, 4,23] record"Row1"layout
            copy list [35,14, 2,28, 9,26] record"Row2"layout
            copy list [30,11, 7,20,32,17] record"Row3"layout
            copy list [ 5,22,34,15, 3,24] record"Row4"layout
            copy list [36,13, 1,27,10,25] record"Row5"layout
            copy list [29,12, 8,19,31,18] record"Row6"layout
        end
    end
    if record"BetType"data < 5 begin
        set list [1,1,2,3,4,6] record"Progression"data
        put 1 record"Progression"data
        if record"BetType"data=1 begin
            put 3 record"MaxSteps"data
        end
        if record"BetType"data=2 begin
            put 4 record"MaxSteps"data
        end
        if record"BetType"data=3 begin
            put 5 record"MaxSteps"data
        end
        if record"BetType"data=4 begin
            put 6 record"MaxSteps"data
        end
    end
end

method "CalculateNextBet" begin
    put 0 record"Progression"data
    put 0 record"Balance"data
    //set max record"BetLayout"layout index
    put 100% record"BetLayout"layout index record"Units"data
    loop until record"Balance"data > record"HighBankroll"data begin
        add 1 record"Progression"data
        duplicate record"Progression" record"Balance"
        put 36 record"Payoff"data
        subtract 100% record"Units"data record"Payoff"data
        multiply 100% record"Payoff"data record"Balance"data
        add 100% bankroll record"Balance"data
    end
end

method "Reset" begin
    set list [0,0,0,0,0,0] record"Row1"data
    set list [0,0,0,0,0,0] record"Row2"data
    set list [0,0,0,0,0,0] record"Row3"data
    set list [0,0,0,0,0,0] record"Row4"data
    set list [0,0,0,0,0,0] record"Row5"data
    set list [0,0,0,0,0,0] record"Row6"data
    put 0 record"TotalSpins" data
    clear record"BetLayout"layout
    set flag "Ready2Bet" false
end

method "CrossOffNumbers" begin
    set flag "Ready2Bet" false
    put 0 record"XY"data
    put 0 record"X"data
    put 0 record"Y"data
    //cross off numbers horizontaly
     if record"LastN"layout found in record"Row1"layout begin
        put 1 record"Row1"layout index
        loop until record"Row1"layout index > record"Row1"layout count begin
            put 100% record"Row1"layout index record"Row1"data index
            if record"LastN"layout=record"Row1"layout begin
                if record"Row1"data=0 begin
                    put 100% record"Row1"layout index record"XY"data
                    put 1 record"Row1"data index
                    put 1 record"Row1"data
                    add 1 record"Row1"data index
                    put 1 record"Row1"data
                    add 1 record"Row1"data index
                    put 1 record"Row1"data
                    add 1 record"Row1"data index
                    put 1 record"Row1"data
                    add 1 record"Row1"data index
                    put 1 record"Row1"data
                    add 1 record"Row1"data index
                    put 1 record"Row1"data
                end
            end
            add 1 record"Row1"layout index
        end
     end
     if record"LastN"layout found in record"Row2"layout begin
        put 1 record"Row2"layout index
        loop until record"Row2"layout index > record"Row2"layout count begin
            put 100% record"Row2"layout index record"Row2"data index
            if record"LastN"layout=record"Row2"layout begin
                if record"Row2"data=0 begin
                    put 100% record"Row2"layout index record"XY"data
                    put 1 record"Row2"data index
                    put 1 record"Row2"data
                    add 1 record"Row2"data index
                    put 1 record"Row2"data
                    add 1 record"Row2"data index
                    put 1 record"Row2"data
                    add 1 record"Row2"data index
                    put 1 record"Row2"data
                    add 1 record"Row2"data index
                    put 1 record"Row2"data
                    add 1 record"Row2"data index
                    put 1 record"Row2"data
                end
            end
            add 1 record"Row2"layout index
        end
     end
     if record"LastN"layout found in record"Row3"layout begin
        put 1 record"Row3"layout index
        loop until record"Row3"layout index > record"Row3"layout count begin
            put 100% record"Row3"layout index record"Row3"data index
            if record"LastN"layout=record"Row3"layout begin
                if record"Row3"data=0 begin
                    put 100% record"Row3"layout index record"XY"data
                    put 1 record"Row3"data index
                    put 1 record"Row3"data
                    add 1 record"Row3"data index
                    put 1 record"Row3"data
                    add 1 record"Row3"data index
                    put 1 record"Row3"data
                    add 1 record"Row3"data index
                    put 1 record"Row3"data
                    add 1 record"Row3"data index
                    put 1 record"Row3"data
                    add 1 record"Row3"data index
                    put 1 record"Row3"data
                end
            end
            add 1 record"Row3"layout index
        end
     end
     if record"LastN"layout found in record"Row4"layout begin
        put 1 record"Row4"layout index
        loop until record"Row4"layout index > record"Row4"layout count begin
            put 100% record"Row4"layout index record"Row4"data index
            if record"LastN"layout=record"Row4"layout begin
                if record"Row4"data=0 begin
                    put 100% record"Row4"layout index record"XY"data
                    put 1 record"Row4"data index
                    put 1 record"Row4"data
                    add 1 record"Row4"data index
                    put 1 record"Row4"data
                    add 1 record"Row4"data index
                    put 1 record"Row4"data
                    add 1 record"Row4"data index
                    put 1 record"Row4"data
                    add 1 record"Row4"data index
                    put 1 record"Row4"data
                    add 1 record"Row4"data index
                    put 1 record"Row4"data
                end
            end
            add 1 record"Row4"layout index
        end
     end
     if record"LastN"layout found in record"Row5"layout begin
        put 1 record"Row5"layout index
        loop until record"Row5"layout index > record"Row5"layout count begin
            put 100% record"Row5"layout index record"Row5"data index
            if record"LastN"layout=record"Row5"layout begin
                if record"Row5"data=0 begin
                    put 100% record"Row5"layout index record"XY"data
                    put 1 record"Row5"data index
                    put 1 record"Row5"data
                    add 1 record"Row5"data index
                    put 1 record"Row5"data
                    add 1 record"Row5"data index
                    put 1 record"Row5"data
                    add 1 record"Row5"data index
                    put 1 record"Row5"data
                    add 1 record"Row5"data index
                    put 1 record"Row5"data
                    add 1 record"Row5"data index
                    put 1 record"Row5"data
                end
            end
            add 1 record"Row5"layout index
        end
     end
     if record"LastN"layout found in record"Row6"layout begin
        put 1 record"Row6"layout index
        loop until record"Row6"layout index > record"Row6"layout count begin
            put 100% record"Row6"layout index record"Row6"data index
            if record"LastN"layout=record"Row6"layout begin
                if record"Row6"data=0 begin
                    put 100% record"Row6"layout index record"XY"data
                    put 1 record"Row6"data index
                    put 1 record"Row6"data
                    add 1 record"Row6"data index
                    put 1 record"Row6"data
                    add 1 record"Row6"data index
                    put 1 record"Row6"data
                    add 1 record"Row6"data index
                    put 1 record"Row6"data
                    add 1 record"Row6"data index
                    put 1 record"Row6"data
                    add 1 record"Row6"data index
                    put 1 record"Row6"data
                end
            end
            add 1 record"Row6"layout index
        end
     end

    if record"XY"data > 0 begin
        //cross off numbers verticaly
        put 100% record"XY"data record"Row1"data index
        put 1 record"Row1"data
        put 100% record"XY"data record"Row2"data index
        put 1 record"Row2"data
        put 100% record"XY"data record"Row3"data index
        put 1 record"Row3"data
        put 100% record"XY"data record"Row4"data index
        put 1 record"Row4"data
        put 100% record"XY"data record"Row5"data index
        put 1 record"Row5"data
        put 100% record"XY"data record"Row6"data index
        put 1 record"Row6"data


    // check how many zeros left
    put 0 record"ZeroesLeft"data
    put 1 record"Row1"data index
    loop until record"Row1"data index > record"Row1"data count begin
        if record"Row1"data=0 begin
            put 100% record"Row1"data index record"X"data
            put 1 record"Y"data
            add 1 record"ZeroesLeft"data
            // save processing time
            if record"ZeroesLeft"data > 1 begin
                exit // get out of the loops
            end
        end
        add 1 record"Row1"data index
    end
    put 1 record"Row2"data index
    loop until record"Row2"data index > record"Row2"data count begin
        if record"Row2"data=0 begin
            put 100% record"Row2"data index record"X"data
            put 2 record"Y"data
            add 1 record"ZeroesLeft"data
            // save processing time
            if record"ZeroesLeft"data > 1 begin
                exit // get out of the loops
            end
        end
        add 1 record"Row2"data index
    end
    put 1 record"Row3"data index
    loop until record"Row3"data index > record"Row3"data count begin
        if record"Row3"data=0 begin
            put 100% record"Row3"data index record"X"data
            put 3 record"Y"data
            add 1 record"ZeroesLeft"data
            // save processing time
            if record"ZeroesLeft"data > 1 begin
                exit // get out of the loops
            end
        end
        add 1 record"Row3"data index
    end
    put 1 record"Row4"data index
    loop until record"Row4"data index > record"Row4"data count begin
        if record"Row4"data=0 begin
            put 100% record"Row4"data index record"X"data
            put 4 record"Y"data
            add 1 record"ZeroesLeft"data
            // save processing time
            if record"ZeroesLeft"data > 1 begin
                exit // get out of the loops
            end
        end
        add 1 record"Row4"data index
    end
    put 1 record"Row5"data index
    loop until record"Row5"data index > record"Row5"data count begin
        if record"Row5"data=0 begin
            put 100% record"Row5"data index record"X"data
            put 5 record"Y"data
            add 1 record"ZeroesLeft"data
            // save processing time
            if record"ZeroesLeft"data > 1 begin
                exit // get out of the loops
            end
        end
        add 1 record"Row5"data index
    end
    put 1 record"Row6"data index
    loop until record"Row6"data index > record"Row6"data count begin
        if record"Row6"data=0 begin
            put 100% record"Row6"data index record"X"data
            put 6 record"Y"data
            add 1 record"ZeroesLeft"data
            // save processing time
            if record"ZeroesLeft"data > 1 begin
                exit // get out of the loops
            end
        end
        add 1 record"Row6"data index
    end

    if record"ZeroesLeft"data = 0 begin
        call"Reset"
        exit
    end

    if record"ZeroesLeft"data = 1 begin
        clear record"BetLayout"layout
        if record"Y"data = 1 begin
            duplicate record"Row1" record"BetLayout"
        end
        if record"Y"data = 2 begin
            duplicate record"Row2" record"BetLayout"
        end
        if record"Y"data = 3 begin
            duplicate record"Row3" record"BetLayout"
        end
        if record"Y"data = 4 begin
            duplicate record"Row4" record"BetLayout"
        end
        if record"Y"data = 5  begin
            duplicate record"Row5" record"BetLayout"
        end
        if record"Y"data = 6 begin
            duplicate record"Row6" record"BetLayout"
        end
        put 7 record"BetLayout"layout index
        put 100% record"X"data record"Row1"layout index
        copy record"Row1"layout record"BetLayout"layout
        add 1 record"BetLayout"layout index
        put 100% record"X"data record"Row2"layout index
        copy record"Row2"layout record"BetLayout"layout
        add 1 record"BetLayout"layout index
        put 100% record"X"data record"Row3"layout index
        copy record"Row3"layout record"BetLayout"layout
        add 1 record"BetLayout"layout index
        put 100% record"X"data record"Row4"layout index
        copy record"Row4"layout record"BetLayout"layout
        add 1 record"BetLayout"layout index
        put 100% record"X"data record"Row5"layout index
        copy record"Row5"layout record"BetLayout"layout
        add 1 record"BetLayout"layout index
        put 100% record"X"data record"Row6"layout index
        copy record"Row6"layout record"BetLayout"layout
        add 1 record"BetLayout"layout index

        set flag "Ready2Bet" true
    end
    end
end

method "LayNumbersOnSquare" begin
    duplicate record"LastN" record"FirstNumber"
    put 1 record"Row1"layout index
    copy record"FirstNumber"layout record"Row1"layout
    add 1 record"Row1"layout index
    put 0 record"Count"data
    loop until record"Row1"layout index > 6 begin
        locate number right record"Count"data gaps from record"FirstNumber"layout record"Row1"layout
        if record"Row1"layout = number 0 begin
            subtract 1 record"Row1"layout index
        end
        add 1 record"Row1"layout index
        add 1 record"Count"data
    end
    put 1 record"Row2"layout index
    loop until record"Row2"layout index > 6 begin
        locate number right record"Count"data gaps from record"FirstNumber"layout record"Row2"layout
        if record"Row2"layout = number 0 begin
            subtract 1 record"Row2"layout index
        end
        add 1 record"Row2"layout index
        add 1 record"Count"data
    end
    put 1 record"Row3"layout index
    loop until record"Row3"layout index > 6 begin
        locate number right record"Count"data gaps from record"FirstNumber"layout record"Row3"layout
        if record"Row3"layout = number 0 begin
            subtract 1 record"Row3"layout index
        end
        add 1 record"Row3"layout index
        add 1 record"Count"data
    end
    put 1 record"Row4"layout index
    loop until record"Row4"layout index > 6 begin
        locate number right record"Count"data gaps from record"FirstNumber"layout record"Row4"layout
        if record"Row4"layout = number 0 begin
            subtract 1 record"Row4"layout index
        end
        add 1 record"Row4"layout index
        add 1 record"Count"data
    end
    put 1 record"Row5"layout index
    loop until record"Row5"layout index > 6 begin
        locate number right record"Count"data gaps from record"FirstNumber"layout record"Row5"layout
        if record"Row5"layout = number 0 begin
            subtract 1 record"Row5"layout index
        end
        add 1 record"Row5"layout index
        add 1 record"Count"data
    end
    put 1 record"Row6"layout index
    loop until record"Row6"layout index > 6 begin
        locate number right record"Count"data gaps from record"FirstNumber"layout record"Row6"layout
        if record"Row6"layout = number 0 begin
            subtract 1 record"Row6"layout index
        end
        add 1 record"Row6"layout index
        add 1 record"Count"data
    end
end

method "WheelType" begin
    if record"Wheel"data=1 begin
        Load Single Wheel
    end
    else begin
        Load Double Wheel
    end
end
