OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 2:11 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Playing against computer... How to program?
PostPosted: Mon Dec 09, 2002 6:56 am 
Let's start with a simple example... Playing 21
If you want to make this game, it's quite simple to play against the computer... You could say for example, that the computer asks to draw a new card until he has 16...

But if you want to make "connect 4" for example... How would you do that? You could make a program so that the computer just stops you from connecting 4 coins. But if you want to make it good, you would have to make the computer 'think ahead', so that the computer connects 4 coins. Does anyone here knows how to calculate the best next step?

Actually I'm more interessed in calculating the best next step for the computer in the game Colony. Download here (this is legal)

I'm trying to make that game, but the hardest (and most needed) thing to program, is to calculate the best next step...

There's probably a lot of mathematics involved, but that's ok, I'll try to understand :)


Top
  
 
 Post subject: Re:Playing against computer... How to program?
PostPosted: Mon Dec 09, 2002 8:33 am 
Ok, just talked to a friend of mine about Connect 4.
He says there's an algorithm to calculate the next step... BUT, if the computers can take the first step, he can't be defeated (you can proove that with maths).

But still, if anyone knows the algorithm for Colony, please tell me!!!


Thanks


Top
  
 
 Post subject: Re:Playing against computer... How to program?
PostPosted: Mon Dec 09, 2002 8:42 am 
Ok, talking to myself... ::) but I found this link:
Combinatoric Algorithms

- Jellebelle


Top
  
 
 Post subject: Re:Playing against computer... How to program?
PostPosted: Mon Dec 09, 2002 10:12 am 
well basically i m not sure m i answering u or just telling u something .. either ways its good so i was thinking that i dont know which game r u talking about and wat r the rules in it ..
u know how to win in this game and how to lose .. now on every computer move u can check that if it is possible that can computer win this game by making that usual winning move ...if yes then just do it .. if not then check if the computer is losing this game from any side .. if yes then first try to undo that .. if not then u can look for any situation ..
even i m not sure about all this .. ;D


Top
  
 
 Post subject: Re:Playing against computer... How to program?
PostPosted: Mon Dec 09, 2002 10:52 am 
I guess I would try it the same way. Make as many if- and while loops as possible to recognise every possible event. I don't know about algorithms really, though. But imagine a game like connect 4, I would make it so that the computer goes through every possible move and analyses what the opponent could do, until he realises a possibility where the player would not be able to win in a set number of moves (one for easiest game then, five for very hard etc...). If the computer knows it can't do this, it tries to do the next best positioning, such as that the player would need four more moves to win on very hard difficulty. If the computer knows the player is going to win he will just set a stone anywhere.

However, I also heard of an early chess program where that went a bit wrong... the result was that the computer made a very easy plan on how to win, not taking all options into account and thinking very short-sightedly. The player made an unexpected move, the computer was confused and sacrificed one figure after another because that would give him the chance to keep his most important figure longer instead of just making up another tactic... ;D


Top
  
 
 Post subject: Re:Playing against computer... How to program?
PostPosted: Mon Dec 09, 2002 12:36 pm 
AI is such an in-depth concept that entire libraries and University programs are dedicated to it. Game AI is complex, but a necessarily limited form of AI. A few things should be taken into consideration.

1) Game AI does NOT act like a real player. This is both too involved and actually provides for less "realistic" AI.
2) Game AI should intentionally make mistakes and other erratic behavior, otherwise it is unbeatable.
3) Game AI should always be as streamlined as possible to meet the speed demands of the game.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 35 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group