QB64.org Forum

Active Forums => Programs => Topic started by: xra7en on November 08, 2021, 06:02:57 pm

Title: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: xra7en on November 08, 2021, 06:02:57 pm
Got rid of some of the spaghetti code..
Mod it, enjoy it. have fun. Im working on a fantasy game that has an inn/bar I might include this as part of the games available there
the utils is for the pause,
you might have to make a inkey$ or look on the forum somewhere, I think my uttils.bi is here. if not I'll post it

original code
https://www.atariarchives.org/basicgames/showpage.php?page=34

Code: QB64: [Select]
  1.  
  2.  
  3. Type tPlayer
  4.     score As Long
  5.  
  6.  
  7.  
  8. Dim As Integer i, j, k ' loop vars
  9.  
  10. Dim score As Integer
  11. Dim Shared calcThrow As Double
  12. Dim Shared oppScore As Integer
  13. Dim Shared throw(3, 5) As Double '      3 types of throws 5 results
  14. Dim Shared player As tPlayer
  15.  
  16.  
  17. THROW_DATA:
  18. Data .65,.55,.5,.5
  19. Data .99,.77,.43,.01
  20. Data .95,.75,.45,.05
  21.  
  22.  
  23. initDartGame
  24.     For i = 1 To 2
  25.  
  26.         Cls
  27.         Print "Player Score    : "; player.score
  28.         Print "Opponent Score  : "; oppScore
  29.         Print
  30.  
  31.  
  32.         '// PLAYER TURN
  33.         If i = 1 Then
  34.             Print "Throw Type", "Description", , "Probable Score"
  35.             Print 1, "Fast Overarm", , "Bullseye or Complete Miss!"
  36.             Print 2, "Controlled Overarm", , "10, 20 or 30pts"
  37.             Print 3, "Frustration Throw", , "Anything! LOL"
  38.  
  39.             Print
  40.  
  41.             Input "Throw Type: "; throwId
  42.  
  43.         Else
  44.             j = r(3)
  45.             Select Case j
  46.                 Case 1: Print "Opponent does an Fast overarm!"
  47.                 Case 2: Print "Opponent tries a controlled overarm"
  48.                 Case 3: Print "Opponent just tosses the dart"
  49.             End Select
  50.         End If
  51.  
  52.         If i = 2 Then throwId = j
  53.  
  54.         Select Case throwId
  55.  
  56.             Case 1 TO 3
  57.                 calcThrow = Rnd(1)
  58.                 miss = 1
  59.                 If miss And calcThrow >= throw(throwId, 1) Then Print "BULLSEYE!!!  40 points": score = 40: miss = 0
  60.                 If miss And calcThrow >= throw(throwId, 2) Then Print "30 point zone": score = 30: miss = 0
  61.                 If miss And calcThrow >= throw(throwId, 3) Then Print "20 point zone": score = 20: miss = 0
  62.                 If miss And calcThrow >= throw(throwId, 4) Then Print "Whew 10 point zone": score = 10: miss = 0
  63.                 If miss Then Print "OOPS!! Wallshot!!! Zero Points!!!"
  64.  
  65.             Case Else
  66.                 Print "Wild throw - score 0"
  67.  
  68.         End Select
  69.  
  70.         Print
  71.         P_AUSE
  72.         If i = 1 Then player.score = player.score + score
  73.         If i = 2 Then oppScore = oppScore + score
  74.  
  75.     Next
  76.  
  77. Loop While player.score < 200 And oppScore < 200
  78.  
  79. If player.score >= 200 Then
  80.     Print "We have a winner"
  81.     Print "Aww too bad. house wins!!"
  82.  
  83.  
  84.  
  85. '$include: 'utils.bi'
  86.  
  87. Sub P_AUSE
  88.     'PAUSE (y, cntr As Integer, DARK As String, MED As String, LIGHT As String, HILITE As String)
  89.     PAUSE 24, 1, "8", "7", "!", "0"
  90.     Color 7
  91.  
  92.  
  93. Sub initDartGame
  94.     Dim i As Integer
  95.  
  96.     Restore THROW_DATA
  97.     For i = 1 To 3
  98.         Read throw(i, 1): Read throw(i, 2): Read throw(i, 3): Read throw(i, 4)
  99.     Next
  100.     player.score = 0
  101.  
  102.  
  103. '// shorthand numbergen
  104.     r = Int(Rnd * num) + 1


utils.bi

Code: QB64: [Select]
  1. Sub number_format (num As Double, flt As Integer)
  2.     Dim number As String '                                              stores whole number(w/o dec) minus "."
  3.     Dim convert As String '                                             stores the orginal number in string format
  4.     Dim I As Integer '                                                  i=loop counter delimeter counter
  5.     Dim tpl As String '                                                 .. using template
  6.  
  7.     convert = Str$(num) '                                               convert it all to a strig
  8.     If Right$(convert, 1) <> "." Then convert = convert + "." '         weird fix for lower numbers
  9.     number = Left$(convert, InStr(convert, ".") - 1) '                  store the integer
  10.     number = RTrim$(LTrim$(number)) '                                   trim it up
  11.  
  12.     tpl = "" '                                                          create a template string for USING
  13.  
  14.     For I = 1 To Len(number): tpl = tpl + "#": Next '                   add a hash per digit per integer digit
  15.     tpl = tpl + "," '                                                   set the comma tag
  16.     If flt > 0 Then '                                                   is the decimal count set?
  17.         tpl = tpl + "." '                                               add the decimal tag
  18.         For I = 1 To flt: tpl = tpl + "#": Next '                       how many places (as per dec)
  19.     End If
  20.     '    PRINT "tpl for "; num
  21.     '    PRINT tpl
  22.     Print Using tpl; num; '                                              now PRINT USING should look cleaner
  23.  
  24.  
  25.  
  26. '// MANY GRID GAME DIST CALCULATOR
  27. Function DIST (x1 As Integer, y1 As Integer, z1 As Integer, x2 As Integer, y2 As Integer, z2 As Integer)
  28.     '3D Distance Calc Pathag Theorym
  29.     DIST = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2 + (z1 - z2) ^ 2)
  30.  
  31.  
  32.  
  33.  
  34. '// DETERMINE IF STRING IS A INTEGER/DOUBLE OR NOT
  35. Function IS_NUMBER (NUM As String) ' returns 1 if string is an integer, 0 if not
  36.     If LTrim$(RTrim$(Str$(Val(NUM$)))) = LTrim$(RTrim$(NUM$)) Then
  37.         IS_NUMBER = 1
  38.     Else
  39.         IS_NUMBER = 0
  40.     End If
  41.  
  42.  
  43. Function GET_OPTION$ (OPTION_STR As String)
  44.     '@option_str = list of characters (can be separated by comma) as only option to seelect from
  45.  
  46.     Dim OPT As String
  47.     OPTION_STR = " " + OPTION_STR 'The space in the INSTR instruction and the > 1 are there as otherwise the loop would exit on the first pass.
  48.     Do
  49.         OPT = UCase$(InKey$)
  50.     Loop Until InStr(UCase$(OPTION_STR), OPT) > 1 And OPT <> ","
  51.     GET_OPTION = OPT
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. '//==========================================================================================================================
  59. '// --- THESE ARE LEGACY FUNCTIONS USE AT OWN DISCRECTION
  60. '//==========================================================================================================================
  61.  
  62. '// DEC(X) -1 TO X
  63. '// INC(X) +1 TO X
  64. '// DISTANCE: DISTANCE BETWEEN 2 X,Y COORDS
  65. '// yesNo (default AS STRING)
  66.  
  67.  
  68. Function TODAYS_DATE$
  69.     Dim month As String, day As String, year As String, moon As String
  70.     Dim m, d, y As Integer
  71.  
  72.  
  73.     month$ = Left$(Date$, 2): m = Val(month$)
  74.     day$ = Mid$(Date$, 4, 2): d = Val(day$)
  75.     day$ = Str$(d) ' eliminate any leading zeros
  76.     year$ = Right$(Date$, 4): y = Val(year$)
  77.     Select Case m
  78.         Case 1: moon$ = "January"
  79.         Case 2: moon$ = "February"
  80.         Case 3: moon$ = "March"
  81.         Case 4: moon$ = "April"
  82.         Case 5: moon$ = "May"
  83.         Case 6: moon$ = "June"
  84.         Case 7: moon$ = "July"
  85.         Case 8: moon$ = "August"
  86.         Case 9: moon$ = "September"
  87.         Case 10: moon$ = "October"
  88.         Case 11: moon$ = "November"
  89.         Case 12: moon$ = "December"
  90.     End Select
  91.     TODAYS_DATE = WeekDay$(m, d, y) + ", " + moon$ + day$ + ", " + year$ + Space$(10)
  92.  
  93.  
  94. Function WeekDay$ (M, D, Y)
  95.     Dim C, Y As Integer
  96.     Dim S1, S2, S3 As Integer
  97.     Dim WKDAY As Integer
  98.     Dim Day As String
  99.  
  100.  
  101.     If M < 3 Then M = M + 12: Y = Y - 1 'add 12 to Jan - Feb month, -1 year
  102.     C = Y \ 100: Y = Y Mod 100 'split century and year number
  103.     S1 = (C \ 4) - (2 * C) - 1 'century leap
  104.     S2 = (5 * Y) \ 4 '4 year leap
  105.     S3 = 26 * (M + 1) \ 10 'days in months
  106.     WKDAY = (S1 + S2 + S3 + D) Mod 7 'weekday total remainder
  107.     If WKDAY < 0 Then WKDAY = WKDAY + 7 'Adjust negative results to 0 to 6
  108.     Select Case WKDAY
  109.         Case 0: Day$ = "Sunday"
  110.         Case 1: Day$ = "Monday"
  111.         Case 2: Day$ = "Tuesday"
  112.         Case 3: Day$ = "Wednesday"
  113.         Case 4: Day$ = "Thursday"
  114.         Case 5: Day$ = "Friday"
  115.         Case 6: Day$ = "Saturday"
  116.     End Select
  117.     WeekDay$ = Day$
  118.  
  119.  
  120.     '============================================================================
  121.     '--- PASCAL FUNCTION: DECREASES X BY 1)
  122.     '============================================================================
  123.     X = X - 1
  124.     DEC = X
  125.  
  126.     '============================================================================
  127.     '--- PASCAL FUNCTION: INCREASE X BY 1)
  128.     '============================================================================
  129.     X = X + 1
  130.     INC = X
  131.  
  132.  
  133. Function DISTANCE (X1, Y1, X2, Y2 As Integer)
  134.     '============================================================================
  135.     '--- DIST BETWEEN 2 POINTS
  136.     '============================================================================
  137.     DISTANCE = Sqr((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2)
  138.  
  139.  
  140. Function yesNo (default As String)
  141.     '// @default = when ENTER is pressed what will be the default answer
  142.  
  143.     Dim ans As String
  144.  
  145.     Do
  146.         ans = InKey$
  147.         ans = LCase$(ans)
  148.     Loop Until ans = "y" Or ans = "n" Or ans = Chr$(13) Or ans = ""
  149.  
  150.     If ans = Chr$(13) Or ans = "" Then ans = default
  151.  
  152.     If ans = "y" Then
  153.         yesNo = 1
  154.     Else
  155.         yesNo = 0
  156.     End If
  157.  
  158.  
  159. Function COUNT_TAGS (TEXT As String)
  160.     '//
  161.     '// RETURNS THE NUMBER OF LORD TAGS IN A STRING
  162.     '//
  163.     Dim I As Integer
  164.     If Len(TEXT) = 0 Then COUNT_TAGS = 0
  165.     Dim COUNT As Integer
  166.     Dim LENGTH As Integer
  167.     LENGTH = Len(TEXT)
  168.     COUNT = 0
  169.  
  170.     For I = 1 To LENGTH
  171.         If Mid$(TEXT, I, 1) = "`" Then COUNT = COUNT + 1
  172.  
  173.     Next
  174.     COUNT_TAGS = COUNT
  175.  
  176.  
  177.  
  178.  
  179. Sub CENTER (text As String, row As Integer)
  180.     '//
  181.     '// CENTER TEXT AS A SPECIFIED ROW
  182.     '//
  183.     Dim textLen, col As Integer
  184.     Dim TAGS As Integer
  185.  
  186.     If InStr(text, "`") >= 1 Then ' There is a tag
  187.  
  188.         TAGS = COUNT_TAGS(text) * 2
  189.         textLen = Int((Len(text) - TAGS) / 2)
  190.     Else
  191.         textLen = Int(Len(text) / 2)
  192.  
  193.     End If
  194.  
  195.     col = 40 - textLen
  196.     Locate row, col
  197.     If TAGS > 0 Then
  198.         LWRITE text
  199.     Else
  200.         Print text
  201.     End If
  202.  
  203.  
  204.  
  205. Sub LWRITE (TXT As String)
  206.     Dim i As Integer
  207.     '======================================================
  208.     '--- THIS IS A POPULAR COLOR ROUTINE BASED ON THE
  209.     '--- SETH ABLE L.O.R.D. BBS GAME COLOR FORMATTING
  210.     '=====================================================
  211.     Color 7 ' DEFAULT COLOR
  212.     For i = 1 To Len(TXT$)
  213.         ' CHECK FOR A COLOR CHANGE
  214.         If Mid$(TXT$, i, 1) = "`" Then
  215.             i = i + 1
  216.             Select Case Mid$(TXT, i, 1)
  217.                 Case "0": Color 10
  218.                 Case "1": Color 1
  219.                 Case "2": Color 2
  220.                 Case "3": Color 3
  221.                 Case "4": Color 4
  222.                 Case "5": Color 5
  223.                 Case "6": Color 6
  224.                 Case "7": Color 7
  225.                 Case "8": Color 8
  226.                 Case "9": Color 9
  227.                 Case "!": Color 11
  228.                 Case "@": Color 12
  229.                 Case "#": Color 13
  230.                 Case "$": Color 14
  231.                 Case "%": Color 15
  232.                 Case "n": Print '           new line
  233.                 Case "t": Print , ; '       TAB
  234.             End Select
  235.             i = i + 1
  236.  
  237.         End If
  238.         Print Mid$(TXT$, i, 1);
  239.     Next
  240.     Print ;
  241.  
  242. Sub LWRITELN (TXT As String)
  243.     LWRITE (TXT$)
  244.     Print
  245.  
  246. Sub EXPLODE (HAYSTACK As String, NEEDLE As String, EXPLODED_ARY() As String)
  247.     '//
  248.     '// speical thanks to SPRIGGYSPRIG for his inspiration to make this sub.
  249.     '// https://www.qb64.org/forum/index.php?topic=3721.0
  250.     '// USAGE
  251.     '//     EXPLODE DELIMITED STRING, DELIMETER, ARRAY TO RETURN
  252.     '//    EXAMPLE:  EXPLODE CONSOLE.Extentions, CHR$(32), SPLIT_EXT()
  253.     '//
  254.  
  255.     Dim CNT As Integer
  256.     Dim i As Integer
  257.     HAYSTACK = _Trim$(HAYSTACK)
  258.  
  259.     CNT = 1
  260.     For i = 1 To Len(HAYSTACK)
  261.         If Mid$(HAYSTACK, i, 1) <> NEEDLE Then
  262.             EXPLODED_ARY(CNT) = EXPLODED_ARY(CNT) + Mid$(HAYSTACK, i, 1)
  263.         Else
  264.             CNT = CNT + 1
  265.         End If
  266.     Next
  267.  
  268.  
  269. 'Sub EXPLODE (SplitMeString As String, delim As String, loadMeArray() As String)
  270. '        Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
  271. '        curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
  272. '        dpos = InStr(curpos, SplitMeString, delim)
  273. '        Do Until dpos = 0
  274. '                loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
  275. '                arrpos = arrpos + 1
  276. '                If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
  277. '                curpos = dpos + LD
  278. '                dpos = InStr(curpos, SplitMeString, delim)
  279. '        Loop
  280. '        loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
  281. '        ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
  282. 'End Sub
  283.  
  284.  
  285.  
  286.  
  287. Sub HEADER (TXT As String, Y As Integer)
  288.     CENTER "`8 --`2------------=`0=`%[ " + TXT + " `%]=`0= `2------------`8-- ", Y
  289.     Print
  290.  
  291. Sub HR '                                        HR
  292.     LWRITELN ("`8 -  --`3------------------=`!=`%*`!=`3------------------`8--  - ")
  293.  
  294. Sub PAUSE (y, cntr As Integer, DARK As String, MED As String, LIGHT As String, HILITE As String)
  295.     'y              = y coord to place it
  296.     'dark           = dark color
  297.     'med            = medium color
  298.     'light          = light color
  299.     'center pause?  = 1(yes), 0(mo)
  300.  
  301.     Dim SPIN(10) As String '    spiner tiles
  302.     Dim k As String '           dummy string to check for user input
  303.     Dim x As Integer '          spin array counter
  304.  
  305.     SPIN(1) = "*": SPIN(2) = "/": SPIN(3) = "-"
  306.     SPIN(4) = "\": SPIN(5) = "|": SPIN(6) = "/"
  307.     SPIN(7) = "-": SPIN(8) = "\": SPIN(9) = "|"
  308.  
  309.     x = 2
  310.     Do
  311.         '// IF NOT CENTERED
  312.         If cntr = 0 Then
  313.             Locate 24, 1
  314.             LWRITE "`" + DARK + "--`" + MED + "------------=`" + LIGHT + "=`" + HILITE + "[ " + SPIN(x) + " `" + HILITE + "]=`" + LIGHT + "= `" + MED + "------------`" + DARK + "-- "
  315.         Else
  316.  
  317.  
  318.             CENTER "`" + DARK + "--`" + MED + "------------=`" + LIGHT + "=`" + HILITE + "[ " + SPIN(x) + " `" + HILITE + "]=`" + LIGHT + "= `" + MED + "------------`" + DARK + "-- ", y
  319.         End If
  320.  
  321.         '// ANIMATE SPINNER
  322.         x = x + 1: If x > 9 Then x = 2
  323.         k = InKey$
  324.         _Delay (.10)
  325.     Loop Until k > ""
  326.  
  327.  

Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: johnno56 on November 09, 2021, 07:40:04 am
I still have the original book... So cool...
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: xra7en on November 09, 2021, 02:15:15 pm
keep in they're worth about $600+ LOL I know I got rid of all mine a long time ago (dumb i know LOL)
I did, however, buy all the Tim hartnell "Creating adventure games on your computer" LOL super rare

But I use these to practice a computer language, by converting the spaghetti code LOL!!
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: johnno56 on November 09, 2021, 06:18:03 pm
Ah. The dreaded line numbers and the 'gotos' that jump all around the program... Conversion for me was a nightmare... lol

My copy of "The Book" is not in very good condition... "Dog ears"; Pen doodles and notes... I basically (no pun intended) collect PDF's of Basic books. Hartnell is a favourite. I have tried scanning the pages and using OCR to convert to a text file was too labourious. Spent so much time correcting scan errors I coud have keyed in the listing... Gotta love those old programs...
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: Cobalt on November 09, 2021, 07:25:40 pm
So a wall shot for the computer is worth 30 points!?
cause that's what just happened, computer had 40points(2- 20 hits) then had a wall shot when I pressed space its points went to 70!
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: bplus on November 09, 2021, 09:11:55 pm
Yeah the game had some rough edges, so I gave it a shot:
Code: QB64: [Select]
  1. _Title "BULLSEYE!" 'b+ 2021-11-09
  2.  
  3. Dim tt_X_p(1 To 3, 1 To 4) ' Throw Type X Probability
  4. tt_X_p(1, 1) = .65: tt_X_p(1, 2) = .55: tt_X_p(1, 3) = .5: tt_X_p(1, 4) = .5 ' sum = 2.2
  5. '              35           10                  5                   0     50
  6. tt_X_p(2, 1) = .99: tt_X_p(2, 2) = .77: tt_X_p(2, 3) = .43: tt_X_p(2, 4) = .01 ' sum = 2.2
  7. '               1           27                 34                  42      1
  8. tt_X_p(3, 1) = .95: tt_X_p(3, 2) = .75: tt_X_p(3, 3) = .45: tt_X_p(3, 4) = .05 ' sum =  2.2
  9. '               5           20                 30                  40      5
  10. '       bulls 40pts        30pts             20pts                10pts     nada!
  11.  
  12.     Cls
  13.     Print: Print
  14.     cp "*** Bulls Eye! ***"
  15.     Print
  16.     cp "AI's Score is " + ts$(Scores(0))
  17.     cp "Your Score is " + ts$(Scores(1))
  18.     Print
  19.     cp "Throw Type:      Description:          Probable Score:      "
  20.     cp "      1          Fast Overarm     Bullseye or Complete Miss!"
  21.     cp "      2       Controlled Overarm       10, 20 or 30 pts     "
  22.     cp "      3        Frustration Throw        Anything! LOL       "
  23.     If turn Then
  24.         Print
  25.         cp "Human, press Throw Type number 1, 2 or 3"
  26.         t = 0
  27.         While t <> 1 And t <> 2 And t <> 3
  28.             k$ = InKey$
  29.             t = Val(k$)
  30.         Wend
  31.         cp ts$(t)
  32.     Else
  33.         t = Int(Rnd * 3) + 1
  34.         Print
  35.         cp "AI is choosing Throw Type: " + ts$(t)
  36.     End If
  37.     luck = Rnd: score = 0
  38.     If luck >= tt_X_p(t, 1) Then cp "BULLSEYE!!!  40 points": score = 40: GoTo 1
  39.     If luck >= tt_X_p(t, 2) Then cp "Hit 30 point zone": score = 30: GoTo 1
  40.     If luck >= tt_X_p(t, 3) Then cp "Hit 20 point zone": score = 20: GoTo 1
  41.     If luck >= tt_X_p(t, 4) Then cp "Whew, Hit 10 point zone": score = 10: GoTo 1
  42.     cp "OOPS!! Wallshot!!! Zero Points!!!"
  43.    1 Scores(turn) = Scores(turn) + score
  44.     Print: Print
  45.     cp "OK    press any... zzz"
  46.     Sleep
  47.     If turn Then 'both players shot their round
  48.         If Scores(0) > Scores(1) And Scores(0) >= 200 Then winner$ = "AI"
  49.         If Scores(1) > Scores(0) And Scores(1) >= 200 Then winner$ = "Human"
  50.         If Scores(0) = Scores(1) And Scores(0) >= 200 Then winner$ = "Tie"
  51.     End If
  52.     turn = (turn + 1) Mod 2
  53. Loop Until winner$ <> ""
  54. cp "AI's Score is " + ts$(Scores(0))
  55. cp "Your Score is " + ts$(Scores(1))
  56. cp "Game goes to " + winner$ + "."
  57.  
  58. Sub cp (s$)
  59.     Print Spc((80 - Len(s$)) / 2); s$
  60.  
  61. Function ts$ (num)
  62.     ts$ = _Trim$(Str$(num))
  63.  

I do like the little gizmo thing going on in xra7en's bottom line.
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: johnno56 on November 09, 2021, 11:00:07 pm
Cool game! Believe it or not, I actually won!

Hmm... Now that I think about it...  If "I" could win, you have obviously made the game too easy... lol

Perhaps with a little twisting of your arm, the next version, could possibly have some graphics... Nudge, nudge, wink, wink... Say no more... lol
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: bplus on November 09, 2021, 11:06:39 pm
Cool game! Believe it or not, I actually won!

Hmm... Now that I think about it...  If "I" could win, you have obviously made the game too easy... lol

Perhaps with a little twisting of your arm, the next version, could possibly have some graphics... Nudge, nudge, wink, wink... Say no more... lol

Actually that's what got me started, imagining some simple graphics.
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: bplus on November 10, 2021, 01:08:57 am
Some graphics help
Code: QB64: [Select]
  1. _Title "BULLSEYE! v2" 'b+ 2021-11-09
  2. Const Xmax = 640, Ymax = 400
  3. Dim tt_X_p(1 To 3, 1 To 4) ' Throw Type X Probability
  4. tt_X_p(1, 1) = .65: tt_X_p(1, 2) = .55: tt_X_p(1, 3) = .5: tt_X_p(1, 4) = .5 ' sum = 2.2
  5. '              35           10                  5                   0     50
  6. tt_X_p(2, 1) = .99: tt_X_p(2, 2) = .77: tt_X_p(2, 3) = .43: tt_X_p(2, 4) = .01 ' sum = 2.2
  7. '               1           27                 34                  42      1
  8. tt_X_p(3, 1) = .95: tt_X_p(3, 2) = .75: tt_X_p(3, 3) = .45: tt_X_p(3, 4) = .05 ' sum =  2.2
  9. '               5           20                 30                  40      5
  10. '       bulls 40pts        30pts             20pts                10pts     nada!
  11. Dim Shared aix(1 To 100), aiy(1 To 100), hx(1 To 100), hy(1 To 100), rounds, turn
  12. Screen _NewImage(Xmax, Ymax, 12)
  13. _ScreenMove 200, 100
  14. rounds = 1
  15.     Cls
  16.     drawTargets
  17.     Print: Print
  18.     cp "*** Bulls Eye! ***"
  19.     Print
  20.     cp "AI's Score is " + ts$(Scores(0))
  21.     cp "Your Score is " + ts$(Scores(1))
  22.     Print
  23.     cp "Throw Type:      Description:          Probable Score:      "
  24.     cp "      1          Fast Overarm     Bullseye or Complete Miss!"
  25.     cp "      2       Controlled Overarm       10, 20 or 30 pts     "
  26.     cp "      3        Frustration Throw        Anything! LOL       "
  27.     If turn Then
  28.         Print
  29.         cp "Human, press Throw Type number 1, 2 or 3"
  30.         t = 0
  31.         While t <> 1 And t <> 2 And t <> 3
  32.             k$ = InKey$
  33.             t = Val(k$)
  34.         Wend
  35.         cp ts$(t)
  36.     Else
  37.         t = Int(Rnd * 3) + 1
  38.         Print
  39.         cp "AI is choosing Throw Type: " + ts$(t)
  40.     End If
  41.     luck = Rnd: score = 0
  42.     If luck >= tt_X_p(t, 1) Then cp "BULLSEYE!!!  40 points": score = 40: GoTo 1
  43.     If luck >= tt_X_p(t, 2) Then cp "Hit 30 point zone": score = 30: GoTo 1
  44.     If luck >= tt_X_p(t, 3) Then cp "Hit 20 point zone": score = 20: GoTo 1
  45.     If luck >= tt_X_p(t, 4) Then cp "Whew, Hit 10 point zone": score = 10: GoTo 1
  46.     cp "OOPS!! Wallshot!!! Zero Points!!!"
  47.    1 Scores(turn) = Scores(turn) + score
  48.     updateTarget score
  49.     Print: Print
  50.     cp "OK    press any... zzz"
  51.     Sleep
  52.     If turn Then 'both players shot their round
  53.         If Scores(0) > Scores(1) And Scores(0) >= 200 Then winner$ = "AI"
  54.         If Scores(1) > Scores(0) And Scores(1) >= 200 Then winner$ = "Human"
  55.         If Scores(0) = Scores(1) And Scores(0) >= 200 Then winner$ = "Tie"
  56.         rounds = rounds + 1
  57.     End If
  58.     turn = (turn + 1) Mod 2
  59. Loop Until winner$ <> ""
  60. cp "AI's Score is " + ts$(Scores(0))
  61. cp "Your Score is " + ts$(Scores(1))
  62. cp "Game goes to " + winner$ + "."
  63.  
  64. Sub cp (s$)
  65.     Locate , (80 - Len(s$)) / 2: Print s$
  66.  
  67. Function ts$ (num)
  68.     ts$ = _Trim$(Str$(num))
  69.  
  70. Sub drawTargets
  71.     cy = Ymax - 90
  72.     For r = 20 To 80 Step 20
  73.         Circle (90, cy), r, 15
  74.         Circle (Xmax - 90, cy), r, 15
  75.     Next
  76.     For y = Ymax - 85 To Ymax - 25 Step 20
  77.         If i Mod 2 Then c = 12 Else c = 15
  78.         Paint (90, y), c, 15
  79.         Paint (Xmax - 90, y), c, 15
  80.         i = i + 1
  81.     Next
  82.     For i = 1 To rounds
  83.         Circle (aix(i), aiy(i)), 2, 0
  84.         drawArrow aix(i), aiy(i)
  85.         Circle (hx(i), hy(i)), 2, 0
  86.         drawArrow hx(i), hy(i)
  87.     Next
  88.     If turn Then
  89.         Circle (aix(rounds + 1), aiy(rounds + 1)), 2, 0
  90.         drawArrow aix(rounds + 1), aiy(rounds + 1)
  91.     End If
  92.  
  93. Sub updateTarget (score)
  94.     If score Then
  95.         cy = Ymax - 90
  96.         dist = (40 - score) * 2 + 2 + Rnd * 16
  97.         angle = Rnd * _Pi * 2
  98.         If turn Then cx = Xmax - 90 Else cx = 90
  99.         x = cx + dist * Cos(angle)
  100.         y = cy + dist * Sin(angle)
  101.         Circle (x, y), 2, 0
  102.         drawArrow x, y
  103.         If turn Then ' save the place
  104.             hx(rounds + 1) = x: hy(rounds + 1) = y
  105.         Else
  106.             aix(rounds + 1) = x: aiy(rounds + 1) = y
  107.         End If
  108.     End If
  109.  
  110. Sub drawArrow (x, y)
  111.     Color 0
  112.     Line (x - 4, y)-(x + 4, y)
  113.     Line (x, y - 4)-(x, y + 4)
  114.     Circle (x, y), 2
  115.     Circle (x, y), 1
  116.     Color 15
  117.  

 
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: johnno56 on November 10, 2021, 06:59:30 am
Cool...
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: johnno56 on November 10, 2021, 02:25:09 pm
Bplus,

I have a simple dartboard program that I made with sdlbasic. Well... maybe not simple.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  

Multiple shades of red, black, green and white. Rather than try to create a routine for a dart(s) to collide with odd shaped segments of a 'pie' I would just use a simple getpixel(x,y) - well that was my intention. Never did get beyond creating the dartboard. If you want the listing, let me know and I will post it. If you want to just use the image be my guest. No credit necessary.

J
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: bplus on November 10, 2021, 06:28:36 pm
Really nice dart board @johnno56 !!!

Instead of redrawing, we could just use the image.

PS Rotozoom might do wonders with a dart image or 2.
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: johnno56 on November 11, 2021, 01:38:33 am
As I mentioned earlier, odd shaped collision detection, for me anyway, was difficult. I figured that getpixel() (point()) would be easier. As a result, not all the black segments are black. Each scoring segment is a slight shade lighter. Same for the greens, reds and whites. I am not certain that a screen capture will pick up the differences. eg: if point(dartx,darty) = whatever then score is whichever... if point(dartx,darty) = grey (wire) then dart bounces off board. No score. Loss of dart.

If the screen capture works then cool. If not, let me know, and I will post the listing.

I like the idea of rotozoom. Couple of thoughts to increase difficulty. Slight gravity. Player will need to aim a little higher. Add slight aiming movement (like the effect of breathing when target shooting). Add a menu of difficulty to determine extent of aiming and moving... How about that? Ideas. Better write them down! This does not happen very often... I surprise myself at times... lol
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: bplus on November 11, 2021, 01:50:36 am
Great idea for collision detection, _putimage I don't think will blend so color should stay true, my opinion and guess, honestly don't know for sure.
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: johnno56 on November 11, 2021, 04:58:19 pm
This is where I got the idea for a dartboard. https://scratch.mit.edu/projects/2261044/
This was made by kids... Checkout how the board is put together. "See Inside".
Each segment of the board is 'patched' together. The dart scores when it hits a 'shape'

If you are up to it, play the game, just to see how it works. The system of aiming and firing are interesting.

In my opinion this could be a fun project to either inspire or duplicate... In my opinion...
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: _vince on November 13, 2021, 03:18:35 pm
I'll finish this on another computer in a bit (maybe never)

Code: [Select]
deflng a-z

const sw = 1000
const sh = 700

dim shared pi as double
pi = 4*atn(1)

dim shared mx, my, mbl, mbr, mw

dim shared aa(19)
aa( 0) = 6
aa( 1) = 10
aa( 2) = 15
aa( 3) = 2
aa( 4) = 17
aa( 5) = 3
aa( 6) = 19
aa( 7) = 7
aa( 8) = 16
aa( 9) = 8
aa(10) = 11
aa(11) = 14
aa(12) = 9
aa(13) = 12
aa(14) = 5
aa(15) = 20
aa(16) = 1
aa(17) = 18
aa(18) = 4
aa(19) = 13

'draw board once
screen _newimage(sw, sh, 32),, 1, 0

for y=-0.800*sh/2 to 0.800*sh/2
for x=-0.800*sh/2 to 0.800*sh/2
        dim a as double
        a = _atan2(y, x) + pi
        r = sqr(x*x + y*y)
        if r <= (0.800*sh/2) then
                am2 = (a*20/(2*pi)) mod 2
                if r >= 0.765*sh/2 or r >= 0.465*sh/2 and r <= 0.500*sh/2 then
                        if am2 = 0 then
                                c = _rgb(0,180,0)
                        else
                                c = _rgb(210,0,0)
                        end if
                else
                        if am2 = 0 then
                                c = _rgb(230,230,200)
                        else
                                c = _rgb(0,0,0)
                        end if
                end if
                if r<=0.060*sh/2 then
                        if r<=0.025*sh/2 then
                                c = _rgb(210,0,0)
                        else
                                c = _rgb(0,180,0)
                        end if
                end if
                pset (sw/2 + x, sh/2 + y), c
        end if
next
next

circle (sw/2, sh/2), sh/2 - 1, _rgb(50, 50, 50)

circle step(0,0), 0.800*sh/2
circle step(0,0), 0.765*sh/2

circle step(0,0), 0.500*sh/2
circle step(0,0), 0.465*sh/2

circle step(0,0), 0.060*sh/2
circle step(0,0), 0.025*sh/2


for i=0 to 19
        dim x as double, y as double
        x = cos(2*pi*(i/20) + 2*pi/40)
        y = sin(2*pi*(i/20) + 2*pi/40)
        pset  (sw/2 + (0.060*sh/2)*x, sh/2 + (0.060*sh/2)*y)
        line -(sw/2 + (0.800*sh/2)*x, sh/2 + (0.800*sh/2)*y)

        x = cos(2*pi*(i/20))
        y = sin(2*pi*(i/20))
        _printstring (sw/2 + (0.900*sh/2)*x - (8*len(ltrim$(str$(aa(i))))/2) - 8, sh/2 + (0.900*sh/2)*y - 8), str$(aa(i))
next

for i=0 to sh
        line (0, i)-step((sw - sh)/2 - 0.05*i*1000/sh, 0), _rgb(50 + 50*2*(atn(0.01*(sh/2 - i)))/pi,50 + 50*2*(atn(0.01*(i - sh/2)))/pi,0)

next

'main screen
screen ,, 0, 0

do
        t = timer*1000
        getmouse

        pcopy 1,0

        locate 1,1
        '? mx, my, mbl, mbr, mw
        ? t

        'for i=0 to 500+500*sin(2*pi*0.5*(t mod 10000)/1000)
                i = 500+500*sin(2*pi*0.5*(t mod 10000)/1000)
                line (0, i*sh/1000)-step((sw - sh)/2 - i*0.05, 0)
        'next

        _display
        '_limit 100
loop until _keyhit=27

sleep
system

sub getmouse()
        do
                mx = _mousex
                my = _mousey
                mbl = _mousebutton(1)
                mbr = _mousebutton(2)
                mw = mw - _mousewheel
        loop while _mouseinput
end sub

sub circlef (x, y, r, c as long)
        x0 = r
        y0 = 0
        e = 0
        do while y0<x0
                line(x-x0,y+y0)-(x+x0,y+y0),c,bf
                line(x-x0,y-y0)-(x+x0,y-y0),c,bf
                line(x-y0,y-x0)-(x+y0,y-x0),c,bf
                line(x-y0,y+x0)-(x+y0,y+x0),c,bf
                if e<=0 then
                        y0=y0+1
                        e=e+2*y0
                else
                        x0=x0-1
                        e=e-2*x0
                end if
        loop
end sub
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: xra7en on November 13, 2021, 03:36:05 pm
now thats cool bplus!

Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: bplus on November 13, 2021, 09:05:16 pm
Nice start @_vince

Fixed mouse to draw hit +- Rnd*10 of mx and my + Rnd*30, the mouse waits until you release the left button before it exits the GetMouse routine (meanwhile updating mx, my until button is released).

Need me to calc scores too?

Code: QB64: [Select]
  1. DefLng A-Z
  2.  
  3. Const sw = 1000
  4. Const sh = 700
  5.  
  6. pi = 4 * Atn(1)
  7.  
  8. Dim Shared mx, my, mbl, mbr, mw
  9.  
  10. Dim Shared aa(19)
  11. aa(0) = 6
  12. aa(1) = 10
  13. aa(2) = 15
  14. aa(3) = 2
  15. aa(4) = 17
  16. aa(5) = 3
  17. aa(6) = 19
  18. aa(7) = 7
  19. aa(8) = 16
  20. aa(9) = 8
  21. aa(10) = 11
  22. aa(11) = 14
  23. aa(12) = 9
  24. aa(13) = 12
  25. aa(14) = 5
  26. aa(15) = 20
  27. aa(16) = 1
  28. aa(17) = 18
  29. aa(18) = 4
  30. aa(19) = 13
  31.  
  32. 'draw board once
  33. Screen _NewImage(sw, sh, 32)
  34. _ScreenMove 100, 40
  35.  
  36. For y = -0.800 * sh / 2 To 0.800 * sh / 2
  37.     For x = -0.800 * sh / 2 To 0.800 * sh / 2
  38.         Dim a As Double
  39.         a = _Atan2(y, x) + pi
  40.         r = Sqr(x * x + y * y)
  41.         If r <= (0.800 * sh / 2) Then
  42.             am2 = (a * 20 / (2 * pi)) Mod 2
  43.             If r >= 0.765 * sh / 2 Or r >= 0.465 * sh / 2 And r <= 0.500 * sh / 2 Then
  44.                 If am2 = 0 Then
  45.                     c = _RGB(0, 180, 0)
  46.                 Else
  47.                     c = _RGB(210, 0, 0)
  48.                 End If
  49.             Else
  50.                 If am2 = 0 Then
  51.                     c = _RGB(230, 230, 200)
  52.                 Else
  53.                     c = _RGB(0, 0, 0)
  54.                 End If
  55.             End If
  56.             If r <= 0.060 * sh / 2 Then
  57.                 If r <= 0.025 * sh / 2 Then
  58.                     c = _RGB(210, 0, 0)
  59.                 Else
  60.                     c = _RGB(0, 180, 0)
  61.                 End If
  62.             End If
  63.             PSet (sw / 2 + x, sh / 2 + y), c
  64.         End If
  65.     Next
  66.  
  67. Circle (sw / 2, sh / 2), sh / 2 - 1, _RGB(50, 50, 50)
  68.  
  69. Circle Step(0, 0), 0.800 * sh / 2
  70. Circle Step(0, 0), 0.765 * sh / 2
  71.  
  72. Circle Step(0, 0), 0.500 * sh / 2
  73. Circle Step(0, 0), 0.465 * sh / 2
  74.  
  75. Circle Step(0, 0), 0.060 * sh / 2
  76. Circle Step(0, 0), 0.025 * sh / 2
  77.  
  78.  
  79. For i = 0 To 19
  80.     Dim x As Double, y As Double
  81.     x = Cos(2 * pi * (i / 20) + 2 * pi / 40)
  82.     y = Sin(2 * pi * (i / 20) + 2 * pi / 40)
  83.     PSet (sw / 2 + (0.060 * sh / 2) * x, sh / 2 + (0.060 * sh / 2) * y)
  84.     Line -(sw / 2 + (0.800 * sh / 2) * x, sh / 2 + (0.800 * sh / 2) * y)
  85.  
  86.     x = Cos(2 * pi * (i / 20))
  87.     y = Sin(2 * pi * (i / 20))
  88.     _PrintString (sw / 2 + (0.900 * sh / 2) * x - (8 * Len(LTrim$(Str$(aa(i)))) / 2) - 8, sh / 2 + (0.900 * sh / 2) * y - 8), Str$(aa(i))
  89.  
  90. For i = 0 To sh
  91.     Line (0, i)-Step((sw - sh) / 2 - 0.05 * i * 1000 / sh, 0), _RGB(50 + 50 * 2 * (Atn(0.01 * (sh / 2 - i))) / pi, 50 + 50 * 2 * (Atn(0.01 * (i - sh / 2))) / pi, 0)
  92.  
  93. board& = _NewImage(_Width - 1, _Height - 1, 32)
  94. _PutImage , 0, board&
  95.  
  96. 'main screen
  97.  
  98.  
  99.     t = Timer * 1000
  100.     getmouse
  101.  
  102.     _PutImage , board&, 0
  103.  
  104.     Locate 1, 1
  105.     '? mx, my, mbl, mbr, mw
  106.     If mbl Then
  107.         rx = Rnd * 20 - 10: ry = Rnd * 30
  108.         For i = 0 To 10 Step 2
  109.             Circle (mx + rx, my + ry), i, _RGB32((11 - i) * 25, (11 - i) * 25, 0)
  110.         Next
  111.         _PutImage , 0, board&
  112.     End If
  113.  
  114.     Print t
  115.  
  116.     'for i=0 to 500+500*sin(2*pi*0.5*(t mod 10000)/1000)
  117.     i = 500 + 500 * Sin(2 * pi * 0.5 * (t Mod 10000) / 1000)
  118.     Line (0, i * sh / 1000)-Step((sw - sh) / 2 - i * 0.05, 0)
  119.     'next
  120.  
  121.     _Display
  122.     _Limit 30
  123.  
  124.  
  125. Sub getmouse ()
  126.         mw = mw - _MouseWheel
  127.     Wend
  128.     mx = _MouseX
  129.     my = _MouseY
  130.     mbl = _MouseButton(1)
  131.     mbr = _MouseButton(2)
  132.     If mbl Then
  133.         Do 'wait for release of mousebutton before leaving this sub
  134.             While _MouseInput: Wend  'poll mouse
  135.             mx = _MouseX
  136.             my = _MouseY
  137.             mbl = _MouseButton(1)
  138.         Loop Until mbl = 0
  139.         mbl = -1
  140.     End If
  141.  
  142. Sub circlef (x, y, r, c As Long)
  143.     x0 = r
  144.     y0 = 0
  145.     e = 0
  146.     Do While y0 < x0
  147.         Line (x - x0, y + y0)-(x + x0, y + y0), c, BF
  148.         Line (x - x0, y - y0)-(x + x0, y - y0), c, BF
  149.         Line (x - y0, y - x0)-(x + y0, y - x0), c, BF
  150.         Line (x - y0, y + x0)-(x + y0, y + x0), c, BF
  151.         If e <= 0 Then
  152.             y0 = y0 + 1
  153.             e = e + 2 * y0
  154.         Else
  155.             x0 = x0 - 1
  156.             e = e - 2 * x0
  157.         End If
  158.     Loop
  159.  
  160.  
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: xra7en on November 13, 2021, 10:01:39 pm
Cool game! Believe it or not, I actually won!

Hmm... Now that I think about it...  If "I" could win, you have obviously made the game too easy... lol

Perhaps with a little twisting of your arm, the next version, could possibly have some graphics... Nudge, nudge, wink, wink... Say no more... lol

well keep in mind this is just a direct rewrite of the original code - just cleaned up a bit and readable. I suppose if your hankerin for punishment you could tweak it, since the spaghetti is all cleaned up
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: johnno56 on November 14, 2021, 01:21:16 am
xra7en,

My comment was not intended to question your skills in converting one basic to another. If I caused offence, then I apologise. The comment that I made, "you have obviously made", was poorly and inaccurately chosen. Direct conversion of the game does not and should not imply that you are the direct cause of my winning or losing. If that implication left you with that conclusion, then for that, I also apologise.

J
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: _vince on November 14, 2021, 04:42:54 am
Scoring should be as easy as drawing the board itself.  I was planning to use this system https://en.wikipedia.org/wiki/Darts#/media/File:Dartboard_heatmap.svg (https://en.wikipedia.org/wiki/Darts#/media/File:Dartboard_heatmap.svg) and all those numbers can be generated just from the outside nums which I put in array aa(19).  I'm also going to stick all the radii in an array to make the game code entirely flexible.  But I don't care for all the formalities of an actual game, I won't go into that.

Mainly, I'm trying to think up of a good scheme for animating the darts and also the game/skill aspect.  The original game goes for the shaky hand and a deterministic power bar that over/underthrows.  There's also no physics or 3D rendering of any sort, it appears to be a single bitmap array animation of the dart in flight that just gets panned around.  This is what I wanted to play around with, not yet sure what I should go with there.
Title: Re: David H. Ahl BULLSEYE (Dart Game) Revisited :-)
Post by: xra7en on November 14, 2021, 05:02:42 am
xra7en,

My comment was not intended to question your skills in converting one basic to another. If I caused offence, then I apologise. The comment that I made, "you have obviously made", was poorly and inaccurately chosen. Direct conversion of the game does not and should not imply that you are the direct cause of my winning or losing. If that implication left you with that conclusion, then for that, I also apologise.

J

oooo nooo, no offense.I understood. after reading that I can see how that came out that way - sooooory!
your fine. :-P