3若c是Mi
的胜局,则:estc例如:c
f313MaxMi
博弈过程:step1以co为根,生成2步博弈树:step2评估博弈树叶节点对应的博弈状态
fstep3进行极大极小运算MaxMi
运算Max按取最大评估值的方向行棋step4等待Mi
行棋,产生新的co返回step132五子棋机器博弈问题varmaxmi
fu
ctio
boarddeepvarbestMINvarpoi
tsge
boarddeep这个函数的作用是生成待选的列表,就是可以下子的
空位
forvari0ipoi
tsle
gthivarppoi
tsiboardp0p1Rcomvarvmi
boarddeep1尝试下一个子找最大值
如果跟之前的一个好,则把当前位子加入待选位子ifvbest
fbestPoi
tspushp找到一个更好的分,就把以前存的位子全部清除ifvbestbestvbestPoi
tsbestPoi
tspushpboardp0p1RemptyvarresultbestPoi
tsMathfloorbestPoi
tsle
gthMathra
dom在分数最高的几个位置中随机选择一个retur
result记得把尝试下的子移除
varmi
fu
ctio
boarddeepvarvevaluateboardifdeep0wi
boardretur
v评价函数,这个函数返回的是对当前局势的估分。
varbestMAX
fvarpoi
tsge
boarddeep
forvari0ipoi
tsle
gthivarppoi
tsiboardp0p1Rhumvarvmaxboarddeep1boardp0p1Remptyifvbestbestvretur
best
varmaxfu
ctio
boarddeepvarvevaluateboardifdeep0wi
boardretur
v
varbestMINvarpoi
tsge
boarddeep
fforvari0ipoi
tsle
gthivarppoi
tsiboardp0p1Rcomvarvmi
boarddeep1boardp0p1Remptyifvbestbestvretur
best
varmi
fu
ctio
boarddeepalphabetavarvevaluateboardtotalifdeep0wi
boardretur
v
varbestMAXvarpoi
tsge
boarddeep
fforvari0ipoi
tsle
gthivarppoi
tsiboardp0p1Rhumvarvmaxboarddeep1bestalphabestalphabetaboardp0p1RemptyifvbestbestvifvbetaAB剪枝ABcutbreakretur
best
varmaxfu
ctio
boarddeepalphabetavarvevaluateboardtotalifdeep0wi
board
fretur
v
varbestMINvarpoi
tsge
boarddeep
forvari0ipoi
tsle
gthivarppoi
tsiboardp0p1Rcomvarvmi
boarddeep1alphabestbetabestbetaboardp0p1RemptyifvbestbestvifvalphaAB剪枝ABcutbreakretur
best
fr