Game Tree Search Technology Introduction:
Game Tree Search algorithm, negative value of the great search, Alpha-beta search, eager to search, PVs very narrow window search and so on. Often, search algorithms are often combined with the following technologies.
As follows:
1. Replace the table, record the game already searched, avoid searching again.
2. Eat the child inspiration, priority to try to eat the other pieces of the way.
3. Killer inspired, history inspired simplified version.
4. Historical inspiration, give priority to the comparison of historical statistics to get a better approach.
5. Stationary search, continue to search some leaf nodes, avoid the horizontal effect.
6. Iterate to deepen the search, based on the search time, status. Decide whether to continue the search.
Interested friends can delve into the above techniques and algorithms.
Eating sub-chess search algorithm:
The initial implementation of my program uses the negative value of the search algorithm, then uses the Alpha-beta search algorithm, and later using the PVs very narrow window search algorithm.
In my own implementation, there is no use of permutation tables, historical inspiration and other techniques. It is because of the relatively small number of walking in each layer of the eating chess, so it is not used.
But we know that these technologies can greatly improve the search efficiency.
Eat son chess search algorithm Source:
Next, look at the source code of the Eating Chess search algorithm:
Negative value maximal algorithm
int Cnegamaxengine::negamax (int depth) {int currentmaxscore = -20000;//init value Mini int score; int nextmovecount; int overnum = Isgameover (curposition, depth); if (overnum! = 0) return overnum; if (depth <= 0) return m_peval->eveluate (Curposition, (m_nmaxdepth-depth)% 2); Nextmovecount = M_pmg->createpossiblemove (curposition, Depth, (m_nmaxdepth-depth)% 2); for (int i = 0; i < Nextmovecount; i++) {Makemove (&m_pmg->m_movelist[depth][i], (m_nmaxdepth-depth) % 2); Score =-negamax (depth-1); Unmakemove (&m_pmg->m_movelist[depth][i]); if (score>currentmaxscore) {currentmaxscore = score; if (depth = = m_nmaxdepth) {m_cmbestmove = m_pmg->m_movelist[depth][i]; }}} return currentmaxscore;}
alpha-beta algorithm
int Calphtbetaengine::alphabeta (int depth,int alpha, int beta) { int score; int nextmovecount; int overnum = Isgameover (curposition, depth); if (overnum! = 0) return overnum; int whoturn = (m_nmaxdepth-depth)% 2; if (depth <= 0) return m_peval->eveluate (curposition, Whoturn); Nextmovecount = M_pmg->createpossiblemove (curposition, depth, whoturn); for (int i = 0; i < Nextmovecount; i++) { makemove (&m_pmg->m_movelist[depth][i], whoturn); Score =-alphabeta (depth-1,-beta,-alpha); Unmakemove (&m_pmg->m_movelist[depth][i]); if (Score>alpha) { alpha = score; if (depth = = m_nmaxdepth) { m_cmbestmove = m_pmg->m_movelist[depth][i]; } } if (Alpha >= beta) break; } return Alpha;}
PVS algorithm:
int cpvs_engine::P rincipalvariation (int depth, int alpha, int beta) {int score; int Count, I; BYTE type; int best; i = Isgameover (curposition, depth); if (i! = 0) return i; if (depth <= 0)//leaf node take valuation return M_peval->eveluate (Curposition, false); Count = M_pmg->createpossiblemove (curposition, Depth, (m_nmaxdepth-depth)% 2); Makemove (&m_pmg->m_movelist[depth][0], (m_nmaxdepth-depth)% 2); Best =-principalvariation (Depth-1,-beta,-alpha); Unmakemove (&m_pmg->m_movelist[depth][0]); if (depth = = m_nmaxdepth) M_cmbestmove = m_pmg->m_movelist[depth][0]; for (i = 1; i<count; i++) {if (Best < Beta) {if (Best > Alpha) Alpha = Best; Makemove (&m_pmg->m_movelist[depth][i], (m_nmaxdepth-depth)% 2); Score =-principalvariation (depth-1,-alpha-1,-alpha); if (Score > Alpha && score < Beta) {best =-principalvariation (Depth-1,-beta,-score); if (depth = = m_nmaxdepth) M_cmbestmove = m_pmg->m_movelist[depth][i]; } else if (Score > Best) {best = score; if (depth = = m_nmaxdepth) M_cmbestmove = m_pmg->m_movelist[depth][i]; } unmakemove (&m_pmg->m_movelist[depth][i]); }} return best;
Man-Machine game-eating chess game (four) search algorithm