Game design : Making computer play

Richard Heathfield rjh at see.sig.invalid
Mon Apr 14 03:35:09 EDT 2008


v4vijayakumar said:

> In computer based, two player, board games, how to make computer play?

Write some code that works out what the computer player should do. If you 
want a better answer, ask a better question.

> Are there any formal ways to _teach_ computer, to choose best possible
> move?

That's a better question. The obvious ways are DFS, BFS, and databases.

For example, take backgammon, and computer goes first. You roll the PRNGs 
and get 6, 1. You (the computer) have never played this game before, so 
you don't have a database of good moves. Your legal moves are:

24,18 and 24,23
24,18 and 8,7
24,18 and 6,5
13,7 and 24,23
13,7 and 8,7
13,7 and 6,5

Of these, which is the best? DFS (Depth-First Search) and BFS 
(Breadth-First Search) can help you answer that question. What you do is 
define an evaluation function for the position, based on things like how 
many blots, how many on the bar, whether you have a prime, and so on. Then 
you *play the game* in simulation, as deeply as you can (which won't be 
very deep, actually), evaluating all the time. Once you've found the 
position that does you most good (or least harm) no matter what die-rolls 
the opponent may get and no matter how skilfully he or she plays, you know 
what to get your computer player to do next.

If you're clever, you'll keep the solution tree around, destroying only the 
bits of it that won't ever be used again - to save processing time on your 
next turn.

If you're really clever, you'll write a lot of this information down in a 
file, a sort of opening "book", so that you don't have to calculate 
everything from scratch every time. For example, in the above situation, 
there is no need to calculate, because it's a no-brainer: 13,7 and 8,7 is 
far and away the best move.

> I know this is kind of off-topic here. Please redirect me, if there
> are more appropriate newsgroup.

comp.programming is probably where you want to be, at least to start off 
with.

-- 
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999



More information about the Python-list mailing list