system "System Carrasco v1"
{
*************************************
    System by Antonio Carrasco
        on the Spanish Forum
    http://www.foros-ruleta.com/
       Roulette Extreme Code
           --- by Moch---
           on the VIP Forum
*************************************
-------------------------------------
           00-compatible
-------------------------------------
INSTRUCTIONS:

1- track 15 spins. If a number repeats 3 times during these 15 spins,
delete the 1st repetion of the number and all numbers before it.

Ex:1,2,5,1,4,5,6,2,5<--Number 5 hit 3 times before spin 16.
we keep: 1,4,5,6,2,5<--we pick numbers after the 1st hit of number 5.
we delete: 1,2,5

2- we bet 1 unit from spin 16 to 25 to all the numbers that repeat twice,
removing all 3rd repeats as in step 1.
If no number hits 2 times until spin 15 (very rare) we keep tracking
until a double repeat or spin 25.

3-If we loose reset and start from scratch.

4- On a win do as in step 1, remove the 1st hit of the 3rd repeat and all numbers before it.

5- Progression-enough to be in profit.

}
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

    // keep last number
    copy last number record"LastN"layout
    // tracking
    track last number for 9999 spins record"Streak"layout
    // find if last number has repeated more than 2 times
    put 1 record"Streak"layout index
    put 0 record"nRepeats"data
    loop until record"Streak"layout index > record"Streak"layout count begin
        if record"LastN"layout = record"Streak"layout begin
            add 1 record"nRepeats"data
        end
        add 1 record"Streak"layout index
    end

    // we need to find the 1st position of this number and remove it along with prior numbers
    if record"nRepeats"data > 2 begin
        put 1 record"Streak"layout index
        set flag "Done" to false
        loop until flag "Done" is true begin
            if record"LastN"layout = record"Streak"layout begin
            // we found it, we remove all numbers before the first repeat and the repeat itself
                move list up by 1 of the items located in record"Streak"layout
                set max record"Streak"layout index
                set flag "Done" true
            end
            else begin
                move list up by 1 of the items located in record"Streak"layout
                put 1 record"Streak"layout index
            end
        end
    end

    // now we find what numbers have 2 repeats.
    duplicate record"Streak" record"Temp"
    clear record"BetLayout"layout
    put 1 record"Streak"layout index
    loop until record"Streak"layout index > record"Streak"layout count begin
        put 0 record"nRepeats"data
        put 1 record"Temp"layout index
        loop until record"Temp"layout index > record"Temp"layout count begin
            if record"Streak"layout = record"Temp"layout begin
                add 1 record"nRepeats"data
            end
            add 1 record"Temp"layout index
        end
        if record"nRepeats"data = 2 begin
            if record"Streak"layout not found in record"BetLayout"layout begin
                copy record"Streak"layout record"BetLayout"layout
                add 1 record"BetLayout"layout index
            end
        end
        add 1 record"Streak"layout index
    end


    // Bankroll
    if bankroll > record"HighBankroll"data begin
        put 100% bankroll record"HighBankroll"data
    end

    // act on a loss
    if net < 0 begin
    end

    // act on a win
    if net > 0 begin
        set flag "qualified" false
    end


    // act when not qualified
    if flag "qualified" false begin
        if record"TotalSpins"data > record"Spins"data begin
            set flag "qualified" true
        end
        if record"TotalSpins"data > record"MaxSpins"data begin
            call "Reset"
            set flag "qualified" false
        end
    end

    //bet only if at least 3 numbers qualify
    if record"BetLayout"layout count < record"MinNums"data begin
        set flag "qualified" false
    end

    // act when  qualified
    if flag "qualified" true begin
        // calculate next bet
        call "CalculateNextBet"
        put 100% record"Progression"data record"BetLayout"layout list
        set flag "qualified" false
    end
end

// Methods
method "Reset" begin
    put 0 record"TotalSpins"data
    clear record"BetLayout"layout
    clear record"Streak"layout
end

method "CalculateNextBet" begin
    put 0 record"Progression"data
    put 0 record"Balance"data
    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 "Init" begin
    put 1 record "Progression" data
    // defaults
    put 15 record"Spins"data
    put 3 record"MinNums"data
    put 25 record"MaxSpins"data
    put 0 record"TotalSpins"data
    // Input
    group begin
        display "System Carrasco"
        display "by Antonio Carrasco"
        display "00-compatible"
        input dropdown " Wheel Type ?
            1:= Single Zero
            2:= Double Zero " record"Wheel"data
        input data "Start Betting after spin" record"Spins"data
        input data "if at least (X) numbers qualify" record"MinNums"data
        input data "Stop Betting on spin" record"MaxSpins"data
        display " "
        display " "
    end
    // flags
    set flag "qualified" false
    // assign
end

method "WheelType" begin
    if record"Wheel"data=1 begin
        Load Single Wheel
    end
    else begin
        Load Double Wheel
    end
end
