0

Dear Sir,

I have made a question by myself. For example: I am playing the card game to my friend. The card has Spade, Heart, Club and Spade as usual but no number. How can I do if I only play five time and finally there is a record of the comparison XX : XX.

The following is my answer:

program Spade;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
        Count, Num, Computer : integer;
        Choice, compChar : char;

begin
   Num:=0;
   Computer:=0;

randomize;
   for Count:=1 to 5 do
   repeat
     writeln('Welcome to play the game of Spades');
     readln(Choice);
   until (Choice = 'S') or (Choice = 'H') or (Choice = 'C') or (Choice = 'D');

case Choice of
'S': writeln('You have got Spade');
'H': writeln('You have got Heart');
'C': writeln('You have got Club');
'D': writeln('You have got Diamond');
end;

Computer:= random(4);

case Computer of
0:
begin
  writeln('Computer have chosen Spade');
  compChar:= 'S';
end;
1:
begin
  writeln('Computer have chosen Heart');
  compChar:= 'H';
end;
2:
begin
  writeln('Computer have chosen Club');
  compChar:= 'C';
end;
3:
begin
  writeln('Computer have chosen Diamond');
  compChar:= 'D';
end;

end;

  if ((Choice='S') and (compChar='H') and (compChar='C') and (compChar='D')) or ((Choice='H') and (compChar='C') and (compChar='D')) or ((Choice='C') and (compChar='D')) then
  begin
    writeln('You win');
  end
  else
    if ((Choice='S') and (compChar='S')) or ((Choice='H') and (compChar='H')) or ((Choice='C') and (compChar='C')) or ((Choice='D') and (compChar='D'))  then
    begin
      writeln('You draw');
    end
    else
      writeln('You loss');
      readln;
end.

But how can I do if I want to make changes to choose randomly?

2
Contributors
8
Replies
9
Views
8 Years
Discussion Span
Last Post by turbomen
0

1,
The computer get value randomly...
Do you want to get your choice randomly too?
2,
"..and finally there is a record of the comparison XX : XX...."
the answer is very simple...
add two variables to the definition section

VAR numyou,numcomputer:Integer;{like these..}
       Count, Num, Computer : integer;
        Choice, compChar : char;
Begin
numyou:=0;
numcomputer:=0;
{
here are your codes
...
...
If you win then increase numyou by one so Inc(numyou) or you can write here too numyou:=numyou+1; 
...
...
But if the computer wins then increase his variable named numcomputer,as Inc(numcomputer)
...
...
And when the five round is done write the result as
}
WriteLn(numyou,' : ',numcomputer);
If numyou > numcomputer Then WriteLn('You''re the best!')
Else WriteLn('Computer wins....');
End.

Or answer if I misunderstand something... :'(

0

1. Yes, I do. But my coding is not for randomly. Could you tell me how to do it?

2. I know how to do this part. Thank you.

Dear Sir,

Would you mind showing it to me clearly? I cannot catch it up.

Cheers,

0

Dear Sir,

I know what I do not understand. It is the coding between both parties. For example when I code RPS, guessing games, Head & Tail are only one part of the parties are random. But both parties need to clip randomly in this time.

Cheers,

0

If you want a random value for your variable then
add a new variable to the definition section

var ch:integer;
{and}
ch:=random(4);  {here!!!!}

   case ch of
      0:choice:='S';
      1:choice:='H';
      2:choice:='C';
      3:choice:='D';
   end;{of case}

   case Choice of
      'S': writeln('You have got Spade');
      'H': writeln('You have got Heart');
      'C': writeln('You have got Club');
      'D': writeln('You have got Diamond');
   end;
0

Dear Sir,

I have some of the problem to catchup your problem. Would you mind expressing it again?

Cheers,

1

here it is

program Spade;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
        Count,{counts the rounds}
        num1you,{counts your total points}
        num2computer, {counts the computer total points}
        num3draw,{counts the draws}
        randomnumber,{add to you a random number between 0 and 3}
        Computer : integer;{computer's choice}
        Choice,{your choice}
        compChar : char; {converted value of computer}

begin
   num1you:=0;
   num2computer:=0;
   num3draw:=0;
   Computer:=0;

   randomize;
   for Count:=1 to 5 do begin
     writeln(count,'. Welcome to play the game of Spades');

   {genrate a random number for your choice}
   randomnumber:=random(4);
   {automate your choice}
   case randomnumber of
        0:choice:='S';
        1:choice:='H';
        2:choice:='C';
        3:choice:='D';
   end;{of case}

   case Choice of
        'S': writeln('You have got Spade');
        'H': writeln('You have got Heart');
        'C': writeln('You have got Club');
        'D': writeln('You have got Diamond');
   end;

   Computer:= random(4);

   case Computer of
        0:begin
               writeln('Computer have chosen Spade');
               compChar:= 'S';
          end;
        1:begin
               writeln('Computer have chosen Heart');
               compChar:= 'H';
          end;
        2:begin
               writeln('Computer have chosen Club');
               compChar:= 'C';
          end;
        3:begin
               writeln('Computer have chosen Diamond');
               compChar:= 'D';
          end;
   end;
   {=======    THE RULE    ========
   Spade > Heart > Club > Diamond.
   ================================}
   if ((choice = 'S') and (compchar = 'H'))
      or((choice = 'H') and (compchar = 'C'))
      or((choice = 'C') and (compchar = 'D')) then begin
      writeln('you win.');
      inc(num1you);
      end
   else if choice = compchar then begin
           writeln('draw.');
           inc(num3draw);
        end
   else begin
           writeln('computer wins.');
           inc(num2computer);
        end;
   writeln;
   readln;
   end;{of for loop}

   writeln('you: ',num1you,'   computer: ',num2computer,'   Draw: ',num3draw);
   readln;
end.{of main program}

{
created by FlamingClaw 2009.08.22.
}

:D

0

Thank you for your clear expression. Are there any changes if the card game has 52 cards?

0

How about if the card game has the numbers 2,3,4,5,6,7,8,9,10,J,Q,K,A. Are there any changes of the program?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.