Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4095
Number of posts: 14004

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
help programming the game Cluedo. Posted by ragnell93 on 2 Mar 2013 at 8:20 AM
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.
Report
Re: help programming the game Cluedo. Posted by _Atex_ on 2 Mar 2013 at 1:38 PM
...
: 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.

Report
Re: help programming the game Cluedo. Posted by ragnell93 on 2 Mar 2013 at 2:59 PM
thanks a lot!

You really helped me!



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.