Converting Minimax to Negamax (python)

[亡魂溺海] 提交于 2019-12-06 06:31:04

I think now that you have implemented minimax it is good enough but you need to implement the most important optimization in minimax that is alpha-beta pruning which would be a simple change to your code with very significant improvement in speed.

EDIT:-

Noticed that you have used alpha-beta so you can implement negamax but your notion that it doesnt switch is not correct but it reduces the code for minimax ( i doubt significant improvement in speed) . The idea here is that the points for a move for one player is always -ve of the other player but same magnitude that allows you to calculate max(a,b) = -min(-a,-b).

Simple translation here is :-

score = -negamax(depth-1,-player)
best = max(score,best)

These are only lines to evaluate minimax using negamax

Here you dont need to evaluate min and max alternatively but the fact that the scores given to minplayer are always negative of positive player is sufficient so that you can always evaluate max to get correct score.

Note:-

This is not significant optimization in terms of speed but makes code simple and readable so its worth it but unfortunately you need erase alot of code to convert your code to negamax so i advice not to.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!