Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To answer your second question:</p> <blockquote> <p>now how can i make the computer choose that the next best option is...</p> </blockquote> <p>This is the task of the minimax algorithm. It peeks the best move from the game-tree. For tic-tac-toe you don't need a very sophisticated evaluation function, it's enough to return a positiv or negativ value <strong>if a player has won</strong> or 0 otherwise. If you like, you can extend it by evaluating if one player <strong>can win in the next move</strong>. More sophisticated evaluation functions you need in games with a greater branching factor and where the game-tree can get much deeper (not only 9 moves).<br> My experience<sup>*</sup> was, that going one ply deeper in game-tree search yields to better results than not reaching this ply (in the same time) because of a smarter evaluation function. It's not so easy to distinguish between deeper searches because of a simple evaluation or not so deep searches because of a sophisticated evaluation. There are a lot of other significant enhancements to the minimax algorithm which are promising, don't get stuck with a complicated evaluation, first think of:</p> <ul> <li><a href="https://chessprogramming.wikispaces.com/Alpha-Beta" rel="nofollow">Alpha-Beta Pruning</a></li> <li><a href="https://chessprogramming.wikispaces.com/Iterative+Deepening" rel="nofollow">Iterative Deepening</a></li> <li><a href="https://chessprogramming.wikispaces.com/Transposition+Table" rel="nofollow">Transposition Table</a></li> </ul> <p>After then you still can improve the evaluation function. Some other thoughts to the evaluation: Maybe it's better to do some work in the function <code>makeMove</code>, here you only need to check one (instead of all) row, one column and one or two diagonals. Then, beside the current board, keep the information got from this check. This information includes, if this was a winning move (set the score), or if the next move from the other player is forced (remember the move the next player has to make, <code>getMoves</code> will only return this one). Last but not least, if one column/row and one diagonal includes a forced move, the player wins in two moves (keep the score).</p> <p>Good luck with your evaluation function!</p> <p><sub>* Some time ago I worked on the evaluation function of a Connect-Four-Game-Engine. The best approach for evaluating a connect-four board was to analyze the odd and even threats as descibed in the chapter "Threat Analysis" of the articel <a href="http://homepages.cwi.nl/~tromp/c4.html" rel="nofollow">Expert Play in Connect-Four</a> from James D. Allen. The algorithm analyzed major and minor threats. After removing the minor threat analisis part, the alpha-beta search performed better!</sub></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload