# help programming the game Cluedo.

Hello.

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.

Next, create a 4th set with the union of the other 3 ( giving the idea of mixing all the cards), exclude the 3 elements previously chosen and do a loop assigning each card to the hand of the player(I think the hand should be an array and this must be done evenly).

Note that the assignment of the cards must be without repetitions , so I guess I have the exclude the chosen card in the loop from the 4th set each round).

Also there are 6 persons cards, 6 arms and 9 places.

Could someone give me insight of how to write this section of the game in Pascal?.

thanks beforehand.

• ...
: 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.
:
....
[code][color=Blue]const names:array[1..21] of string=('Ms. Scarlett','Col. Mustard',
'Mrs. White' ,'Rvnd. Green',
'Mrs. Peacock','Prof. Plum',
'Candlestick' ,'Dagger',
'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;