Author Topic: Deal or No Deal  (Read 6593 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Deal or No Deal
« on: January 14, 2020, 11:50:52 pm »
Here is good introduction from which I had the details needed to build the game:
(not secure) http://datagenetics.com/blog/january12015/index.html

And from watching the show, I added the random chance of having more than one Million Dollar case in the prize pool, if selected (80% chance) you can get up to 12!

This is bare bones text no fancy sounds or images of scantily clad female models ;(

Code: QB64: [Select]
  1. _TITLE "Deal or No Deal" 'b+ started 2020-01-13
  2.  
  3. CONST xmax = 800, ymax = 600, nCases = 26
  4. DIM SHARED offers(1 TO 10) AS STRING
  5. DIM SHARED caseSelected(1 TO nCases) AS INTEGER
  6. DIM SHARED moneySlot(1 TO 26) AS INTEGER
  7. DIM SHARED caseHolds(1 TO nCases) AS DOUBLE
  8. DIM SHARED moneyBoard(1 TO nCases) AS DOUBLE
  9. DIM SHARED PlayerCase AS INTEGER, round AS INTEGER
  10. SCREEN _NEWIMAGE(xmax, ymax, 32)
  11. _SCREENMOVE 300, 40
  12.  
  13. 'the game goes about 10 rounds
  14. FOR round = 0 TO 10
  15.     IF round = 0 THEN 'get things started and get the Player's case
  16.         IF RND < .8 THEN
  17.             LOCATE 15, 1
  18.             CP "Host: Congratulations! You have been randomly selected to play the slot"
  19.             CP "machine for more than just one Million Dollar Case in the prize pool."
  20.             CP "Press any key when the moment seems lucky..."
  21.             WHILE LEN(INKEY$) = 0
  22.                 n% = INT(RND * 11) + 2
  23.                 LOCATE 20, 1: CP RIGHT$("0" + TS$(n%), 2)
  24.                 _LIMIT 5
  25.             WEND
  26.             PRINT: CP "Aha! " + TS$(n%) + " Million Dollar cases!"
  27.             _DELAY 4
  28.         ELSE
  29.             n% = 1
  30.         END IF
  31.         init n%
  32.         showB
  33.         COLOR &HFFFFFFFF
  34.         PRINT: CP "Host: Please click your case from the 26 available..."
  35.         WHILE mx > 33 * 8 OR mx < 29 * 8 OR my < 16 * 2 OR my > 28 * 16
  36.             WHILE _MOUSEINPUT: WEND
  37.             md = _MOUSEBUTTON(1)
  38.             IF md THEN mx = _MOUSEX: my = _MOUSEY
  39.             _LIMIT 60
  40.         WEND
  41.         PlayerCase = my \ 16 - 1
  42.         caseSelected(PlayerCase) = 1
  43.         _DELAY 2
  44.     ELSEIF round = 10 THEN 'offer to swap your case with the case remaining
  45.         showB
  46.         COLOR &HFFFFFFFF
  47.         FOR lastCase% = 1 TO nCases 'find last case number
  48.             IF caseSelected(lastCase%) = 0 THEN EXIT FOR
  49.         NEXT
  50.         PRINT: CP "Host: Down to 2 cases, you have the option to switch cases at this time."
  51.         CP "Press s for switch, n for no switch..."
  52.         switch$ = getChar$("sn")
  53.         IF switch$ = "s" THEN
  54.             SWAP PlayerCase, lastCase%
  55.             SWAP caseSelected(lastCase%), caseSelected(PlayerCase)
  56.         END IF
  57.         showB
  58.         COLOR &HFFFFFFFF: PRINT
  59.         CP "Host: The last case holds " + money$(caseHolds(lastCase%))
  60.         CP "and your case has " + money$(caseHolds(PlayerCase)): _DELAY 5: CP "Goodbye!": _DELAY 5: SYSTEM
  61.     ELSE
  62.         FOR r = 1 TO nSelect(round) 'select these many cases open and update money board
  63.             showB
  64.             COLOR &HFFFFFFFF
  65.             PRINT: CP "Host: Now click a case, " + TS$(r) + " of " + TS$(nSelect(round)) + " cases for this round."
  66.  
  67.             tryAgain:
  68.             mx = 0: my = 0
  69.             WHILE mx > 33 * 8 OR mx < 29 * 8 OR my < 16 * 2 OR my > 28 * 16
  70.                 WHILE _MOUSEINPUT: WEND
  71.                 md = _MOUSEBUTTON(1)
  72.                 IF md THEN mx = _MOUSEX: my = _MOUSEY
  73.                 _LIMIT 60
  74.             WEND
  75.             caseN = my \ 16 - 1
  76.             IF caseN > 0 AND caseN <= nCases THEN
  77.                 IF caseSelected(caseN) = 0 THEN caseSelected(caseN) = 1 ELSE GOTO tryAgain
  78.             END IF
  79.             PRINT: CP "Case " + TS$(caseN) + " contained: " + money$(caseHolds(caseN))
  80.  
  81.             _DELAY 2
  82.             FOR c = 1 TO nCases 'update MoneyBoard
  83.                 IF moneyBoard(c) = caseHolds(caseN) AND moneySlot(c) = 0 THEN moneySlot(c) = 1: EXIT FOR
  84.             NEXT
  85.         NEXT
  86.         showB 'now banker makes an offer
  87.         COLOR &HFFFFFFFF
  88.         _AUTODISPLAY
  89.         PRINT: CP "'Ring' Host: Hello (silence) ..."
  90.         _DELAY 3
  91.         PRINT: CP "Host: The Banker has offered " + money$(INT(100 * expectedValue * offer(round)) / 100) + ",  Deal or No Deal?"
  92.         offers(round) = money$(INT(100 * expectedValue * offer(round)) / 100)
  93.         CP "Press d for deal, n for no deal "
  94.         deal$ = getChar$("dn")
  95.         IF deal$ = "d" THEN CP "Your case had " + money$(caseHolds(PlayerCase)) + " Goodbye!": _DELAY 10: SYSTEM
  96.     END IF
  97.  
  98. SUB showB
  99.     CLS
  100.     COLOR &HFF224488
  101.     CP "Blue Number is the Expected Value = the Average of the Sum of Prizes in Play."
  102.     'IF PlayerCase THEN LOCATE 1, 60: PRINT "Debug: "; money$(caseHolds(PlayerCase)) ELSE PRINT
  103.     COLOR &HFFFFFFFF
  104.     PRINT " Money Prizes Left:  Cases Left:";
  105.     IF PlayerCase THEN PRINT " Your Case is #"; TS$(PlayerCase);
  106.     IF round > 1 THEN PRINT "  Offers for your case:" ELSE PRINT
  107.     FOR i = 1 TO nCases
  108.         IF moneySlot(i) = 0 THEN COLOR &HFFFFFF00 ELSE COLOR &HFF333333
  109.         PRINT RIGHT$(SPACE$(19) + money$(moneyBoard(i)), 19);
  110.         IF caseSelected(i) = 0 THEN COLOR &HFFFF9900 ELSE COLOR &HFF333333
  111.         PRINT USING "#############"; i
  112.     NEXT
  113.     IF round > 1 THEN
  114.         COLOR &HFF00AA00
  115.         FOR i = 1 TO round - 1
  116.             LOCATE 2 + i, 73 - LEN(offers(i)): PRINT offers(i)
  117.         NEXT
  118.     END IF
  119.     ''check expectedValue
  120.     COLOR &HFF0000FF
  121.     LOCATE 2 + nCases + 1, 1: PRINT RIGHT$(SPACE$(19) + money$(expectedValue#), 19)
  122.  
  123. SUB init (nMillionDollarCases%)
  124.     'load moneyBoard and cases
  125.     startM% = nCases - nMillionDollarCases%
  126.     FOR i = 1 TO nCases
  127.         IF i <= startM% THEN
  128.             moneyBoard(i) = mB(i): caseHolds(i) = mB(i)
  129.         ELSE
  130.             moneyBoard(i) = 1000000.00#: caseHolds(i) = 1000000.00#
  131.         END IF
  132.     NEXT
  133.     'shuffle case contents
  134.     FOR i = nCases TO 2 STEP -1
  135.         SWAP caseHolds(INT(RND * i) + 1), caseHolds(i)
  136.     NEXT
  137.  
  138. FUNCTION mB# (n)
  139.     SELECT CASE n
  140.         CASE 1: mB# = .01
  141.         CASE 2: mB# = 1
  142.         CASE 3: mB# = 5
  143.         CASE 4: mB# = 10
  144.         CASE 5: mB# = 25
  145.         CASE 6: mB# = 50
  146.         CASE 7: mB# = 75
  147.         CASE 8: mB# = 100
  148.         CASE 9: mB# = 200
  149.         CASE 10: mB# = 300
  150.         CASE 11: mB# = 400
  151.         CASE 12: mB# = 500
  152.         CASE 13: mB# = 750
  153.         CASE 14: mB# = 1000
  154.         CASE 15: mB# = 5000
  155.         CASE 16: mB# = 10000
  156.         CASE 17: mB# = 25000
  157.         CASE 18: mB# = 50000
  158.         CASE 19: mB# = 75000
  159.         CASE 20: mB# = 100000
  160.         CASE 21: mB# = 200000
  161.         CASE 22: mB# = 300000
  162.         CASE 23: mB# = 400000
  163.         CASE 24: mB# = 500000
  164.         CASE 25: mB# = 750000
  165.         CASE 26: mB# = 1000000
  166.     END SELECT
  167.  
  168. FUNCTION offer (round)
  169.     SELECT CASE round
  170.         CASE 1: offer = .15
  171.         CASE 2: offer = .24
  172.         CASE 3: offer = .34
  173.         CASE 4: offer = .43
  174.         CASE 5: offer = .52
  175.         CASE 6: offer = .62
  176.         CASE 7: offer = .72
  177.         CASE 8: offer = .81
  178.         CASE 9: offer = .9
  179.         CASE 10: offer = .95
  180.     END SELECT
  181.  
  182. FUNCTION nSelect (round)
  183.     SELECT CASE round
  184.         CASE 1: nSelect = 6
  185.         CASE 2: nSelect = 5
  186.         CASE 3: nSelect = 4
  187.         CASE 4: nSelect = 3
  188.         CASE 5: nSelect = 2
  189.         CASE 6: nSelect = 1
  190.         CASE 7: nSelect = 1
  191.         CASE 8: nSelect = 1
  192.         CASE 9: nSelect = 1
  193.         CASE 10: nSelect = 1
  194.     END SELECT
  195.  
  196. FUNCTION expectedValue#
  197.     FOR i = 1 TO 26
  198.         IF moneySlot(i) = 0 THEN
  199.             n = n + 1
  200.             tot## = tot## + moneyBoard(i)
  201.         END IF
  202.     NEXT
  203.     expectedValue# = _ROUND(100 * tot## / n) / 100
  204.  
  205. FUNCTION TS$ (n) 'single for small single or integer
  206.     TS$ = _TRIM$(STR$(n))
  207.  
  208. SUB CP (s$) 'for xmax pixel wide graphics screen
  209.     LOCATE CSRLIN, (xmax / 8 - LEN(s$)) / 2: PRINT s$
  210.  
  211. 'this might make a nice Money format yeah! added to toolbox
  212. FUNCTION money$ (n#) 'only works right for double# type
  213.     DIM place AS INTEGER, s$, front$, back$
  214.     money$ = _TRIM$(STR$(n#))
  215.     IF LEFT$(money$, 1) = "-" THEN s$ = "-": money$ = MID$(money$, 2) ELSE s$ = ""
  216.     place = INSTR(money$, ".")
  217.     IF place = 0 THEN place = LEN(money$) + 1
  218.     WHILE place > 4
  219.         money$ = MID$(money$, 1, place - 4) + "," + MID$(money$, place - 3)
  220.         place = INSTR(money$, ",")
  221.     WEND
  222.  
  223.     'fix this for 2 places after decimal
  224.     place = INSTR(money$, ".")
  225.     IF place THEN
  226.         front$ = MID$(money$, 1, place)
  227.         back$ = MID$(money$, place + 1)
  228.         IF LEN(back$) > 2 THEN money$ = front$ + LEFT$(back$, 2)
  229.         IF LEN(back$) < 2 THEN money$ = front$ + LEFT$(back$ + "00", 2)
  230.     ELSE
  231.         money$ = money$ + ".00"
  232.     END IF
  233.     money$ = "$" + s$ + money$
  234.  
  235. FUNCTION getChar$ (fromStr$)
  236.     DIM OK AS INTEGER, k$
  237.     WHILE OK = 0
  238.         k$ = INKEY$
  239.         IF LEN(k$) THEN
  240.             IF INSTR(fromStr$, k$) <> 0 THEN OK = -1
  241.         END IF
  242.         _LIMIT 200
  243.     WEND
  244.     _KEYCLEAR
  245.     getChar$ = k$
  246.  
  247.  

EDIT: update wording of a line.
« Last Edit: January 15, 2020, 12:01:14 am by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Deal or No Deal
« Reply #1 on: January 15, 2020, 01:12:02 am »
Nice to know you finally figured out how to use: SELECT CASE

Pete :D
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: Deal or No Deal
« Reply #2 on: January 15, 2020, 01:43:18 am »
Quote
This is bare bones text no fancy sounds or images of scantily clad female models

After this disappointing caveat, I just couldn’t bring myself to try it.  /cry!

No “scantily clad female models”?  No deal!
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: Deal or No Deal
« Reply #3 on: January 15, 2020, 02:24:26 am »
Yeah, common Mark...

DIM SHARED G AS STRING
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: Deal or No Deal
« Reply #4 on: January 15, 2020, 06:59:46 am »
Sharing a g string is un-hygenic...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Deal or No Deal
« Reply #5 on: January 15, 2020, 11:37:25 am »
OK dumped SELECT CASE now just select figures :D
Code: QB64: [Select]
  1. _TITLE "Deal or No Deal v Split " 'b+ mod 2020-01-15
  2.  
  3. CONST xmax = 800, ymax = 600, nCases = 26
  4. 'load data in init
  5. REDIM SHARED offer(1 TO 1) AS DOUBLE
  6. REDIM SHARED moneyBoard(1 TO 1) AS DOUBLE
  7. DIM SHARED caseHolds(1 TO nCases) AS DOUBLE
  8. 'track during game
  9. DIM SHARED moneySlot(1 TO nCases) AS INTEGER
  10. DIM SHARED caseSelected(1 TO nCases) AS INTEGER
  11. DIM SHARED offers(1 TO 10) AS STRING
  12.  
  13. DIM SHARED PlayerCase AS INTEGER, round AS INTEGER
  14. SCREEN _NEWIMAGE(xmax, ymax, 32)
  15. _SCREENMOVE 300, 40
  16.  
  17. 'the game goes about 10 rounds
  18. FOR round = 0 TO 10
  19.     IF round = 0 THEN 'get things started and get the Player's case
  20.         IF RND < .8 THEN
  21.             LOCATE 15, 1
  22.             CP "Host: Congratulations! You have been randomly selected to play the slot"
  23.             CP "machine for more than just one Million Dollar Case in the prize pool."
  24.             CP "Press any key when the moment seems lucky..."
  25.             WHILE LEN(INKEY$) = 0
  26.                 n% = INT(RND * 11) + 2
  27.                 LOCATE 20, 1: CP RIGHT$("0" + TS$(n%), 2)
  28.                 _LIMIT 5
  29.             WEND
  30.             PRINT: CP "Aha! " + TS$(n%) + " Million Dollar cases!"
  31.             _DELAY 4
  32.         ELSE
  33.             n% = 1
  34.         END IF
  35.         init n%
  36.         showB
  37.         COLOR &HFFFFFFFF
  38.         PRINT: CP "Host: Please click your case from the 26 available..."
  39.         WHILE mx > 33 * 8 OR mx < 29 * 8 OR my < 16 * 2 OR my > 28 * 16
  40.             WHILE _MOUSEINPUT: WEND
  41.             md = _MOUSEBUTTON(1)
  42.             IF md THEN mx = _MOUSEX: my = _MOUSEY
  43.             _LIMIT 60
  44.         WEND
  45.         PlayerCase = my \ 16 - 1
  46.         caseSelected(PlayerCase) = 1
  47.         _DELAY 2
  48.     ELSEIF round = 10 THEN 'offer to swap your case with the case remaining
  49.         showB
  50.         COLOR &HFFFFFFFF
  51.         FOR lastCase% = 1 TO nCases 'find last case number
  52.             IF caseSelected(lastCase%) = 0 THEN EXIT FOR
  53.         NEXT
  54.         PRINT: CP "Host: Down to 2 cases, you have the option to switch cases at this time."
  55.         CP "Press s for switch, n for no switch..."
  56.         switch$ = getChar$("sn")
  57.         IF switch$ = "s" THEN
  58.             SWAP PlayerCase, lastCase%
  59.             SWAP caseSelected(lastCase%), caseSelected(PlayerCase)
  60.         END IF
  61.         showB
  62.         COLOR &HFFFFFFFF: PRINT
  63.         CP "Host: The last case holds " + money$(caseHolds(lastCase%))
  64.         CP "and your case has " + money$(caseHolds(PlayerCase)): _DELAY 5: CP "Goodbye!": _DELAY 5: SYSTEM
  65.     ELSE
  66.         nSelect% = 7 - round
  67.         IF nSelect% < 1 THEN nSelect% = 1
  68.         FOR r = 1 TO nSelect% 'select these many cases open and update money board
  69.             showB
  70.             COLOR &HFFFFFFFF
  71.             PRINT: CP "Host: Now click a case, " + TS$(r) + " of " + TS$(nSelect%) + " cases for this round."
  72.  
  73.             tryAgain:
  74.             mx = 0: my = 0
  75.             WHILE mx > 33 * 8 OR mx < 29 * 8 OR my < 16 * 2 OR my > 28 * 16
  76.                 WHILE _MOUSEINPUT: WEND
  77.                 md = _MOUSEBUTTON(1)
  78.                 IF md THEN mx = _MOUSEX: my = _MOUSEY
  79.                 _LIMIT 60
  80.             WEND
  81.             caseN = my \ 16 - 1
  82.             IF caseN > 0 AND caseN <= nCases THEN
  83.                 IF caseSelected(caseN) = 0 THEN caseSelected(caseN) = 1 ELSE GOTO tryAgain
  84.             END IF
  85.             PRINT: CP "Case " + TS$(caseN) + " contained: " + money$(caseHolds(caseN))
  86.  
  87.             _DELAY 2
  88.             FOR c = 1 TO nCases 'update MoneyBoard
  89.                 IF moneyBoard(c) = caseHolds(caseN) AND moneySlot(c) = 0 THEN moneySlot(c) = 1: EXIT FOR
  90.             NEXT
  91.         NEXT
  92.         showB 'now banker makes an offer
  93.         COLOR &HFFFFFFFF
  94.         _AUTODISPLAY
  95.         PRINT: CP "'Ring' Host: Hello (silence) ..."
  96.         _DELAY 3
  97.         PRINT: CP "Host: The Banker has offered " + money$(INT(100 * expectedValue * offer(round)) / 100) + ",  Deal or No Deal?"
  98.         offers(round) = money$(INT(100 * expectedValue * offer(round)) / 100)
  99.         CP "Press d for deal, n for no deal "
  100.         deal$ = getChar$("dn")
  101.         IF deal$ = "d" THEN CP "Your case had " + money$(caseHolds(PlayerCase)) + " Goodbye!": _DELAY 10: SYSTEM
  102.     END IF
  103.  
  104. SUB showB
  105.     CLS
  106.     COLOR &HFF224488
  107.     CP "Blue Number is the Expected Value = the Average of the Sum of Prizes in Play."
  108.     'IF PlayerCase THEN LOCATE 1, 60: PRINT "Debug: "; money$(caseHolds(PlayerCase)) ELSE PRINT
  109.     COLOR &HFFFFFFFF
  110.     PRINT " Money Prizes Left:  Cases Left:";
  111.     IF PlayerCase THEN PRINT " Your Case is #"; TS$(PlayerCase);
  112.     IF round > 1 THEN PRINT "  Offers for your case:" ELSE PRINT
  113.     FOR i = 1 TO nCases
  114.         IF moneySlot(i) = 0 THEN COLOR &HFFFFFF00 ELSE COLOR &HFF333333
  115.         PRINT RIGHT$(SPACE$(19) + money$(moneyBoard(i)), 19);
  116.         IF caseSelected(i) = 0 THEN COLOR &HFFFF9900 ELSE COLOR &HFF333333
  117.         PRINT USING "#############"; i
  118.     NEXT
  119.     IF round > 1 THEN
  120.         COLOR &HFF00AA00
  121.         FOR i = 1 TO round - 1
  122.             LOCATE 2 + i, 73 - LEN(offers(i)): PRINT offers(i)
  123.         NEXT
  124.     END IF
  125.     ''check expectedValue
  126.     COLOR &HFF0000FF
  127.     LOCATE 2 + nCases + 1, 1: PRINT RIGHT$(SPACE$(19) + money$(expectedValue#), 19)
  128.  
  129. SUB init (nMillionDollarCases%)
  130.     offerDat$ = ".15,.24,.34,.43,.52,.62,.72,.82,.90,.95"
  131.     Split offerDat$, ",", offer()
  132.     mbDat$ = ".01,1,5,10,25,50,75,100,200,300,400,500,750,1000,5000,10000,25000,50000,75000,100000,200000,300000,400000,500000,750000,1000000"
  133.     Split mbDat$, ",", moneyBoard()
  134.     'load moneyBoard and cases
  135.     startM% = nCases - nMillionDollarCases%
  136.     FOR i = 1 TO nCases
  137.         IF i <= startM% THEN
  138.             caseHolds(i) = moneyBoard(i)
  139.         ELSE
  140.             moneyBoard(i) = 1000000.00#: caseHolds(i) = 1000000.00#
  141.         END IF
  142.     NEXT
  143.     'shuffle case contents
  144.     FOR i = nCases TO 2 STEP -1
  145.         SWAP caseHolds(INT(RND * i) + 1), caseHolds(i)
  146.     NEXT
  147.  
  148. FUNCTION expectedValue#
  149.     FOR i = 1 TO 26
  150.         IF moneySlot(i) = 0 THEN
  151.             n = n + 1
  152.             tot## = tot## + moneyBoard(i)
  153.         END IF
  154.     NEXT
  155.     expectedValue# = _ROUND(100 * tot## / n) / 100
  156.  
  157. 'modified type from String to Double  for this app
  158. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS DOUBLE)
  159.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  160.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  161.     dpos = INSTR(curpos, SplitMeString, delim)
  162.     DO UNTIL dpos = 0
  163.         loadMeArray(arrpos) = VAL(MID$(SplitMeString, curpos, dpos - curpos))
  164.         arrpos = arrpos + 1
  165.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS DOUBLE
  166.         curpos = dpos + LD
  167.         dpos = INSTR(curpos, SplitMeString, delim)
  168.     LOOP
  169.     loadMeArray(arrpos) = VAL(MID$(SplitMeString, curpos))
  170.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS DOUBLE 'get the ubound correct
  171.  
  172. FUNCTION TS$ (n) 'single for small single or integer
  173.     TS$ = _TRIM$(STR$(n))
  174.  
  175. SUB CP (s$) 'for xmax pixel wide graphics screen
  176.     LOCATE CSRLIN, (xmax / 8 - LEN(s$)) / 2: PRINT s$
  177.  
  178. 'this might make a nice Money format yeah! added to toolbox
  179. FUNCTION money$ (n#) 'only works right for double# type
  180.     DIM place AS INTEGER, s$, front$, back$
  181.     money$ = _TRIM$(STR$(n#))
  182.     IF LEFT$(money$, 1) = "-" THEN s$ = "-": money$ = MID$(money$, 2) ELSE s$ = ""
  183.     place = INSTR(money$, ".")
  184.     IF place = 0 THEN place = LEN(money$) + 1
  185.     WHILE place > 4
  186.         money$ = MID$(money$, 1, place - 4) + "," + MID$(money$, place - 3)
  187.         place = INSTR(money$, ",")
  188.     WEND
  189.  
  190.     'fix this for 2 places after decimal
  191.     place = INSTR(money$, ".")
  192.     IF place THEN
  193.         front$ = MID$(money$, 1, place)
  194.         back$ = MID$(money$, place + 1)
  195.         IF LEN(back$) > 2 THEN money$ = front$ + LEFT$(back$, 2)
  196.         IF LEN(back$) < 2 THEN money$ = front$ + LEFT$(back$ + "00", 2)
  197.     ELSE
  198.         money$ = money$ + ".00"
  199.     END IF
  200.     money$ = "$" + s$ + money$
  201.  
  202. FUNCTION getChar$ (fromStr$)
  203.     DIM OK AS INTEGER, k$
  204.     WHILE OK = 0
  205.         k$ = INKEY$
  206.         IF LEN(k$) THEN
  207.             IF INSTR(fromStr$, k$) <> 0 THEN OK = -1
  208.         END IF
  209.         _LIMIT 200
  210.     WEND
  211.     _KEYCLEAR
  212.     getChar$ = k$
  213.  
  214.  

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Deal or No Deal
« Reply #6 on: January 18, 2020, 02:12:09 pm »
LOL that was fun to play! I suggest adding a better ending though than just a quick "Goodbye!" But it was cool!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Deal or No Deal
« Reply #7 on: January 18, 2020, 02:56:24 pm »
Hi Ken,

Thanks, I am / was in process of adding Top Ten scores from Tool Box routine which also asks if you want to play again. In fact that is already done, but I want to update Top Ten to like Top 100 or something, make screen a little nicer, add date time stamps to name and score since being the only player, date and time more of interest than name.

I confess, Deal No Deal never really appealed to me, 26 beautiful models, so what? ;-))
Well OK there's that, but I can't really duplicate that in a game. But when I started watching it at lunch time because it way more pleasant than news, well I started asking questions about probability and wanted to test some ideas, if there were a better strategy like the Monty Hall 3 doors question that does have a real mathematical strategy. eg if you make all the way to 2 cases left yours and the one still unrevealed, should you swap? I suspect unlike Money Hall question it makes much less difference (but still not sure, it might be worked out with Bayes).

Anyway, Yes, thanks if you play one round and it leaves you wanting more, it is a good sign that you have the game right. Compare bare bones game to TV and fact you have only one shot to get it right in real game, you get an appreciation of art of entertainment eg after all the big cases are gone, is it game over or do you still play to get best deal?

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Deal or No Deal
« Reply #8 on: January 18, 2020, 03:37:16 pm »
Hang  on! There could have been "26 beautiful models"? Wow! That could have made my resounding defeat a little easier to cope with.... lol

I can remember only watching that show maybe twice... Probably why I found it difficult to play your version. The game. in and of itself is not difficult, just my understanding of how it is supposed to be played... The models would have probably distracted me even more.... lol

Nicely done!

J
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Deal or No Deal
« Reply #9 on: January 18, 2020, 04:22:10 pm »
Hey Johnno,

How is your new year going? Are you anywhere near the fires?

Quote
Probably why I found it difficult to play your version.
Ha! that's always the thing for the author of a game, he knows how it's supposed to go but has no idea how others will get stuck by some neglected to mention detail... oh well this started out as a model of game and then I was going to let all the picking be done randomly so I could run hundreds of sims to get some stats... still might do that but at moment I've been distracted by non programming subjects.

I was thinking maybe you'd like to put some assets together to jazz up the game but don't want you to get in trouble with your wife, so I won't ask. :D


Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Deal or No Deal
« Reply #10 on: January 18, 2020, 05:16:26 pm »
Assets? This looks like a job for a Screen Zero Hero...

A couple of ascii-sets for you: (_|_) (_|_)     (_|_) (_|_) 



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

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Deal or No Deal
« Reply #11 on: January 18, 2020, 09:47:26 pm »
Bplus,

Our year is going along just fine and no, we are not anywhere near the fires. About 250-300 kms to the east but we have been affected by the smoke to varying degrees. Thankfully we have had some good soaking rains and have eased the fires a little but our summer is far from over....

As for assets... I would have to watch the show again to get some ideas... But, from what I can remember from the old Australian version, a bunch of people holding briefcases does not fire up the imagination... Perhaps after watching?
Logic is the beginning of wisdom.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Deal or No Deal
« Reply #12 on: January 18, 2020, 09:51:04 pm »
Perhaps after watching... the Internet has a wide range of images, looks like different countries have different versions.

Don't think Pete's version of Moon River will do :D

Perhaps it is useful to know the Banker is stingy, always shown as shadow and is played up as the wise cracking,  wait... Pete?

Here I am down to 2 cases both contain $1 Million, what does the Banker offer for my case?

Stingy Banker.PNG
* Stingy Banker.PNG (Filesize: 19.77 KB, Dimensions: 803x627, Views: 213)
« Last Edit: January 18, 2020, 10:16:52 pm by bplus »

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Deal or No Deal
« Reply #13 on: January 18, 2020, 10:19:53 pm »
Ida only offeared ya five hundy thousand fur it.

 - 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: Deal or No Deal
« Reply #14 on: January 18, 2020, 10:20:10 pm »
Here is updated version with Top 20 scores with date automatically added onto the name:
Code: QB64: [Select]
  1. _TITLE "Deal or No Deal Top 20" 'b+ mod 2020-01-15   add Top 20 Scores tracker
  2.  
  3. CONST xmax = 800, ymax = 600, nCases = 26
  4. 'load data in init
  5. REDIM SHARED offer(1 TO 1) AS DOUBLE
  6. REDIM SHARED moneyBoard(1 TO 1) AS DOUBLE
  7. DIM SHARED caseHolds(1 TO nCases) AS DOUBLE
  8. 'track during game
  9. DIM SHARED moneySlot(1 TO nCases) AS INTEGER
  10. DIM SHARED caseSelected(1 TO nCases) AS INTEGER
  11. DIM SHARED offers(1 TO 10) AS STRING
  12.  
  13. DIM SHARED PlayerCase AS INTEGER, round AS INTEGER
  14. SCREEN _NEWIMAGE(xmax, ymax, 32)
  15. _SCREENMOVE 300, 40
  16.  
  17. restart: ' the endings are inside this main do loop
  18. FOR round = 0 TO 10 'the game goes for 10 rounds unless player sells case to banker
  19.     IF round = 0 THEN 'get things started and get the Player's case
  20.         IF RND < .8 THEN
  21.             CLS
  22.             LOCATE 15, 1
  23.             CP "Host: Congratulations! You have been randomly selected to play the slot"
  24.             CP "machine for more than just one Million Dollar Case in the prize pool."
  25.             CP "Press any key when the moment seems lucky..."
  26.             WHILE LEN(INKEY$) = 0
  27.                 n% = INT(RND * 11) + 2
  28.                 LOCATE 20, 1: CP RIGHT$("0" + TS$(n%), 2)
  29.                 _LIMIT 5
  30.             WEND
  31.             PRINT: CP "Aha! " + TS$(n%) + " Million Dollar cases!"
  32.             _DELAY 4
  33.         ELSE
  34.             n% = 1
  35.         END IF
  36.         init n%
  37.         showB
  38.         COLOR &HFFFFFFFF
  39.         PRINT: CP "Host: Please click your case from the 26 available..."
  40.         mx = 0: my = 0
  41.         WHILE mx > 33 * 8 OR mx < 29 * 8 OR my < 16 * 2 OR my > 28 * 16
  42.             WHILE _MOUSEINPUT: WEND
  43.             md = _MOUSEBUTTON(1)
  44.             IF md THEN mx = _MOUSEX: my = _MOUSEY
  45.             _LIMIT 60
  46.         WEND
  47.         PlayerCase = my \ 16 - 1
  48.         caseSelected(PlayerCase) = 1
  49.         _DELAY 2
  50.     ELSEIF round = 10 THEN 'offer to swap your case with the case remaining
  51.         showB
  52.         COLOR &HFFFFFFFF
  53.         FOR lastCase% = 1 TO nCases 'find last case number
  54.             IF caseSelected(lastCase%) = 0 THEN EXIT FOR
  55.         NEXT
  56.         PRINT: CP "Host: Down to 2 cases, you have the option to switch cases at this time."
  57.         CP "Press s for switch, n for no switch..."
  58.         switch$ = getChar$("sn")
  59.         IF switch$ = "s" THEN
  60.             SWAP PlayerCase, lastCase%
  61.             SWAP caseSelected(lastCase%), caseSelected(PlayerCase)
  62.         END IF
  63.         showB
  64.         COLOR &HFFFFFFFF: PRINT
  65.         CP "Host: The last case holds " + money$(caseHolds(lastCase%))
  66.         CP "and your case has " + money$(caseHolds(PlayerCase)): _DELAY 5
  67.         goAgain$ = topTenGoAgain$(INT(caseHolds(PlayerCase)))
  68.         IF LEN(goAgain$) THEN SYSTEM ELSE GOTO restart
  69.     ELSE
  70.         nSelect% = 7 - round
  71.         IF nSelect% < 1 THEN nSelect% = 1
  72.         FOR r = 1 TO nSelect% 'select these many cases open and update money board
  73.             showB
  74.             COLOR &HFFFFFFFF
  75.             PRINT: CP "Host: Now click a case, " + TS$(r) + " of " + TS$(nSelect%) + " cases for this round."
  76.  
  77.             tryAgain:
  78.             mx = 0: my = 0
  79.             WHILE mx > 33 * 8 OR mx < 29 * 8 OR my < 16 * 2 OR my > 28 * 16
  80.                 WHILE _MOUSEINPUT: WEND
  81.                 md = _MOUSEBUTTON(1)
  82.                 IF md THEN mx = _MOUSEX: my = _MOUSEY
  83.                 _LIMIT 60
  84.             WEND
  85.             caseN = my \ 16 - 1
  86.             IF caseN > 0 AND caseN <= nCases THEN
  87.                 IF caseSelected(caseN) = 0 THEN caseSelected(caseN) = 1 ELSE GOTO tryAgain
  88.             END IF
  89.             PRINT: CP "Case " + TS$(caseN) + " contained: " + money$(caseHolds(caseN))
  90.             _DELAY 2
  91.             FOR c = 1 TO nCases 'update MoneyBoard
  92.                 IF moneyBoard(c) = caseHolds(caseN) AND moneySlot(c) = 0 THEN moneySlot(c) = 1: EXIT FOR
  93.             NEXT
  94.         NEXT
  95.         showB 'now banker makes an offer
  96.         COLOR &HFFFFFFFF
  97.         _AUTODISPLAY
  98.         PRINT: CP "'Ring' Host: Hello (silence) ..."
  99.         _DELAY 3
  100.         bankerOffer# = INT(100 * expectedValue * offer(round)) / 100
  101.         PRINT: CP "Host: The Banker has offered " + money$(bankerOffer#) + ",  Deal or No Deal?"
  102.         offers(round) = money$(bankerOffer#)
  103.         CP "Press d for deal, n for no deal "
  104.         deal$ = getChar$("dn")
  105.         IF deal$ = "d" THEN
  106.             CP "Your case had " + money$(caseHolds(PlayerCase))
  107.             _DELAY 5
  108.             goAgain$ = topTenGoAgain$(INT(bankerOffer#))
  109.             IF LEN(goAgain$) THEN SYSTEM ELSE GOTO restart
  110.         END IF
  111.     END IF
  112.  
  113. SUB showB
  114.     CLS
  115.     COLOR &HFF224488
  116.     CP "Blue Number is the Expected Value = the Average of the Sum of Prizes in Play."
  117.     'IF PlayerCase THEN LOCATE 1, 60: PRINT "Debug: "; money$(caseHolds(PlayerCase)) ELSE PRINT
  118.     COLOR &HFFFFFFFF
  119.     PRINT " Money Prizes Left:  Cases Left:";
  120.     IF PlayerCase THEN PRINT " Your Case is #"; TS$(PlayerCase);
  121.     IF round > 1 THEN PRINT "  Offers for your case:" ELSE PRINT
  122.     FOR i = 1 TO nCases
  123.         IF moneySlot(i) = 0 THEN COLOR &HFFFFFF00 ELSE COLOR &HFF333333
  124.         PRINT RIGHT$(SPACE$(19) + money$(moneyBoard(i)), 19);
  125.         IF caseSelected(i) = 0 THEN COLOR &HFFFF9900 ELSE COLOR &HFF333333
  126.         PRINT USING "#############"; i
  127.     NEXT
  128.     IF round > 1 THEN
  129.         COLOR &HFF00AA00
  130.         FOR i = 1 TO round - 1
  131.             LOCATE 2 + i, 73 - LEN(offers(i)): PRINT offers(i)
  132.         NEXT
  133.     END IF
  134.     ''check expectedValue
  135.     COLOR &HFF0000FF
  136.     LOCATE 2 + nCases + 1, 1: PRINT RIGHT$(SPACE$(19) + money$(expectedValue#), 19)
  137.  
  138. SUB init (nMillionDollarCases%)
  139.     IF UBOUND(offer) < 2 THEN 'not been here before
  140.         offerDat$ = ".15,.24,.34,.43,.52,.62,.72,.82,.90,.95"
  141.         Split offerDat$, ",", offer()
  142.     END IF
  143.     'load moneyBoard
  144.     mbDat$ = ".01,1,5,10,25,50,75,100,200,300,400,500,750,1000,5000,10000,25000,50000,75000,100000,200000,300000,400000,500000,750000,1000000"
  145.     Split mbDat$, ",", moneyBoard()
  146.     'load moneyBoard with extra million dollar cases and load and shuffle cases
  147.     startM% = nCases - nMillionDollarCases%
  148.     FOR i = 1 TO nCases
  149.         'clear other arrays
  150.         IF i <= 10 THEN offers(i) = ""
  151.         caseSelected(i) = 0
  152.         moneySlot(i) = 0
  153.         IF i <= startM% THEN
  154.             caseHolds(i) = moneyBoard(i)
  155.         ELSE
  156.             moneyBoard(i) = 1000000.00#: caseHolds(i) = 1000000.00#
  157.         END IF
  158.     NEXT
  159.     'shuffle case contents
  160.     FOR i = nCases TO 2 STEP -1
  161.         SWAP caseHolds(INT(RND * i) + 1), caseHolds(i)
  162.     NEXT
  163.  
  164. FUNCTION expectedValue#
  165.     FOR i = 1 TO 26
  166.         IF moneySlot(i) = 0 THEN
  167.             n = n + 1
  168.             tot## = tot## + moneyBoard(i)
  169.         END IF
  170.     NEXT
  171.     expectedValue# = _ROUND(100 * tot## / n) / 100
  172.  
  173. ' From my Tool Box  https://www.qb64.org/forum/index.php?topic=1511.m
  174. ' This FUNCTION creates a file in the same folder as your .bas source or .exe
  175. 'EDIT: 2019-07-29 change to FUNCTION to combine Top Ten update functions with Go Again reply.
  176. ' modified for this for Deal or No Deal and uses CP sub
  177. FUNCTION topTenGoAgain$ (compareScore AS LONG) '<<<<  modified compareScore from Integer to Long
  178.     DIM fName$, n AS INTEGER, names$(1 TO 20), NAME$, i AS INTEGER, dt$, n$
  179.     DIM settleScore AS LONG, scores(1 TO 20) AS LONG, score AS LONG '<<<<  modified to LONG
  180.     fName$ = "Top 20 Scores.txt" '<<<  since this is toolbox code change this as needed for app
  181.     dt$ = " " + MID$(DATE$, 7) + "-" + LEFT$(DATE$, 5) + "_" + MID$(TIME$, 1, 5)
  182.     CLS: PRINT: CP "Your score was: " + TS$(compareScore): PRINT: CP "Top 20 Scorers and Scores:"
  183.     IF _FILEEXISTS(fName$) THEN
  184.         OPEN fName$ FOR INPUT AS #1
  185.         WHILE EOF(1) = 0 AND n < 20
  186.             n = n + 1
  187.             INPUT #1, NAME$
  188.             INPUT #1, score
  189.             IF compareScore >= score AND settleScore = 0 THEN
  190.                 CP "You have made the Top 20!"
  191.                 CP "Type your name: "
  192.                 LOCATE CSRLIN, (xmax / 8 - 8) / 2
  193.                 INPUT "", n$
  194.                 names$(n) = n$ + dt$
  195.                 scores(n) = compareScore
  196.                 settleScore = -1
  197.                 n = n + 1
  198.                 IF n <= 20 THEN names$(n) = NAME$: scores(n) = score
  199.             ELSE
  200.                 scores(n) = score: names$(n) = NAME$
  201.             END IF
  202.         WEND
  203.         CLOSE #1
  204.         IF n < 20 AND settleScore = 0 THEN
  205.             CP "There is a slot open for your name and score."
  206.             CP "Type your name:"
  207.             LOCATE CSRLIN, (_WIDTH / 8 - 8) / 2
  208.             INPUT " "; n$
  209.             IF n$ <> "" THEN n = n + 1: names$(n) = n$ + dt$: scores(n) = compareScore
  210.         END IF
  211.         OPEN fName$ FOR OUTPUT AS #1
  212.         IF n > 20 THEN n = 20
  213.         PRINT
  214.         FOR i = 1 TO n
  215.             PRINT #1, names$(i): PRINT #1, scores(i)
  216.             LOCATE CSRLIN, 20: PRINT RIGHT$("  " + TS$(i), 2) + RIGHT$(SPACE$(8) + TS$(scores(i)), 8) + ", " + names$(i)
  217.         NEXT
  218.         CLOSE #1
  219.     ELSE
  220.         CP "You are first into file of top scores!"
  221.         CP "Type your name"
  222.         LOCATE CSRLIN, (_WIDTH / 8 - 8) / 2
  223.         INPUT " "; n$
  224.         OPEN fName$ FOR OUTPUT AS #1
  225.         PRINT #1, n$ + dt$: PRINT #1, compareScore
  226.         CLOSE #1
  227.     END IF
  228.     PRINT: CP "Press <Enter> to play again, <q (or any) + Enter> to quit... "
  229.     LOCATE CSRLIN, (_WIDTH / 8 - 8) / 2
  230.     INPUT " "; topTenGoAgain$
  231.  
  232. 'modified type from String to Double  for this app
  233. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS DOUBLE)
  234.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  235.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  236.     dpos = INSTR(curpos, SplitMeString, delim)
  237.     DO UNTIL dpos = 0
  238.         loadMeArray(arrpos) = VAL(MID$(SplitMeString, curpos, dpos - curpos))
  239.         arrpos = arrpos + 1
  240.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS DOUBLE
  241.         curpos = dpos + LD
  242.         dpos = INSTR(curpos, SplitMeString, delim)
  243.     LOOP
  244.     loadMeArray(arrpos) = VAL(MID$(SplitMeString, curpos))
  245.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS DOUBLE 'get the ubound correct
  246.  
  247. FUNCTION TS$ (n) 'single for small single or integer
  248.     TS$ = _TRIM$(STR$(n))
  249.  
  250. SUB CP (s$) 'for xmax pixel wide graphics screen
  251.     LOCATE CSRLIN, (_WIDTH / 8 - LEN(s$)) / 2: PRINT s$
  252.  
  253. 'this might make a nice Money format yeah! added to toolbox
  254. FUNCTION money$ (n#) 'only works right for double# type
  255.     DIM place AS INTEGER, s$, front$, back$
  256.     money$ = _TRIM$(STR$(n#))
  257.     IF LEFT$(money$, 1) = "-" THEN s$ = "-": money$ = MID$(money$, 2) ELSE s$ = ""
  258.     place = INSTR(money$, ".")
  259.     IF place = 0 THEN place = LEN(money$) + 1
  260.     WHILE place > 4
  261.         money$ = MID$(money$, 1, place - 4) + "," + MID$(money$, place - 3)
  262.         place = INSTR(money$, ",")
  263.     WEND
  264.  
  265.     'fix this for 2 places after decimal
  266.     place = INSTR(money$, ".")
  267.     IF place THEN
  268.         front$ = MID$(money$, 1, place)
  269.         back$ = MID$(money$, place + 1)
  270.         IF LEN(back$) > 2 THEN money$ = front$ + LEFT$(back$, 2)
  271.         IF LEN(back$) < 2 THEN money$ = front$ + LEFT$(back$ + "00", 2)
  272.     ELSE
  273.         money$ = money$ + ".00"
  274.     END IF
  275.     money$ = "$" + s$ + money$
  276.  
  277. FUNCTION getChar$ (fromStr$)
  278.     DIM OK AS INTEGER, k$
  279.     WHILE OK = 0
  280.         k$ = INKEY$
  281.         IF LEN(k$) THEN
  282.             IF INSTR(fromStr$, k$) <> 0 THEN OK = -1
  283.         END IF
  284.         _LIMIT 200
  285.     WEND
  286.     _KEYCLEAR
  287.     getChar$ = k$
  288.  
  289.  

Next up to strip down the version to get some stats.