Home | About | Account | Forums | Games
Guest   | Login
  Index  | Recent Threads  | Register  | Search  | Help  | RSS feeds  | View Unanswered Threads  
  Search  


Quick Go »
Thread Status: Normal
Forum Status: Locked
Total posts in this thread: 8
[Add To My Favorites] [Watch this Thread]
Author
Previous Thread This topic has been viewed 6648 times and has 7 replies Next Thread
br261330
Stranger



Joined: Mar 24, 2007
Posts: 10
Status: Offline

How to write a computer player (AI)?

Hi, I am totally lost at how you can write an AI for a game. Could anybody tell me how to start (e.g. with Reversi)?

What surprises me is that the example "atlantis" has an option to play against AI, but I cannot find any code related to AI. The only thing I can find is the <ai> tag in the xml description. Does the GG framework provide a default AI that moves randomly???

Thanks for any help. - Ben
[Nov 3, 2007 12:13:55 PM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
tcarr
Advanced Member



Joined: Jun 3, 2004
Posts: 362
Status: Offline

Re: How to write a computer player (AI)?

The code goes in your Manager (or in a class that is invoked from your manager). In the Atlantis code, look at AtlantisManager's turnDidStart method. This gives the code that is run if the current player is a bot.

I use AI bots in GCPP Nibbler but players do not take turns. I have an array for multiple AIs, so I do this:

if (isAI(playerID))
_bots[playerID].makeMoves(_teamBoard);

I have a NibblerBot object class, and the _bots array holds one NibblerBot object for each of my bots.
[Nov 3, 2007 3:19:51 PM] Show Printable Version of Post        Send Private Message    http://www.frontiernet.net/~otherwhen/ [Link]  Go to top 
br261330
Stranger



Joined: Mar 24, 2007
Posts: 10
Status: Offline

Re: How to write a computer player (AI)?

Thanks a lot. :-) That was not easy to find. My Reversi AI works at last.

Now, if I wrote a lot of AIs for my game, is there a way to setup a kind of tournament? I think of two approaches, each having an obstacle to overcome:

1. Server based AIs: It looks like you cannot create a table with only AIs playing. You have to play yourself. A work around would be to configure the game as to be a 3-player game and then ignore the input from the human player. But that is very ugly, indeed. Any other ideas?

2. Client based AIs: It seems impossible to setup an AI client. I spent several hours of crawling through all the client code. It is very hard to call the directors and services directly without the help of any GUI. Has anybody tried and succeeded in that?

I look forward to any helpful post.

Ben
[Nov 4, 2007 5:25:55 AM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
tcarr
Advanced Member



Joined: Jun 3, 2004
Posts: 362
Status: Offline

Re: How to write a computer player (AI)?

You need to be able to report what the AIs do, right? So the human client would need some type of display, showing what the AIs have done.

You can have the single human client include all the AI code. I did that with Feasting because I wrote that game before I had a solid grasp on how the GameGardens AIs work, and also because the AI for Feasting needs about 10ms to determine each move which is a bit of a strain on the server.

If all you want is the AIs running, and reporting to you..... why bother to do it on GameGardens? Just do it in a normal Java applet. However, if you want it on GameGardens it can be done. /e rummages for Feasting code.....

ok, my Feasting AI opponent is an object that is local to the BoardView. I have a ticker running, and each second it checks to see if the AI is allowed to move yet (the Manager sets a variable on the game object). Feasting doesn't do turn taking, but after you make your move you have to wait to make your next move unless your opponent makes one. Anyway, if the AI is allowed to make a move, then a method is called to pick a random valid move to make - all on the client side. The bot's move is sent to the server using a method in Manager that is similar to that invoked when a human makes a move.

If this doesn't give you enough details let me know. The Feasting code isn't very pretty (but it was a great learning experience).
[Nov 4, 2007 10:44:32 AM] Show Printable Version of Post        Send Private Message    http://www.frontiernet.net/~otherwhen/ [Link]  Go to top 
RazaHel
Stranger
Member's Avatar


Joined: Sep 11, 2006
Posts: 18
Status: Offline
Re: How to write a computer player (AI)?

Hi,

I have written a small 3 player game and I wanna make the third player an Ai.
The thing is the Ai should run on one client and should also be abale to send information to the server. Is there an easy way to do so instead of creating a shared object which runs its calculation on the server?


kind regards
RazaHel

BTW: I know this thread is kind'a old, but the topic isn't ;)
[Aug 11, 2008 11:40:43 AM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
br261330
Stranger



Joined: Mar 24, 2007
Posts: 10
Status: Offline

Re: How to write a computer player (AI)?

Hi RazaHel,

I finally succeeded in what I wanted to do, and it seems that you want to do the same: Having an AI playing as a client without the server knowing this client to be an AI.

But: My code is neither nice nor easy. If want to try, then look at my sources. Maybe they are a little help to get started:

http://rapidshare.com/files/136773770/ai-client.zip

Kind regards, Ben
[Aug 12, 2008 6:25:33 AM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
RazaHel
Stranger
Member's Avatar


Joined: Sep 11, 2006
Posts: 18
Status: Offline
Re: How to write a computer player (AI)?

Hmm my case is a little different. Because the server can know that this is an AI, but all other clients should not know it.
But thanks for the code I will look into it.

regards RazaHel
[Aug 14, 2008 8:09:02 AM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
helfan
Stranger



Joined: Aug 25, 2009
Posts: 12
Status: Offline

Re: How to write a computer player (AI)?

i am very happy that you got the solution of you problem.
[Aug 27, 2009 9:39:59 PM] Show Printable Version of Post        Send Private Message [Link]  Go to top 
[Show Printable Version of Thread]

Home | About | Account | Forums | Games           ©2005 Three Rings Design, Inc