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

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 30 Line Game Challenge
« Reply #15 on: September 17, 2018, 07:47:53 am »
    PRINT "i="; i
    22 guess = guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i)

for 21, i = -1 and 2 ^ -1 = .5

typo on line 22 to match line 14
 22 guess = guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i +1)  '  i + 1 fixes
« Last Edit: September 17, 2018, 07:59:52 am by bplus »

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: 30 Line Game Challenge
« Reply #16 on: September 17, 2018, 12:32:20 pm »
here is my entry, less than 30 lines,  no IF\THEN or SELECT\CASE.

Code: QB64: [Select]
  1. 'Card Guessing Game, Kobolt 9/17/2018-12:15pm Ver 1.0, 22 lines!
  2. DIM hints(8) AS STRING
  3. FOR i% = 1 TO 8
  4.  READ hints(i%)
  5. NEXT i%
  6.  CLS
  7.  c% = INT(RND * 4) + 1
  8.  n% = INT(RND * 13) + 1
  9.  PRINT "(S)pade, (C)lubs, (H)earts, (D)iamonds, Ace-1, Jack-11, Queen-12, King-13", SPACE$(80)
  10.  PRINT "Hint - "; hints(c%), SPACE$(80)
  11.  DO
  12.   INPUT "What card is it (ex-D8=8 of Diamonds)"; a$
  13.   Try~% = Try~% + 1
  14.  LOOP UNTIL UCASE$(a$) = (hints(4 + c%) + LTRIM$(RTRIM$(STR$(n%))))
  15.  Good~% = Good~% + 1
  16.  INPUT "Try again?"; a$
  17. LOOP UNTIL LCASE$(a$) = "n"
  18. PRINT "Total trys:"; Try~%; " for "; Good~%; " Correct!"
  19. DATA "a garden tool","used when somebody is bad","gotta love with this","Ladies best friend","S","C","H","D"
  20.  
Granted after becoming radioactive I only have a half-life!

Offline Omerta7486

  • Newbie
  • Posts: 33
  • √𝜋²
    • View Profile
Re: 30 Line Game Challenge
« Reply #17 on: September 17, 2018, 01:12:55 pm »
I don't know why the math is acting the way it is, but as a game designer, I follow the "first fix wins now, best fix wins later" principle.

Putting INT() around the final guess at least undoes the whole .5 thing and makes the guess correct:
Code: QB64: [Select]
  1.    23 PRINT "Your number is "; INT(guess)

You're right, Steve, how does binary math produce decimals? Without division, there should be no .5's in there. Do we actually have an instance of binary math producing fractional numbers?

Quote from: American Dad
You know what that'll do to society? Girls playing with trucks. Boys playing with dolls. Horses eating each other. Yes, horses eating each other! It's in the Bible, Fracine!

I tried to DIM guess as _byte, and it would guess 22 for 21, 6 for 5, 2 for 1. I tried to DIM guess, a, i, j as _byte, it brought back the .5's! I'm going to look more into this.
The knowledge that's seeking the favor of another means the murder of self.

Latest version of my game, here  Omertris: Invasion

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: 30 Line Game Challenge
« Reply #18 on: September 17, 2018, 01:19:36 pm »
    PRINT "i="; i
    22 guess = guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i)

for 21, i = -1 and 2 ^ -1 = .5

typo on line 22 to match line 14
 22 guess = guess + (2 AND a) * 2 ^ (i) - (1 AND a) * 2 ^ (i +1)  '  i + 1 fixes

That's what it is!  The formula is correct, which is why I couldn't sort out what the heck was wrong with it!!  ;D

Typos are hell to find.  Your brain knows what *should* be there, and it just overlooks the issue completely.  NOW, the guessing game actually guesses like it's supposed to. 

One good thing about the glitch: It probably helped everyone understand how it actually works now -- Binary search up/down in powers of 2 until it finds the solution.  :D

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

Post corrected with the proper formula. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Omerta7486

  • Newbie
  • Posts: 33
  • √𝜋²
    • View Profile
Re: 30 Line Game Challenge
« Reply #19 on: September 17, 2018, 01:35:23 pm »
Dang, I didn't read on to page two... B+ beat me by two posts making me both the later AND worst fix... Foot in mouth. 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 #20 on: September 17, 2018, 02:42:08 pm »
Have you tried putting peanut butter between your toes? I find it it helps take the edge off.

Dammit Steve, I remember when that typo crap started with me. It's just a sign of aging. Pretty soon you'll be wondering where you put your keys, and then discovering it doesn't matter, because you can't remember where you parked your car. After that, well, just hang on to that URL I posted for those "PEP" pills.

Kidding aside, thanks for posting this challenge. It got me off my duff from endless organizing, which I hate to do anyway, and got me back to doing something fun, even though I didn't read the directions. That card suit technique I came up with was new, and new stuff makes me happy. I seldom pull code from my repository, which sounds strangely akin to pulling something out of something else, but I digress. If I can code something fresh,  it's more fun but I have to admit, aging hasn't helped when it comes to the occasional goofs.

Pete

- I'm thinking of skipping my birthday this year, whenever the hell that is.

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 #21 on: September 18, 2018, 10:21:58 am »
Hey I got it! Here is Digit Thief Level 2:

You have only 3 digits 0, 1, 2 because you live in a world where everyone has 1 finger on the upper hand and 2 digits on their lower hand... but I guess that's a different story...  ;-))
BTW this could just as easily been 10 digits but I wanted a real threat of loosing all your digits before you are done guessing. Still there is one sure strategy to never loose, boring though... Come to think, could have a rule to prevent that but that would be more lines and IF's, anyway...  ;-))

So using only FOR loops to substitute for IF's and all other flow control mechanisms except GOTO, here is Digit Thief Level 2 at 24 lines (no colons except for line labels and no externals) plus 1 code debugger line I left in:
Code: QB64: [Select]
  1. RANDOMIZE TIMER ' Digit Thief 2 minus IF.bas for QB64 2018-09-18 B+
  2. jumpStart:
  3. gCount% = 0
  4. thief% = INT(RND * 3)
  5. digits$ = "012"
  6. loopAgain:
  7. 'PRINT "(debug thief is here:"; thief%; ")" '<<<<< I used this line to check my code
  8. INPUT "Enter Guess (0 to 2) where the digit thief is now "; guess%
  9. gCount% = gCount% + 1
  10. kstart = -1 * (guess% <> thief%)
  11. FOR k = kstart TO 0
  12.     PRINT "You caught the thief in" + STR$(gCount%) + " guesses."
  13.     GOTO jumpStart
  14. MID$(digits$, thief% + 1, 1) = " "
  15. PRINT "Digits Left Update: " + digits$
  16. thief% = ABS(INT(RND * 3) - 1 + thief%) MOD 3
  17. lstart = -1 * (digits$ <> STRING$(3, " "))
  18. FOR l = lstart TO 0
  19.     PRINT "Dang! too late! Gone in" + STR$(gCount%) + " guesses."
  20.     GOTO jumpStart
  21. GOTO loopAgain
  22.  

BTW there is no escape from Level 2. ha, ha, ha....

EDIT: one less FOR loop, one less line 23 lines plus a debugger commented out.
« Last Edit: September 18, 2018, 10:49:05 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 30 Line Game Challenge
« Reply #22 on: September 18, 2018, 11:10:22 am »
Oh I just made 30 Line limit, Digit Thief 3 minus IF.bas now prevents digit guarding.
Code: QB64: [Select]
  1. RANDOMIZE TIMER ' Digit Thief 3 minus IF.bas for QB64 2018-09-18 B+  prevent "digit guarding"
  2. jumpStart:
  3. gCount% = 0
  4. thief% = INT(RND * 3)
  5. digits$ = "012"
  6. lastGuess% = -999
  7. loopAgain:
  8. INPUT "Enter Guess (0 to 2) where the digit thief is now "; guess%
  9. jstart = -1 * (guess% <> lastGuess%)
  10. FOR j = jstart TO 0
  11.     PRINT "Give Digit Thief a 50/50 chance! No digit guarding, make a different choice."
  12.     GOTO loopAgain
  13. gCount% = gCount% + 1
  14. lastGuess% = guess%
  15. kstart = -1 * (guess% <> thief%)
  16. FOR k = kstart TO 0
  17.     PRINT "You caught the thief in" + STR$(gCount%) + " guesses."
  18.     GOTO jumpStart
  19. MID$(digits$, thief% + 1, 1) = " "
  20. PRINT "Digits Left Update: " + digits$
  21. thief% = ABS(INT(RND * 3) - 1 + thief%) MOD 3
  22. lstart = -1 * (digits$ <> STRING$(3, " "))
  23. FOR l = lstart TO 0
  24.     PRINT "Dang! too late! Gone in" + STR$(gCount%) + " guesses."
  25.     GOTO jumpStart
  26. GOTO loopAgain
  27.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: 30 Line Game Challenge
« Reply #23 on: September 18, 2018, 11:36:00 am »
Wait jus ah dad-burn minute thar Varmint! You stole that thar name from me! Oops, sorry, err, my version was called Idgit Thief.

 - Sam
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 #24 on: September 18, 2018, 12:37:57 pm »
And here is: 21 minus IF.bas
Code: QB64: [Select]
  1. RANDOMIZE TIMER '21 minus IF.bas for QB64 2018-09-18 B+
  2. DIM deck%(1 TO 52)
  3. DATA 2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11,2,3,4,5,6,7,8,9,10,10,10,10,11
  4. FOR i% = 1 TO 52
  5.     READ deck%(i%)
  6. 'DO 'to run in loop uncomment, commented lines == Way more fun!!!
  7. 'CLS: di% = 0: playerT% = 0: dealerT% = 0
  8. FOR i% = 52 TO 2 STEP -1 'shuffle
  9.     r% = INT(RND * i%) + 1
  10.     SWAP deck%(r%), deck%(i%)
  11. FOR i% = -1 TO 0
  12.     di% = di% + 1
  13.     playerT% = playerT% + deck%(di%)
  14.     _PRINTSTRING (27, di% + 5), "Player card: " + RIGHT$(SPACE$(2) + STR$(deck%(di%)), 2) + " total is " + RIGHT$(SPACE$(2) + STR$(playerT%), 2)
  15.     i% = (playerT% < 15)
  16. istart% = -1 * (playerT% > 21)
  17. FOR i% = istart% TO 0
  18.     di% = di% + 1
  19.     dealerT% = dealerT% + deck%(di%)
  20.     _PRINTSTRING (27, di% + 7), "Dealer card: " + RIGHT$(SPACE$(2) + STR$(deck%(di%)), 2) + " total is " + RIGHT$(SPACE$(2) + STR$(dealerT%), 2)
  21.     i% = (dealerT% < playerT%)
  22. istart% = -1 * (playerT% > 21 OR (dealerT% < 22 AND dealerT% >= playerT%))
  23. FOR i% = istart% TO 0
  24.     PRINT "Hey Player, you Won!"
  25.     GOTO skip
  26. PRINT "Sorry Player, Dealer Won!"
  27. skip:
  28. '_DELAY 4
  29. 'LOOP 'this is line 34 minus 4 commented lines  = 30 !
  30.  

Offline Omerta7486

  • Newbie
  • Posts: 33
  • √𝜋²
    • View Profile
Re: 30 Line Game Challenge
« Reply #25 on: September 18, 2018, 07:25:16 pm »
Here is my entry. Started it last night. Finished it about an 30mins ago, then played it a little.
It's a simple dice game. No IFs, WHILEs, DOs, SELECTs, and all logic is math based. Please tell me if the instructions are clear enough. It's quite a complex little game for 30 lines! Which made it kind of hard to sum up. Lol.
Code: QB64: [Select]
  1. 2 FOR a% = 0 TO 20000
  2.    3 FOR die%% = 1 TO 6
  3.        4 keep(die%%) = 0
  4.        5 tally(die%%) = 0
  5.        6 dice(die%%) = INT(RND * 6 + 1)
  6.    7 NEXT
  7.    8 kept%% = 0
  8.    9 FOR hand%% = 0 TO 6
  9.        10 FOR hold%% = 0 TO 2
  10.            11 this%% = kept%%
  11.            12 FOR die%% = kept%% + 1 TO 6
  12.                 PRINT "Welcome to DICE!"; CHR$(13); CHR$(13); "Choose your selections carefully, as after you have made decisions on all dice,"; "the game rerolls. You MUST keep at least 1 die each roll, and once you have kept"; "6 dice, you will receive your score for the round."; CHR$(13); "REMEMBER: When you do not keep a die, it is rerolled."; CHR$(13); CHR$(13); "Your goal is to reach 20000pts! Have Fun!"; CHR$(13); CHR$(13); "SCORE HELP"; CHR$(13); "----------"; CHR$(13); "1=100  2=0  3=0  4=0  5=50  6=0"; CHR$(13); "Triple 1's=1000 Triple 4's=400"; CHR$(13); "Triple 2's=200  Triple 5's=500"; CHR$(13); "Triple 3's=300  Triple 6's=600"; CHR$(13); "A straight of 1-6=2000"; STRING$(4, 13); "Current score is:"; score%; "/ 20000"; CHR$(13); "Dice rolled in this hand:       "; dice(1); dice(2); dice(3); dice(4); dice(5); dice(6); CHR$(13); "Dice you have kept this round:  "; keep(1); keep(2); keep(3); keep(4); keep(5); keep(6); CHR$(13); CHR$(13); "Keep die"; RTRIM$(STR$(die%%)); "? [It's a"; RTRIM$(STR$(dice(die%%))); "] (1=y 0=n)";
  13.                14 INPUT "", in
  14.                15 keep(kept%% + 1) = in * dice(die%%)
  15.                16 kept%% = kept%% + in
  16.                17 tally(keep(kept%%)) = tally(keep(kept%%)) + in
  17.            18 NEXT
  18.            19 hold%% = 2 * (kept%% - this%%)
  19.        20 NEXT
  20.        21 FOR die%% = 1 TO 6
  21.            22 dice(die%%) = (ABS(keep(die%%) <> 0) * 0) + (ABS(keep(die%%) = 0) * INT(RND * 6 + 1))
  22.        23 NEXT
  23.        24 hand%% = kept%%
  24.    25 NEXT
  25.     score% = score% + (tally(1) * 100) + (INT(tally(1) / 3) * 700) + (INT(tally(2) / 3) * 200) + (INT(tally(3) / 3) * 300) + (INT(tally(4) / 3) * 400) + (tally(5) * 50) + (INT(tally(5) / 3) * 350) + (INT(tally(6) / 3) * 600) + (INT(ABS((tally(1) = 1) + (tally(2) = 1) + (tally(3) = 1) + (tally(4) = 1) + (tally(5) = 1) + (tally(6) = 1)) / 6) * 2000)
  26.    27 a% = score%
  27.    28 CLS
  28. 29 NEXT
  29. 30 PRINT "Congratulations! You beat 20000pts! Your score was:"; score%

[EDIT]Fixed code in code box.
« Last Edit: September 18, 2018, 09:15:46 pm by Omerta7486 »
The knowledge that's seeking the favor of another means the murder of self.

Latest version of my game, here  Omertris: Invasion

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 30 Line Game Challenge
« Reply #26 on: September 18, 2018, 07:44:56 pm »
Ah nice, as I understand it, all the choices are prearranged and it is matter of choosing combination with yes = * 1 or no * 0 questions. Completely different approach from what I had done.

My tests seem to be getting stuck on choice for selecting 6th die, I keep choosing no and it keeps showing me the same number.  I don't fully understand game like how many times you are allowed to reject a die.

Offline Omerta7486

  • Newbie
  • Posts: 33
  • √𝜋²
    • View Profile
Re: 30 Line Game Challenge
« Reply #27 on: September 18, 2018, 09:13:13 pm »
Ahh... I knew I was forgetting to explain some things. That was my bad. It should explain it better now in the above code.

In case it doesn't(Oh, I broke the challenge rules and used a CASE XD), here is a breakdown of DICE.

You roll a hand of 6 dice.

You get 6 6 4 1 1 5

You decide to take 1 1 5 and keep them.

You now have 1 1 5, and you reroll the 6 6 4 and get 1 3 2.

You decide to take the 1.

You now have 1 1 5 1, and you reroll the 3 2 and get 5 5.

You decide to take both fives.

You end this round with 1 1 5 1 5 5 and earn 1500pts. 1000 for the triple 1's and 500 for the triple 5's.

That ends that round, and then the game rerolls all 6 dice for the next round.

You roll 6 3 1 2 4 5.

You decide to keep all six dice, because you have a straight 1-2-3-4-5-6.

You end the round with 6 3 1 2 4 5 and earn 2000pts. for the straight. You now have a score of 3500pts.

You ALWAYS have to keep at least one(1) die, whether it scores points or not, and you can keep between 1-6 dice from each hand.
The knowledge that's seeking the favor of another means the murder of self.

Latest version of my game, here  Omertris: Invasion

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: 30 Line Game Challenge
« Reply #28 on: September 18, 2018, 09:26:06 pm »
I needed a distraction, this challenge was perfect.

Here is my entry - Yellow GOOD ... Red BAD

Code: QB64: [Select]
  1. DIM box(50) AS STRING
  2. SCREEN _NEWIMAGE(640, 480, 32) ' *** YELLOW GOOD ... RED BAD ***
  3.     _LIMIT 30
  4.     CLS
  5.     LOCATE 1, 1
  6.     PRINT STR$(score)
  7.     WEND
  8.     m$ = RIGHT$("0" + LTRIM$(STR$(_MOUSEX)), 3) + RIGHT$("0" + LTRIM$(STR$(_MOUSEY)), 3) ' xxxyyy
  9.     LINE (VAL(LEFT$(m$, 3)) - 10, VAL(RIGHT$(m$, 3)) - 10)-(VAL(LEFT$(m$, 3)) + 10, VAL(RIGHT$(m$, 3)) + 10), _RGB32(255, 255, 255), BF ' white box
  10.     FOR x = 1 TO 50
  11.         IF box(x) = "" OR VAL(MID$(box(x), 4, 3)) > 500 THEN box(x) = RIGHT$("0" + LTRIM$(STR$(INT(RND(1) * 600) + 20)), 3) + "-40" + RIGHT$("0" + LTRIM$(STR$(INT(RND(1) * 10) + 1)), 2) + LTRIM$(STR$(INT(RND(1) * 2)))
  12.         box(x) = LEFT$(box(x), 3) + RIGHT$("0" + STR$(VAL(MID$(box(x), 4, 3)) + VAL(MID$(box(x), 7, 2))), 3) + RIGHT$(box(x), 3) ' add speed to y
  13.         LINE (VAL(LEFT$(box(x), 3)) - 20, VAL(MID$(box(x), 4, 3)) - 20)-(VAL(LEFT$(box(x), 3)) + 20, VAL(MID$(box(x), 4, 3)) + 20), _RGB32(255, VAL(RIGHT$(box(x), 1)) * 255, 0), BF
  14.         IF VAL(LEFT$(m$, 3)) - 10 <= VAL(LEFT$(box(x), 3)) + 20 AND VAL(LEFT$(m$, 3)) + 10 >= VAL(LEFT$(box(x), 3)) - 20 AND VAL(RIGHT$(m$, 3)) - 10 <= VAL(MID$(box(x), 4, 3)) + 20 AND VAL(RIGHT$(m$, 3)) - 10 >= VAL(MID$(box(x), 4, 3)) - 20 THEN
  15.             IF VAL(RIGHT$(box(x), 1)) = 1 THEN
  16.                 score = score + 1
  17.                 box(x) = ""
  18.                 SOUND 220, 1
  19.                 SOUND 440, 1
  20.             ELSE
  21.                 SOUND 220, 10
  22.                 END
  23.             END IF
  24.         END IF
  25.     NEXT x
  26.     _DISPLAY
« Last Edit: September 18, 2018, 09:31:40 pm by TerryRitchie »
In order to understand recursion, one must first understand recursion.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: 30 Line Game Challenge
« Reply #29 on: September 18, 2018, 09:31:52 pm »
Hi Omerta,

Ahhh, you must accept at least 1 die, got it! Thanks

Omerta: "In case it doesn't(Oh, I broke the challenge rules and used a CASE XD), here is a breakdown of DICE."
LOL that one case might be forgiven :)

Now, how many hands are there? If you have answered this question already, I apologize for my poor reading skills.

Append" OK "For hands = 0 to 6" so seven hands OK
« Last Edit: September 18, 2018, 09:35:59 pm by bplus »