MarbleDrop

by Adam Renak: L6 Age ~16

Introduction

In this program random numbers are used to good effect in deciding whether the marble will fall to the left or right in each stage of its descent. The program has been constructed with care and is very effective. The gambling element has not yet been introduced but you can still have a bet on which of the eight positions the marble will end up. (Of course you will wish to work out the odds of ending up in each position - and to do that you can use Pascal's triangle! Neat eh?)

The Program

```program MarbleDrop;
{\$APPTYPE CONSOLE}

{

use this file except in compliance with the License, as described at
}

uses
SysUtils;
var
Route:array[1..9]of integer;
iFinPosn, iTheirGuess :integer;
Procedure drawroute1;
Begin
writeln('         .');
writeln('        .O.');
writeln('       . . .');   //route[2]
writeln('      . . . .');   //route[3]
writeln('     . . . . .');   //route[4]
writeln('    . . . . . .');    //route[5]
writeln('   . . . . . . .');      //route[6]
writeln('  . . . . . . . .');      //route[7]
writeln(' . . . . . . . . .');     //route[8]
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure drawroute2;
Begin
writeln('         .');
writeln('        . .');  //route[1]
case route[2] of
2: writeln('       .O. .');
3: writeln('       . .O.');
end;
writeln('      . . . .');   //route[3]
writeln('     . . . . .');   //route[4]
writeln('    . . . . . .');    //route[5]
writeln('   . . . . . . .');      //route[6]
writeln('  . . . . . . . .');      //route[7]
writeln(' . . . . . . . . .');     //route[8]
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure drawroute3;
Begin
writeln('         .');
writeln('        . .');  //route[1]
writeln('       . . .');   //route[2]
case route[3] of
4: writeln('      .O. . .');
5: writeln('      . .O. .');
6: writeln('      . . .O.');
end;

writeln('     . . . . .');   //route[4]
writeln('    . . . . . .');    //route[5]
writeln('   . . . . . . .');      //route[6]
writeln('  . . . . . . . .');      //route[7]
writeln(' . . . . . . . . .');     //route[8]
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure drawroute4;
Begin
writeln('         .');
writeln('        . .');  //route[1]
writeln('       . . .');   //route[2]
writeln('      . . . .');   //route[3]
case route[4] of
7: writeln('     .O. . . .');
8: writeln('     . .O. . .');
9: writeln('     . . .O. .');
10:writeln('     . . . .O.');
end;
writeln('    . . . . . .');    //route[5]
writeln('   . . . . . . .');      //route[6]
writeln('  . . . . . . . .');      //route[7]
writeln(' . . . . . . . . .');     //route[8]
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure drawroute5;
Begin
writeln('         .');
writeln('        . .');  //route[1]
writeln('       . . .');   //route[2]
writeln('      . . . .');   //route[3]
writeln('     . . . . .');   //route[4]
case route[5] of
11: writeln('    .O. . . . .');
12: writeln('    . .O. . . .');
13: writeln('    . . .O. . .');
14: writeln('    . . . .O. .');
15: writeln('    . . . . .O.');
end;

writeln('   . . . . . . .');      //route[6]
writeln('  . . . . . . . .');      //route[7]
writeln(' . . . . . . . . .');     //route[8]
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure drawroute6;
Begin
writeln('         .');
writeln('        . .');  //route[1]
writeln('       . . .');   //route[2]
writeln('      . . . .');   //route[3]
writeln('     . . . . .');   //route[4]
writeln('    . . . . . .');    //route[5]
case route[6] of
16: writeln('   .O. . . . . .');
17: writeln('   . .O. . . . .');
18: writeln('   . . .O. . . .');
19: writeln('   . . . .O. . .');
20: writeln('   . . . . .O. .');
21: writeln('   . . . . . .O.');
end;

writeln('  . . . . . . . .');      //route[7]
writeln(' . . . . . . . . .');     //route[8]
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure drawroute7;
Begin
writeln('         .');
writeln('        . .');  //route[1]
writeln('       . . .');   //route[2]
writeln('      . . . .');   //route[3]
writeln('     . . . . .');   //route[4]
writeln('    . . . . . .');    //route[5]
writeln('   . . . . . . .');      //route[6]
case route[7] of
22: writeln('  .O. . . . . . .');
23: writeln('  . .O. . . . . .');
24: writeln('  . . .O. . . . .');
25: writeln('  . . . .O. . . .');
26: writeln('  . . . . .O. . .');
27: writeln('  . . . . . .O. .');
28: writeln('  . . . . . . .O.');
end;

writeln(' . . . . . . . . .');     //route[8]
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure drawroute8;
Begin
writeln('         .');
writeln('        . .');  //route[1]
writeln('       . . .');   //route[2]
writeln('      . . . .');   //route[3]
writeln('     . . . . .');   //route[4]
writeln('    . . . . . .');    //route[5]
writeln('   . . . . . . .');      //route[6]
writeln('  . . . . . . . .');      //route[7]
case route[8] of
29: writeln(' .O. . . . . . . .');
30: writeln(' . .O. . . . . . .');
31: writeln(' . . .O. . . . . .');
32: writeln(' . . . .O. . . . .');
33: writeln(' . . . . .O. . . .');
34: writeln(' . . . . . .O. . .');
35: writeln(' . . . . . . .O. .');
36: writeln(' . . . . . . . .O.');
end;
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure drawFinPosn;
Begin
writeln('         .');
writeln('        . .');  //route[1]
writeln('       . . .');   //route[2]
writeln('      . . . .');   //route[3]
writeln('     . . . . .');   //route[4]
writeln('    . . . . . .');    //route[5]
writeln('   . . . . . . .');      //route[6]
writeln('  . . . . . . . .');      //route[7]
writeln(' . . . . . . . . .');     //route[8]

case iFinPosn of
1: writeln(' |O| | | | | | | |');
2: writeln(' | |O| | | | | | |');
3: writeln(' | | |O| | | | | |');
4: writeln(' | | | |O| | | | |');
5: writeln(' | | | | |O| | | |');
6: writeln(' | | | | | |O| | |');
7: writeln(' | | | | | | |O| |');
8: writeln(' | | | | | | | |O|');
end;
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
End;
Procedure BallDrop;
Begin
route[1]:=1;
route[2]:=(RANDOM(2)+route[1]+1);
route[3]:=(RANDOM(2)+route[2]+2);
route[4]:=(RANDOM(2)+route[3]+3);
route[5]:=(RANDOM(2)+route[4]+4);
route[6]:=(RANDOM(2)+route[5]+5);
route[7]:=(RANDOM(2)+route[6]+6);
route[8]:=(RANDOM(2)+route[7]+7);
//route[9]:=(RANDOM(2)+route[8]+8);

//writeln(route[1],' ',route[2],' ',route[3],' ',route[4],' ',route[5],' ',route[6],' ',route[7],' ',route[8]);
iFinPosn:=(route[8]-28);
drawroute1; sleep(1000);
drawroute2; sleep(1000);
drawroute3; sleep(1000);
drawroute4; sleep(1000);
drawroute5; sleep(1000);
drawroute6; sleep(1000);
drawroute7; sleep(1000);
drawroute8; sleep(1000);
drawFinPosn;

writeln('The marble finished in position ',iFinPosn);
End;

begin
writeln('FOR BEST VIEWING, PRESS ALT+ENTER');
writeln('TO MAKE COMMAND LINE FULL SCREEN');
writeln;
writeln('Press Enter to continue');
writeln('*******************************');
writeln('-------------------------------');
writeln('MARBLE DROP                    ');
writeln('-------------------------------');
writeln;
writeln('*******************************');
repeat

writeln('         .');
writeln('        . .');  //route[1]
writeln('       . . .');   //route[2]
writeln('      . . . .');   //route[3]
writeln('     . . . . .');   //route[4]
writeln('    . . . . . .');    //route[5]
writeln('   . . . . . . .');      //route[6]
writeln('  . . . . . . . .');      //route[7]
writeln(' . . . . . . . . .');     //route[8]
writeln(' | | | | | | | | |');
writeln(' |1|2|3|4|5|6|7|8|');      //iFinposn
//ADD GAMBLING IN HERE: Player A v Player B. Each starts with 100 pounds??
writeln('Keep your eyes in the bottom-left of the screen');
writeln('3...'); sleep(1000);
writeln('2...'); sleep(1000);
writeln('1...'); sleep(1000);
writeln('Lets Go!'); sleep(1000);
Balldrop;