...
: I have to program the game cluedo for a project; my problem is in
: in the phase of selecting the 3 cards that will be the killer, the
: weapon and the place. Then group all the cards and give them
: randomly the the players (between 3-6 selected by the user).
:
: The idea I have is to create 3 sets (1 of each kind) so I can
: select randomly 1 of each set to determine the killer, the weapon
: and the place.
:
....
const names:array[1..21] of string[13]=('Ms. Scarlett','Col. Mustard',
'Mrs. White' ,'Rvnd. Green',
'Mrs. Peacock','Prof. Plum',
'Candlestick' ,'Dagger',
'Lead Pipe' ,'Revolver',
'Rope' ,'Wrench',
'Kitchen' ,'Ballroom',
'Conservatory','Billiard room',
'Library' ,'Study',
'Hall','Lounge','Dining room');
bscrlf=#8#8#32#32#13#10; // BckSpc BckSpc Space Space CR LF
sep=' / '; // Separator
var cards:array[1..21] of byte; // 1..6 person, 7..12 weapon, 13..21 place
p,w,r,np,i,k,n:byte;
procedure swap(var a,b:byte); // swaps 2 bytes
begin if a<>b then begin a:=a xor b;b:=a xor b;a:=a xor b;end;end;
begin
randomize; // init rnd no. generator
p:=succ(random(6));w:=6+succ(random(6));r:=12+succ(random(9)); // pick inital 3 card
for i:=1 to 21 do cards[i]:=i; // init card deck
write('Enter number of players (3 or 6): ');
repeat readln(np);until ((np=3) or (np=6));writeln; // get no. of players
writeln('Cards picked: ',names[p],sep,names[w],sep,names[r],#13#10);
for i:=0 to 255 do // mix cards
swap(cards[succ(random(21))],cards[succ(random(21))]);
np:=18 div np;n:=1;k:=1;
for i:=1 to 21 do begin // display cards for each player
if ((cards[i]<>p) and (cards[i]<>w) and (cards[i]<>r)) then begin // don't include cards already picked
if n=1 then begin write(bscrlf,'Player ',k,' cards: ');inc(k);end;
if n=np then n:=1 else inc(n);
write(names[cards[i]],sep);end;end;
write(bscrlf);readln;
end.