Extending the Card Game Plugin

Forum for plugin, effect and behavior programmers. Please use the Help & Support forum for help using Construct.

Post » Fri Jan 02, 2009 4:52 pm

I really think there's a heavy interest in using Construct for developing card games.

[url:3gzazy96]http://www.scirra.com/phpBB3/viewtopic.php?f=3&t=2244[/url:3gzazy96]
[url:3gzazy96]http://www.scirra.com/phpBB3/viewtopic.php?f=3&t=2264[/url:3gzazy96]

Perhaps a good question to ask is how the card game plugin could be extended to offer a higher level of support for making card games.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Fri Jan 02, 2009 6:15 pm

I think it is planned that the object be improved; the problem is how. I mean, we could hard-code in features for specific card games like poker, but then where do we stop? Should it be a library of all card games possible? How can it be made general enough to usefully apply to any card game?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,554

Post » Fri Jan 02, 2009 9:24 pm

Yeah, you don't want to have 20 different types of poker premade.
Dunno perhaps a few tutorials would probably be better. Perhaps some more expressions for betting, players, and maybe "looseness"..? But that's all stuff you can do with loops, and variables.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Jan 03, 2009 1:48 am

If this is turning into a feature request thread, I'd like to throw out a few suggestions for discussion.

[list:1qrzmewx]
[*:1qrzmewx]Action: return card to deck (card number).
Append the parameter to the end of the list of not-yet-drawn cards. (Perhaps perform a sanity check and complain via the debugger if the parameter is on that list already? But what if multiple decks are implemented?)
Useful for games where cards can be drawn but not actually put into play, e.g. Solitaire. Also for games where you occasionally need to shuffle the cards that have been played, but not the players' hands (Crazy 8s and its five hundred million variants spring to mind).

Alternative: maintain two lists. The "draw pile" is what is called the "deck" in the current implementation; the "discard pile" is initially empty and can have specific cards added to it via an action. Another action appends the discard pile (maintaining the order) to the draw pile and clears the discard. Problem: sanity checks become even more complicated ("User wants to add card #15 to the discard pile, so if the number of cards #15 in the draw pile plus the number of cards #15 in the discard pile equals the number of decks in use, throw an error message on the debugger.")[/*:1qrzmewx]

[*:1qrzmewx]Conditions: same rank (card number, card number), same suit (card number, card number).
Return true if the two parameters refer to cards of the same rank or suit respectively. For bonus points, accept an arbitrary number of parameters and return true only if they all match.[/*:1qrzmewx]

[*:1qrzmewx]For convenience and readability, add "suit" and "rank" expressions that basically do card%13 and floor(card/13) respectively. (Or (card%13)+1 and ceil(card/13), if you prefer to number the ranks and suits from 1 rather than 0).[/*:1qrzmewx]

[*:1qrzmewx]Allow multiple decks. This probably shouldn't be runtime-editable because removing a deck in mid-air is messy and underdefined. A property "number of decks" that defaults to 1 seems more plausible. Also, I don't expect users to want to know which specific deck a card came from; so a "draw pile" with two decks could simply(?) have two copies each of the numbers 1..52.[/*:1qrzmewx]

[*:1qrzmewx]As an alternative, ignore everything I said above and go for flexibility: have a property "number of cards" that can be set to an arbitrary number. Remove all the conditions and let the users calculate (or look up in an array) what each number means in card terms. This would open the object as a shuffling mechanism for games with non-standard deck sizes (CCGs, Tarock and many more), but make it slightly less convenient for actual traditional card games.[/*:1qrzmewx][/list:u:1qrzmewx]
B
2
S
1
G
4
Posts: 60
Reputation: 1,320

Post » Sat Jan 03, 2009 4:11 am

[quote="Znirk":2mtu4ol2]Allow multiple decks. This probably shouldn't be runtime-editable because removing a deck in mid-air is messy and underdefined. A property "number of decks" that defaults to 1 seems more plausible. Also, I don't expect users to want to know which specific deck a card came from; so a "draw pile" with two decks could simply(?) have two copies each of the numbers 1..52.[/quote:2mtu4ol2]
Couldn't you just use separate Card Game objects?
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,554

Post » Sat Jan 03, 2009 5:47 pm

[quote="Ashley":36dngk88]Couldn't you just use separate Card Game objects?[/quote:36dngk88]

"Could", yes; but unless I'm missing something, "just" is a bit optimistic. Keeping separate decks would indeed be easy that way, but I'm assuming here usually a game that uses multiple decks would want them shuffled together into one big pile. You'd have to do something like:

Check some flags to see which decks have cards left in them (and jump to the "No Cards Left" route if none have).

Generate a random number between 1 and (number of remaining decks).

Draw a random card from the chosen deck -- AFAICT there's no case switch statement and no way to pick an object based on the content of a variable, so this in itself is a whole christmas tree of ... I don't even know ... Compare events? Anyway, get that value and write it to a global variable; otherwise we'll have to write the deck-picking structure twice.

If the card is "-1", that means the deck had no cards left after all: update the flags and start over. Otherwise, we're done.

So, yeah, it's possible, but possible in a way that makes reimplementing the plugin in event code (or Python, once that's fixed) seem the easy option.
B
2
S
1
G
4
Posts: 60
Reputation: 1,320


Return to Construct engineering

Who is online

Users browsing this forum: No registered users and 0 guests