Author Topic: 30 Line Game Challenge  (Read 14168 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
30 Line Game Challenge
« on: September 16, 2018, 04:53:23 pm »
Code: QB64: [Select]
  1. 1 SCREEN _NEWIMAGE(1280, 720, 32)
  2. 2
  3. 3 FOR j = 0 TO 1
  4.    4 CLS
  5.    5 PRINT "Bite MY Lucky Seven"
  6.    6 PRINT "Most games want you to guess from 1 to 100, but I'm smarter than them."
  7.    7 PRINT "Choose any whole number from 0 to 127, and give me 7 guesses."
  8.    8 PRINT "I bet after that time, I can tell you what the number is."
  9.    9 PRINT CHR$(13); "Choose your number and press any key to begin"
  10.    10 junk$ = INPUT$(1)
  11.    11 guess = 64
  12.    12 CLS
  13.    13 FOR i = 5 TO 0 STEP -1
  14.        14 guess = guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i + 1)
  15.        15 PRINT "For Guess #"; (6 - i); ", my guess is"; guess
  16.        16 PRINT CHR$(13); "Am I:  (0) Correct   (1) High   (2) Low"; CHR$(13)
  17.        17 PRINT "PRESS 0, 1, or 2 please for your answer =>";
  18.        18 a = VAL(INPUT$(1))
  19.        19 PRINT a; CHR$(13); CHR$(13)
  20.        20 i = i - ((a - 1) AND 2) / 2 * i 'answer 0, and we win
  21.    21 NEXT
  22.    22 guess = guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i +1)
  23.    23 PRINT "Your number is "; guess
  24.    24 PRINT
  25.    25 PRINT "Would you like to:     (1) Try again"
  26.    26 PRINT "                       (2) Run away crying, unable to stop my awesome power"
  27.    27 a = VAL(INPUT$(1))
  28.    28 j = 1 - (1 AND a)
  29. 29 NEXT
  30. 30 END

Digging around one of my old drives, and I found this old gem, which was something I came up with for a 30 line game challenge...

If you look close, you'll be able to see what made this program a real challenge to write:  It has no conditional statements in it, at all!  No IF.  No SELECT CASE.... No WHILE-WEND cheatery...

The challenge was:

30 Lines maximum, without cheating with :
No use of standard conditional operators.
It has to be a playable "game" of some approximation.
And a time limit of some sort which it had to be finished by...

Anyone else want to give it a go?  You have to get creative to follow the rules and make something work, and I'd love to see what other folks come up with to meet the challenge.  It definitely made my brain think out of the box, and out of my usual comfort zone.  ;)
« Last Edit: September 17, 2018, 01:12:41 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: 30 Line Game Challenge
« Reply #1 on: September 16, 2018, 04:59:35 pm »
Well right off the bat I'm wondering why you just didn't make your print statements one line, as you can add line break characters using the plus sign?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 30 Line Game Challenge
« Reply #2 on: September 16, 2018, 05:11:03 pm »
Well right off the bat I'm wondering why you just didn't make your print statements one line, as you can add line break characters using the plus sign?

Pete

Just so I could "pad" the program to 30 lines.   (Same reason for the END statement.). ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: 30 Line Game Challenge
« Reply #3 on: September 16, 2018, 05:16:58 pm »
Ah, you were under 30. My mind went to 30 or less, less being better. Most of these types of challenges I got involved in at N54 involved the least amount of code to accomplish something; you know, like make a list of all of the valuable accomplishments made by Democrats. The winner is the one who just leaves the IDE blank... which really upset the guy who coded CLS, and thought he had it in the bag.

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: 30 Line Game Challenge
« Reply #4 on: September 16, 2018, 06:16:02 pm »
Hi
So Steve , TOSHIBA, but I must do these two questions for a better understanding the challenge rules
1.
 is void line good for this 30 o less Line Game Challenge?
for example your line of code 2

2.
is good the game also if it is not effective ?

3.
Are REM or ' lines  not valid for counting lines of the game?

4.
are tricky '$include:'filename' forbidden?

again TOSHIBA I have made a wrong computation of the number of questions.

Thanks

PS
 it seems clear to me that NO standard conditional operators(>=,<=,==), if-then-else, select case end select, while-wend  and I suppose no do-until
Programming isn't difficult, only it's  consuming time and coffee

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: 30 Line Game Challenge
« Reply #5 on: September 16, 2018, 07:31:53 pm »
OK, I had to add some padding crap at the end like Steve did to get it to 30-lines, and I used variables when I could have cut them out and used VAL() but again, the challenge was 30-lines, not less.

This is a boring little guess higher or lower card game that keeps track of your score. It randomizes a deck of 52 cards and displays them in, you guessed it, SCREEN 0, the only screen mode anyone needs. Anyway, try not to fall asleep while trying it out; however, It might be fun for some to explore, because it really uses the hell out of one of my favorite QB keywords, INSTR.

Pete

Code: QB64: [Select]
  1.     a$ = LTRIM$(STR$(INT(RND * 13 + 2))) + "." + LTRIM$(STR$(INT(RND * 4 + 1)))
  2.     IF INT(VAL(a$)) > 10 THEN b$ = MID$("JQKA", VAL(a$) - 10, 1) + MID$(CHR$(3) + CHR$(4) + CHR$(5) + CHR$(6), VAL(MID$(a$, INSTR(a$, ".") + 1)), 1) ELSE b$ = LTRIM$(STR$(INT(VAL(a$)))) + MID$(CHR$(3) + CHR$(4) + CHR$(5) + CHR$(6), VAL(MID$(a$, INSTR(a$, ".") + 1)), 1)
  3.     IF INSTR(mystring$, b$) = 0 THEN mystring$ = b$ + "=" + MID$(a$, 1, INSTR(a$, ".") - 1) + "|" + mystring$
  4. LOOP WHILE LEN(mystring$) < 284
  5.     msg$ = MID$(mystring$, 1, INSTR(mystring$, "=") - 1) + " "
  6.     x = VAL(MID$(mystring$, INSTR(mystring$, "=") + 1))
  7.     DO
  8.         IF LEN(msg$) < 5 THEN PRINT msg$;
  9.         LINE INPUT "Will the next card be [h]igher or [l]ower? "; hl$
  10.         mystring$ = MID$(mystring$, INSTR(mystring$, "|") + 1)
  11.         y = VAL(MID$(mystring$, INSTR(mystring$, "=") + 1))
  12.         IF UCASE$(hl$) = "H" THEN IF y > x THEN msg$ = "1|correct!" ELSE IF y = x THEN msg$ = "0|It's a push, try again!" ELSE msg$ = "-1|Wrong dirt farmer!!!"
  13.         IF UCASE$(hl$) = "L" THEN IF y < x THEN msg$ = "1|correct!" ELSE IF y = x THEN msg$ = "0|It's a push, try again!" ELSE msg$ = "-1|Wrong dirt farmer!!!"
  14.     LOOP WHILE LEN(msg$) < 5
  15.     score = score + VAL(msg$)
  16.     PRINT " ... "; MID$(msg$, INSTR(msg$, "|") + 1) + " Score = "; LTRIM$(STR$(score)); CHR$(13)
  17.     IF mystring$ = "" THEN EXIT DO
  18. PRINT "Thanks for playing. Your final score is: " + LTRIM$(STR$(score))
  19. PRINT "Press Esc to end or any key to play again!"
  20.     _LIMIT 30
  21.     b$ = INKEY$
  22.     IF LEN(b$) THEN IF b$ = CHR$(27) THEN SYSTEM ELSE EXIT DO
« Last Edit: September 17, 2018, 05:32:39 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: 30 Line Game Challenge
« Reply #6 on: September 16, 2018, 07:45:55 pm »
Well beyond my skills (I only write multi-thousand line train wrecks), but I found a bit of a bug in "Bite My Lucky Seven". When I choose the number 1 it came up with 1.5, twice. Still, that is pretty innovative coding.

I put an INT around the argument in line 22 and it seemed to work.

P.S. I shouldn't muck about with things I know nothing about. The INT fragged it for catching higher numbers. Fascinating work.
« Last Edit: September 16, 2018, 07:55:22 pm by OldMoses »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 30 Line Game Challenge
« Reply #7 on: September 16, 2018, 07:50:01 pm »
BZZZZZZT!! 

Pete's been hanging around with the democrats in his state so long, he's forgotten to follow the main challenge of the rules:   No use of IF, SELECT CASE, and other common conditional keywords. 

You're fired!  :P

************************

Quote
Hi
So Steve , TOSHIBA, but I must do these two questions for a better understanding the challenge rules
1.
 is void line good for this 30 o less Line Game Challenge?
for example your line of code 2

2.
is good the game also if it is not effective ?

3.
Are REM or ' lines  not valid for counting lines of the game?

4.
are tricky '$include:'filename' forbidden?


Users are limited to 30 lines, so a blank line is perfectly fine.  Count it -- don't count it -- you'd still come in under that 30 line limit.  Same way with a line of solid comment with REM or '.  Just don't use OVER 30 lines -- and use of $INCLUDE would be a violation of the rules just as a colon would be. 

X = 2: Y = 3 <-- this would count as 2 lines, so why wouldn't $INCLUDE:'XYset.bas'??

As for it being "effective", that's entirely subjective.  The main challenge was to write a program/game WITHOUT using IF, SELECT, and such, which requires some outside the box thinking.   ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 30 Line Game Challenge
« Reply #8 on: September 16, 2018, 07:56:10 pm »
Well beyond my skills (I only write multi-thousand line train wrecks), but I found a bit of a bug in "Bite My Lucky Seven". When I choose the number 1 it came up with 1.5, twice. Still, that is pretty innovative coding.

I put an INT around the argument in line 22 and it seemed to work.

Now how the BEEP did it do that??  It should move along in powers of 2...   64, 32, 16, 8, 4, 2, 1...

I'm gonna have to dig around and see if it's my math that's wrong, or just some quirk of single precision routines that's off, or what the heck is happening.  All answers should be integer values, which change by the power of 2.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: 30 Line Game Challenge
« Reply #9 on: September 16, 2018, 08:06:59 pm »
Now how the BEEP did it do that??  It should move along in powers of 2...   64, 32, 16, 8, 4, 2, 1...

I'm gonna have to dig around and see if it's my math that's wrong, or just some quirk of single precision routines that's off, or what the heck is happening.  All answers should be integer values, which change by the power of 2.

It was doing that until I tried to fix it. It really didn't like that. I should have known it wouldn't be that easy...

Offline Omerta7486

  • Newbie
  • Posts: 33
  • √𝜋²
    • View Profile
Re: 30 Line Game Challenge
« Reply #10 on: September 16, 2018, 08:37:00 pm »
Yeah. I chose 21, it proudly declared my answer was 21.5! I played around 10 times and it got it right on the nose 8 out of the 10, and was 0.5 off the other 2. Not bad. 4 in 5 is better than I could have done! Lol
The knowledge that's seeking the favor of another means the murder of self.

Latest version of my game, here  Omertris: Invasion

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: 30 Line Game Challenge
« Reply #11 on: September 16, 2018, 08:42:20 pm »
Oh, you assumed I read the instructions. I didn't, just the 30-lines and make a game. It's a 30-line game. :D

Writing a program without conditional statements would be like having sex without a partner.

Oh well, it was so much fun, I'll just post it as a new challenge. In other words, take matters into my own hand. Oh wait, why do I suddenly feel guilty of hypocrisy?

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 30 Line Game Challenge
« Reply #12 on: September 16, 2018, 08:57:20 pm »
Yeah. I chose 21, it proudly declared my answer was 21.5! I played around 10 times and it got it right on the nose 8 out of the 10, and was 0.5 off the other 2. Not bad. 4 in 5 is better than I could have done! Lol

And somehow, this just totally astounds me...

guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i + 1)

guess starts at 64.   a starts at 0.  i starts at 5....   

First guess:  64 + (2 AND 0... which is 0) - (1 AND 0... Which is 0).... Gives 64 in the end.

Second guess: guess starts at 64.  a would be 1 (guessed high).  i is now 4.

64 +  0 - 1 * 2 ^ 5....   64-32 = 32

Third guess: 32 + 0 - 1 * 2 ^ 4 = 16

Fourth guess: 8
Fifth guess: 4
Sixth guess: 2
Seventh guess: 1

2 + 0 - 1 * 2 ^ (-1 + 1) = 1

How can the math generate half digit values??  I'm completely baffled by the reports you guys are giving.   

We start with 64, then +/- 32, then +/- 16...  8.. 4... 2.... 1...   How do we EVER get a half point in there??

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: 30 Line Game Challenge
« Reply #13 on: September 16, 2018, 09:27:21 pm »
I made a simple addition program to add up some rental improvement tax crap a couple of weeks ago, and ran into the same problem. Now for my office software, I made a function to fix these screwy mistakes computers make, apparently because they count in binary instead of base 10. So I'm not sure if this is what your guessing game is encountering, but I am saying you can't trust binary counting systems to do simple math without applying correctional methods to ensure the proper outcome.

Pete

Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 30 Line Game Challenge
« Reply #14 on: September 17, 2018, 07:29:16 am »
Yeah. I chose 21, it proudly declared my answer was 21.5! I played around 10 times and it got it right on the nose 8 out of the 10, and was 0.5 off the other 2. Not bad. 4 in 5 is better than I could have done! Lol

And somehow, this just totally astounds me...

guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i + 1)

guess starts at 64.   a starts at 0.  i starts at 5....   

First guess:  64 + (2 AND 0... which is 0) - (1 AND 0... Which is 0).... Gives 64 in the end.

Second guess: guess starts at 64.  a would be 1 (guessed high).  i is now 4.

64 +  0 - 1 * 2 ^ 5....   64-32 = 32

Third guess: 32 + 0 - 1 * 2 ^ 4 = 16

Fourth guess: 8
Fifth guess: 4
Sixth guess: 2
Seventh guess: 1

2 + 0 - 1 * 2 ^ (-1 + 1) = 1

How can the math generate half digit values??  I'm completely baffled by the reports you guys are giving.   

We start with 64, then +/- 32, then +/- 16...  8.. 4... 2.... 1...   How do we EVER get a half point in there??

Did you try 21?