Coding AI

Status
Not open for further replies.

Dibber

Seniorius Lurkius
15
Hey everyone, long time Ars Reader but I just signed up the other day when I saw they had this new forum. So howdy.

I was wondering if anyone has any experience doing any sort of AI programming? I'm not really sure what is involved. Is it just a bunch of if/case statements? I would imagine not, especially for building a system that can learn. I'm writing a little poker app just for fun and I thought it would be neat to make a smart AI that could learn from your playing style (almost like a real poker player reading your tells) and get better, but I really have no idea where to start. Any advice, links, etc would be greatly appreciated.

Dibber
 

Catfish

Ars Tribunus Angusticlavius
9,954
Hmmmm. Totally depends on the task in hand.

If you want a system that learns, the easiest way is a neural net. These are ideally suited to pattern recognition - eg recognising a photo of someone / something, even when it hasn't seen that specific photo before, or speech recognition (which I did for my second year university project).
There was a Quake2 bot that used neural net AI - took a while to train up, and was extremely processor intensive, but worked quite well after that.
It's a fairly simple task to set up a neural net to play something like Tic Tac Toe. It's much more difficult to have it play a card game, since there are so many variables. A better way would be to give it a general style of play with symbolic AI (your if/case statements), but let the neural net handle the details.

IMO, neural nets are far more interesting to work with, and are finally becoming properly useful. Go program one, see if you can get it to recognise a photo of yourself or something. Then see if you can come up with interesting ways of wedging it into a game :)
 

Catfish

Ars Tribunus Angusticlavius
9,954
Artificial Intelligence by Elaine Rich & Kevin Knight is an overview of the field of AI, mostly from a symbolic (non neural nets) view.

Neural Computing - an introduction, by Beale & Jackson covers neural networks. It covers a lot of different techniques, and isn't bad.

Or, take a look at my 2nd year lecture notes. If you go up a directory & look at year 1, there's probably a set of notes covering basic AI, and there should be a basic neural net somewhere in there...
 

EgalitarianBovine

Ars Tribunus Angusticlavius
8,086
AI programming can use a variety of techniques to achieve what you want.

neural networks are useful for learning to recognize complex patterns.

genetic algorithms allow you to evolve good solutions for specific problem sets. While GAs are good for finding specific solutions (i.e., what's the best value that will give me the best result for this situation), they have a harder time coming up with abstract solutions to generic tasks.

there are some other methods, like swarms (which model social interactions to derive intelligent behaviour).

For a poker game, I think all you need is a good heuristic to tell your the value of your current hand, and some well-tuned functions for telling what to do given a hand with a particular value. You'll probably get much better results that way - unless you're specifically trying to use AI, not just trying to come up with a good computer poker player.

-EB
 
As has been said before, "Artificial Intelligence" is an extremely broad term, used differently in many situations.

Do your Quake bots need to be able to play chess? Did IBM need to program Deep Blue to be able to blow Gary Kasparov away with a sniper rifle? Of course not. Specialization is key, though there are many similarities.

Most AI works like this:

1. Determine your possible options.
2. Rank these options according to criteria.
3. Choose the best option and do it.

Obviously, most of the hard programming work goes into steps 1 and 2.
 

Catfish

Ars Tribunus Angusticlavius
9,954
Ummm...yeah. Like others have said, I should probably point out that AI isn't the most efficient way of programming most game routines.

But, to me at least, it's a hell of a lot more fun creating a neural net and watching it learn for itself, than just writing endless if/else statements, and figuring out algorithms to say 'do this if x^2 + y^0.9 > 3'.
 

Statik

Ars Scholae Palatinae
1,451
Well, just off the top of my head, without any AI instruction, it seems to me that you need to do two things, in software.

Determine the value of the hand being played as a numeric constant. Thus every possible hand should have a value, not necessarily unique, where better hands have better values. This is probably already standardized somewhere.

Determine the player's probability of behavior based on previously recorded behaviors for the same value of hand. From these two values, you can derrive a function that will plot the two behaviours. Here's a rough idea of the graph, in my sucky ascii code:
code:<HR>
Code:
H |.
A |..
N |..
D |...
  |....
V |.........
A |.....
L |...
U |..   
E |.
  +--------------------------
  Behaviour Probability

From there you can use your AI to determine the program's behavior.
Such as if player's probability of bluffing is > 60%, call.

I don't know much about poker, but this is one way to go about it.
 

Dibber

Seniorius Lurkius
15
The Neural Net idea is an interesting one, like I said, I'm more interested in having the program learn your playing style over time them just having a standard AI that would play the same against every person. Actually, what I would like to do (eventually), is have players log in and then the computer would play differently against them based on it's history of playing against them, and if a different player logged in, then it would play differently against them. So obviously there would have to be some mechanism for saving the information it learns about each player in some sort of useable way for later on.

I also like the idea of genetic algorithms, but I'm not sure they would apply here.

I don't know a lot about Neural nets, though. I would have no idea how to go about implementing one, so I'll have to look at some of the references you guys have been throwing out. Thanks.

Dibber
 

kuya

Ars Scholae Palatinae
881
well i'm no expert, but i do dabble a little in the forbidden art.

ai is (as was said before) a pretty broad subject. at least in its application to games, usually what it comes down to is some brute force searching with some heuristics thrown in here or there.

chess for example will basically evaluate as many possible legal moves as it can to n levels deep evaluating the moves against a certain criteria as it goes a long. if the search has time to complete (good luck, all these problems are exponential growth), then the 'best' move is selected, else the best move that you had time to search for is selected. the best move for you usually is the worst move the other player can expect in 2 player games. you may want to look into alpha beta pruning/minimax algorithms for that.

in quake and stuff, there are pathfinding algorithms abound. study on this subject goes all the way back to the 15 puzzle. (those stupid little plastic tile games where you try to arrange the numbers 1-15 sequentially in a 4x4 matrix with one empty square). A* and variants are typically the algorithms utilized here. the character's space is broken up into some graph representation (using octrees, line of sight, etc...) and then the graph is travered. A* is a dfs with heuristic that guarantees an optimal solution. usually the heuristic is some estimation that is quick to evaluate, not necessarily correct, but never overestimates the cost. ...it just so happens i'm looking into variants of A*, and permiter searching and stuff for coding a way to solve the rubik's cube.

but alas i digress...
 
Status
Not open for further replies.