| Home | About | Account | Forums | Games |
| Guest | Login |
|
Index
| Recent Threads
| Register
| Search
| Help
| |
![]() |
Forums » List all forums » Forum: Tutorials and Help » Thread: How to write a computer player (AI)? |
|
Thread Status: Normal Forum Status: Locked Total posts in this thread: 8 |
[Add To My Favorites] [Watch this Thread] |
| Author |
|
|
br261330
Stranger
|
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 |
||
|
|
tcarr
Advanced Member
|
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. |
||
|
|
br261330
Stranger
|
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 |
||
|
|
tcarr
Advanced Member
|
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). |
||
|
|
RazaHel
Stranger Joined: Sep 11, 2006 Posts: 18 Status: Offline |
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 ;) |
||
|
|
br261330
Stranger
|
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 |
||
|
|
RazaHel
Stranger Joined: Sep 11, 2006 Posts: 18 Status: Offline |
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 |
||
|
|
helfan
Stranger
|
i am very happy that you got the solution of you problem. |
||
|
| [Show Printable Version of Thread] |
| Powered by mvnForum 1.1 dev (Build: 15 April 2006) - Copyright © 2002-2006 by MyVietnam.net |
