(PC-1211) Multiple Dice Throw
|
03-20-2021, 11:48 AM
(This post was last modified: 03-24-2021 03:45 PM by SlideRule.)
Post: #1
|
|||
|
|||
(PC-1211) Multiple Dice Throw
An excerpt from Science and Engineering Sourcebook, page 87:
Description Many games, e.g. the popular YAH-T-ZEE, and even computer modeling simulations, are based on the outcome of the multiple dice throw. This program permits a throw of 1 to 9 dice and displays the results of each multiple throw. The pseudo random generator shown in line 70, which does the "throwing," works well in the applications to which I submitted it; however, if you have your own favorite feel free to replace that line. Program Listing 10: "Z"CLEAR :PAUSE "MULTIPLE DICE":USING 20: INPUT "STARTER= ";B 30: INPUT "HOW MANY DICE?";A 40: IF (A>0)*(A<10)*(A=INT A)THEN 60 50: BEEP 1:PAUSE "ERROR":GOTO 30 60: FOR I=1TO A 70: B=997B+π :B=B-INT B:C=INT 6B+1 80: D=C*10^(I-1)+D:NEXT I 90: PRINT A;" DICE=";D 100: D=0:GOTO 30 INSTRUCTIONS Shift Z initializes the program and displays a prompt for a seed to start the pseudo random sequence. For best results, enter a number between 0 and 1. Next comes the prompt HOW MANY DICE for this throw. After a number n between 1 and 9 is entered, the program displays a n-digit number where each digit is between 1 and 6 and corresponds to a die. Pressing ENTER starts the sequence for another dice throw. BEST! SlideRule correction made |
|||
03-20-2021, 01:00 PM
Post: #2
|
|||
|
|||
RE: (PC-1211) Multiple Dice Throw
It appears there is a missing ")" on line 80.
Also, does this flavor of BASIC allow implied multiplication, look at line 70?? --Bob Prosperi |
|||
03-20-2021, 02:40 PM
Post: #3
|
|||
|
|||
RE: (PC-1211) Multiple Dice Throw
Thanks for the 'eyeball', my error.
Line 70 listing as published; [attachment=9257] BEST! SlideRule |
|||
03-20-2021, 04:26 PM
Post: #4
|
|||
|
|||
RE: (PC-1211) Multiple Dice Throw
(03-20-2021 01:00 PM)rprosperi Wrote: Also, does this flavor of BASIC allow implied multiplication, look at line 70?? Yes, it does, i.e. 2ABC -> 2*A*B*C , SIN 3A -> SIN(3*A), etc. Have a nice weekend. V. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
03-21-2021, 09:29 AM
(This post was last modified: 03-21-2021 10:21 AM by C.Ret.)
Post: #5
|
|||
|
|||
RE: (PC-1211) Multiple Dice Throw
Hello cheer PC-1211 enthusiasts !
Yes, a good flavor of BASIC with a lot of tricks and short-cuts which make this pocket a useful calculator... Except for PRINT capabilities and, due to it's great age, speed of running (walking ?) programs ! As in most of applications (i.e.; Yahtzee, poker dice, ...), we need to display or print the listing of values of the dices we have just throwed. Here is my solution for this delicate implementation on the venerable PC-1211 machine: 1:PRINT T;USING "##";A:RETURN 2:PRINT T;USING "##";A;B:RETURN 3:PRINT T;USING "##";A;B;C:RETURN 4:PRINT T;USING "##";A;B;C;D:RETURN 5:PRINT T;USING "##";A;B;C;D;E:RETURN 6:PRINT T;USING "##";A;B;C;D;E;F:RETURN 7:PRINT T;USING "##";A;B;C;D;E;F;G:RETURN 8:PRINT T;USING "##";A;B;C;D;E;F;G;H:RETURN 9:PRINT T;USING "##";A;B;C;D;E;F;G;H;I:RETURN 10:PRINT T;USING "##";A;B;C;D;E;F;G;H;I;J:RETURN 12:"Z"AREAD Z:BEEP (Z<=0)+(Z>=1):END 13:"N"AREAD N:IF (N<1)+(N>10)+(N<>INT N)BEEP 1:END 14:T=0:FOR K=1TO N:Z=(∏+Z)^5,Z=Z-INT Z,A(K)=1+INT 6Z,T=T+A(K):NEXT K:USING "###.":GOSUB N:GOTO 14 This code is conveniently use in DEF mode. Enter a fractional seed and press [shift]+[ Z ] to initiate randomizing seed. The pocket beeps when seed if out of the ] 0 ; 1 [ range. Enter the number of dices to throw and press [shit]+[ N ]. The pocket will display the total and all the dice’s values. It beeps when user ask for less than one dice or more than ten dices. Pressing the [ ENTER ] key re-throw a full set of dices. P.S.#1: To enter lines from 1 to 10, start with complete line 10 and go down to 1 by erasing extra characters with space, you will spare time and efforts... P.S.#2: For the laziest of us, but limited to height dices throws: 1:"Z"AREAD Z:BEEP (Z<=0)+(Z>=1:END 2:"N"AREAD N:IF (N<1)+(N>8)+(N<>INT NBEEP 1:END 3:T=0:USING :FOR K=1TO N:Z=(∏+Z)^5,Z=Z-INT Z,T=T+(1+INT 6Z)*(1+10^-K:NEXT K:PRINT T:GOTO 3 |
|||
03-23-2021, 02:43 PM
(This post was last modified: 03-23-2021 02:50 PM by robve.)
Post: #6
|
|||
|
|||
RE: (PC-1211) Multiple Dice Throw
(03-20-2021 11:48 AM)SlideRule Wrote: 70: B=997B+π :B=B-INT B:C=INT 6B+1 Thank you for sharing this code! Line 70 uses an interesting pseudo-random number generator. The PRNG is very simple, yet seems to be good enough to reliably simulate multiple dice throws, perhaps. It passes the spectral test when I tested this with a simple program on a PC-1350 (select image to view): 10 "A" CLS: WAIT 0: B=0 20 FOR I=1 TO 32*150 30 B=997*B+π,B=B-INT B:X=150*B 40 B=997*B+π,B=B-INT B:Y=32*B 50 PSET (X,Y) 60 NEXT I 70 WAIT: GPRINT: END Disclaimer: this spectral test code may not meet official test requirements. By comparison, the PC-1350 RND function spectacularly fails the spectral test, so I would not use it to throw dice for example (select image to view): 10 "A" CLS: WAIT 0: FOR I=1 TO 32*150: PSET (RND 150-1,RND 32-1): NEXT I: WAIT: GPRINT: END The number 997 is used by other PRNGs. See also previous HP Forum threads on this subject: https://hpmuseum.org/forum/thread-7196.html https://hpmuseum.org/forum/thread-2041.html - Rob "I count on old friends to remain rational" |
|||
03-23-2021, 03:34 PM
Post: #7
|
|||
|
|||
RE: (PC-1211) Multiple Dice Throw
(03-23-2021 02:43 PM)robve Wrote:(03-20-2021 11:48 AM)SlideRule Wrote: 70: B=997B+π :B=B-INT B:C=INT 6B+1 Shouldn't you use RANDOM before invoking RND, unless you want to use the same seed each time? Greetings, Massimo -+×÷ ↔ left is right and right is wrong |
|||
03-23-2021, 03:56 PM
(This post was last modified: 03-23-2021 04:04 PM by robve.)
Post: #8
|
|||
|
|||
RE: (PC-1211) Multiple Dice Throw
(03-23-2021 03:34 PM)Massimo Gnerucci Wrote: Shouldn't you use RANDOM before invoking RND, unless you want to use the same seed each time? RANDOM and RANDOMIZE set the seed of the sequence. Testing a PRNG is independent of its seeding. In other words, when a PRNG is periodic (all LCGs are but periods differ and large periods are preferable) it does not matter where you start. Also, most RANDOM implementations that take no seed value simply use TIME or some other system clock value. Many mistakes in the past made cryptographic operations insecure because the PRNG was predicable and the seed was simply TIME, which is also predictable see e.g. random number generator attacks such as the successful attack on Netscape's secure HTTPS page browsing. By contrast, modern CPUs offer RDRAND or similar instructions for "true" randomness required by secure cryptographic operations. EDIT: answer: setting B=0 (the seed) or not using RANDOM in the other code does not help or hinder. Running the programs multiple times with or without seeding produces very similar results. - Rob "I count on old friends to remain rational" |
|||
03-23-2021, 04:06 PM
(This post was last modified: 03-23-2021 04:14 PM by pyedog.)
Post: #9
|
|||
|
|||
RE: (PC-1211) Multiple Dice Throw
(03-20-2021 11:48 AM)SlideRule Wrote: 70: B=997B+π :B=B-INT B:C=INT 6B+1I think this random number generator might come from page 241 of "119 Practical Programs For The TRS-80 Pocket Computer", although the book's author probably got it from somewhere else. A very similar slightly faster version from https://www.aldweb.com/articles.php?lng=en&pg=51 Code: R=221R + 0.2113:R=R-INT R BSD used to use something like Code: R=1103515245+12345 MOD 2^31 I think Microsoft Windows uses (or used to use) something like Code: R=214013R+2531011 MOD 2^31 But on a PC-1211 the BSD and Microsoft variations are significantly slower. |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 4 Guest(s)