Penney's Game from BBC BASIC for Windows
Richard Ashbery (495) 163 posts |
A rather neat implementation of the head’s and tails guessing game (Penney’s Game) and written in BBC BASIC for Windows does not run correctly in RISC OS. The problem seems to be the last 2 entries of the RND keyword which seem to be ‘fixed’ at zero. Program runs perfectly under Windows OS. Can anyone verify this and perhaps provide an edited version that works? The 2 instances of WAIT need substituting with a simple loop… Scroll down to Contents. The BBC BASIC version is the second entry. |
Richard Ashbery (495) 163 posts |
Website address not displayed. |
Steve Fryatt (216) 2046 posts |
It looks correct and seems to work fine here, aside from the different use of |
Gulli (1646) 42 posts |
Shouldn’t you be checking UNTIL TIME >= 100? |
Steve Fryatt (216) 2046 posts |
In BB4W, you should be doing
as the original code did: delay loops aren’t a good idea due to the fact that BB4W can’t idle during them, whereas it can with In ARM BBC BASIC,
and then replace
I can’t see that having any bearing on Richard’s reported problem with |
Jeff Doggett (257) 231 posts |
Please don’t do this – it doesn’t allow for timer rollover.
|
Richard Ashbery (495) 163 posts |
Thanks Steve and others for taking the time to look at this. I have included both output files and it is obvious that the RISC OS version doesn’t pick-up on the RND function properly but how can I resolve this? Have a look at the Output from the program firstly when run on BBC BASIC for Windows and the second on RISC OS.
Heads you pick first, tails I pick first. Heads you pick first, tails I pick first.
Heads you pick first, tails I pick first. Heads you pick first, tails I pick first. The RISC OS version always chooses T, no matter how many times it is run. |
Steve Fryatt (216) 2046 posts |
Hmm. It certainly doesn’t do that here (RISC OS 5.23 from June, with BASIC from 28 May 2016).
I did say that
…and then have another go.
I think I’d start by making absolutely sure that the version of the program you’re running is correct. How did you get it from Rosetta Code to your machine? I copied the text off the web page (using Firefox on Linux), pasted it into a Linux text editor, saved it as a text file called “Penny/txt” and then proceeded as above on the RISC OS side. |
Steve Pampling (1551) 7932 posts |
Similar pattern done here with Firefox on Windows to drop it into RPEmu since this is supposed to be a BASIC issue rather than any platform issue. Same working behaviour. RND seems to be as random as it ever is. |
Richard Ashbery (495) 163 posts |
I have absolutely no idea what’s happening here – alright I’m operating with BASIC V dated 01 Aug 2015 but surely this wouldn’t be the issue would it? Are you both using a more recent version of BASIC? Whichever way I run the program I get back the same problem (as in my last posting). Since it works for you guys I’m totally mystified. I always run BASIC files either directly by double-clicking them or from a TaskObey. Even if I go into a TaskWindow and enter BASIC using LOAD “Penney’s_Game” and RUN, I still get the same problem. |
Steve Pampling (1551) 7932 posts |
Not sure of the relevance but *h. basic If it was anything to do with RND then the following would print the same value every time PRINT RND |
Steve Drain (222) 1620 posts |
You can do To get some semblence of idling I think you need to run as a wimp task and use PollIdle, or an alternative. |
Martin Avison (27) 1418 posts |
My understanding is that RND is used to seed the generator, not return a random number, and the returned value should be discarded. This might explain problems with your first RND … but not the rest. I do not think RND has changed since 2015. What version is your Basic module? |
Richard Ashbery (495) 163 posts |
Victim of my own bad delay code I’m afraid. I have to be honest Steve I didn’t check the results correctly when I substituted my own delay code for WAIT and you suggested I delete it. It seems that the TIME keyword in my delay code conflicts with the TIME used in the 3 RND lines causing the program to fail. Jeff was correct and on leaving it out as you suggest program works correctly. Thanks for all your help – will I ever learn :-( |
Steve Pampling (1551) 7932 posts |
Looks like you did. Remember most of us learn from mistakes. |
Steve Fryatt (216) 2046 posts |
There seem to be two distinct forms of
which uses the fact that The other use is
which is more subtle. Assuming that As a pedantic aside, note that while
but it’s worth bearing in mind if the variable will get used in further logical expressions. The ‘safe’ way to get a
because the 1 Which is more of a valid assumption in BB4W, as |
Steve Drain (222) 1620 posts |
Indeed, that is logically ‘safe’ as is:
but I personally feel them a bit pedantic. If you know how BASIC deals with ‘boolean’ values then this works too:
Just another choice on offer. ;-) |
Steve Drain (222) 1620 posts |
I wrote Basalt’s There is a problem with using |
Steve Pampling (1551) 7932 posts |
Just a bit over. 497 days 2 hours 52 seconds 95 centiseconds I’m familiar with the timer effect in Nortel Baystack 470 switches which reset the management agent when the 32 bit counter rolls over. Overdue for replacement (massively so, bloody PFI) |
Doug Webb (190) 1130 posts |
So that is how so many went in and were sold then. PFI does have a lot to answer for , the public sector version of the Brighthouse store model. Back on track its always good explore why certain odd things happen between different versions and just proves why backward compatibility is so difficult to manage. |
Steve Pampling (1551) 7932 posts |
It’s about the only bug I know of in those units and I been working with them for over 13 years. In use 24/7/365 and still working, that’s probably connected to the large numbers Nortel sold.
You don’t know the half of it.
In this instance it’s more a case of a difference in a forked version that is deceptively similar. |