Help with randomizing stuff
Author Message Help with randomizing stuff

Hi,
I use Turbo Pascal 7.0.  I need to pick a random number in 4 different
arrays.  Here is what I have.  I hope that you can understand it.  Its
supposed to be a blackjack program, im not done, this is just the array -

type
TArray1 = Array[2..10] of Byte;
TArray2 = Array[2..10] of Byte;
TArray3 = Array[2..10] of Byte;
TArray4 = Array[2..10] of Byte;
SArray1 = Array[1..4] of Byte;

var
Array1: TArray1;
Array2: TArray2;
Array3: TArray3;
Array4: TArray4;
SArray1a: SArray1;
Count1,Count2,Count3,Count4,Count5,
Num1,Num2,Num3,Num4,Num5: Integer;
x,a,b,c,d: String;

Begin
{ Define Variables }
x := 'A';
a := #003;
b := #004;
c := #005;
d := #006;
{ Define Array's }
for Count1 := 2 to 10 do
Array1[Count1] := Count1;
for Count2 := 2 to 10 do
Array2[Count2] := Count2;
for Count3 := 2 to 10 do
Array3[Count3] := Count3;
for Count4 := 2 to 10 do
Array4[Count4] := Count4;
for Count5 := 1 to 4 do
SArray1a[Count5] := Count5;
{ Display Cardset }
TextColor(Red);
for Count5 := 1 to 4 do begin
Num5 := SArray1a[Count5];
if Count5 = 1 then Write ('A',#004' ');
end;
for Count1 := 2 to 10 do begin
Num1 := Array2[Count1];
Write(Num1,#004' ');
end;
for Count5 := 1 to 4 do begin
Num5 := SArray1a[Count5];
if Count5 = 2 then Write ('J',#004' ');
if Count5 = 3 then Write ('Q',#004' ');
if Count5 = 4 then Write ('K',#004' ');
end;
WriteLn;
TextColor(DarkGray);
for Count5 := 1 to 4 do begin
Num5 := SArray1a[Count5];
if Count5 = 1 then Write ('A',#005' ');
end;
for Count2 := 2 to 10 do begin
Num2 := Array2[Count2];
Write(Num2,#005' ');
end;
for Count5 := 1 to 4 do begin
Num5 := SArray1a[Count5];
if Count5 = 2 then Write ('J',#005' ');
if Count5 = 3 then Write ('Q',#005' ');
if Count5 = 4 then Write ('K',#005' ');
end;
WriteLn;
TextColor(Red);
for Count5 := 1 to 4 do begin
Num5 := SArray1a[Count5];
if Count5 = 1 then Write ('A',#003' ');
end;
for Count4 := 2 to 10 do begin
Num4 := Array4[Count4];
Write(Num4,#003' ');
end;
for Count5 := 1 to 4 do Begin
Num5 := SArray1a[Count5];
if Count5 = 2 then Write ('J',#003' ');
if Count5 = 3 then Write ('Q',#003' ');
if Count5 = 4 then Write ('K',#003' ');
end;
WriteLn;
TextColor(DarkGray);
for Count5 := 1 to 4 do begin
Num5 := SArray1a[Count5];
if Count5 = 1 then Write ('A',#006' ');
end;
for Count3 := 2 to 10 do begin
Num3 := Array3[Count3];
Write(Num3,#006' ');
end;
for Count5 := 1 to 4 do begin
Num5 := SArray1a[Count5];
if Count5 = 2 then Write ('J',#006' ');
if Count5 = 3 then Write ('Q',#006' ');
if Count5 = 4 then Write ('K',#006' ');
end;
WriteLn;
WriteLn;
end;

any help?
Thanks,
Kane

Wed, 18 Jun 1902 08:00:00 GMT  Help with randomizing stuff

Quote:

>Hi,
>    I use Turbo Pascal 7.0.  I need to pick a random number in 4 different
>arrays.  Here is what I have.  I hope that you can understand it.  Its
>supposed to be a blackjack program, im not done, this is just the array -

>type
>  TArray1 = Array[2..10] of Byte;
>  TArray2 = Array[2..10] of Byte;
>  TArray3 = Array[2..10] of Byte;
>  TArray4 = Array[2..10] of Byte;

Any particular reason why you created four user-defined types
for the identical data structure?

Wed, 18 Jun 1902 08:00:00 GMT  Help with randomizing stuff
Hi,

Quote:
>     I use Turbo Pascal 7.0.  I need to pick a random number in 4 different
> arrays.  Here is what I have.  I hope that you can understand it.  Its
> supposed to be a blackjack program, im not done, this is just the array -

Actually, I fail to understand what you want to do. However,
considering that you are working on a Blackjack (that is, a card game)
program, and you want to "randomize stuff", could it be that you are
looking for a shuffling algorithm? In this case, T. Salmi's FAQ is for
you; faqpas6.txt contains a discussion of this problem. See

Quote:
> type
>   TArray1 = Array[2..10] of Byte;
>   TArray2 = Array[2..10] of Byte;
>   TArray3 = Array[2..10] of Byte;
>   TArray4 = Array[2..10] of Byte;

This is neither necessary nor unlikely to cause trouble in the future
when you want to assign variables of these types to each other.

Quote:
>   { Define Array's }
>   for Count1 := 2 to 10 do
>    Array1[Count1] := Count1;
>   for Count2 := 2 to 10 do
>    Array2[Count2] := Count2;
>   for Count3 := 2 to 10 do
>    Array3[Count3] := Count3;
>   for Count4 := 2 to 10 do
>    Array4[Count4] := Count4;

This is overly complicated (and also inefficient). It would be possible
to initialize all variable in one loop:

for Count := 2 to 10 do
begin
Array1[Count] := Count;
Array2[Count] := Count;
Array3[Count] := Count;
Array4[Count] := Count;
end;

(Of course, these remarks have no significance in regard to the

- Sebastian

Wed, 18 Jun 1902 08:00:00 GMT  Help with randomizing stuff

Quote:

>    I use Turbo Pascal 7.0.  I need to pick a random number in 4 different
>arrays.  Here is what I have.  I hope that you can understand it.  Its
>supposed to be a blackjack program, im not done, this is just the array -

You have not, IMHO, indicated what it is that you need.  But my
http://www.merlyn.demon.co.uk/pas-rand.htm  may help.

Quote:

>type
>  TArray1 = Array[2..10] of Byte;
>  TArray2 = Array[2..10] of Byte;
>  TArray3 = Array[2..10] of Byte;
>  TArray4 = Array[2..10] of Byte;

Unlikely that 4 different Types are needed.

Quote:
>  SArray1 = Array[1..4] of Byte;

>var
>  Array1: TArray1;
>  Array2: TArray2;
>  Array3: TArray3;
>  Array4: TArray4;
>  SArray1a: SArray1;
>  Count1,Count2,Count3,Count4,Count5,
>  Num1,Num2,Num3,Num4,Num5: Integer;
>  x,a,b,c,d: String;

>Begin
>  { Define Variables }
>  x := 'A';
>  a := #003;
>  b := #004;

not used.

Quote:
>  c := #005;
>  d := #006;
>  { Define Array's }

^ omit.

Quote:
>  for Count1 := 2 to 10 do
>   Array1[Count1] := Count1;
>  for Count2 := 2 to 10 do
>   Array2[Count2] := Count2;
> ...

for Count1 := 2 to 10 do begin
Array1[Count1] := Count1;
Array2[Count2] := Count2;
...
end ;

--

<URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
<URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Wed, 18 Jun 1902 08:00:00 GMT  Help with randomizing stuff
On Fri 14 Apr 2000 08:14:00a,  In article

Quote:

>>  for Count1 := 2 to 10 do
>>   Array1[Count1] := Count1;
>>  for Count2 := 2 to 10 do
>>   Array2[Count2] := Count2;
>> ...

>  for Count1 := 2 to 10 do begin
>   Array1[Count1] := Count1;
>   Array2[Count2] := Count2;
>   ...
>   end ;

I'm assuming that was a typo and this is what you really meant? :

for Count := 2 to 10 do begin
Array1[Count] := Count;
Array2[Count] := Count;
...
end ;

Wed, 18 Jun 1902 08:00:00 GMT  Help with randomizing stuff

Quote:
>   for Count1 := 2 to 10 do begin
>    Array1[Count1] := Count1;
>    Array2[Count2] := Count2;
>    ...
>    end ;

You mean, of course, Count1 rather than Count2 in the third line.

--
______________________________________________________________________
The Scarlet Manuka,      |        Nitpickers' Party motto:
Pratchett Quoter At Large,  |  "He who guards his lips guards his
First Prophet of Bonni, is:  |  soul, but he who speaks rashly will

______________________________|_______________________________________

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages