Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 19:49 20 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Game: various *mites: Four Equals Ten

     Page 1 of 2    
Author Message
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 05:40am 12 Jan 2023
Copy link to clipboard 
Print this post

Greetings All,

Here is a silly little arithmetic game based on the app 4 = 10 (which is available for various mobile devices.) My version is a bit easier than the app version in that mine allows all arithmetic operations to be used to solve each problem. The app version occasionally denies the use some operations, making some problems more difficult. I may add that feature in the future.

This has been tested on the CMM2, PicoMiteVGA and MMB4W. It should run on a PicoMite with a properly configured 320x240 LCD screen. If someone tests this, please let me know of the results.

The object of the game is to use simple arithmetic and (one set of) brackets to create an expression with four given digits that equal 10. You can use the digits in any order, and you can use whichever math operations you like. Only one set of brackets is available, so something like (7-2)*(3-1) is not allowed. Instead, in this case, 7*2-3-1 is a solution. Using brackets is optional, although some problems can only be solved with carefully placed brackets. The order of operations is of course very important.

For example, given the 4 digits 1 2 3 4, the expression 1+2+3+4 equals 10. Many problems have more than one solution. For example, 1*3*4-2 is an equally valid solution.

The BackSpace key allows you to delete your expression character by character if required.

Have fun!

=====================
edit:
Oops, sorry folks, there's a bug in the program, results in nesting error after level 39 on the PicoMiteVGA. I'll fix it shortly and upload a new version. (Caused by the improper use of EXIT DO in lines 143 and 144, which occurred when the ShowCurrent subroutine was created.)
=====================


FourTen v0.2.zip

PS: There is extra code in the program that some might find useful. I'll let you explore and see what you can find...
Edited 2023-01-12 16:13 by vegipete
Visit Vegipete's *Mite Library for cool programs.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3496
Posted: 07:49am 12 Jan 2023
Copy link to clipboard 
Print this post

Nice !!

I'll play with it and show it to my wife. She has a few kids in het class that could use a training like this to become more fluent juggling with numbers...

Volhout
PicomiteVGA PETSCII ROBOTS
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 891
Posted: 10:00am 12 Jan 2023
Copy link to clipboard 
Print this post

very nice puzzle game.
'no comment
 
LouisG
Senior Member

Joined: 19/03/2016
Location: Australia
Posts: 121
Posted: 02:20am 13 Jan 2023
Copy link to clipboard 
Print this post

Yes, very nice.
Did you consider utilising the touch screen for entering the math characters? It seems eminently suitable. It would eliminate the need for a computer.

Louis

-
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 05:05am 13 Jan 2023
Copy link to clipboard 
Print this post

Here's a bug-fix version:
FourTen v0.3.zip

However, there still seems to be some sort of problem that I haven't identified yet. It causes random crashes on the latest PicoMiteVGA firmware. One crash was such that I had to reboot Windoze to be able to re-connect to the Pico. Usually the error message suggests a nesting issue, and the displayed error causing program line is subtly changed from the actual line in memory. (I loose console connection, so I can't check and test stuff.)

It's better on a previous version (5.070408) but there are oddities such as:
[361] If ans < .1 Then soln$ = e$ : TestMath = 1 : Exit Function
Error : IF without THEN


I'll continue to study my code to find my error...

===================
Yes, I've thought that a touch screen would be ideal. I don't have a Pico setup with a 320X240 LCD at the moment, so nothing developed yet.
Visit Vegipete's *Mite Library for cool programs.
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1773
Posted: 05:29am 13 Jan 2023
Copy link to clipboard 
Print this post

My experience with multiple commands on one line is all IFs must have : after THEN and finish with : ENDIF :

eg
If ans < .1 Then : soln$ = e$ : ENDIF : TestMath = 1 : Exit Function

or
If ans < .1 Then : soln$ = e$ : TestMath = 1 : ENDIF : Exit Function

or
If ans < .1 Then : soln$ = e$ : TestMath = 1 : Exit Function : ENDIF

I am not sure where your IF ends and I don't think MMBasic knows either.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 06:06am 13 Jan 2023
Copy link to clipboard 
Print this post

My understanding is that because there is no colon after the THEN, the IF statement ends at the end of the line.
Visit Vegipete's *Mite Library for cool programs.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5886
Posted: 06:34am 13 Jan 2023
Copy link to clipboard 
Print this post

  vegipete said  
It's better on a previous version (5.070408) but there are oddities such as:
[361] If ans < .1 Then soln$ = e$ : TestMath = 1 : Exit Function
Error : IF without THEN


I'll continue to study my code to find my error...


I don't like using multiple statements with a one line IF but it is valid and should work.
I couldn't get it to throw an error in MMB4W

Jim
VK7JH
MMedit   MMBasic Help
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1773
Posted: 06:47am 13 Jan 2023
Copy link to clipboard 
Print this post

When there is only one command on a line it works. More than one and it doesn't.
Try it. I have banged my head against the wall before discovering this.

The compiler says ERROR. Argue your case with it!
Edited 2023-01-13 16:52 by phil99
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5886
Posted: 07:03am 13 Jan 2023
Copy link to clipboard 
Print this post

'
a = 1
b = 2
c = 3
IF a = 1 THEN b = 0 : c = 0 : PRINT "test complete"
PRINT "b = ";b
PRINT "c = " ; c




result:

RUN
test complete
b =  0
c =  0
>

Tested on picomite, DOS and MMB4W

There must be something else at play.
Give an example that fails. Preferably every time.

Jim
Edited 2023-01-13 17:04 by TassyJim
VK7JH
MMedit   MMBasic Help
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1773
Posted: 07:28am 13 Jan 2023
Copy link to clipboard 
Print this post

Tested on Picomite 5.07.06 and no error.

> ans =1
> e$="test"
> If ans < .1 Then soln$ = e$ : TestMath = 1 : ? testmath : ?ans, soln$, e$
> ans=0
> If ans < .1 Then soln$ = e$ : TestMath = 1 : ? testmath : ?ans, soln$, e$
1
0      test    test
> If ans < .1 Then : soln$ = e$ : TestMath = 1 : ? testmath : ?ans, soln$, e$ :endif
1
0      test    test
> ans=1
> If ans < .1 Then : soln$ = e$ : TestMath = 1 : ? testmath : ?ans, soln$, e$ :endif
>


Yet in the past I have got "Error : IF without THEN" just as VegiePete gets.
Adding a colon after Then fixed that but gave "Error : No matching ENDIF" so added EndIf
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8569
Posted: 08:55am 13 Jan 2023
Copy link to clipboard 
Print this post

  Quote  IF a = 1 THEN b = 0 : c = 0 : PRINT "test complete"


Personally I hate this syntax as it breaks any common sense rules within Basic (and certainly doesn't work in C)
If : is essentially the equivalent of a end-of-statement/newline how can c=0 be executed as part of the condition?

My advice and practice is always to have either a simple
IF condition THEN onestatement

or the normal IF ENDIF
Edited 2023-01-13 18:57 by matherp
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 05:17pm 13 Jan 2023
Copy link to clipboard 
Print this post

I've been removing colons (as statement separators) from my program, as I agree that IF THEN multiple:statements is a bit evil. I suppose it's a left over from the One Page Program Challenge.

The point of the example though is that that particular line worked just fine through many iterations, until it didn't, with the indicated error. At least in that case, I could copy the error, because the console connection hadn't dropped. Other such events, especially with the latest firmware version, dropped the console, without displaying the error on the console, only on the VGA screen. Furthermore, the displayed line with the error was changed slightly from the actual program line, by one statement or variable name (I think.) This suggests I've messed up with sub/function calls and returns, resulting in clobbering.

My CMM2 didn't show any of this during testing, perhaps because it has so much more memory, so a much bigger mess can built before it shows up. Perhaps too the newest PicoMite firmware has less room for this nesting error to build, so it appears sooner. Either way, I have to figure out where I've messed up...
Visit Vegipete's *Mite Library for cool programs.
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3649
Posted: 06:39pm 13 Jan 2023
Copy link to clipboard 
Print this post

  matherp said  
  Quote  IF a = 1 THEN b = 0 : c = 0 : PRINT "test complete"


Personally I hate this syntax as it breaks any common sense rules within Basic (and certainly doesn't work in C)
If : is essentially the equivalent of a end-of-statement/newline how can c=0 be executed as part of the condition?

My advice and practice is always to have either a simple
IF condition THEN onestatement

or the normal IF ENDIF

I'm not keen, either.

In C you can get a rough equivalent if you abuse the comma operator but should I post an example?  Maybe not!

John
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8569
Posted: 06:52pm 13 Jan 2023
Copy link to clipboard 
Print this post

I've done some investigating and the cause is definitely the C stack overflowing.
You can monitor this with MM.INFO(STACK). If it get below &H2003F480 then the program will abort. You will need to simplify the logic to avoid this.
The only way I can make the stack bigger is by not moving key firmware routines into RAM which would slow Basic down
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 07:14pm 13 Jan 2023
Copy link to clipboard 
Print this post

Is there any chance this is related to the constant use of the EVAL statement, with a string that will generate an eval error roughly half the time?
Visit Vegipete's *Mite Library for cool programs.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8569
Posted: 07:33pm 13 Jan 2023
Copy link to clipboard 
Print this post

  Quote  Is there any chance this is related to the constant use of the EVAL statement, with a string that will generate an eval error roughly half the time?


Can't be certain but that is certainly a horrible thing to do. The use of ON ERROR in that way is asking for trouble. You really shouldn't call eval unless you know the string is syntactically correct.
Should be easy to check. Just print mm.info stack every time eval errors and see what happens
Edited 2023-01-14 05:34 by matherp
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 05:18pm 14 Jan 2023
Copy link to clipboard 
Print this post

Some quick testing with different strings seems to indicate that the EVAL statement is well behaved with errors. The C stack doesn't change, even with "Syntax", "No closing bracket" and "Divide by zero" errors.

The following does not generate an error: (stuff after a close bracket is ignored - hmmm...)
Dim te$ = "1)+2"

c = 0
Do
 Inc c
 On error skip
 ans = Eval(te$)
 Print c, te$ " =" ans, MM.Info(stack), MM.ErrMsg$
 Pause 50
Loop


Feeding errors to EVAL is horrible? Perhaps, but for this game application, I'd pretty much have to perform all the functionality of EVAL just to determine if the string is syntactically correct. Sort of defeats the purpose. Fortunately you (Matherp) have done an awesome job coding EVAL into MMBasic and it works splendidly.

My bug chasing continues...
Visit Vegipete's *Mite Library for cool programs.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5886
Posted: 08:01pm 14 Jan 2023
Copy link to clipboard 
Print this post

What happens if you change the one line IF to a multiline.
 IF ans < .1 THEN
   soln$ = e$
   TestMath = 1
   EXIT FUNCTION
 ENDIF


It won't change the logic but it will be interesting to see which line reports the error.

I still haven't seen the error.

Jim
VK7JH
MMedit   MMBasic Help
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1082
Posted: 05:20pm 15 Jan 2023
Copy link to clipboard 
Print this post

The program shown below doesn't output as expected:
...
48     &h20041578 &h18700
49     &h20041578 &h18700
50     &h20041578 &h18700
[6] Sub Recurr i
Error : Too many nested SUB/FUN
> list
CLS
c = 0
Recurr c
End

Sub Recurr i
 Inc i
 Print i, "&h" Hex$(MM.Info(STACK)) " &h" Hex$(MM.Info(HEAP))
 Pause 100
 Recurr i
endsub
> option list
PicoMiteVGA MMBasic Version 5.07.06
OPTION KEYBOARD US
>


  Quote  It won't change the logic but it will be interesting to see which line reports the error.
No line in particular will generate an error. It presumably happens whenever MMBasic's internals get thrashed.
Visit Vegipete's *Mite Library for cool programs.
 
     Page 1 of 2    
Print this page
© JAQ Software 2024