Re: Ok, So i finish the program: Error, MEMORY


[Prev][Next][Index][Thread]

Re: Ok, So i finish the program: Error, MEMORY



Sean wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Oh yes, I did it on a TI-83
> program background:
> Blackjack! (I was bored last week)
>
> I think the problem is in this segment
>
> while p<=21 and d<=21
>  lbl c
>  if d<17
>   then
----------------------
>    randint(1,13)->H
>    if H>=10
>     then
>      10+D->D
>     else
>       D+H->D
>    end
----------------------

The above isolated lines of code can be substituted with:
----------------------
D+Min(10,randint(1,13))->D
----------------------

> end
> randint(1,13)->C
> if C=1
>  then
>   goto A
>  else
----------------------
>   if C>=10
>    then
>    10+P->P
>    else
>     if C<10 and c>1    <-- You already know that C>1.
>      then
>       C+P->P
>     end
>  end
----------------------

Here, substitute with:
----------------------
P+Min(10,C)->P
----------------------
If C=1 you Goto A, making the above marked query (C>1 ?) unnecessary.
Therefore you can shorten the code as shown.
Already here you should note that a very important rule when programming
the TI-8x calculators is that it can be very memory consuming to exit a
query structure with a Goto command, as the rest of the structure stays
memory resident, i.e. in time your calc will be filled up with unusable
info.

> LBL Q
> prgmZVBSHOW  {Setups screen}
> if D>21 and P>21 and D=P
> then
> prgmZVBHEADR {Setups graph screen header}
> text
> pause
> goto B {Further up in program, not a problem}

Then again, maybe it is a problem. Here you exit another query structure
via Goto.

> end
> LBL T
> if p>21 or (D=21 and P<D)
>  then
>   goto L {Loss screen}    <--- *slap* ;-)
>  else
>   if D>21 or (P=21 and D<P)
>    then
>     goto W                <--- *slap* ;-)
>    else
>      text
>      text
>      text
>      text
>      repeat ans=92 or ans=93 or ans=94
>       getkey
>      end
----------------------
>      if ans=94
>       then
>        clrdraw
>        clrhome
>        stop
>       else
>        if ans = 92
>         then
>          goto C
>         else
>           goto S
>         end
>        end
>       end
>      end
----------------------
*slap* - you do it again.
I hope you're learning from this :)

>    prgmZVBSHOW {header}
>    Lbl S
>    if P<D and D<=21
>     then
>      goto L        <--- *cough*
>     else
>     while D<=P and D<21
----------------------
>      randint(1,13)->C
>      if C>=10
>       then
>        10+D->D
>        else
>       C+D->D
>      end
----------------------

Here, use instead:
----------------------
D+Min(10,randint(1,13))->D
----------------------

>     prgmZVBSHOW
>     for(Z,1,50)
>     end
>    end
>   if D>P and D<=21
>    then
>     goto L
>    else
>     goto W
>    end
>  goto T
> LBL A
> text
> text
> text
> line
> line
> line
> line
> :::::::
>
> Thats pretty much it ;)
[...]

Suggestion: Re-write your code(!)
All the Goto's are _probably_ (I talk not of personal experience but
what seems to be general agreement in this forum) what uses up your
memory.
Every time you use a Goto and don't return you cause the calc to
remember the rest of e.g. an If structure that really isn't necessary.
If you use a routine a lot, try and make it a sub-program instead. Then,
in your queries, call the program. Remember that once you return, the If
structure will end itself and free up the memory. Then if you need to
use another part of your main program, you can Goto to it. This use of
the operation costs you only constant time and uses no extra memory
whereas the way you use it now costs an unpredictable amount of time and
extra memory.

On a sidenote: For those of us who count the cards it'd be nice if you
actually had a deck and shuffled it instead of making a sort of
dice-blackjack (dice have no memory as it goes, but decks do :)

HTH. HAND, and if in doubt about anything or in need of clarification -
feel free to ask again (if the prog doesn't work after rearranging, send
the entire code ;)

Regards,

--
          Rene Kragh Pedersen
------------------------------------------------------------------
What incredible irony!  | If you strangle a smurf,
        - Kyle.         | what colour will its face be?


References: