AI for solving problems
Hi,
right now i am working on a game suite (for single player) containing (skill)games like 'Mahjong', 'NumRunner', 'BLOCS', etc. (see www.gameaccount.com).
I am wondering which AI-methods would best fit to solve such games in a certain amount of time (creating different skilled cpu-opponents).
Usually these games call for search problems, sometimes with some planning ahead that can be performed using trees of various kinds. Basically it all depends on the game/puzzle you are trying to solve. Mahjongg for example can be as easy as "find two open tiles and remove them" - I'm not sure that there is a matter of order in Mahjongg but I may be wrong.
Anyway, once you have the algorithm for finding "the next move" you can limit it (thus creating "levels" of the CPU) by several tactics:
1. Time - there are games in which the competition is time based. In this kind of games all you need to do is simply delay the CPU answer; maybe throw in some randomness factor, but that's about it. These are usually games where you cannot make "mistakes". It's either you progress or not, and what matters is just how fast you are.
2. Logic - sometimes the move you take out of several optional moves might influence the game further down the road, or it might give you more points. For example, take Bejewelled - you might have one move that will get rid of 3 jewels, but you might have another move which will free you of 5 jewels. Basically you should be aiming for the latter (I made a simplification here but never mind that now). You can then make a "stupid" CPU that picks the "wrong" move in some probability, and this probability is your tool for making it more or less stupid. In games like chess there is a "blunder" effect where the CPU makes one mistake during the game and you should take advantage of it.
Like I said before, it all depends on the game. Think about the game and think how a weak player is likely to play - what will be the characteristic of their game? will they be slower? do stupid things? and then, when you have it, try to implement it :-)
Anyway, once you have the algorithm for finding "the next move" you can limit it (thus creating "levels" of the CPU) by several tactics:
1. Time - there are games in which the competition is time based. In this kind of games all you need to do is simply delay the CPU answer; maybe throw in some randomness factor, but that's about it. These are usually games where you cannot make "mistakes". It's either you progress or not, and what matters is just how fast you are.
2. Logic - sometimes the move you take out of several optional moves might influence the game further down the road, or it might give you more points. For example, take Bejewelled - you might have one move that will get rid of 3 jewels, but you might have another move which will free you of 5 jewels. Basically you should be aiming for the latter (I made a simplification here but never mind that now). You can then make a "stupid" CPU that picks the "wrong" move in some probability, and this probability is your tool for making it more or less stupid. In games like chess there is a "blunder" effect where the CPU makes one mistake during the game and you should take advantage of it.
Like I said before, it all depends on the game. Think about the game and think how a weak player is likely to play - what will be the characteristic of their game? will they be slower? do stupid things? and then, when you have it, try to implement it :-)
Dubito, Cogito ergo sum.
Thanks for the answer.
As for 'Mahjong' the order of the 'stone-pairs' matters, because each pair-type has a certain value and the points are calculated by :
points = points + <stone-pair-value> x <numer-of-remaining pairs>
So its important to play pairs with higher values first.
In 'Mahjong' there are 72 pairs of stones. So obviously there too many moves to calculate for finding the best solution. So the algorith needs to discard some moves dpwn the path.
I know that each game hast its own special charateristic which i need to 'research'.
I was thinking if NN or genetic algorithms could be usefull tools here.
As for 'Mahjong' the order of the 'stone-pairs' matters, because each pair-type has a certain value and the points are calculated by :
points = points + <stone-pair-value> x <numer-of-remaining pairs>
So its important to play pairs with higher values first.
In 'Mahjong' there are 72 pairs of stones. So obviously there too many moves to calculate for finding the best solution. So the algorith needs to discard some moves dpwn the path.
I know that each game hast its own special charateristic which i need to 'research'.
I was thinking if NN or genetic algorithms could be usefull tools here.
I wouldn't say genetic algorithms are a good way to find the best solution really. In every step you have some choices to choose from, and the choice you make obviously change all the rest; Genetic algorithms could for example order your pairs, but this order must also be feasible to actually remove from the board. The probability of getting a random order that is a valid order for a given board is very, very slim, thus most of the chromosomes would be invalid and GA won't really be useful.
A neural network is based on some inputs and gives some outputs, usually a single output though it can be parameterized; I can't see any way you could use NNs in a Mahjongg case as well.
For starters, if you just pick the highest pair, you have a basic CPU player. If you look one step ahead the tree shouldn't be TOO big, and it is feasible for a CPU and quite hard for a human player to calculate. A depth of three or more steps might be a very strong CPU player. You would need to use a minmax approach in order to minimize the human player's score while maximizing the CPU score. If you take the best solution in a depth of 5, for example, you'll have a very strong CPU player. Then you can play with second best solution, or a lesser solution, in order to control the level of the CPU.
A neural network is based on some inputs and gives some outputs, usually a single output though it can be parameterized; I can't see any way you could use NNs in a Mahjongg case as well.
For starters, if you just pick the highest pair, you have a basic CPU player. If you look one step ahead the tree shouldn't be TOO big, and it is feasible for a CPU and quite hard for a human player to calculate. A depth of three or more steps might be a very strong CPU player. You would need to use a minmax approach in order to minimize the human player's score while maximizing the CPU score. If you take the best solution in a depth of 5, for example, you'll have a very strong CPU player. Then you can play with second best solution, or a lesser solution, in order to control the level of the CPU.
Dubito, Cogito ergo sum.
I implemented now a different approach which results surprised me very.
I did the most simple way you can do, i just calculated the possible moves and picked one by random, played it and so on. After some 10000 iterations i had some very good results which i saved. So last night i had another idea to improve my random algo and i implemented it and indeed the results got much more improved:
After finding the "best" moves after a vertain number of iterations, i took the best moves and searched for better moves along the "best moves". So you can say i search for better moves near my "best moves" and i got even better results.
You cannt say that what i did belongs really to "AI", so thats why i asked if some known AI-algorithms could help here to get even better results.
I did the most simple way you can do, i just calculated the possible moves and picked one by random, played it and so on. After some 10000 iterations i had some very good results which i saved. So last night i had another idea to improve my random algo and i implemented it and indeed the results got much more improved:
After finding the "best" moves after a vertain number of iterations, i took the best moves and searched for better moves along the "best moves". So you can say i search for better moves near my "best moves" and i got even better results.
You cannt say that what i did belongs really to "AI", so thats why i asked if some known AI-algorithms could help here to get even better results.
Well, AI is anything that makes the computer seem like a "thinking machine". It doesn't mean that you necessarily have to use some buzzword like GA/NN/Fuzzy logic/etc - it means that the end result should make the player think they're playing against a thinking machine and not against some dump random picker.
Think of it this way - Half Life for example (the first game) was considered a gem as far as AI was involved (among other things). The soldiers were taking cover, calling for help and so on. If you'll check you'll see that the whole team strategy topic is being learned, analyzed and played with. However, in the actual HL game, all of it was purely scripted. This means their AI was basically an If-Then system - if something happens, do this; if something else happens, do that; and so on! Now, this might be considered as a "fake AI" to some - but the end result was great.
So what is AI? does it mean you have to use some complex method to achieve the same result, and only then will it be AI, or does it mean you just have to get to the result as efficiently as possible?
What you did is actually in the general line of genetic algorithms - you have several ways to go through (let's say chromosomes), and then you start checking each of them out, trying to improve them (mutations?). Throw in the mating part and you have implemented a basic GA. It might just happen that the mating part is infeasible or simply ruining the good result - so just stay at random and mutations, if it gets you good results.
Think of it this way - Half Life for example (the first game) was considered a gem as far as AI was involved (among other things). The soldiers were taking cover, calling for help and so on. If you'll check you'll see that the whole team strategy topic is being learned, analyzed and played with. However, in the actual HL game, all of it was purely scripted. This means their AI was basically an If-Then system - if something happens, do this; if something else happens, do that; and so on! Now, this might be considered as a "fake AI" to some - but the end result was great.
So what is AI? does it mean you have to use some complex method to achieve the same result, and only then will it be AI, or does it mean you just have to get to the result as efficiently as possible?
What you did is actually in the general line of genetic algorithms - you have several ways to go through (let's say chromosomes), and then you start checking each of them out, trying to improve them (mutations?). Throw in the mating part and you have implemented a basic GA. It might just happen that the mating part is infeasible or simply ruining the good result - so just stay at random and mutations, if it gets you good results.
Dubito, Cogito ergo sum.
I am distinguishing between being "smart" and "brute-force".
Obviously what i did was brute-force with a little bit smartness (searching for moves around the best solution). I was hoping to find a smart-algorithm to help me to reduce the number of "useless" moves which are processed during the random moves algorithm. Maybe the way i use "randomness" -> could Monte-Carlo simulation help here ?
Even if each game has its own special rules and behaviour, usually most games share the same complexity and "nature" so one can sum games into similar group. By finding a "group" then one could use known algorithms on them to solve the problem. I know that what i am wriiting here is very general, i just try to find some structured methods to solve the games instead of just using random moves.
Obviously what i did was brute-force with a little bit smartness (searching for moves around the best solution). I was hoping to find a smart-algorithm to help me to reduce the number of "useless" moves which are processed during the random moves algorithm. Maybe the way i use "randomness" -> could Monte-Carlo simulation help here ?
Even if each game has its own special rules and behaviour, usually most games share the same complexity and "nature" so one can sum games into similar group. By finding a "group" then one could use known algorithms on them to solve the problem. I know that what i am wriiting here is very general, i just try to find some structured methods to solve the games instead of just using random moves.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement