简体   繁体   English

在Prolog中实现alpha beta修剪

[英]Implementing alpha beta pruning in Prolog

I'm developing the game Teeko in Prolog and I try to implement alpha beta pruning but I do not know where to start. 我正在开发Prolog中的Teeko游戏,我尝试实现alpha beta修剪,但我不知道从哪里开始。 Could someone please guide me? 有人可以指导我吗? I have already found the minimax algorithm. 我已经找到了minimax算法。

I try to implement alpha beta pruning but I do not know where to start. 我尝试实现alpha beta修剪,但我不知道从哪里开始。

Could someone please guide me? 有人可以指导我吗?

I have already found the minimax algorithm. 我已经找到了minimax算法。

The short look into alpha beta pruning algorithm 简要介绍alpha beta修剪算法

Choosing a move using minimax with alpha-beta pruning 选择使用minimax进行alpha-beta修剪的移动

The new relation scheme is alpha_beta( Depth, Position, Alpha, Beta, Move, Value ) , 新的关系方案是alpha_beta( Depth, Position, Alpha, Beta, Move, Value )

which extends minimax by replacing the minimax flag with alpha and beta. 通过用alpha和beta替换minimax标志来扩展minimax。 The same relation holds with respect to evaluate_and_choose . evaluate_and_choose相同的关系成立。

The program can be generalized by replacing the base case of alpha_beta by a test of whether the position is terminal. 通过测试位置是否为alpha_beta ,可以通过替换alpha_beta的基本情况来推广该程序。 This is necessary in chess programs, for example, for handling incomplete piece exchanges. 这在国际象棋程序中是必要的,例如,用于处理不完整的棋子交换。


evaluate_and_choose ( Moves, Position, Depth, Alpha, Beta, Record, BestMove )

  • Chooses the BestMove from the set of Moves from the current 从当前的Moves集中选择BestMove

  • Position using the minimax algorithm with alpha-beta cutoff searching 使用minimax算法定位 alpha-beta截止搜索

  • Depth ply ahead. 深度领先。

  • Alpha and Beta are the parameters of the algorithm. AlphaBeta是算法的参数。

  • Record records the current best move. 记录当前最佳动作。


evaluate_and_choose([ Move | Moves ], Position, D, Alpha, Beta, Move1, BestMove ) :-
    move( Move, Position, Positionl ),
    alpha_beta( D, Positionl, Alpha, Beta, MoveX, Value ),
    Value1 is -Value,
    cutoff( Move, Value1, D, Alpha, Beta, Moves, Position, Move1, BestMove ).

evaluate_and_choose( [], Position, D, Alpha, Beta, Move, ( Move, Alpha )).

alpha_beta( 0, Position, Alpha, Beta, Move, Value ) :- 
    value( Position, Value ).

alpha_beta( D, Position, Alpha, Beta, Move, Value ) :- 
    findall( M, move( Position, M ), Moves ),
    Alphal is -Beta,
    Betal is -Alpha,
    D1 is D-l,
    evaluate_and_choose( Moves, Position, D1, Alphal, Betal, nil, ( Move, Value )).


cutoff( Move, Value, D, Alpha, Beta, Moves, Position, Movel, ( Move,Value )) :- 
    Value > Beta.
cutoff(Move, Value, D, Alpha, Beta, Moves, Position, Movel, BestMove ) :- 
    Alpha < Value, Value < Beta,
    evaluate_and_choose( Moves, Position, D, Value, Beta, Move, BestMove ).

cutoff( Move, Value, D, Alpha, Beta, Moves, Position, Movel, BestMove ) :- 
    Value < Alpha,
    evaluate_and_choose( Moves, Position, D, Alpha, Beta, Move1, BestMove ).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM