Cardgame framework question

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Cardgame framework question

#1 Post by Glazed Donuts »

I'm wondering. What would be needed to create the AI for an opponent (CPU) for the cardgame framework? For example, suppose you wanted to make a poker game. Would the AI just consist of timers and random numbers to choose which card it would play? Is it possible to do timers in Ren'Py? And I mentioned 'timer' because I wasn't sure how else the CPU would know when the player turn is over.

KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Cardgame framework question

#2 Post by KimiYoriBaka »

I'm not sure why you would need timers for something turn-based. I should think a poker game would just keep track of the current player's turn as a variable and then keep track of each phase of each hand as another variable (or just good structuring of the code), with perhaps some uses of renpy.pause to simulate the ai opponents trying to think. Then whenever the player needs to choose whether or not to do something, some menus would pop up.

Ai on the other hand is one of those complex things that even professionally made games tend to horribly screw up. In the case of a poker game in a vn, I think the most efficient way (in terms of how much work it takes to make) would be a probability system based on how likely the cpu thinks it is to get each possible hand. I don't mean, of course, actual probability or anything like that, but just something simple and arbitrary like, eg. if the cpu has four cards of one suit and no pairs, it could have a 90% chance of going for a flush.

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Cardgame framework question

#3 Post by Jake »

KimiYoriBaka wrote: In the case of a poker game in a vn, I think the most efficient way (in terms of how much work it takes to make) would be a probability system based on how likely the cpu thinks it is to get each possible hand.
In theory, from a mathematical point of view, it would actually be relatively straightforward to write a poker AI which gave a 'perfect' assessment of any given hand. This is only a small factor in a game of poker, though, and psychology and risk come into it significantly as well. If you're playing against a timid, easy manipulated player then you might be able to win a round with a lousy hand by bluffing, but if you're playing against a well-practised pro that won't necessarily work.

Here's one article giving a few ideas:
http://cowboyprogramming.com/2007/01/04 ... -poker-ai/
- there are plenty of other references around on the web.

But this is largely beside the point; if you're planning on making anything with the cardgame framework, you should really put some time into understanding how it runs together first; as KimiYoriBaka said, there shouldn't be any need for timers. I would start with the Klondike example, see if you can follow through how it goes and maybe modify it to use different rules or something, before trying to do anything radical like trying to program AIs!

(I would also seriously consider what the point of the poker game inside the VN is, to be honest. If you're trying to make a VN with a particular story, then it may even be better to rig the poker hands somewhat... ensure that despite the seemingly-random drawing of cards that the player loses big-time at the beginning of the story to set up his journey with a big fall, and wins by the skin of his teeth in the final climatic game.)
Server error: user 'Jake' not found

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Cardgame framework question

#4 Post by PyTom »

Making an entertaining poker AI is actually quite hard in practice. The hand evaluator is easy (but hard to make fast, unless you use a library). Poker is a game about betting strategy, and finding multiple betting strategies that are reasonable yet entertaining is hard. (IIRC, we had about three personalities in Card Sweethearts, and I'm not sure we used all of them, since they didn't differ all that much from each other.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Jake
Support Hero
Posts: 3826
Joined: Sat Jun 17, 2006 7:28 pm
Contact:

Re: Cardgame framework question

#5 Post by Jake »

PyTom wrote: The hand evaluator is easy (but hard to make fast, unless you use a library).
I'm curious - when you say 'hard to make fast', do you mean 'hard to make efficient', or 'hard to make such that it doesn't take a noticeable period of time on an ancient machine', or 'hard to make such that it doesn't take a noticeable period of time on a modern machine'

'Cause I can see how the first would be true, and maybe the middle, but the last one seems unlikely unless I'm missing something... I mean, surely you just have to check for each other player what the probabilities are that they have each hand in descending order until you get to the one you have yourself, which becomes easier or harder depending on variant (in five-card stud, it should be pretty straightforward - in Texas hold-em, less so) but still hardly on the order of making Chess moves?
Server error: user 'Jake' not found

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Cardgame framework question

#6 Post by PyTom »

For Texas holdem, you have to enumerate every combination of cards you can have, and cards your opponent can have, as compared to the possible common cards. (Since cards can interact a lot, you can't consider your hand in isolation from your opponent's.) This is combinatorially large, and takes a couple of seconds on a relatively modern machine. It's slow enough that I precomputed games in a background thread, so as not to slow down interactive response. (The poker code was in C)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Cardgame framework question

#7 Post by Glazed Donuts »

PyTom: I understand that part. You have to do constant evaluations, which would really slow the system down if it has to keep doing this with every move you make.

What about something in terms of a TCG (Trading Card Game) opposed to a Poker game? Would a TCG (like making the mechanics and AI) be even more complex/difficult to do in Ren'Py than something like poker?

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Cardgame framework question

#8 Post by PyTom »

It really depends on the details of the TCG. A simple card game (like the one in Princess Waltz) would probably be easy to create. But, from what I understand, it's hard-to-impossible to code the rules of Magic: The Gathering.

(I wouldn't want to be the guy who had to implement Chaos Confetti.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
jack_norton
Lemma-Class Veteran
Posts: 4085
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

Re: Cardgame framework question

#9 Post by jack_norton »

I made a sort of Magic-style game myself years ago, and it's really a pain to code (I used C, but wouldn't be much easier in python) and it's much simpler than magic :)
follow me on Image Image Image
computer games

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: Cardgame framework question

#10 Post by LordShiranai »

PyTom wrote:It really depends on the details of the TCG. A simple card game (like the one in Princess Waltz) would probably be easy to create. But, from what I understand, it's hard-to-impossible to code the rules of Magic: The Gathering.

(I wouldn't want to be the guy who had to implement Chaos Confetti.)
That card sure brings back memories. :lol:

The very thought of fully implementing every card and rule in MTG makes my head explode.
Don't Blame Me. I Voted for Vermin Supreme.

Glazed Donuts
Regular
Posts: 121
Joined: Thu Aug 12, 2010 11:47 am
Contact:

Re: Cardgame framework question

#11 Post by Glazed Donuts »

Wow, is that an actual playable card? O_O that's crazy!

LordShiranai
Regular
Posts: 188
Joined: Wed Jul 07, 2010 5:49 pm
Completed: Mobile Food Madness, Super Otome Quest
Location: Pacific Northwest
Contact:

Re: Cardgame framework question

#12 Post by LordShiranai »

It was part of the "unglued" set, which was a parody set. It was not a tournament legal set, IIRC.

It was a parody of Chaos Orb. There was an urban legend that someone won a game in a tournament match by tearing up their Chaos Orb and sprinkling the pieces all over their opponent's cards. I'm pretty sure it wasn't true.

Regardless of the truth behind the story, chaos orb caused so many problems / arguments over its use that it was banned in Tournament play.
Don't Blame Me. I Voted for Vermin Supreme.

Post Reply

Who is online

Users browsing this forum: Google [Bot]