(i'm the dude who ask about the effects and rules, ... maybe next time I sign up...)
Well, I alredy thought about making the game like a state machine (using a class for changing the actual state of the game, but there are card effects which change the rules of the game, not only those internal variables.
For example, there's a card saying something like: "While this card is on the game, your opponent can't win the game and you can't lose the game", so even if you lose all your lifes, still you can't lose, and that is a modification of a game rule. (when a player's life reach 0, that player lose).
Another example: there's acard saying something like: "You can play 2 lands on your turn", changing the rule "a player can only play 1 in his/her turn".
And there's a lot of cards changing the rules ...
So, how can I manage those effects? (they change the rules, not the regular variables)
What AI for a card game ?
Quote:
Well, I alredy thought about making the game like a state machine (using a class for changing the actual state of the game, but there are card effects which change the rules of the game, not only those internal variables.
For example, there's a card saying something like: "While this card is on the game, your opponent can't win the game and you can't lose the game", so even if you lose all your lifes, still you can't lose, and that is a modification of a game rule. (when a player's life reach 0, that player lose).
Another example: there's acard saying something like: "You can play 2 lands on your turn", changing the rule "a player can only play 1 in his/her turn".
And there's a lot of cards changing the rules ...
So, how can I manage those effects? (they change the rules, not the regular variables)
The 'rules' in a game are nothing more than a relation between the current state and successor/goal states. If you may play two cards at once, that means your actions of that state includes playing two cards. If the opponent cannot win while some card is in effect, it merely ensures that the goal state function returns false til then. All of these are effects local merely to the current state of the game. If the actions can alter them, they belong to the state, there is nothing else which considers the temporal relationships of the game. The alterable 'rules' are just direct or indirect internal variables (indirect in the sense of the existence of a card but no explicit variable for example).
A state machine is something else than what we're talking about. We're speaking of states in search, an autonoma is similar but it's functionalities wouldn't be of any use here unless you wish to design the AI (meaning the addition of quite specific behaviour which relies much on you, rather than emerging from advanced means of evaluation).
Damnit. Why is there no prompt that I didn't entter my username on these forums? I just entered only my password and lost the whole post. Grrr....
Anyway, I'll summarise what I was going to write:
Initially, it's only worth looking ahead to the end of the AI's current turn, i.e
1) AI spellcasting phase
2) AI attack phase
3) Opponent defence phase
4) end of turn
At this level of lookahead you can easily afford to generate just about every possibility, without really worrying about pruning.
Your first goal should be to build an accurate board evaluation algorithm to give a score for the 'end of turn' phase. You could identify as many factors as you can which may affect this (number of life points remaining, creatures in play, etc) and assign each an importance variable. Tweaking these variables thus gives different AI behaviour. You could then run a Genetic Algorithm to get optimum values. If the resulting AI is still really stupid, you need to either improve your GA starting point/evolution procedures, or else add more useful factors to your board evaluation metric.
Once the AI is acting 'smart' for it's current position, then you know you have a good board evaluation metric. After this you start looking forward multiple turns and developing your AI further with pruning techniques.
Anyway, I'll summarise what I was going to write:
Initially, it's only worth looking ahead to the end of the AI's current turn, i.e
1) AI spellcasting phase
2) AI attack phase
3) Opponent defence phase
4) end of turn
At this level of lookahead you can easily afford to generate just about every possibility, without really worrying about pruning.
Your first goal should be to build an accurate board evaluation algorithm to give a score for the 'end of turn' phase. You could identify as many factors as you can which may affect this (number of life points remaining, creatures in play, etc) and assign each an importance variable. Tweaking these variables thus gives different AI behaviour. You could then run a Genetic Algorithm to get optimum values. If the resulting AI is still really stupid, you need to either improve your GA starting point/evolution procedures, or else add more useful factors to your board evaluation metric.
Once the AI is acting 'smart' for it's current position, then you know you have a good board evaluation metric. After this you start looking forward multiple turns and developing your AI further with pruning techniques.
The most important thing is the evaluation of the current game state, i.e. assigning a score to the position on the table. This should take into account the tactical value of cards still in hand, if any (i.e. a one-turn creature upgrade spell); creature strength versus players' life (any enemy creature that does 1 damage is only a small negative score if you're on 20 life, or if you have creatures to defend against it, but a huge negative if you're on 1 life with no defenders); the value of creatures'/permanent enchantments' special abilities.
Once you have that, you can simply calculate the score on the table for all possible moves of playing/not playing the cards in your hand, and pick the best. For a 7 card hand that's only 128 even if you don't assume independence of which cards are good to play.
As for attacks, I'd use a similar system: calculate the estimated value of the attack (just sum(probability*value) for each outcome). Potential attacks with multiple creatures on both sides make things more difficult, as there are a lot of choices to make, and it might be necessary to remember the best (i.e. highest estimated value, even if too low to attack with) 4 or so configurations. Remember that for any one creature there are typically five outcomes: the attack is not blocked and the other player loses life (+ve); the attack is blocked and the blocking creature dies (+ve); the attack is blocked and neither creature dies (usually neutral, though damage-causing abilities on either side could change that); the attack is blocked and both creatures die (variable value); the attack is blocked and the attacking creature dies (-ve).
The use or otherwise of abilities can be treated similarly.
Both parts (playing cards and attacking/spellcasting) will produce lots of tunable parameters, which should probably be the target of a GA to produce decent players.
Part of the reason games like Magic are fun is because they require thinking to play B-) ... so they are naturally hard to write a good AI for.
Once you have that, you can simply calculate the score on the table for all possible moves of playing/not playing the cards in your hand, and pick the best. For a 7 card hand that's only 128 even if you don't assume independence of which cards are good to play.
As for attacks, I'd use a similar system: calculate the estimated value of the attack (just sum(probability*value) for each outcome). Potential attacks with multiple creatures on both sides make things more difficult, as there are a lot of choices to make, and it might be necessary to remember the best (i.e. highest estimated value, even if too low to attack with) 4 or so configurations. Remember that for any one creature there are typically five outcomes: the attack is not blocked and the other player loses life (+ve); the attack is blocked and the blocking creature dies (+ve); the attack is blocked and neither creature dies (usually neutral, though damage-causing abilities on either side could change that); the attack is blocked and both creatures die (variable value); the attack is blocked and the attacking creature dies (-ve).
The use or otherwise of abilities can be treated similarly.
Both parts (playing cards and attacking/spellcasting) will produce lots of tunable parameters, which should probably be the target of a GA to produce decent players.
Part of the reason games like Magic are fun is because they require thinking to play B-) ... so they are naturally hard to write a good AI for.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement