apotapov / tafl

Android implementation of a Tafl game
Apache License 2.0
2 stars 0 forks source link

Figure out Eval Function for AI #30

Closed ghost closed 10 years ago

ghost commented 10 years ago

Eval function as linear transformation. In other words it's a sum of factors and coefficients:

a * f1( ) + b * f2( ) + ... + z * f3( )

Per http://www.gamedev.net/page/resources/_/technical/artificial-intelligence/chess-programming-part-vi-evaluation-functions-r1208, the four factors are:

f1( ) is Material Balance, i.e. number of pieces of each type. For Tafl, all the pieces are "rooks" and worth the same. While Material Balance for chess can be the Eval function for a decent AI, in Tafl this is not the case. Keeping pieces is important, but it's much more about board control and limiting the mobility of the King.

f2( ) is Board Control, i.e. moving the pieces into the most advantageous parts of the board. It is extremely important in Tafl. While Material Balance is most important in Chess, Board Control is likely the most important in Tafl. In Tafl, the best way to think about is to divide the board into quandrants by the "3rd ranks" (for a 11 x 11 board). In other words, there are four "corner quandrants", four "edge quandrants", and the "center quadrant". So, there are 9 quandrants in total. The game is all about moving the Defender pieces from "center quadrant" to the edge or corner. Once the King gets to the edge or corner quadrant, the game gets close to being over.

f3( ) is Mobility, i.e. how many good legal moves all the pieces can make at any given time. When I think about it, Mobility is much more important in Tafl than in Chess. Limiting the mobility of the Defender pieces is the key to Tafl. The entire point of the Attacker is to form a perimeter around all the Defender pieces and "squeeze" them, which is limiting mobility. Once this is done, Defender can either draw or lose, which also boils down to mobility. Mobility of the King is worth much more than that of Rooks.

f4( ) is Development, i.e. how much closer a player is inching towards favorable formations or board control. For the Defender, getting the King unblocked by its own pieces is an example. For the Attacker, it is how much closer the player is forming a perimeter around all the white pieces.

f5( ) is Formations, i.e. getting pieces into known good formations. In Chess, it's mainly about Pawn Formation. In Tafl, since all pieces are the same, formation is quite useful. For example, the "Tower formation" (four pieces forming a square) is a known protective formation where the opponent cannot take any of the pieces. For the Attacker, there are numerous "Cordon" formations, which are essentially lines of pieces side-by-side that sweep across the board. Also, there are the obvious "Barricade" formations, especially for fully protecting the corner squares.

f6( ) is King Safety and Tropism, i.e. how safe the King is from being captured and how much pressure there is on the King. In Chess, this is important, but in Tafl, overly focusing on King Safety is actually harmful. The Defender actually wants the King out as fast as possible and leading the charge. The King is by far the most powerful piece and is very hard to capture, especially if the Defender plays good formations. We should think about King Safety like the Endgame in Chess, where the King becomes a powerful piece.

Q: Where do we detect things like Pins and Forces? In other words, if there is a great move for forcing an opponent to lose MB (Material Balance) or lose a formation, shouldn't that be favored over the mere possibility of a good outcome? Is this detected by Eval function, or are these just part of the Minimax search? In other words, does the search function already favor Pins and Forces?

Q: As in Chess, opening (the first ~8 moves) is really important for Tafl, especially the Attacker. Should we implement it? It's outside the scope of the Eval function, but getting the right opening will make the Eval function much more effective and keep the AI from being stuck in some devastating local maximum early on.


For Tafl, if I sorted the six factors with highest weight to lowest weight, I think the linear combination would look like this:

a * (Board Control) + b * (Mobility) + c * (Material Balance) + d * (Formation) + e * (King Safety/Tropism) + f * (Development)

Note: I put Development last partially because I don't understand Tafl enough to know what is good development and strategically how good and important it is.