Author Topic: New and BETTER Challenge. Make a game 20-lines or less.  (Read 7725 times)

0 Members and 1 Guest are viewing this topic.

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
New and BETTER Challenge. Make a game 20-lines or less.
« on: September 16, 2018, 08:49:11 pm »
It just has to be stand alone code, that means no $INCLUDE files, library calls, etc. and no colons. No tricks like using REM or a long variable that the program parses and feeds to another program, and then runs that much larger (More program lines) program.

2-Line Card Game Example:

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.         IF UCASE$(hl$) = "H" THEN IF VAL(MID$(mystring$, INSTR(mystring$, "=") + 1)) > x THEN msg$ = "1|Correct! Plus 1-Point." ELSE IF VAL(MID$(mystring$, INSTR(mystring$, "=") + 1)) = x THEN msg$ = "0|It's a push, try again!" ELSE msg$ = "-1|Wrong. Minus 1-Point."
  12.         IF UCASE$(hl$) = "L" THEN IF VAL(MID$(mystring$, INSTR(mystring$, "=") + 1)) < x THEN msg$ = "1|Correct! Plus 1-Point." ELSE IF VAL(MID$(mystring$, INSTR(mystring$, "=") + 1)) = x THEN msg$ = "0|It's a push, try again!" ELSE msg$ = "-1|Wrong. Minus 1-Point."
  13.     LOOP WHILE LEN(msg$) < 5
  14.     score = score + VAL(msg$)
  15.     PRINT " ... "; MID$(msg$, INSTR(msg$, "|") + 1) + " Score = "; LTRIM$(STR$(score)); CHR$(13)
  16.     IF mystring$ = "" THEN EXIT DO



« Last Edit: September 17, 2018, 05:38:37 am by Pete »
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #1 on: September 17, 2018, 12:21:23 pm »
Here you go 20 lines of code for a game!(ish) padded it out to 20 lines, the original was only 16
Simple card guessing game with 1 hint.
Code: QB64: [Select]
  1. 'Card Guessing Game, Kobolt 9/17/2018-12:15pm Ver 1.0, 20 line Challenge!
  2. DIM hints(8) AS STRING
  3. FOR i% = 1 TO 8
  4.  READ hints(i%)
  5. NEXT i%
  6.  c% = INT(RND * 4) + 1
  7.  n% = INT(RND * 13) + 1
  8.  PRINT hints(c%)
  9.  DO
  10.   INPUT "What card is it (S,C,H,D:A-1,J-11,Q-12,K-13|ex-D8=8 of Diamonds)"; a$
  11.   Try~% = Try~% + 1
  12.  LOOP UNTIL UCASE$(a$) = (hints(4 + c%) + LTRIM$(RTRIM$(STR$(n%))))
  13.  Good~% = Good~% + 1
  14.  INPUT "Try again?"; a$
  15. LOOP UNTIL LCASE$(a$) = "n"
  16. PRINT "Total trys:"; Try~%; " for "; Good~%; " Correct!"
  17. DATA "a garden tool","used when somebody is bad","gotta love with this","Ladies best friend","S","C","H","D"
  18.  
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #2 on: September 17, 2018, 01:59:04 pm »
FUN! But I had difficulty because I thought a "Ladies best friend." started with a "V" and I couldn't find that as one of the selection choices. Other than that, nice job! It really gave me a good vibe!

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

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #3 on: September 17, 2018, 04:08:35 pm »
FUN! But I had difficulty because I thought a "Ladies best friend." started with a "V" and I couldn't find that as one of the selection choices. Other than that, nice job! It really gave me a good vibe!

Pete :)

You know somebody I used to work with brought back a deck of cards like that from Vegas! Instead of the normal spade,clubs,hearts,and diamonds it was right up the "V" alley!(or gutter if you like)
One thing a program of only 20 lines comes up short on is instructions!(and pictures like the ones on the deck of cards ;)
Glad you found it interesting, never done one of these challenges before.
Granted after becoming radioactive I only have a half-life!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #4 on: September 17, 2018, 04:40:47 pm »
Glad you enjoyed it. We had a whole forum dedicated to QB coding challenges at the N54 QBasic forum. We had a couple of coders who made it their home. I hardly ever got involved but I the ones I did participate in were fun. My friend Mac, who ran the forum at the time and who was a career programmer for IBM couldn't believe I just programmed as a hobby. I often thought if I had been somehow introduced to BASIC programming just a year earlier, instead of the BS FORTRAN cards I had to punch to take chemistry tests for an idiot chem teacher, I might have chosen this as my field instead of healthcare.

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: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #5 on: September 17, 2018, 08:20:53 pm »
Code: QB64: [Select]
  1. RANDOMIZE TIMER ' digit thief.bas for QB64 2018-09-16 B+
  2.     gCount% = 0
  3.     thief% = INT(RND * 10)
  4.     robbed$ = "0123456789"
  5.     PRINT
  6.     WHILE _KEYDOWN(27) = 0 AND robbed$ <> STRING$(10, " ")
  7.         INPUT "Enter Guess (0 to 9) where the digit thief is now "; guess%
  8.         gCount% = gCount% + 1
  9.         IF guess% = thief% THEN
  10.             PRINT "You caught the thief in" + STR$(gCount%) + " guesses."
  11.             EXIT WHILE
  12.         ELSE
  13.             MID$(robbed$, thief% + 1, 1) = " "
  14.             PRINT "Game Update: " + robbed$
  15.             thief% = ABS(INT(RND * 3) - 1 + thief%) MOD 10
  16.             IF robbed$ = STRING$(10, " ") THEN PRINT "Dang! too late! Gone in" + STR$(gCount%) + " guesses."
  17.         END IF
  18.     WEND
  19.  

It is really hard to loose all your digits. ;)
« Last Edit: September 17, 2018, 08:27:35 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #6 on: September 17, 2018, 09:39:52 pm »
It took me 13 guesses to catch the Democrat. Is that a lot?

Nice job! I just guessed at random, not sure if there is a strategy.

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: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #7 on: September 17, 2018, 10:51:08 pm »
I think I have the essence of it:
Code: QB64: [Select]
  1. RANDOMIZE TIMER '21.bas for QB64 2018-09-17 B+
  2. DIM deck%(1 TO 52)
  3. FOR i% = 1 TO 52
  4.     IF i% MOD 13 + 1 > 10 THEN deck%(i%) = 10 ELSE deck%(i%) = i% MOD 13 + 1
  5.     IF deck%(i%) = 1 THEN deck%(i%) = 11 'aces always 11
  6. FOR i% = 52 TO 2 STEP -1 'shuffle
  7.     r% = INT(RND * i%) + 1
  8.     SWAP deck%(r%), deck%(i%)
  9. WHILE playerT% < 15
  10.     di% = di% + 1
  11.     playerT% = playerT% + deck%(di%)
  12.     _PRINTSTRING (27, di% + 5), "Player card: " + RIGHT$(SPACE$(2) + STR$(deck%(di%)), 2) + " total is " + RIGHT$(SPACE$(2) + STR$(playerT%), 2)
  13. WHILE playerT% < 22 AND dealerT% < playerT%
  14.     di% = di% + 1
  15.     dealerT% = dealerT% + deck%(di%)
  16.     _PRINTSTRING (27, di% + 7), "Dealer card: " + RIGHT$(SPACE$(2) + STR$(deck%(di%)), 2) + " total is " + RIGHT$(SPACE$(2) + STR$(dealerT%), 2)
  17.  

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #8 on: September 18, 2018, 01:58:15 am »
Ah Black Jack, nice! I wrote a much larger version in the 1980s to evaluate different strategies. I actually found one that if you played enough hands and bet enough money, you might want to quit your day job and consider moving to Vegas. The problem was that would be putting in a 16 hour day and 100-500 bets. The odds also went down if you were playing from a shoe. Now what kept me from it is the days that you played a lot of hands, but were still down. Also, a book I read. It stated that if you think the people who put Vegas together with drugs, booze, and broads wouldn't cheat you at cards, well, you deserve what's coming to you. I actually saw a dealer wipe a player out in Reno by dealing seconds. I had a great view of him flipping the deck from a balcony. The guy was doing pretty well, so he started to bet heavy. He got wiped out in 7 straight losses.

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: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #9 on: September 18, 2018, 10:52:47 pm »
My Graphical Game:  CHASE IT!!

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. GOTO movebox
  3. DO UNTIL loss = 3
  4.     CLS
  5.     IF TIMER > timelimit## THEN
  6.         loss = loss + 1
  7.         movebox:
  8.         timelimit## = TIMER + 10 * 0.9 ^ (loss + tag)
  9.         x = RND * (_WIDTH - 50)
  10.         y = RND * (_HEIGHT - 25)
  11.     END IF
  12.     LINE (x, y)-STEP(50, 25), &HFFFF0000, BF
  13.     'Two lines from combined WEND statement above
  14.     IF _MOUSEX >= x AND _MOUSEX <= x + 50 AND _MOUSEY >= y AND _MOUSEY <= y + 25 THEN tag = tag + 1: GOTO movebox 'clicked in the box
  15.     'Two lines from combined IF statement above
  16.     PRINT "You've tagged the box"; STR$(tag); " times."; CHR$(13); "You've missed the box"; loss; "times."; CHR$(13); "Time Limit this turn"; timelimit## - TIMER
  17.     _DISPLAY

The challenge here is to see how many times you can chase and tag the red box with your mouse.   

GASP!!

That's RIGHT!!   A 20 line game which even includes mouse support to play it!   HURRAH!!

/STRUT  /PRANCE  /GIGGLE

It's nothing too fancy, but I think it's nice for the short number of lines which comprises it.   We have mouse support, increasing time constraints, a counter so we can compete against ourselves or others...   Basically, we have a cheesy little "game" in 20 lines. 

And I didn't even have to break Pete's rules to post an entry,  or change them to make a new challenge.  :P
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #10 on: September 19, 2018, 01:07:31 am »
Nice to see graphics in 20 lines and a real game but weird jumping into middle of loop and this:
timelimit## = TIMER + 10 * 0.9 ^ (loss + tag)

that one needs some study. :)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #11 on: September 19, 2018, 01:14:22 am »
Nice to see graphics in 20 lines and a real game but weird jumping into middle of loop and this:
timelimit## = TIMER + 10 * 0.9 ^ (loss + tag)

that one needs some study. :)

TIMER plus ( 10 seconds...  reduced by 90% each time you tag the box or "lose")

10
9
8.1
7.21

And down it counts, giving less response time as it goes.
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: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #12 on: September 19, 2018, 01:21:04 am »
BZZZZZZZZZ

The rules clearly state no colons. ICE has been notified and you will be de-ported to FREEBASIC, immediately! :D

OK, just kidding about the Idiot Code Enforcement people. They've been under staffed ever since FB came on the seen, anyway.

It works! Actually it would be pretty darn challenging if you had to click the mouse on the box before it moved. That's especially true using just one finger on a touch pad. Now is getting that in 20-lines possible?

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: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #13 on: September 19, 2018, 01:30:12 am »
BZZZZZZZZZ

The rules clearly state no colons. ICE has been notified and you will be de-ported to FREEBASIC, immediately! :D

OK, just kidding about the Idiot Code Enforcement people. They've been under staffed ever since FB came on the seen, anyway.

It works! Actually it would be pretty darn challenging if you had to click the mouse on the box before it moved. That's especially true using just one finger on a touch pad. Now is getting that in 20-lines possible?

Pete

You could if you took out the RANDOMIZE TIMER.  Or perhaps actually label the lines 1,2,3...  Then you could remove the movebox: label, freeing up a line of code.

Just add a OldButton = _MOUSEBUTTON(1) to track old mouse button state before the _DISPLAY, and then add 2 conditions to the IF check....

IF (existing junk)  AND _MOUSEBUTTON(1) AND NOT OldButton THEN.....

Then the user would have to UP the mouse each "click", before the next DOWN would register for the button.

Close enough to "mouse click" behavior for such a line limitation program.   
« Last Edit: September 19, 2018, 01:32:34 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: New and BETTER Challenge. Make a game 20-lines or less.
« Reply #14 on: September 30, 2018, 04:10:18 pm »
Hi guys
in this weekend I got some time to code my little idea
here the game
Pick Highest card
you start the game and pick a card, after AI does the same
you can replay while the program shows the scores of the two player (user vs AI)

Code: QB64: [Select]
  1. PRINT "WELCOME TO HIGH CARD GAME:"
  2. PRINT "Pick a card and see if you have more fortune than AI"
  3. 6 CLS , 4
  4. PRINT "To play press Enter, another key to quit       Player "; scoreP%; " vs AI "; scoreA%
  5. IF (INPUT$(1) <> CHR$(13)) THEN END
  6. PLAYER(1) = (INT(RND * 12) + 1) + ((INT(RND * 4) + 1) * 100)
  7.     PLAYER(0) = (INT(RND * 12) + 1) + ((INT(RND * 4) + 1) * 100)
  8. LOOP UNTIL PLAYER(1) <> PLAYER(0)
  9. PRINT "Player card: "; RIGHT$(STR$(PLAYER(1)), 2) + MID$("", (PLAYER(1) \ 100), 1)
  10. PRINT "AI card: "; RIGHT$(STR$(PLAYER(0)), 2) + MID$("", (PLAYER(0) \ 100), 1)
  11. IF (PLAYER(1) - PLAYER(0) > 0) THEN PRINT "Player wins. AI looses"
  12. IF (PLAYER(1) - PLAYER(0) > 0) THEN scoreP% = scoreP% + 1
  13. IF (PLAYER(1) - PLAYER(0) < 0) THEN PRINT "Player looses. AI wins"
  14. IF (PLAYER(1) - PLAYER(0) < 0) THEN scoreA% = scoreA% + 1
  15.  

Thanks to try
Programming isn't difficult, only it's  consuming time and coffee