Please HELP - Losing Sanity ! 
Author Message
 Please HELP - Losing Sanity !

Can anyone please explain/correct the failure of the indicated Repeat ...
Until loop in this
*simple* text based game ?

I am slowly losing my marbles trying to figure this out !!
TIA & Regards
Andy

BEGIN {Start of Program}

Initialise;
ClrScr;

Write ('Do you want to see instructions ? (y/n) :
');readln(PlayerResponse);

if PlayerResponse = 'y' then Introduction Else Start_Game;

==>>>   Repeat   <<<==

   Throw_The_Dice;

   If Gameflag = 1  then

    Begin

       Case Dice_Total_Value of

            7,11 : Win;
            1,2,3,12 : Lose;
            4,5,6,8,9,10 :Play_Again;

      Else

         If Gameflag >1  Then

            If Dice_total_Value = 7 then Lose Else
            If Dice_total_Value = Playerspoint Then Win Else Play_Again;

      End;

         repeat

                Write('Play again (y/n) ? ');Readln(PlayerResponse);
                PlayerResponse := UpCase(PlayerResponse);

          until (PlayerResponse = 'N') or (PlayerResponse = 'Y');

          If (PlayerResponse = 'Y') then

           Begin

             Dice_Total_Value := 0;
             Dice1Value := 0;
             Dice2Value := 0;
             Gameflag := 0;
             PlayersPoint := 0;
             PlayerResponse := ' ';
             Start_Game;

            End;

           If (PlayerResponse = 'N') then

             Begin

              End_Game;

             End;

===>>     Until PlayerResponse = 'N'  <<<==

   Readln;

END.{program Craps}



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !


Quote:
> Can anyone please explain/correct the failure of the indicated Repeat ...
> Until loop in this
> *simple* text based game ?
> I am slowly losing my marbles trying to figure this out !!

   I can see why - I started to reformat your code (to make some sense
out of it), and I got truly lost as to what you are trying to do here.
   First, your (lack of) coding style makes it impossible for anyone
(yourself included) to make any sense of what the code is doing.  Having
a consistent coding style (naming conventions, physical structure,
indentation, etc.) is _really_ important in programming, and it looks as
though you merely started to "throw down" Pascal statements which might
do some things, but did so without any design or planning.  Your code
here is hopelessly jumbled and out of any order, and it's no wonder
you're having real difficulty.
   Did you plan anything here?  Did you write any sort of "logic flow",
diagram, pseudo-code to tell yourself what you wanted this process to do?  
Honestly, I'm sure you didn't, because what you have here is a complete
mess which has no logical flow or coherence - sorry, but that's the
truth.  It looks only that you started to code...
   As such, I believe making "corrections" to something like this is (1)
hopeless and (2) a major waste of time - you really need to design/plan
what the program is to do (notice I said the "program", not the "code"),
because I feel you're much too hasty to code and don't want to "waste
time" designing.  The reality of programming is that the bulk of any
programming effort _must_ be spent on problem solving, defining
objectives, design, understanding inputs and outputs..._before_ coding
beings, and this latter should only be a translation of the design into
the target language.  Debugging should only be correction of syntax
errors and the like, and NOT where you work out design problems!
   I know that doesn't seem like "fun", but all experienced professional
programmers will attest to this concept, and they've learned to spend the
effort "up front", before coding, so they'll get the work done faster,
easier, and with fewer mistakes.  My reason for saying all this? I've
been a professional programmer for over 38 years and I taught programming
in college for 9...
   So, here's what I can offer on your program.  I did some reformatting
and a few minor Pascal structure fixes, and most of all I cut it down to
let you see what's actually happening - you should be able to see more
clearly that most of it is of the "cart before the horse" processing.  I
hope this helps..
program Craps;
uses CRT;
var C1,C2 : char;
BEGIN {Start of Program}
  Initialise; ClrScr;
  Write ('Do you want to see instructions ? (Y/n): ');
  C1 := UpCase(ReadKey);
  if C1 = #00 then
    begin
      C2 := ReadKey;  { flush scan code }
      C1 := 'Y'  { set default }
    end;
  if C1 = 'Y' then Introduction Else Start_Game;
  Repeat
    Throw_The_Dice;
    If Gameflag = 1  then
      Case Dice_Total_Value of
        7,11 : Win;
        1,2,3,12 : Lose;
        4,5,6,8,9,10 :Play_Again;
      end
    Else
      If Gameflag >1  Then
        If Dice_total_Value = 7 then Lose
        Else
          If Dice_total_Value = Playerspoint Then Win
          Else Play_Again;
    repeat
      Write('Play again (Y/n) ? '); C1 := UpCase(ReadKey);
      if C1 = #00 then
        begin
          C2 := ReadKey; C1 := 'Y'
        end;
      Play_Again
    until (C1 = 'N');
    If (C1 = 'Y') then
      Begin
        Dice_Total_Value := 0; Dice1Value := 0; Dice2Value := 0;
        Gameflag := 0; PlayersPoint := 0; PlayerResponse := ' ';
        Start_Game;
      End
    else End_Game
  Until C1 = 'N'
END.{program Craps}


Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !

: Can anyone please explain/correct the failure of the indicated Repeat ...
: Until loop in this
: *simple* text based game ?

       In order to have multiple statements within
the loop work correctly there must be a begin immediately
after the repeat and an end immediately before the until.

: I am slowly losing my marbles trying to figure this out !!

       Gosh, if its that bad, use a GOTO. :-)

Ken Fischer

---



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !

Quote:

> Can anyone please explain/correct the failure of the indicated
> Repeat ... Until loop in this *simple* text based game ?
> I am slowly losing my marbles trying to figure this out !!

-----------------------------------------------------------------
You've got a few problems other than the use of the REPEAT-UNTIL
loop, mostly in the areas of program flow and logic.  The problem
with the loop is simple - there are two things which may have to
be done more than once, throwing the dice and playing a game.
You're trying to control both of these using a single REPEAT -
UNTIL structure.  You have to employ a nested loop (Throws are
repeated within games).  Here's some pseudo-code which shows how
I think you want this program to work

Procedures INITIALISE, INTRODUCTION, WIN, LOSE, THROW_THE_DICE,
ENDGAME, go here

BEGIN {Main}
  ClrScr;
  Write ('Do you want to see instructions ? (y/n) :
  readln(PlayerResponse);
  PlayerResponse := UpCase(PlayerResponse);
  if PlayerResponse = 'Y' then INTRODUCTION
  Repeat {Shooter coming out}
    INITIALISE;
    NewShooter:=False;
    Num_of_Rolls:=0;
    ClrScr;
    Repeat {Start throwing the dice}
      Num_of_Rolls:=Num_of_Rolls+1
      THROW_THE_DICE;
      If Num_of_Rolls = 1
         then
           Case Dice_Total_Value of
                    7,11 : WIN;
                           NewShooter:=True;
                1,2,3,12 : LOSE;
                           NewShooter:=True;
             4,5,6,8,9,10: Playerspoint=Dice_Total_Value
           end;{Case}
         else
           if Dice_Total_Value =  7
              then
                LOSE;
                NewShooter:=True;
              else
                If Dice_total_Value = Playerspoint
                   then
                     WIN;
                     NewShooter:=True;
    Until NewShooter;
    Write('Play again (y/n) ? ');
    Repeat
      Readln(PlayerResponse);
      PlayerResponse := UpCase(PlayerResponse);
    Until (PlayerResponse = 'N') or (PlayerResponse = 'Y');
  Until PlayerResponse = 'N'
  ENDGAME;
End.{program Craps}
-----------------------------------------------------------------
Derek Asari



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !

Quote:


> : Can anyone please explain/correct the failure of the indicated Repeat ...
> : Until loop in this
> : *simple* text based game ?

>        In order to have multiple statements within
> the loop work correctly there must be a begin immediately
> after the repeat and an end immediately before the until.

Nope. Repeat-until loops are one of te few that don't need that. It should loop
everything between 'Repeat' and 'Until'.However, I'm not saying it's not worth
a try. . .

Quote:

> : I am slowly losing my marbles trying to figure this out !!

>        Gosh, if its that bad, use a GOTO. :-)

> Ken Fischer

> ---

--
 _______________________________________________
|   Sam Jones   | "You can't harm me! My wings  |
+------aka------+  are like a shield of steel!" |
| Flash  Gordon |                    ---Batfink |
 


Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !



Quote:
>       In order to have multiple statements within
>the loop work correctly there must be a begin immediately
>after the repeat and an end immediately before the until.

Sorry. This is nonsense. What do you expect this code to do ?

        i=0;
        repeat
          writeln(i);
          inc(i)
        until i=10;

Have you got a compiler ?

Regards
Horst

Regards
Horst

 *** Las orillas del Nahuel Huapi ***



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !

: (Ken Fischer)
: >       In order to have multiple statements within
: >the loop work correctly there must be a begin immediately
: >after the repeat and an end immediately before the until.
:
: Sorry. This is nonsense. What do you expect this code to do ?

       Identify the beginning and end of the loop,
provided it is documented properly.
       The prmary purpose of Pascal is to teach
good programming methods and habits.

:         i=0;
:       repeat
:         writeln(i);
:           inc(i)
:         until i=10;
:
: Have you got a compiler ?

       Yes, TP2.0, TP3.0, TP4.0 and TP6.0,
TP2.0 for Victor 9000, TP3.0 for Texas Instruments
Professional Computer, TP2.0 for Dot Computer,
and several other versions of Pascal.

       I looked at another response to this thread,
and someone posted code without a begin-end after
an ELSE statement, and that is certain to cause
a problem, AFAIK only the first instruction afte
the ELSE is conditional.
       Organizing the begin and end place keepers
helps the programmer in addition to telling the
compiler.
Ken Fischer
---

: Regards
: Horst

:  *** Las orillas del Nahuel Huapi ***



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !

Quote:

>       I looked at another response to this thread, and someone
> posted code without a begin-end after an ELSE statement, and
> that is certain to cause a problem, AFAIK only the first
> instruction afte the ELSE is conditional. Organizing the begin
> and end place keepers helps the programmer in addition to
> telling the compiler.
> Ken Fischer ---

----------------------------------------------------------------
As the person who posted the response refered to, I feel I should
point out that the BEGIN - END keys words were left out on
purpose, and that if what I posted was Pascal code, this would be
an error.  However, if you had taken the trouble to read all of
my response, you would have seen that I specifically stated that
I was posting PSEUDO-CODE which does not have to comply with
Pascal's syntax rules.  It was my decision that the reduction in
response size, the lessening of work (ie. typing) on my part, and
the redundancy of using block indentation had distinct advantages
over posting Pascal source code.
----------------------------------------------------------------
Derek Asari



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !



Quote:

>: (Ken Fischer)
>: >       In order to have multiple statements within
>: >the loop work correctly there must be a begin immediately
>: >after the repeat and an end immediately before the until.
>:
>: Sorry. This is nonsense. What do you expect this code to do ?
>       Identify the beginning and end of the loop,
>provided it is documented properly.
>       The prmary purpose of Pascal is to teach
>good programming methods and habits.

REPEAT _is_ indicating the beginning of the loop and UNTIL _is_
indicating the end of the loop. This is the Pascal language
definition. What is your point ?

Quote:

>:         i=0;
>:      repeat
>:        writeln(i);
>:           inc(i)
>:         until i=10;

[...]

Quote:
>       I looked at another response to this thread,
>and someone posted code without a begin-end after
>an ELSE statement, and that is certain to cause
>a problem, AFAIK only the first instruction afte
>the ELSE is conditional.

Yes. If the ELSE branch is to include several statements, they have to
be bracketed by BEGIN END. Otherwise the IF branch wouldn't know where
to go.

But this has nothing to do with REPEAT ..... UNTIL. REPEAT includes
implictly BEGIN and UNTIL includes implicitly END. There can never be
an ambiguity because the UNTIL marks the end of the loop. Logical or
not ?

Regards
Horst

 *** Las orillas del Nahuel Huapi ***



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !


: >       I looked at another response to this thread,
: >and someone posted code without a begin-end after
: >an ELSE statement, and that is certain to cause
: >a problem, AFAIK only the first instruction afte
: >the ELSE is conditional.
:
: Yes. If the ELSE branch is to include several statements, they have to
: be bracketed by BEGIN END. Otherwise the IF branch wouldn't know where
: to go.
:
: But this has nothing to do with REPEAT ..... UNTIL. REPEAT includes
: implictly BEGIN and UNTIL includes implicitly END. There can never be
: an ambiguity because the UNTIL marks the end of the loop. Logical or
: not ?

       While the begin-end statements are required
by the compiler, they generate no machine code,
and the original poster did not have a good habit
showing in the placement of the begin-ends.
       I simply suggest that that can be used to
help the programmer keep track, the compiler won't
mind.  I do other things now, like using upper case
for ELSE, and I try to use indentation to keep track.
       There may be other cases where extra begin-ends
can be used to help the programmer, and cases where
nested loops cause more trouble than they are worth.
       If any of my impressions or opinions are
wrong, pardon me.

Ken Fischer

---



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !



Quote:

>: [...]
>: But this has nothing to do with REPEAT ..... UNTIL. REPEAT includes
>: implictly BEGIN and UNTIL includes implicitly END. There can never be
>: an ambiguity because the UNTIL marks the end of the loop. Logical or
>: not ?
>       While the begin-end statements are required
>by the compiler, they generate no machine code,
>and the original poster did not have a good habit
>showing in the placement of the begin-ends.

Sorry. I fear you are not able to read. Begin-End is not needed if you
use repeat-until.

Quote:
>       I simply suggest that that can be used to
>help the programmer keep track, the compiler won't
>mind.

No, you didn't. You said

Quote:
>       In order to have multiple statements within
>the loop work correctly there must be a begin immediately
>after the repeat and an end immediately before the until.

This claim is wrong. It's working correctly without begin-end because
Pascal defined it to work without being-end. I answered to this claim
and only to this claim. Everything you replied was not referring to
repeat-until. I have no objections towards your indenting styles or
whatever you were mentioning.

Regards
Horst

 *** Las orillas del Nahuel Huapi ***



Wed, 18 Jun 1902 08:00:00 GMT  
 Please HELP - Losing Sanity !

: >       In order to have multiple statements within
: >the loop work correctly there must be a begin immediately
: >after the repeat and an end immediately before the until.
:
: This claim is wrong. It's working correctly without begin-end because
: Pascal defined it to work without being-end. I answered to this claim
: and only to this claim. Everything you replied was not referring to
: repeat-until. I have no objections towards your indenting styles or
: whatever you were mentioning.

      Please forgive me for my past mistakes.  The
repeat-until without begin-end seems to me to be
an oversight without specified nesting rules, and
a pascal learning language surely is not the place
for a beginner to be learning nesting rules with
one of the most used loop statements.

      Ok, I admit it, I don't use repeat-until. :-)

Ken Fischer

---



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. Please HELP - Losing Sanity !

2. Lost database connection - Please Help !

3. TP 7.0 Lost Disk: Can Anyone Help?

4. Help : error COM1 "data lost"

5. I lost FAQ--help with timing

6. Help: Lost Data / TBDEDataSet.Handle

7. Help. I lost my auto-increment column

8. Help! A table that keeps losing records

9. FTP site URL lost, can anyone help

10. Please Please, help me with memo-fields, real problem

11. PLEASE PLEASE HELP ME

12. please, I beg of you help me please.

 

 
Powered by phpBB® Forum Software