Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gin Rummy
#1
Quote:' 2026-02-21&22 I WAS all set to add card images to this but dang! to show a hand properly
' I have to have room to display the whole deck a 4 rows by 13 columns proposition. That PLUS
' I am just too plain lazy to Mod this code to card images when it works so well without!
' So I decided to fix the colors up 2 shades of red for red suits and 2 shades of black for
' black suits plus a dark print would work better on lite blue background that I like.

Code: (Select All)
Option _Explicit
_Title "Regular Gin Rummy" 'b+ rebuild start 2020-10-18
' from the revised cards of Grin Rummy add the 10-18 Optimze code to the Grim Rummy update,
' cleanup and debug the mess as well as establish scoring rules for this Variation.
' 2020-10-19 fix running fan waiting for screen click, readjust message lines,
' readjust colors for redder red for hearts and greener green for clubs.

' 2026-02-21&22 I WAS all set to add card images to this but dang! to show a hand properly
' I have to have room to display the whole deck a 4 rows by 13 columns proposition. That PLUS
' I am just too plain lazy to Mod this code to card images when it works so well without!
' So I decided to fix the colors up 2 shades of red for red suits and 2 shades of black for
' black suits plus a dark print would work better on lite blue background that I like.

DefInt A-Z
Randomize Timer
Const xmax = 800, ymax = 400 'screen to be expanded when start card images

'y Constants for locating and displaying
Const DeckY = 150 ' cards remain and discard top changing
Const ScoreY = 190 ' least changing item in middle
Const MessageY = 238 ' bottom
Const CardOffsetX = 20
Const CCardsOffsetY = 16
Const PCardsOffsetY = 288 ' now in pixels

' for current and future card images
Const CardW = 32 'pixels  3 chars wide
Const CardH = 16 'pixels  1 char high

'some colors
Const Black = &HFF000000, White = &HFFFFFFBB, BColor = &HFF6677DD
Const Ref = &HFF000033 ' dark blue on lite blue background  ' color changes 2/22/2026
Dim Shared Clr(3) As _Unsigned Long
Clr(0) = &HFFAA0033 'red touch of blue        hearts  chr$(3)  ' color changes 2/22/2026
Clr(1) = &HFFFF2200 'red gold                  diamonds chr$(4)
Clr(2) = &HFF003300 'dark green almost black  clubs    chr$(5)
Clr(3) = &HFF000022 'dark blue almost black    spades  chr$(6)

' card format = "##s" = 3 chars = space or 1 for 10 + # or Letter for digit/Face + card symbol

Dim Shared Deck$(0 To 51), DeckPointer As Integer ' contains shuffled cards, deckpointer points to last card out
Dim Shared Discard$, Turn$ 'discard$ is card always face up that both players see
Dim Shared P$(12, 3), C$(12, 3) '                                      p = human or c = computer
Dim Shared PMeldCards$, PNM, PMeldPts, PDeadCards$, PND, PDeadPts 'see updateStatus
Dim Shared CMeldCards$, CNM, CMeldPts, CDeadCards$, CND, CDeadPts
Dim Shared PScore, CScore, Laydown, ShowComputerHand
Dim Shared Pick1$(2), Pick2$(3) 'human player's button choices at each play
Pick1$(0) = "Quit": Pick1$(1) = "Draw Discard": Pick1$(2) = "Draw from Deck"
Pick2$(0) = "Quit": Pick2$(1) = "Gin - all cards melded": Pick2$(2) = "Knock": Pick2$(3) = "Pass to computer"

'local variables for main loop of game round and laydown section
Dim clicked 'human's button choice
Dim card$ ' used often for passing back and forth with routines
Dim message$ ' used for reporting results of laydown
Dim wf$ 'winflag
Dim oldMouse

Screen _NewImage(xmax, ymax, 32)
_ScreenMove 300, 150
SetupGame 'create deck, human is first up
restart:
ResetRound
wf$ = ""
Do
    If Turn$ = "p" Then 'player's turn
        clicked = GetButtonNumberChoice%(Pick1$())
        If clicked = 0 Then
            System
        ElseIf clicked = 1 Then '      Human draws discard
            AddCard P$(), Discard$ '  put the discard into the humans hand
            Discard$ = "" '            show the discard missing because in human hand
        ElseIf clicked = 2 Then '      Human draws from deck if there are enough cards
            If 52 - DeckPointer < 2 Then Laydown = 5: GoTo skip Else AddCard P$(), DealCard$
        End If
        UpdateStatus '                display all this
        card$ = GetDiscardClick$ '    get human's discard
        RemoveCard P$(), card$ '      take this card out of human hand
        Discard$ = card$ '            put into discard catagory
        UpdateStatus '                show the changes
        clicked = GetButtonNumberChoice%(Pick2$())
        Select Case clicked
            Case 0: System ' quit
            Case 1: If PDeadPts <> 0 Then Beep: Turn$ = "c" Else Laydown = 1
            Case 2: If PDeadPts > 10 Then Beep: Turn$ = "c" Else Laydown = 2
            Case 3: Turn$ = "c" ' pass
        End Select
    ElseIf Turn$ = "c" Then 'computer's turn
        card$ = Discard$
        CardDiscard card$ '
        If card$ = Discard$ Then 'computer passed on the discard by passing it back
            ' so draw from deck if not out of cards?
            If 52 - DeckPointer < 2 Then Laydown = 5: GoTo skip Else card$ = DealCard$
            CardDiscard card$
            Discard$ = card$
            UpdateStatus
            YCP MessageY, "Computer drew from Deck and discarded."
        Else 'computer kept discard
            Discard$ = card$
            UpdateStatus
            YCP MessageY, "Computer kept Discard and discarded another."
        End If
        _Delay 2
        If CDeadPts = 0 Then
            Laydown = 3
        ElseIf CDeadPts <= 10 Then
            Laydown = 4
        Else
            Turn$ = "p"
        End If
    End If
    skip:
Loop Until Laydown
'                                                            scoring round
ShowComputerHand = 1 'to show computer hand
Select Case Laydown
    Case 1 ' human gin
        message$ = "Human: 15 + " + TS$(PMeldPts) + " + " + TS$(CDeadPts) + " has been added to your score."
        PScore = PScore + 15 + PMeldPts + CDeadPts
        wf$ = "p"
        Turn$ = "c"
    Case 2, 4 'knock
        If PDeadPts > CDeadPts Then
            message$ = "Computer: " + TS$(CMeldPts) + " + " + TS$(PDeadPts) + " has been added to your score."
            CScore = CScore + CMeldPts + PDeadPts
            wf$ = "c"
            Turn$ = "p"
        ElseIf CDeadPts > PDeadPts Then
            message$ = "Human: " + TS$(PMeldPts) + " + " + TS$(CDeadPts) + " has been added to your score."
            PScore = PScore + PMeldPts + CDeadPts
            wf$ = "p"
            Turn$ = "p"
        Else
            message$ = "Tie, No winner this round."
            If Turn$ = "c" Then Turn$ = "p" Else Turn$ = "c"
        End If
    Case 3 ' computer gin
        message$ = "Computer: 15 + " + TS$(CMeldPts) + " + " + TS$(PDeadPts) + " has been added to your score."
        CScore = CScore + 15 + CMeldPts + PDeadPts
        wf$ = "c"
        Turn$ = "p"
    Case 5
        message$ = "The deck has < 2 cards, this round is Null!" ' turn is same as was
End Select
UpdateStatus
If wf$ = "p" Then
    DrwBtn xmax - 210, ymax - 100, "WIN Smile"
ElseIf wf$ = "c" Then
    DrwBtn xmax - 210, 50, "WIN Smile"
End If
If CScore >= 500 Or PScore >= 500 Then message$ = message$ + "  Winner!" ' cant clear score yet
YCP MessageY, message$ + "  click..."
oldMouse = -1
Do ' winner button showing somethimes wait for click to clear buttons, reset score if game won.
    While _MouseInput: Wend
    If _MouseButton(1) And oldMouse = 0 Then
        Line (xmax - 210, 0)-(xmax, ymax), BColor, BF 'blank out button area
        If InStr(message$, "Winner!") Then PScore = 0: CScore = 0 'reset main scores
        Exit Do
    End If
    oldMouse = _MouseButton(1)
    _Limit 200
Loop
GoTo restart

Sub SetupGame 'Intro to this version, create deck of cards, set turn to human
    Dim suit, value, i, bn
    Dim m$(2): m$(0) = "Quit": m$(1) = "Gin Rummy Intro": m$(2) = "Let's play Gin Rummy"
    Color Ref, BColor 'once and for all on bColor
    Cls
    YCP 160, "'Gin Rummy Intro' Button will load the text file"
    YCP 180, "'Gin Rummy Intro.txt' into your favorite editor"
    YCP 200, "for you to refer to now or during play of Gin Rummy."
    YCP 220, "You are free to add your own notes to the file."

    bn = GetButtonNumberChoice(m$())
    If bn = 0 Then System
    If bn = 1 Then Shell _DontWait "Gin Rummy Intro.txt" 'oh nice! don't have to load and show!
    If Deck$(0) = "" Then 'create deck
        For suit = 1 To 4
            For value = 1 To 13
                Deck$(i) = Mid$(" A 2 3 4 5 6 7 8 910 J Q K", 2 * (value - 1) + 1, 2) + Mid$(Chr$(3) + Chr$(4) + Chr$(5) + Chr$(6), suit, 1) 'Suit_Value
                i = i + 1
            Next
        Next
    End If
    Turn$ = "p" 'player always starts game
End Sub

Sub ResetRound
    Dim i, r 'locals, wow not many for all the code here
    Erase P$, C$ 'clear hands  13 cols and 4 rows arrays  copy of ordered deck

    Laydown = 0: ShowComputerHand = 0 '< 1 for debug or cheating

    'shuffle deck
    For i = 51 To 1 Step -1
        r = Int(Rnd * (i + 1))
        Swap Deck$(i), Deck$(r)
    Next
    DeckPointer = 0 'deal some cards out
    For i = 1 To 10
        AddCard P$(), DealCard$
        AddCard C$(), DealCard$
    Next
    Discard$ = Deck$(DeckPointer): DeckPointer = DeckPointer + 1 'set first discard$
    UpdateStatus
End Sub

Sub UpdateStatus
    Optimize C$(), CMeldCards$, CNM, CMeldPts, CDeadCards$, CND, CDeadPts
    Optimize P$(), PMeldCards$, PNM, PMeldPts, PDeadCards$, PND, PDeadPts
    Color Ref, BColor
    Cls
    Show "p" '                    show updates pDeadPts  cardDiscard updates cDeadPts
    If ShowComputerHand Then Show "c"

    'fixed I think
    Color Clr(InStr(Chr$(3) + Chr$(4) + Chr$(5) + Chr$(6), Right$(Discard$, 1)) - 1), White

    _PrintString (411, DeckY), Discard$
    Color Ref, BColor
    YCP DeckY, "Cards remaining: " + TS$(52 - DeckPointer) + "  Discard: "
    YCP ScoreY, "Human: " + TS$(PScore) + "  Computer: " + TS$(CScore)
End Sub

' this is only used in UpdateStatus
Sub Show (player$) 'players hand is displayed 5 lines above bottom of screen in 4 lines
    Dim r, c
    For r = 0 To 3
        Color Clr(r)
        For c = 0 To 12
            If player$ = "p" Then
                If P$(c, r) = "" Then
                    _PrintString (c * 40 + CardOffsetX, r * 16 + PCardsOffsetY), "  "
                Else
                    Color , White
                    _PrintString (c * 40 + CardOffsetX, r * 16 + PCardsOffsetY), P$(c, r)
                    Color , BColor
                End If

            Else
                If C$(c, r) = "" Then
                    _PrintString (c * 40 + CardOffsetX, r * 16 + CCardsOffsetY), "  "
                Else
                    Color , White
                    _PrintString (c * 40 + CardOffsetX, r * 16 + CCardsOffsetY), C$(c, r)
                    Color , BColor
                End If
            End If
        Next
    Next
    Color &HFFFFFF00 'dark brown sort a like cMeldTotal?
    If player$ = "p" Then
        YCP 80 + PCardsOffsetY, "  Player:  Meld = " + TS$(PMeldPts) + "    Deadwood = " + TS$(PDeadPts)
    Else
        YCP 80 + CCardsOffsetY, "Computer:  Meld = " + TS$(CMeldPts) + "    Deadwood = " + TS$(CDeadPts)
    End If
    Color White
End Sub

'player reviews card rec'd and discards through mouse click
Function GetDiscardClick$ 'this has to be reworked
    Dim oldMouse, mCol, mRow, mb
    YCP MessageY, "Click Discard"
    oldMouse = -1
    Do
        While _MouseInput: Wend 'convert mouse positions to array row and col
        mCol = Int((_MouseX - CardOffsetX) / (CardW + 8) + .25)
        mRow = Int((_MouseY - PCardsOffsetY) / (CardH))
        mb = _MouseButton(1)
        'LOCATE 13, 2: PRINT mCol, mRow
        If mb And oldMouse = 0 Then
            If mRow >= 0 And mRow <= 3 Then
                If mCol >= 0 And mCol <= 12 Then
                    If P$(mCol, mRow) <> "" Then GetDiscardClick$ = P$(mCol, mRow): Exit Function
                End If
            End If
        End If
        oldMouse = mb
        _Limit 200
    Loop
End Function

'computer gets card and discards through this AI    ================== Computer's AI
Sub CardDiscard (card$) 'for AI  2020-10-11 rewrite this for new Optimize
    Dim cCards$, low, d$, saveI, i, tm$, tn, tp, dn, deadPts, oPts
    cCards$ = ListCards$(C$())

    Optimize C$(), tm$, tn, tp, d$, dn, deadPts
    low = deadPts: saveI = 0: oPts = deadPts
    AddCard C$(), card$
    For i = 1 To 10 ' with card in hand swap all cards out for best points
        RemoveCard C$(), Mid$(cCards$, i * 3 - 2, 3)
        Optimize C$(), tm$, tn, tp, d$, dn, deadPts
        If deadPts < low Then saveI = i: low = deadPts
        AddCard C$(), Mid$(cCards$, i * 3 - 2, 3)
    Next
    RemoveCard C$(), card$ ' back to original 10 cards
    If card$ = Discard$ Then
        If oPts - low > 4 Then
            AddCard C$(), card$
            RemoveCard C$(), Mid$(cCards$, saveI * 3 - 2, 3)
            card$ = Mid$(cCards$, saveI * 3 - 2, 3)
        End If
    Else 'card <> discard$ take the best
        If saveI <> 0 Then
            AddCard C$(), card$
            RemoveCard C$(), Mid$(cCards$, saveI * 3 - 2, 3)
            card$ = Mid$(cCards$, saveI * 3 - 2, 3)
        End If
    End If
End Sub

Function DealCard$
    DealCard$ = Deck$(DeckPointer): DeckPointer = DeckPointer + 1
End Function

Function Points% (card$)
    Dim place
    place = InStr(" A 2 3 4 5 6 7 8 910 J Q K", Mid$(card$, 1, 2))
    If (place + 1) / 2 < 10 Then Points% = (place + 1) / 2 Else Points% = 10
End Function

Sub AddCard (a$(), card$)
    'PRINT card$
    Dim r, c
    r = InStr(Chr$(3) + Chr$(4) + Chr$(5) + Chr$(6), Right$(card$, 1)) - 1: c = (InStr(" A 2 3 4 5 6 7 8 910 J Q K", Mid$(card$, 1, 2)) - 1) / 2
    'PRINT c, r, card$
    a$(c, r) = card$
End Sub

Sub RemoveCard (a$(), card$)
    Dim r, c
    r = InStr(Chr$(3) + Chr$(4) + Chr$(5) + Chr$(6), Right$(card$, 1)) - 1: c = (InStr(" A 2 3 4 5 6 7 8 910 J Q K", Mid$(card$, 1, 2)) - 1) / 2
    a$(c, r) = ""
End Sub

'modified for this app
Sub YCP (y, s$) 'for xmax pixel wide graphics screen Center Print at pixel y row
    _PrintString ((_Width - 220 - Len(s$) * 8) / 2, y), s$
End Sub

'this sub uses drwBtn
Function GetButtonNumberChoice% (choice$()) 'developed for this app but likely can use as is elsewhere
    Dim ub, b, oldmouse, mx, my, mb

    ub = UBound(choice$)
    For b = 0 To ub
        DrwBtn xmax - 210, b * 60 + 90, choice$(b)
    Next
    oldmouse = -1
    Do
        While _MouseInput: Wend
        mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
        If mb And oldmouse = 0 Then
            If mx > xmax - 210 And mx <= xmax - 10 Then
                For b = 0 To ub
                    If my >= b * 60 + 90 And my <= b * 60 + 140 Then
                        Line (xmax - 210, 0)-(xmax, ymax), BColor, BF
                        GetButtonNumberChoice% = b: Exit Function
                    End If
                Next
                Beep
            Else
                Beep
            End If
        End If
        oldmouse = _MouseButton(1)
        _Limit 200
    Loop
End Function

Sub DrwBtn (x, y, s$) '200 x 50
    Dim th, tw, gray~&
    th = 16: tw = 8 * Len(s$): gray~& = _RGB32(190, 190, 190)
    Line (x, y)-Step(204, 54), _RGB32(0, 0, 0), BF
    Line (x - 2, y - 2)-Step(201, 51), _RGB32(255, 255, 255), BF
    Line (x, y)-Step(200, 50), gray~&, BF
    Color _RGB32(0, 0, 0), gray~&
    _PrintString (x + 100 - 4 * Len(s$), y + 17), s$
    Color White, BColor
End Sub

Sub SAppend (arr() As String, addItem$)
    ReDim _Preserve arr(LBound(arr) To UBound(arr) + 1) As String
    arr(UBound(arr)) = addItem$
End Sub

Function TS$ (number)
    TS$ = _Trim$(Str$(number))
End Function


' ========================================== add Optimizer Code and fix it for new cards design

' 5 SUBs 2 FUNCTIONs
' needs FUNCTION cards$(hand$()), FUNCTION cardRemovedSet$ (set$, card$) for deadwood calcs
' needs SUB ListStraights (hand$(), StrCards$, nStrCards AS INTEGER, strPoints AS INTEGER)
' needs SUB ListGroups (hand$(), grpCards$, nGrpCards AS INTEGER, grpPoints AS INTEGER)
' needs SUB ListIntersects (strt$, grp$, listI$()) , FUNCTION TS$
' needs SUB addCard (hand$(), card$), SUB removeCard (hand$(), card$)
Sub Optimize (hand$(), meld$, nMeld, meldPts, deadwood$, nDeadwood, deadwoodPts)

    Dim sCards$, gCards$, copyS$, copyG$, comb$, combine$, temp$, d$
    Dim nSt As Integer, nGr As Integer, stPts As Integer, grPts As Integer, i As Integer, j As Integer
    Dim nI As Integer, nCombos As Integer, highSet$, nHiCards, hiPts
    Dim c As Integer, r As Integer
    ReDim dbl$(0) ' cards that intersect so appear twice once in straight sets and then in group
    Dim justS$(12, 3), justG$(12, 3)
    Dim copyS$(12, 3), copyG$(12, 3)

    ListStraights hand$(), sCards$, nSt, stPts
    For i = 1 To nSt 'put only straight cards in justS$
        AddCard justS$(), Mid$(sCards$, i * 3 - 2, 3)
    Next
    ListGroups hand$(), gCards$, nGr, grPts
    For i = 1 To nGr 'put only straight cards in justS$
        AddCard justG$(), Mid$(gCards$, i * 3 - 2, 3)
    Next
    ListIntersects sCards$, gCards$, dbl$()
    If UBound(dbl$) > 0 Then 'then we have intersects
        nI = UBound(dbl$): nCombos = 2 ^ nI
        For i = 1 To nI ' build a template for deciding what to do with each intersect
            temp$ = temp$ + TS$(i)
        Next

        ' look for the best sum of cards and points of all combinations of removing intersect cards from straight set or group
        For i = 1 To nCombos
            comb$ = "" ' for building a combination
            For j = 0 To nI - 1 'generate comb$ here now instead of in array
                If (i - 1) And 2 ^ j Then
                    If comb$ = "" Then comb$ = Mid$(temp$, j + 1, 1) Else comb$ = comb$ + ", " + Mid$(temp$, j + 1, 1)
                End If
            Next

            'make copys of the straight set and the group set  because we will be removing cards as comb$ dictates
            For r = 0 To 3
                For c = 0 To 12
                    copyS$(c, r) = justS$(c, r)
                    copyG$(c, r) = justG$(c, r)
                Next
            Next
            If comb$ = "" Then ' copys$ stays same
                For j = 1 To Len(temp$) ' remove all intersects from copyG$()
                    RemoveCard copyG$(), dbl$(j)
                Next
            Else
                For j = 1 To Len(temp$) 'remove card from straight set according to dictates of comb$
                    d$ = TS$(j) 'if combo generated here
                    If InStr(comb$, d$) Then ' all combs are 1 digit less than intersect number
                        RemoveCard copyS$(), dbl$(j)
                    Else 'it's remove the card from one or the other
                        RemoveCard copyG$(), dbl$(j)
                    End If
                Next
            End If

            'run the counts from the sets again
            ListStraights copyS$(), sCards$, nSt, stPts
            ListGroups copyG$(), gCards$, nGr, grPts
            combine$ = sCards$ + gCards$
            If i = 1 Then
                highSet$ = combine$: nHiCards = nSt + nGr: hiPts = stPts + grPts
            Else
                If nSt + nGr > nHiCards Then
                    highSet$ = combine$: nHiCards = nSt + nGr: hiPts = stPts + grPts
                ElseIf stPts + grPts > hiPts Then
                    highSet$ = combine$: nHiCards = nSt + nGr: hiPts = stPts + grPts
                End If
            End If
        Next
    Else ' no intersects between straights and groups
        highSet$ = sCards$ + gCards$: nHiCards = nSt + nGr: hiPts = stPts + grPts
    End If

    'OK we should have the optimum set!
    meld$ = highSet$: nMeld = nHiCards: meldPts = hiPts

    'calc Deadwood set
    deadwood$ = ListCards$(hand$()) ' all the cards
    For i = 1 To nHiCards ' minus meld
        deadwood$ = CardRemovedSet$(deadwood$, Mid$(highSet$, i * 3 - 2, 3))
    Next
    nDeadwood = Len(deadwood$) / 3 'number of deadwood cards
    deadwoodPts = 0
    For i = 1 To nDeadwood
        deadwoodPts = deadwoodPts + Points%(Mid$(deadwood$, i * 3 - 2, 3))
    Next
End Sub

' needs points%(card$)
Sub ListStraights (hand$(), StrCards$, nStrCards As Integer, strPoints As Integer)
    ' hand is 2D array
    Dim r As Integer, c As Integer, quit As Integer, cStart As Integer, cEnd As Integer, ci As Integer
    StrCards$ = "": nStrCards = 0: strPoints = 0
    For r = 0 To 3 'suits
        c = 0: quit = 0
        Do While quit = 0 And c < 13
            While hand$(c, r) = "" 'search blanks until hit a card
                c = c + 1
                If c > 11 Then quit = 1: Exit While
            Wend
            If c < 11 Then 'have enough for 3 card straight
                cStart = c
                While hand$(c, r) <> "" ' while cards are next to each other
                    c = c + 1
                    If c = 13 Then quit = 1: Exit While
                Wend
                If c = 13 Then cEnd = 12 Else cEnd = c - 1
                If cEnd - cStart + 1 > 2 Then 'enough for straight
                    For ci = cStart To cEnd '  STEP -1 ' load highest cards first into straight set < reversed this back 10-18
                        StrCards$ = StrCards$ + hand$(ci, r)
                        nStrCards = nStrCards + 1
                        strPoints = strPoints + Points%(hand$(ci, r))
                    Next
                End If
                If c > 11 Then quit = 1
            Else
                Exit Do
            End If
        Loop
    Next
End Sub

' needs points%(card$)
Sub ListGroups (hand$(), grpCards$, nGrpCards As Integer, grpPoints As Integer)
    Dim c As Integer, count As Integer, ci As Integer
    grpCards$ = "": nGrpCards = 0: grpPoints = 0
    For c = 0 To 12 ' now for the groups
        count = 0
        For ci = 0 To 3
            If hand$(c, ci) <> "" Then count = count + 1
        Next
        If count > 2 Then
            For ci = 0 To 3
                If hand$(c, ci) <> "" Then
                    grpCards$ = grpCards$ + hand$(c, ci)
                    nGrpCards = nGrpCards + 1
                    grpPoints = grpPoints + Points%(hand$(c, ci))
                End If
            Next
        End If
    Next
End Sub

'needs sAppend(arr$(), insert$)
Sub ListIntersects (strt$, grp$, listI$())
    Dim NS As Integer, NG As Integer, i As Integer, j As Integer
    NS = Len(strt$) / 3: NG = Len(grp$) / 3
    ReDim listI$(0)
    If (NS > 0) And (NG > 0) Then
        For i = 1 To NS
            For j = 1 To NG
                If Mid$(strt$, i * 3 - 2, 3) = Mid$(grp$, j * 3 - 2, 3) Then
                    SAppend listI$(), Mid$(strt$, i * 3 - 2, 3)
                End If
            Next
        Next
    End If
End Sub

Function ListCards$ (hand$())
    Dim c As Integer, r As Integer, rtn$
    For c = 0 To 12 ' now for the groups
        For r = 0 To 3
            If hand$(c, r) <> "" Then rtn$ = rtn$ + hand$(c, r)
        Next
    Next
    ListCards$ = rtn$
End Function

Function CardRemovedSet$ (set$, card$)
    Dim i, nCards, newSet$
    nCards = Len(set$) / 3
    For i = 1 To nCards
        If card$ <> Mid$(set$, i * 3 - 2, 3) Then newSet$ = newSet$ + Mid$(set$, i * 3 - 2, 3)
    Next
    CardRemovedSet$ = newSet$
End Function

PLUS without Card images we don't have to attach or embed image file!

You will find the AI for the Computer player quite good! 

Here are some snaps to get the gist of the game, what melding looks like:
   
   
   
   
   

Dang I am getting like Walter with all the pics but needed for How to Play without reading all the rules though that would help. 

Double dang there IS a Help / Intro text file to attach with this. I will attach a zip for bas source and Help file.


Attached Files
.zip   Gin Rummy 2026-02-22.zip (Size: 8.3 KB / Downloads: 6)
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply
#2
PS I am curious if the Help / Intro file loads in Linux or Mac, works fine for me in Windows and loads right into my favorite WP Notepad++ for reading or adding notes while I play Gin Rummy.

There are 4 links to Gin Rummy Rules or reference files in that text file. Those link right up also in the Notepad++ app, neat!
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Forum Jump:


Users browsing this thread: