Liberty BASIC Community Forum
« Card Game Contest! »

Welcome Guest. Please Login or Register.
May 25th, 2017, 5:01pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2 3 4 5  6 Notify Send Topic Print
 veryhotthread  Author  Topic: Card Game Contest!  (Read 6465 times)
jaba
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 325
smiley Re: Card Game Contest!
« Reply #30 on: Aug 9th, 2011, 1:07pm »

@Janet,

Sorry to take so long to acknowledge your reply.Thanks for your solution. It took awhile to get things right, but I think I finally understand how to handle it now.

jaba
User IP Logged

If I didn't first try it and get it wrong, I may never have figured out how to get it right.
jaba
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 325
smiley Re: Card Game Contest!
« Reply #31 on: Aug 17th, 2011, 10:40pm »

This is proving to be more difficult than I had imagined. I don't think I can complete my program in time.

I'm having a problem selecting a card that is blocked by another. I'm trying to use InitDrag and the isBlocked function, but not having any luck. I've included a picture of the result when I click a card in an area that has another card underneath. I've also included some code that is where I'm trying to select the right card and move it up 50 pixels before I check if the computer hand has any of that rank card - or else I Go Fish!

Any help appreciated.
jaba

screen shot

Code:
    '[P2]
    noOfCards=7
    'player's hand needs sorted
    sort PP$(), 46, 52

    'create player's hand array by value
    for i = 1 to noOfCards
        P2(i)=val(word$(PP$(i+45), 2,"-"))
    next i
    'deal player's hand
    for i = 1 to noOfCards
        scan
        'set face down=0
        call SetCardStatus P2(i), 1   '<---change to 0 when ready
        'window handle, card index number, x, y
        call DealCard hBox, P2(i),i*48,300
        call Pause 100
    next
    #1.g "flush"
'wait

[checkIndex]    'activated by leftButtonDown event
    x=0:y=300 'reset values
    mx=MouseX   : my=MouseY 'mouse x and y location
    nCard=InitDrag(hBox, mx, my) 'discover index of card under mouse
    'for checking
    #1.g "place 10 420;\Drag Card Index is ";nCard;space$(100)
    isBlocked=GetCardBlocked(nCard)    'see if card is blocked
    if isBlocked then call AdjustCardBlocked nCard,0

    x=GetCardX(nCard)
    y=GetCardY(nCard)
    call DealCard hBox, nCard, x, y-50
    call AbortDrag     'release DLL mouse capture
'    call DealCard hBox, nCard, x, y
    if nCard=0 then wait
wait

 
User IP Logged

If I didn't first try it and get it wrong, I may never have figured out how to get it right.
Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
smiley Re: Card Game Contest!
« Reply #32 on: Aug 17th, 2011, 10:58pm »

I had trouble with overlapping cards as well. I finally resorted to doing a full redraw of the playing card hand area each time a card is clicked.

Use boxfilled to cover up the entire playing area of the range of cards. It's not necessary to cover up the entire graphics box.

call DealCard again for the entire hand.

That was the only way I could solve the problem. Maybe I'm just not following the directions as I should, but it was sure driving me crazy.

My biggest problem now is the AI algorithm. I may have to abandon smart moves and just go with random moves. undecided

User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Re: Card Game Contest!
« Reply #33 on: Aug 18th, 2011, 05:07am »

on Aug 17th, 2011, 10:40pm, jaba wrote:
This is proving to be more difficult than I had imagined. I don't think I can complete my program in time.

I'm having a problem selecting a card that is blocked by another. I'm trying to use InitDrag and the isBlocked function, but not having any luck. I've included a picture of the result when I click a card in an area that has another card underneath. I've also included some code that is where I'm trying to select the right card and move it up 50 pixels before I check if the computer hand has any of that rank card - or else I Go Fish!

Any help appreciated.
jaba



Jaba, I do not see a place in the code snippet where you set any card's blocked status so that it is "blocked". You must do this. The DLL does not do it.

The "blocked" status is meant for use in a solitaire game to check for a valid move and for block dragging operations. The blocked status should be used to either indicate that a card is not valid if a user tries to select it, or to see if it is beneath other cards and will require a block drag for the column. (I believe you must stack cards at the same x location for block dragging.)

I see no reason to set card status to "blocked" or check for blocked status when the entire hand of cards is available for play.

I haven't experimented with pulling a card from beneath another card.

Janet mentions redealing a hand after effectively erasing the hand by drawing a filled box over it. That's fine if you prefer to do it that way, but the DLL is meant to work differently.

Removing Cards at the end of Turn

Quote:
Removing Cards at the end of Turn

We first query the value and suit of the two cards, then remove them from the table. It is important to remove cards before dealing them again. If they are not placed on a blank table, the DLL records the image of the tabletop with the card displayed and uses that to replace the tabletop when the card is later removed. If we deal a card face up, for instance, then deal it in the same place face down, then remove it, the tabletop will appear to have a face up version of the card on it, even though no card is there.




Instead of dragging a card that is selected, abort the drag after you've retrieved its index. (InitDrag is used to retrieve the card index. You must then use AbortDrag to stop the DLL from capturing mouse movements.)

Remove all cards in the hand. Redeal all cards in the hand after changing the coordinates of the selected card.

I'll try to work out a demo of what I mean and post that.

Even if your game is not done, please submit it. There may be multiple unfinished programs, but all will be fun and useful!



« Last Edit: Aug 18th, 2011, 05:09am by Admin » User IP Logged

Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
smiley Re: Card Game Contest!
« Reply #34 on: Aug 18th, 2011, 05:44am »

Jaba (and Janet!), this is a very quick demo of selecting a card, getting the index with InitDrag, aborting the drag, removing the hand, and redrawing the hand with the selected card higher than the rest of the hand.

Remove ALL cards, then redeal all cards to insure that the DLL has the proper image of the table under the cards.

I know it has glitches and errors. It's just meant to demonstrate what I'm talking about.

Code:
dim card(4)            'array to hold cards
gosub [fillCardArray]  'fill array with card values

nomainwin
    WindowWidth=640:WindowHeight=480
    UpperLeftX=1:UpperLeftY=1

    menu #1, "&File", "E&xit", [quit]
    graphicbox #1.g, 0, 0, 640, 440
    open "Cards" for window_nf as #1
    #1 "trapclose [quit]"

    'get graphicbox handle
    hBox=hwnd(#1.g)

    'open the dll
    open "qcard32.dll" for dll as #qc
    'initialize the deck
    Call InitializeDeck hBox

[new]
    Call SetDefaultValues

    'draw a nice background
    #1.g "down; fill 10 190 225"
    #1.g "backcolor 10 190 225"
    'temp message for this demo only
    #1.g "place 10 40;\Left-click a card to select it."

    'set xy location to start deal
    x=10:y=200
        for i = 1 to 4
        Call DealCard hBox,card(i),x,y
        x=x+50
        scan
    next
    #1.g "when leftButtonDown [initDrag]"
    #1.g "when leftButtonUp [redraw]"
wait

[initDrag]
    cardIndex=InitDrag(hBox,MouseX,MouseY)
    #1.g "place 10 420;\Drag Card Index is ";cardIndex;space$(100)
    wait

[redraw]
    if cardIndex=0 then wait
    call AbortDrag
    for i = 1 to 4
        call RemoveCard hBox, card(i)
    next
    x=10:y=200
        for i = 1 to 4
        if cardIndex=card(i) then y=140 else y=200
        Call DealCard hBox,card(i),x,y
        x=x+50
        scan
    next
    wait

[fillCardArray]
    card(1)=3
    card(2)=18
    card(3)=33
    card(4)=51
    RETURN

[quit] close #qc:close #1:end


''''''''''''''''''''
'subs and functions:

Function InitDrag(hndle, x, y)
    calldll #qc, "InitDrag",_
        hndle as ulong, x as long, y as long,_
        InitDrag as long
    end function

Sub AbortDrag
    calldll #qc, "AbortDrag",re as void
    end sub

Sub InitializeDeck hndle
    calldll #qc, "InitializeDeck",_
    hndle as ulong,r as long
    End Sub

Sub DealCard hndle,nC,x,y
    'places card on window whose handle is hndle at x,y
    'nC is number of card - 1-52 in first deck and
    '53-104 in second deck, if used
    calldll #qc, "DealCard",hndle as ulong,nC as long,_
    x as long,y as long,r as void
    End Sub

Sub RemoveCard hndle,nC
    'removes a card from screen that was
    'drawn with DealCard, replacing screen background
    calldll #qc, "RemoveCard",hndle as ulong,_
    nC as long,r as void
    End Sub

Sub SetDefaultValues
    'reset all card properties back to their default values.
    calldll #qc, "SetDefaultValues",r as void
    End Sub

 
« Last Edit: Aug 18th, 2011, 05:51am by Admin » User IP Logged

Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
smiley Re: Card Game Contest!
« Reply #35 on: Aug 18th, 2011, 05:54am »

I'll try to add a lesson to the tutorial series for the selection of a single card from a hand.

Note that I didn't use InitDrag to discover the card under the mouse in the early memory card game. I checked MouseX and MouseY against the locations of cards.

There are many ways to skin that darned cat!
User IP Logged

Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
smiley Re: Card Game Contest!
« Reply #36 on: Aug 18th, 2011, 07:58am »

As I wrote, the demo above for dealing a hand of cards that overlaps horizontally has at least one bug.

The DLL is written so that the LOWEST card at a given coordinate is returned by InitDrag. We want to know the HIGHEST card at those coordinates.

I've fixed the demo and I'm currently writing a small tutorial about it to place in the QCard series on LBPE. It will be there soon.

The best "fix" for the horizontal overlap issue might be to avoid using InitDrag and check coordinates as I did in the early demos for the Memory card game (the early tutorials in the QCard series.)


« Last Edit: Aug 18th, 2011, 08:00am by Admin » User IP Logged

Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
smiley Re: Card Game Contest!
« Reply #37 on: Aug 18th, 2011, 08:54am »

Horizontal overlap with card selection.

http://lbpe.wikispaces.com/QCard13

User Image
« Last Edit: Aug 18th, 2011, 08:57am by Admin » User IP Logged

Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
smiley Re: Card Game Contest!
« Reply #38 on: Aug 18th, 2011, 08:57am »


Alyce, I did call RemoveCard before calling DealCard, but the underneath portion of should-be-blank areas under the cards held remnants of the removed card images. That's why I finally resorted to starting each new deal over a fresh canvas. I don't have any trouble with vertical moves, but I'm definitely pulling my hair out with horizontal moves. ;-/

Once I get the computerPlayer to select its first card to play, I'll post my code. Should be in a day or two.
User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Re: Card Game Contest!
« Reply #39 on: Aug 18th, 2011, 09:05am »

on Aug 18th, 2011, 08:57am, Janet wrote:
Alyce, I did call RemoveCard before calling DealCard, but the underneath portion of should-be-blank areas under the cards held remnants of the removed card images. That's why I finally resorted to starting each new deal over a fresh canvas.


I wondered if there might be instances where this happened, because we deal in a certain order and the DLL records the image underneath a card in that order. (I didn't realize you were removing cards first.) I think your boxfilled idea sounds like a winner. I may need to modify the QCard tutorial after I see how you do it.

smiley smiley smiley
User IP Logged

Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
smiley Re: Card Game Contest!
« Reply #40 on: Aug 18th, 2011, 09:11am »

Okay, Alyce, I modified your demo ever so slightly. I want to keep the clicked card elevated so that, eventually, all clicked cards would be moved up. The only changes I made are in [redraw]. Essentially, when a card is moved up, the value of that card is changed to the negative equivalent. Still, when I click a second card, the redraw shows any previously removed in both lower and upper rows.
Code:

'An open project card game, begun by Alyce Watson, May 27, 2003.
'Uses Qcard32.dll, a freeware library of playing card images.
'DLL by Stephen Murphy.  Qcard32.DLL website:
'http://www.telusplanet.net/public/stevem/

xOffset=50     'horizontal offset for dealing hand
dim card(8,2)  'array to hold cards
'fill array with demo hand of cards
'in a game, the logic would dictate how hands are created
'first dimension is card index
    card(1,1)=3
    card(2,1)=18
    card(3,1)=33
    card(4,1)=51
    card(5,1)=44
    card(6,1)=12
    card(7,1)=39
    card(8,1)=22

nomainwin
    WindowWidth=640:WindowHeight=480
    UpperLeftX=1:UpperLeftY=1

    menu #1, "&File", "E&xit", [quit]
    graphicbox #1.g, 0, 0, 640, 440
    open "Cards" for window_nf as #1
    #1 "trapclose [quit]"

    'get graphicbox handle
    hBox=hwnd(#1.g)

    'open the dll
    open "qcard32.dll" for dll as #qc
    'initialize the deck
    Call InitializeDeck hBox

[new]
    Call SetDefaultValues

    'draw a nice background
    #1.g "down; fill 10 190 225"
    #1.g "backcolor 10 190 225"
    'temp message for this demo only
    #1.g "place 10 40;\Left-click a card to select it."

    'set xy location to start deal
    x=10:y=200
        for i = 1 to 8
        Call DealCard hBox,card(i,1),x,y
        'save the x location of each card
        card(i,2)=x
        x=x+xOffset
        scan
    next
    #1.g "when leftButtonDown [initDrag]"
    #1.g "when leftButtonUp [redraw]"
wait

[initDrag]
    cardIndex=InitDrag(hBox,MouseX,MouseY)
    if cardIndex=0 then wait

    'retrieve the index of card in array that matches index returned by DLL
    for i = 1 to 8
        if cardIndex=card(i,1) then arrayIndex=i
    next

    'Check to see if user clicked the card at an x value
    'greater than the xOffset. If this is true, change
    'cardIndex to be the index of the next card in the card array.
    if MouseX > card(arrayIndex,2)+xOffset then
        cardIndex=card(arrayIndex+1,1)
    end if
    #1.g "place 10 420;\Selected Card Index is ";cardIndex;space$(100)
    wait

[redraw]
    if cardIndex=0 then wait
    call AbortDrag
    for i = 1 to 8
        call RemoveCard hBox, card(i,1)
    next
    x=10:y1=200:y2=100
        for i = 1 to 8
        if cardIndex=card(i,1) then
            card(i,1)=0-card(i,1)
            y=y2
        else
            y=y1
        end if
        card=abs(card(i,1))
        Call DealCard hBox,card,x,y
        x=x+xOffset
        scan
    next
    wait


[quit] close #qc:close #1:end


''''''''''''''''''''
'subs and functions:

Function InitDrag(hndle, x, y)
    calldll #qc, "InitDrag",_
        hndle as ulong, x as long, y as long,_
        InitDrag as long
    end function

Sub AbortDrag
    calldll #qc, "AbortDrag",re as void
    end sub

Sub InitializeDeck hndle
    calldll #qc, "InitializeDeck",_
    hndle as ulong,r as long
    End Sub

Sub DealCard hndle,nC,x,y
    'places card on window whose handle is hndle at x,y
    'nC is number of card - 1-52 in first deck and
    '53-104 in second deck, if used
    calldll #qc, "DealCard",hndle as ulong,nC as long,_
    x as long,y as long,r as void
    End Sub

Sub RemoveCard hndle,nC
    'removes a card from screen that was
    'drawn with DealCard, replacing screen background
    calldll #qc, "RemoveCard",hndle as ulong,_
    nC as long,r as void
    End Sub

Sub SetDefaultValues
    'reset all card properties back to their default values.
    calldll #qc, "SetDefaultValues",r as void
    End Sub
 

I'm sure it has something to do with the dll preserving the memory/image of its underlying background. This is why I finally gave up and gave the dll a blank canvas to work with each redeal.
User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
smiley Re: Card Game Contest!
« Reply #41 on: Aug 18th, 2011, 09:13am »

And, as an aside, this is why I just love these challenges so much. It's not so much the finished product as it is the dialogue and learning along the way. grin
User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
xx Re: Card Game Contest!
« Reply #42 on: Aug 18th, 2011, 09:26am »

on Aug 18th, 2011, 09:13am, Janet wrote:
And, as an aside, this is why I just love these challenges so much. It's not so much the finished product as it is the dialogue and learning along the way. grin


I couldn't agree more! grin That's also why folks should submit entries, even if they are not finished.

The boxfilled idea is already incorporated into the tutorial and demo, which I just updated. Thank you, Janet! wink
« Last Edit: Aug 18th, 2011, 09:28am by Admin » User IP Logged

Janet
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 4111
smiley Re: Card Game Contest!
« Reply #43 on: Aug 18th, 2011, 09:35am »

Here's what I have so far. I've removed the AI stuff as, right now, it's a mess with far too many variables and would only be confusing.

JLT Contest Entry

I'm off to tackle the computer's selection, abandoning computer for graph paper and decisional flow chart. wink
User IP Logged

Windows 7 Professional, SP1, 64 bit Intel Core i5-4200U CPU @ 1.60 GHz 2.30 GHz 6.00 GB

"I am very busy finding out what people mean by what they say." -
Admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 14484
smiley Re: Card Game Contest!
« Reply #44 on: Aug 18th, 2011, 10:09am »

Janet, what fun! Not only am I learning new coding techniques from the entries, but I'm also learning new games!
User IP Logged

Pages: 1 2 3 4 5  6 Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls