• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
t3685

Best practice needed for implementing an AI for a turn-based game

6 posts in this topic

Hi,

 

 

I am dabbling into game making by implementing a boardgame (Hive) I have at home. I am doing this in C++ (with Qt) and have more less the basics I need for a player vs player game.

 

I will now try to make an AI for the game, but I've come to face with a couple of decisions and I wonder whether you guys could give me some advice?

 

My question boils to the fact whether I should make a separate "board" for the AI to evaluate and test its moves or to use some kind of undo function (so make all the moves and then move all the pieces to their original position).

 

Making a separate move does not appeal to me because it involves making deep copies of the objects (I only keep pointers to them, and the game logic depend on the pointers in lists). However, using an "undo" function, requires me to tell the game the AI is thinking, because right now any change to the internal game causes the GUI part to move as well.

 

What is common practice in this case?

 

Thanks in advance,

 

t3685

1

Share this post


Link to post
Share on other sites

Your game state should be fairly simple to encapsulate; if it isn't, you should do that before you attempt any sort of AI. The complete representation of a board game's state should be a simple, relatively shallow object (ie. containing at most some arrays of basic data types) with a copy constructor.

 

For instance, a checkers game can at its simplest be represented with three 32-bit fields; the 8x4 valid board positions is 32 places, and the three fields store black's pieces, red's pieces, and kinged pieces. Your AI will need this "gamestate" object to evaluate options, and if your AI is recursive (some not-mutually-exclusive alternatives being strategy-based, heuristic-based, and table-based; but you can combine all four types easily) it will need to make at least one copy of this gamestate to recurse upon and evaluate its choices.

1

Share this post


Link to post
Share on other sites
If you are going to use some sort of adversarial search (minimax/alphabeta + extensions, etc) then it is common to have an undo move. This is because adversarial search is expensive and the cost of recreating the board for each node is higher than applying a move/undo on a single board
0

Share this post


Link to post
Share on other sites
Having an `undo move' doesn't mean that you do the thinking on the same board structure that you use to represent the position to display to the user, and I actually don't recommend you do it that way: Whatever representation is convenient for displaying might not be optimal for the AI, so I would allow them to be different.

The best architecture I know for this problem is what chess programs have settled for after many years: The GUI and the AI (a.k.a., the "engine") run on separate processes, which communicate via a simple text-based protocol. This allows interoperability between GUIs and engines, so people can pick whatever combination suits them. It also makes debugging much easier, and you can easily run automated matches between engines by using a program that pretends to be the GUI, as far as the engines are concerned. Check out the Universal Chess Interface specification, to get a feel for what the protocol looks like (there is a competing protocol to use with XBoard, but I really don't like it).

Even if you don't go all the way to separating the AI into its own process, you should clearly specify what the interface to the AI is, and have the AI have its own copy of the board.

I should mention that besides minimax and its variations, there is another major class of algorithms that can be used for board games, generically known as Monte Carlo Tree Search. MCTS has been developed in the last decade and is currently the best approach to computer go and to several other games (I believe it's particularly well suited to connectivity games like hex).

One thing that makes MCTS very interesting to me is that it works well with a much larger class of games than minimax: It can take multiple players, games with randomness and games with simultaneous decisions with no problem, while these things are pretty much show stoppers for minimax. Dealing with hidden information is trickier, but even that can be accommodated.

I have heard of Hive, although I have never played it. So I don't know if MCTS is appropriate for this game or not.
2

Share this post


Link to post
Share on other sites
Álvaro makes some very good points about architecting your AI.<br /><br />It certainly would be interesting to see how MCTS stacks up to minimax for Hive. Having played Hive, my gut feel is that minmax would still be preferable in this instance because the branching factor is not too large to be prohibitive (something that MCTS tends to handle better), but more importantly Hive can have quite tight tactical lines and I think this is the one area that MCTS can fall down in (one of the reasons MCTS hasn't stood up well to minimax in games like chess and arimaa).
1

Share this post


Link to post
Share on other sites
Thanks for the advice guys. I will make a separate board object for the AI to work on. I'll probably do this by updating this object while updating the real board. Making a copy constructor is rather messy, because I have lists of pointers (for convenience sake) as data members. I will also implement a "undo" function (shouldn't be too hard :)).

I haven't thought it through, but I inclining toward minimax right now (that's the one they use for chess right? [edit: yes, yes it is]). From what I understand of Monte Carlo methods is that they can fickly in terms of parameters of the randomness. I'll keep you guys posted :) Edited by t3685
0

Share this post


Link to post
Share on other sites
One thing that I guess should have been mentioned as a big difference between MCTS and minimax is that minimax relies upon a good evaluation function and MCTS doesn't. This is the reason why MCTS excels in GO where it is difficult to evaluate a board position. I'm not sure what a good evaluation fucntion is going to be for hive (besides the obvious # pieces surrounding queen). Something to think about.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0