-+-+-+-+-+-+-+-+ START OF PART 35 -+-+-+-+-+-+-+-+ X get_com('',command); X clear(2,1); X display_commands; X end Xend; X X Xprocedure print_positions(row,col : integer); X var X i1 : integer; X begin X for i1 := 1 to 4 do X begin X`09if (horse_bet=fastest`5Bi1`5D) then X`09 put_buffer('-->',row-1+i1,col) X`09else X`09 put_buffer(' ',row-1+i1,col); X`09 writev(out_val,fastest`5Bi1`5D:1,' ',horse`5Bfastest`5Bi1`5D`5D); X put_buffer(out_val,row-1+i1,col+3); X end; X end; X X(* row is the dependant variable, column depends on horse stats *) Xprocedure start; X var X i1,i2,row,col`09: integer; X exit_flag`09`09: boolean; X count`09`09: integer; X win_count,new_win_count : integer; X which_screen,screen_low,screen_high : integer; X still_racing`09: h_bool; X adjust`09`09: integer; X command`09`09: char; X `20 X X procedure start_race; X var i1 : integer; X begin X for i1 := 1 to num_horse do X`09begin X`09 writev(out_val,i1:1); X`09 put_buffer(out_val,i1+3,2); X`09end; X msg_print('The horses are now entering the starting gate...'); X msg_print('And they''re off!!'); X for i1 := 1 to num_horse do X`09put_buffer(' ',3+i1,2); X end; X X procedure get_positions; X var i1,i2,t : integer; X begin X for i1 := win_count+1 to num_horse-1 do X`09for i2 := num_horse-1 downto i1 do X`09 if (dist`5Bfastest`5Bi2`5D`5D < dist`5Bfastest`5Bi2+1`5D`5D) then X`09 begin X`09 t := fastest`5Bi2`5D; X`09 fastest`5Bi2`5D := fastest`5Bi2+1`5D; X`09 fastest`5Bi2+1`5D := t; X`09 end; X for i1 := win_count+1 to num_horse do X`09order`5Bfastest`5Bi1`5D`5D := i1; X end; X X`20 X function find_plot(horse : integer; var row,col : integer) : boolean; X var t : integer; X begin X find_plot := false; X t := dist`5Bhorse`5D; X if ((t >= screen_low) and (t <= screen_high)) then X`09begin X`09 find_plot := true; X`09 if (t <= 730) then row := 3+(horse*(750-t)+(lane`5Bhorse`5D*t) div 2) d Viv 730 X`09 else if (t > 3770) then row := 8+lane`5Bhorse`5D X`09 else if ((t <= 1090) or (t > 3410)) then row := 11+lane`5Bhorse`5D div V 2 X`09 else if (t <= 1310) then row := 3+trunc(cos((t-1090)/140)*(120+10*lane` V5Bhorse`5D)/15) X`09 else if (t <= 1530) then row := 23+trunc(cos((t-1090)/140)*(120+10*lane V`5Bhorse`5D)/15) X`09 else if (t <= 2970) then row := 14-lane`5Bhorse`5D div 2 X`09 else if (t <= 3190) then row := 23-trunc(cos((t-2970)/140)*(120+10*lane V`5Bhorse`5D)/15) X`09 else row := 3 - trunc(cos((t-2970)/140)*(120+10*lane`5Bhorse`5D)/15); X`09 if (t <= 730) then col := 1 + t div 10 X`09 else if (t <= 1090) then col := t div 10 - 72 X`09 else if (t <= 1530) then col := 37+trunc(sin((t-1090)/140)*(120+lane`5B Vhorse`5D*10)/10) X`09 else if (t <= 1890) then col := 190 - t div 10 X`09 else if (t <= 2610) then col := 262 - t div 10 X`09 else if (t <= 2970) then col := 338 - t div 10 X`09 else if (t <= 3410) then col := 41-trunc(sin((t-2980)/140)*(120+lane`5B Vhorse`5D*10)/10) X`09 else if (t <= 3770) then col := t div 10 - 300 X`09 else col := (t - 3761) div 10; X`09end; X end; X X procedure predict_order; X var i1,i2,sum,t : integer; X`09temp`09: h_stat; X begin X for i2 := 1 to num_horse do X`09final_order`5Bi2`5D := 0; X for i1 := 1 to num_horse do X`09begin X`09 sum := 0; X`09 for i2 := 1 to num_horse do X`09 begin`09`7Bfind chance of horse finishing in place i1`7D X`09 if (final_order`5Bi2`5D = 0) then`20 X`09`09sum := sum + trunc(10000*i1*true_odds`5Bi2`5D / X`09`09 ((i1*(i1+1)+2*true_odds`5Bi2`5D)*(i1*(i1-1)+2*true_odds`5Bi2`5D))); X`09 temp`5Bi2`5D := sum; X`09 end; X`09 t := randint(sum); X`09 i2 := 0; X`09 repeat X`09 i2 := i2 + 1; X`09 until (t <= temp`5Bi2`5D); X`09 final_order`5Bi2`5D := i1; X`09 final_fastest`5Bi1`5D := i2; X`09end; X end; X X procedure predict_race; X var X`09t,t2,try_speedy,speedy,old_speedy,i1,i2,seg,pokey : integer; X begin X old_speedy := 99999; X for i1 := 1 to num_horse do X begin X`09i2 := 0; X`09t := final_fastest`5Bi1`5D; X`09t2 := hstat`5Bt`5D*hstat`5Bt`5D; X`09speedy := 0; X`09for i2 := 1 to 6 do X`09 begin X`09 try_speedy := (randint(t2)+randint(t2)+randint(t2)) div 100 X`09`09`09`09+2*(num_horse-i1+1); X`09 if ((try_speedy > speedy) and (try_speedy < old_speedy)) then X`09 speedy := try_speedy; X`09 end; X`09if (speedy = 0) then X`09 speedy := old_speedy - randint(3) + 1; X`09old_speedy := speedy; X`7B horse run time = 6000 - 2*speedy; times`5B1..20`5D is time for each segm Vent `7D X`09times`5B0,t`5D := 0; X`09for i2 := 1 to 20 do X`09 times`5Bi2,t`5D := 31 - speedy div 10; `7Btime to move distance x`7D X`09pokey := randint(randint(6)); X `09speedy := speedy mod 10 + 10 + pokey*2; X`09for i2 := 1 to pokey do X`09 begin`09`7Bslowdown near end of race`7D X`09 seg := 21 - randint(randint(4)); X`09 times`5Bseg,t`5D := times`5Bseg,t`5D+4; X`09 end; X`09for i2 := 1 to speedy do X`09 begin X`09 if (randint(2)=1) then X`09`09seg := randint(20) X`09 else X`09`09seg := (13+randint(5)+randint(5)) mod 20 + 1; X`09 times`5Bseg,t`5D := times`5Bseg,t`5D-2; X`09 end; X`09for i2 := 1 to 20 do`09`7Bmake moves cumulative`7D X`09 times`5Bi2,t`5D := times`5Bi2-1,t`5D + times`5Bi2,t`5D; X`09times`5B21,t`5D := times`5B20,t`5D + 40; X end; X end; X`09 `20 X begin X which_screen := 1; X screen_high := 0; X count := 0; X win_count := 0; X new_win_count := 0; X predict_order; X predict_race; X for i1 := 1 to num_horse do X begin X`09fastest`5Bi1`5D := i1; X`09area`5Bi1`5D := 0; X`09still_racing`5Bi1`5D := true; X end; X for which_screen := 1 to 7 do X begin X`09screen_low := screen_high + 1; X`09get_positions; X`09case which_screen of X`09 1 : begin X`09`09display_track1; X`09`09start_race; X`09`09screen_high := 730; X`09 end; X`09 2 : begin X`09`09display_track2; X`09`09print_positions(3,3); X`09`09screen_high := 1310; X`09 end; X`09 3 : begin X`09`09display_track3; X`09`09print_positions(18,3); X`09`09screen_high := 1890; X`09 end; X`09 4 : begin X`09`09screen_high := 2610; X`09`09display_track1; X`09`09print_positions(18,30); X`09 end; X`09 5 : begin X`09`09display_track4; X`09`09print_positions(18,55); X`09`09screen_high := 3190; X`09 end; X`09 6 : begin X`09`09display_track5; X`09`09print_positions(3,55); X`09`09screen_high := 3770; X`09 end; X`09 7 : begin X`09`09display_track1; X`09`09print_positions(18,30); X`09`09screen_high := 4549; `7Bbut race stops at 4400`7D X`09`09for i1 := 3 to 15 do X`09`09 put_buffer('`7C',i1,63); X`09 end; X`09end; X`09for i1 := 1 to num_horse do X`09 case (order`5Bi1`5D mod 4) of X`09 0 : lane`5Bi1`5D := 2; X`09 1 : lane`5Bi1`5D := 1; X`09 2 : lane`5Bi1`5D := 3; X`09 3 : lane`5Bi1`5D := 0; X`09 end; X`09exit_flag := false; X`09repeat X`09 count := count + 2; X`09 for i1 := 1 to num_horse do X`09 begin X`09 if find_plot(i1,row,col) then X`09`09put_buffer(' ',row,col); X`09 if ((count > times`5Barea`5Bi1`5D,i1`5D) and (area`5Bi1`5D < 21)) t Vhen X`09`09area`5Bi1`5D := area`5Bi1`5D + 1;`09`09 `20 X`09 dist`5Bi1`5D := 220*area`5Bi1`5D-((times`5Barea`5Bi1`5D,i1`5D - cou Vnt)*220) div X`09`09`09(times`5Barea`5Bi1`5D,i1`5D-times`5Barea`5Bi1`5D-1,i1`5D) + randint V(2); X`09 if find_plot(i1,row,col) then X`09`09if (i1 = horse_bet) then X`09`09 put_buffer('*',row,col) X`09`09else X`09`09 begin X`09`09 writev(out_val,i1:1); X`09`09 put_buffer(out_val,row,col); X`09`09 end; X`09 if (which_screen < 7) then X`09`09begin X`09`09 if (dist`5Bi1`5D > screen_high) then X`09`09 exit_flag := true; X`09`09end X`09 else X`09`09if ((dist`5Bi1`5D > 4400) and still_racing`5Bi1`5D) then X`09`09 begin X`09`09 new_win_count := new_win_count + 1; X`09`09 still_racing`5Bi1`5D := false; X`09`09 put_buffer('`7C',row,63); X`09`09 end; X`09 end; X`09 if (which_screen = 7) then X`09 if (new_win_count > win_count) then X`09 begin X`09`09get_positions; X`09`09win_count := new_win_count; X`09`09exit_flag := (win_count >= 4); X`09 end; X`09until (exit_flag); X end; X for i1 := 1 to num_horse do X begin X`09order`5Bi1`5D := final_order`5Bi1`5D; X`09fastest`5Bi1`5D := final_fastest`5Bi1`5D; X end; X get_com('',command); X clear(1,1); X end; X`20 X(* displays the amount paid per $2 bet *) Xprocedure display_winnings; X var X command : char; X win1,win2,win3,show3,place2,place3,earnings : real; X begin X`09win1 := odds`5Bfastest`5B1`5D`5D*2 + 2; X`09win2 := odds`5Bfastest`5B1`5D`5D/1.5 + 2; X`09if win2 < 2.20 then win2 := 2.20; X`09win3 := odds`5Bfastest`5B1`5D`5D/3 + 2; X`09if win3 < 2.20 then win3 := 2.20; X`09place2 := odds`5Bfastest`5B2`5D`5D/1.5 + 2; X`09if place2 < 2.20 then place2 := 2.20; X`09place3 := odds`5Bfastest`5B2`5D`5D/3 + 2; X`09if place3 < 2.20 then place3 := 2.20; X`09show3 := odds`5Bfastest`5B3`5D`5D/3 + 2; X`09if show3 < 2.20 then show3 := 2.20; X`09earnings := 0; X`09if (horse_bet=fastest`5B1`5D) then X`09 case (horse_bet_type) of X`09 'w' : earnings := win1; X`09 'p' : earnings := win2; X`09 's' : earnings := win3; X`09 otherwise ; X`09 end X`09else if ((horse_bet=fastest`5B2`5D) and (horse_bet_type='p')) then X`09 earnings := place2 X`09else if ((horse_bet=fastest`5B2`5D) and (horse_bet_type='s')) then X`09 earnings := place3 X`09else if ((horse_bet=fastest`5B3`5D) and (horse_bet_type='s')) then X`09 earnings := show3; X`09gld := gld + trunc(earnings*bet/2); X`09if (earnings > 0) then X`09 case randint(2) of X`09 1 : msg_print('you won.'); X`09 2 : msg_print('your horse came in.'); X`09 end X`09else msg_print('no luck this time.'); X`09clear(2,1); X`09print_positions(10,1); X`09writev(out_val,win1:8:2); X`09put_buffer(out_val,10,42); X`09writev(out_val,win2:8:2); X`09put_buffer(out_val,10,53); X`09writev(out_val,win3:8:2); X`09put_buffer(out_val,10,64); X`09writev(out_val,place2:8:2); X`09put_buffer(out_val,11,53); X`09writev(out_val,place3:8:2); X`09put_buffer(out_val,11,64); X`09writev(out_val,show3:8:2); X`09put_buffer(out_val,12,64); X`09prt('`5Bhit any key to continue`5D',23,24); X`09get_com('',command); X`09clear(1,1); X end; X X Xfunction get_race_bet : boolean; X var X comment : vtype; X i1 : integer; X exit_flag : boolean; X horse_flag : boolean; X X function get_bet_type : boolean; X var X command : char; X exit_flag : boolean; X begin X get_bet_type := true; X exit_flag := false; X repeat X`09msg_print('What kind of bet? (in,

lace, or how) '); X`09if get_com('',command) then X`09 case ord(command) of X 119,112,115 : begin X`09`09 horse_bet_type := command; X`09`09 exit_flag := true; X`09`09end; X`09 end X`09else X`09 begin X`09 get_bet_type := false; X`09 exit_flag := true; X`09 end; X until (exit_flag) X end; X`20 X`20 X function get_bet_horse : boolean; X var X exit_flag : boolean; X comment : vtype; X i1`09: integer; X begin X get_bet_horse := true; X exit_flag := false; X list_horses; X repeat X`09comment := 'Which horse do you want to bet on?'; X`09if get_response(comment,i1) then X`09 exit_flag := (i1>0) and (i11) and (bet<1001) then exit_flag := true X else prt('Improper value.',1,1) X else X begin X exit_flag := true; X bet := 0 X end; X until (exit_flag); X if (bet > gld) then X begin X prt('You have not the gold!',1,1); X bet := 0; X end; X if (bet > 0) then X if get_bet_horse then X if get_bet_type then X`09begin X`09 get_race_bet := true; X`09 gld := gld - bet; X`09 bets`5Bhorse_bet`5D := bets`5Bhorse_bet`5D + bet; X`09 sum_bets := sum_bets + bet; X`09 for i1 := 1 to num_horse do X`09 odds`5Bi1`5D := sum_bets*0.9/bets`5Bi1`5D - 1; X`09end;`09 `20 Xend; X`20 X`20 Xfunction get_horse_command : boolean; X var X command : char; Xbegin X get_horse_command := false; X if get_com('', command) then X begin X case (ord(command)) of X 112 : get_horse_command := get_race_bet; X (*`5ER*) 18 : begin X clear(1,1); X display_commands; X end; X 118 : list_horses; X 115 : begin X get_horse_stats; X msg_print('You skip a race.'); X`09`09 spend_time(4800 div races_per_day,'at the track',false); X end; X otherwise prt('Invalid Command.',1,1); X end X end X else exit_flag := true; Xend; X`20 X`20 Xprocedure game_horse; X var X n,i1`09`09: integer; X command`09: char; Xbegin Xclear(1,1); Xexit_flag := false; X case (randint(4)) of X 1,2,3: prt('It is a beautiful day at the track.',1,1); X 4 : prt('It is pouring down rain and the track is muddy.',1,1); X end; Xdisplay_commands; Xget_horse_stats; Xrepeat X display_gold; X if get_horse_command then X begin X start; X`09 display_winnings; X`09 spend_time(4800 div races_per_day,'at the track',false); X`09 display_commands; X`09 display_gold; X`09 get_horse_stats; X end; X check_casino_kickout; X with py.misc.cur_age do X`09if ((py.misc.cur_age.day mod 7) in `5B2..7`5D) and X`09 (hour >= 6) and (hour < 18) then X`09 begin X`09 closed := true; X`09 exit_flag := true; X`09 msg_print('There are no more races today...Come back tomorrow.'); X`09 msg_print(' '); X`09 end; Xuntil(exit_flag) Xend; $ CALL UNPACK HORSE.INC;1 1682199068 $ create 'f' +-+-+-+-+-+-+-+- END OF PART 35 +-+-+-+-+-+-+-+-