uses s_utils;
{Script for thomasgrant}

var chips, k_el, k_el1, start_amount, wish_amount, amount, yesno, spin_count, fl_stop, was_betting, sim_mode, stop_loss;
var elements, elements1, elements_played, total_elements, last_nr;

procedure el_init(ei_elements; var ei_elements);
begin
 for k_el:=0 to VarArrayHighBound(ei_elements,1) do begin
   ei_elements[k_el,8]:=VarArrayHighBound(ei_elements[k_el,4],1)+1;//how much elelemnts we have in this row
   ei_elements[k_el,0]:=VarArrayCreate([0,ei_elements[k_el,8]-1],12); for k_el1:=0 to ei_elements[k_el,8]-1 do ei_elements[k_el,0,k_el1]:=0;//alerts
   ei_elements[k_el,2]:=VarArrayCreate([0,ei_elements[k_el,8]-1],12); for k_el1:=0 to ei_elements[k_el,8]-1 do ei_elements[k_el,2,k_el1]:=0;//cnt_progression
   fl_stop:=ei_elements[k_el,7,0]; ei_elements[k_el,7]:=VarArrayCreate([0,ei_elements[k_el,8]-1],12); for k_el1:=0 to ei_elements[k_el,8]-1 do ei_elements[k_el,7,k_el1]:=fl_stop;//play_cnt
   total_elements:=total_elements+ei_elements[k_el,8];
 end;
end;

procedure el_bet(eb_elements; var eb_elements);
begin
  for k_el:=0 to VarArrayHighBound(eb_elements,1) do begin
    for k_el1:=0 to eb_elements[k_el,8]-1 do begin
      if (eb_elements[k_el,0,k_el1]>=eb_elements[k_el,1])and(eb_elements[k_el,7,k_el1]<>0) then begin //here we check if red didn't apear the wished spins and the play_cnt<>0
        eb_elements[k_el,2,k_el1]:=eb_elements[k_el,2,k_el1]+1;//if red didn't apear the wished numbers of spin we increase the cnt_progression
        if eb_elements[k_el,2,k_el1]=1 then print('Start betting on '+eb_elements[k_el,4,k_el1]+'.');
        if eb_elements[k_el,2,k_el1]>VarArrayHighBound(eb_elements[k_el,5],1) then begin fl_stop:=1; break; end;; //here we check if we reach the end of progresion and loose, in this case the game stops
        if sim_mode<>1 then begin //if it is not the simulation mode
          bet_x_on_y(eb_elements[k_el,5,eb_elements[k_el,2,k_el1]],[eb_elements[k_el,4,k_el1]],chips);//here we bet
          was_betting:=1;
        end;
      end;
      if eb_elements[k_el,7,k_el1]=0 then elements_played:=elements_played+1;
    end;
  end;
end;

procedure stack_array(sa_elements; var sa_elements);
 var k, k1;
begin
 for k:=0 to VarArrayHighBound(sa_elements,1) do begin//here we go through the all elements
   for k1:=0 to sa_elements[k,8]-1 do begin
     if sa_elements[k,7,k1]=0 then continue;//in case play_cnt=0 we ignore this element
     if number_is(last_nr,sa_elements[k,4,k1]) then begin
       sa_elements[k,0,k1]:=0;//in case the red land counter is again 0
       if sa_elements[k,2,k1]>=1 then begin
         if sa_elements[k,3]=-1 then begin //in case we have voisins or orphelins
           if sa_elements[k,4,k1]='orphelins' then begin //in case we have orphelins
             if last_nr=1 then begin//in case we have landed single1
               amount:=amount+(sa_elements[k,5,sa_elements[k,2,k1]]*35)-(sa_elements[k,5,sa_elements[k,2,k1]]*4);
             end else begin
               if last_nr<>17 then amount:=amount+(sa_elements[k,5,sa_elements[k,2,k1]]*17)-(sa_elements[k,5,sa_elements[k,2,k1]]*4)//in case we have landed split
                              else amount:=amount+(sa_elements[k,5,sa_elements[k,2,k1]]*17*2)-(sa_elements[k,5,sa_elements[k,2,k1]]*3);//in case we have landed 17 - 2 splits won
             end;
           end else begin //in case we have voisins
             if in_array(last_nr,[0,2,3]) then begin
               amount:=amount+(sa_elements[k,5,sa_elements[k,2,k1]]*11*2)-(sa_elements[k,5,sa_elements[k,2,k1]]*7);//in case we have landed street*2
             end else begin
               if in_array(last_nr,[25,26,28,29]) then amount:=amount+(sa_elements[k,5,sa_elements[k,2,k1]]*8*2)-(sa_elements[k,5,sa_elements[k,2,k1]]*7)//in case we have landed corner*2
                                                  else amount:=amount+(sa_elements[k,5,sa_elements[k,2,k1]]*17)-(sa_elements[k,5,sa_elements[k,2,k1]]*8);//in case we have landed some split
             end;
           end;
         end else amount:=amount+(sa_elements[k,5,sa_elements[k,2,k1]]*(sa_elements[k,3]-(sa_elements[k,6]-1)));//in case the red win we increase the amount
         print('Spin count - '+IntToStr(spin_count)+'. We have bet $'+FormatFloat('0.##',sa_elements[k,5,sa_elements[k,2,k1]])+' on '+sa_elements[k,4,k1]+' and win.');
         if sa_elements[k,7,k1]<>-1 then sa_elements[k,7,k1]:=sa_elements[k,7,k1]-1;//we decrease the play_cnt
       end;
       sa_elements[k,2,k1]:=0;//in case the red land cnt_progression became 0, so we again wait for red not to apear x times
     end else begin
       if sa_elements[k,2,k1]>=1 then begin
         amount:=amount-(sa_elements[k,5,sa_elements[k,2,k1]]*sa_elements[k,6]);//in case the red lose we decrese amount with how much we bet on red
         print('Spin count - '+IntToSTr(spin_count)+'. We have bet $'+FormatFloat('0.##',sa_elements[k,5,sa_elements[k,2,k1]])+' on '+sa_elements[k,4,k1]+' and lose.');
       end;
       sa_elements[k,0,k1]:=sa_elements[k,0,k1]+1;//in case the red didn't land counter is increased
     end;
   end;
 end;
end;

begin
 {Wait for a element not to hit in "X" times, and then bet progression.
0 didn_apear - indicate how much spins the element didn't lan
1 alert - indicate how much spins we must wait for element didn't apear
2 cnt_progression - store the current number from progresiion array
3 win_coeficient - indicate how much increase the bet on winning
4 names - indicate the name of element (look at the s_utils module to get the name, or to add your own names)
5 martingale_progression - indicate the element's progression
6 cnt_elements - indicate how much same table-elements we have in the group, usuall =1 (for example we have [0,10,0,??,'groupA'[0,1,1,1,2,2,3,4,5,7,9,12]
  where groupA - is the 9 singles. In this case the win_coeficient must remain 35, and the cnt_elements=9.
  So the correct will be [0,10,0,35,'groupA',[0,1,1,1,2,2,3,4,5,7,9,12],9])
7 play_cnt - indicate how much times the element will play
  (-1 - the element will always play; 0 - the element will not play; 1 - the element will play only once; 2 - only 2 times; 3 - only 3 times; ...)
  (in this example: red - will play always; column1 - will play 3 times; single0-will never play; street4 - will play 1 time.)
8 will indicate how much elements we have in this row

 you must change only the alert, win_coeficient, names, martingale_progression, cnt_elements, play_cnt - these value will be used for all the same elements}

 elements:=[
            [[0],5,[0], 1,['red','black','high','low','odd','even'],[0,1,2,4,8,16,32,1,2,4,8,16,32,64,128,256,512],1,[-1],0],
            [[0],6,[0], 2,['column1','column2','column3','dozen1','dozen2','dozen3'],[0,1,1,2,3,4,6,9,14,21,31,47,1,1,2,3,4,6,9,14,21,31,47,70,105,158,237,355,533],1,[3],0],
            [[0],6,[0], 5,['line1','line2','line3','line4','line5','line6','line7','line8','line9','line10','line11'],[0,1,1,1,1,1,1,2,2,2,3,3,4,5,6,7,8,10,12,14,18,21,25,30,36,43,1,1,1,1,1,1,2,2,2,3,3,4,5,6,7,8,10,12,14,18,21,25,30,36,43],1,[-1],0],
            [[0],10,[0],11,['street012','street023','street1','street2','street3','street4','street5','street6','street7','street8','street9','street10','street11','street12'],[0,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50],1,[-1],0],
            [[0],15,[0], 8,['corner1','corner2','corner3','corner4','corner5','corner6','corner7','corner8','corner9','corner10','corner11','corner12','corner13','corner14','corner15','corner16','corner17','corner18','corner19','corner20','corner21','corner22'],[0,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,7,8,9,10,12,14,16,18,20,22,25,28,32,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,7,8,9,10,12,14,16,18,20,22,25,28,32,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,7,8,9,10,12,14,16,18,20,22,25,28,32],1,[-1],0],
            [[0],100,[0],35,['single0','single1','single2','single3','single4','single5','single6','single7','single8','single9','single10','single11','single12','single13','single14','single15','single16','single17','single18','single19','single20','single21','single22','single23','single24','single25','single26','single27','single28','single29','single30','single31','single32','single33','single34','single35','single36'],[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,6,6,6,6,6,6,7,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,12,12,12,13,13,13,14,15,15,15,15,16,16,17,17,18,18,19,19,20,20,21,22,22,23,24,24,25,26,26,27,28,29,30,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,48,49,50,52,53,55],1,[-1],0],
            [[0],50,[0],17,['split0_1','split0_2','split0_3','split1_2','split1_4','split2_3','split2_5','split3_6','split4_5','split4_7','split5_6','split5_8','split6_9','split7_8','split7_10','split8_9','split8_11','split9_12','split10_11','split10_13','split11_12','split11_14','split12_15','split13_14','split13_16','split14_15','split14_17','split15_18','split16_17','split16_19'],[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,7,7,8,8,9,9,10,10,11,11,12,13,14,14,15,16,18,18,19,20,21,22,22,25,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,7,7,8,8,9,9,10,10,11,11,12,13,14,14,15,16,18,18,19,20,21,22,22,25],1,[-1],0],
            [[0],50,[0],17,['split17_18','split17_20','split18_21','split19_20','split19_22','split20_21','split20_23','split21_24','split22_23','split22_25','split23_24','split23_26','split24_27','split25_26','split25_28','split26_27','split26_29','split27_30','split28_29','split28_31','split29_30','split29_32','split30_33','split31_32','split31_34','split32_33','split32_35','split33_36','split34_35','split35_36'],[0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,7,7,8,8,9,9,10,10,11,11,12,13,14,14,15,16,18,18,19,20,21,22,22,25,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,7,7,8,8,9,9,10,10,11,11,12,13,14,14,15,16,18,18,19,20,21,22,22,25],1,[-1],0],
            [[0],75,[0],17,['tier'],[0,1,2,4,8,16,32,1,2,4,8,16,32,64,128,256,512],6,[-1],0],
            [[0],75,[0],-1,['voisins'],[0,1,2,4,8,16,32,1,2,4,8,16,32,64,128,256,512],9,[-1],0],
            [[0],75,[0],-1,['orphelins'],[0,1,2,4,8,16,32,1,2,4,8,16,32,64,128,256,512],5,[-1],0],
            [[0],1006,[0],35,['neighbors0','neighbors1','neighbors2','neighbors3','neighbors4','neighbors5','neighbors6','neighbors7','neighbors8','neighbors9','neighbors10','neighbors11','neighbors12','neighbors13','neighbors14','neighbors15','neighbors16','neighbors17','neighbors18','neighbors19','neighbors20','neighbors21','neighbors22','neighbors23','neighbors24','neighbors25','neighbors26','neighbors27','neighbors28','neighbors29','neighbors30','neighbors31','neighbors32','neighbors33','neighbors34','neighbors35','neighbors36'],[0,1,1,1,1,1,1,1,2,2,2,3,3,4,4,5,6,7,8,9,10,12,14,16,19,22,1,1,1,1,1,1,1,2,2,2,3,3,4,4,5,6,7,8,9,10,12,14,16,19,22],5,[-1],0],
            [[0],1006,[0],35,['finalbet0','finalbet1','finalbet2','finalbet3','finalbet4','finalbet5','finalbet6'],[0,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,7,8,9,10,11,12,14,16,18,20,1,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,5,5,6,7,8,9,10,11,12,14,16,18,20],4,[-1],0],
            [[0],1006,[0],35,['finalbet7','finalbet8','finalbet9'],[0,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,15,16,18,20,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,15,16,18,20],3,[-1],0]
           ];

 elements1:=[
            [[0],10,[0], 5,['line1_3','line1_4'],[0,1,1,2,3,4,6,9,14,21,31,47,1,1,2,3,4,6,9,14,21,31,47,70,105,158,237,355,533],2,[3],0],
            [[0],10,[0],11,['street1_3','street1_4'],[0,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,4,4,5,5,6,6,7,7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50],2,[-1],0]
           ];

 //chips value's
 //chips:=[0,0.01,0.10,1,5,10,25,100];//here you need to specify chip values
 chips:=[0,0.1,1,5,10,25,100,500];//here you need to specify chip values

 //enter the start_amount
 start_amount:=3341;
 amount:=start_amount;//current amount became start_amount

 //enter how much you want to increase your start_amount
 wish_amount:=start_amount+100;

 //enter the stop_loss, if stop_loss=0 it will not be used, with other words stop_loos will be the end of balance
 stop_loss := 0;

 //option for simulation mode
 sim_mode:=0;
 InputQuery('Query window','Simulation mode - enter 1. Otherwise - enter 0.',sim_mode);

 yesno:='no';
 InputQuery('Query window','Are you sure to run? yes/no ',yesno);
 if not ((yesno='yes') or (yesno='y')) then exit;

 set_roulette_window_name('Roulette Pro - Casino Tropez');
 total_elements:=0;
 el_init(elements,elements); el_init(elements1,elements1);//here we set the elements

 spin_count:=1; was_betting:=1; fl_stop:=0; elements_played:=0;
 randomize;

while amount<wish_amount do begin
  if (was_betting=1)and(sim_mode<>1) then begin ide_delay:=250;click_chip3();click_red();delay(200);click_chip3();click_even();delay(200);click_clear_bets(); end;
  was_betting:=0;

  elements_played:=0;
  el_bet(elements,elements); el_bet(elements1,elements1);//here we bet

  if was_betting=0 then ide_delay:=200;//the speed of free spins. Very small value increase the speed but may pause the script itself, you can try 150
  if (fl_stop=1)or(elements_played=total_elements) then break;

  click_spin; last_nr:=get_last_number();
  stack_array(elements,elements); stack_array(elements1,elements1);
  print('Spin count - '+IntToSTr(spin_count)+'. Landed numbrer is '+IntToStr(last_nr)+'. Current amount is $'+FormatFloat('0.##',amount));
  print('-------------------------------------------');
  if amount<=stop_loss then break;
  Inc(spin_count);
end;

if not (amount>=wish_amount) then print('The game stops because we reach the end of progression or reach the stop loss or all elements played their games, and lose.'+'. Current amount is $'+FormatFloat('0.##',amount))
                             else print('Congratulations! The game stops because we reach wishing amount.'+'. Current amount is $'+FormatFloat('0.##',amount));
print('Current amount is $'+FormatFloat('0.##',amount)+'. Start balance is $'+FormatFloat('0.##',start_amount)+'. Stop loss is $'+FormatFloat('0.##',stop_loss)+'. Wishing amount is $'+FormatFloat('0.##',wish_amount)+'.');
end;
