ideas regarding artificial intelligence in simple game (for ex : Tic Tac Toe) C++ [closed]
i have totally no idea regarding making artifi开发者_运维知识库cial intelligence in a game (i am going to apply it on a simple Tic Tac Toe game)
my current idea is to make an array of possible options to win the game (like 3 X in row 1 = win or something) and then makes the computer try to fill the grid with one of the arrays, but how to choose the most appropriate option from others, and how to make it smart/stupid (difficulties) if possible i need an algorithm to use, and if possible a book that fills the gap in my brain =P
Best Regards
Check out the wikipedia page on Game trees, tic-tac-toe is actually used as an example.
Here's the complete solution for you:
courtesy: xkcd
Tic-Tac-Toe is a type of Zero-sum game and the "common" approach to such games is the Minimax algorithm. It's very efficient and fast, especially when combined with a good heuristic function.
There are some good C++ implementation of Minimax for Tic-Tac-Toe.
Update
Despite the fact that search algorithms such as Minimax fall under the AI algorithms category, I don't really consider them to be AI algorithms. I consider Minimax to be efficient search algorithms, so if you want an actual AI algorithm I would recommend looking into machine learning concepts such as: support vector machines, neural networks, genetic algorithms, genetic programming, etc. However, nearly all of the machine learning algorithms are going to be an overkill for the purposes of making a Tic-Tac-Toe agent/bot.
The Tic Tac Toe game is a "solved" game in Game Theory. That means there is an ability to say is one or another game situation win or lose.
I think this link might help you.
One possibility for simple games like tic-tac-toe would be brute force. If you have a winning move make it; otherwise if your opponent would have a winning move block that; otherwise consider every possible move recursively.
Look, pretty much every AI issue comes down to some sort of search. In the case of tic-tac-toe, you're searching among all the possible board positions. There are 9 cells, and 3 values, so there aer only 39 possible boards. If you generate them at the start, your search is very straightforward: start with you current position, look at all the pathways that result in a win for your side, and pick that.
精彩评论