develop
huangjielun 3 years ago
parent 2e4d5c1bab
commit c9cfd6321d

@ -0,0 +1,41 @@
import main
import math
'''
// 负极大值算法
int negamax(GameState S, int depth, int alpha, int beta) {
// 游戏是否结束 || 探索的递归深度是否到边界
if ( gameover(S) || depth == 0 ) {
return evaluation(S);
}
// 依据预估(历史, 经验)对可行步, 进行排序
sort (candidate list);
// 遍历每一个候选步
foreach ( move in candidate list ) {
S' = makemove(S);
value = -negamax(S', depth - 1, -beta, -alpha);
unmakemove(S')
if ( value > alpha ) {
// alpha + beta剪枝点
if ( value >= beta ) {
return beta;
}
alpha = value;
}
}
return alpha;
}
'''
def h(State):
return 0
def negaMax(State,depth,alpha,beta,moveList):
if depth == 0:
return h(State)
moveList=sorted(moveList)
for move in moveList:
newState = State#update state
value = -negaMax(newState,depth - 1,-beta,-alpha)

@ -2005,7 +2005,6 @@ def main():
status = 0 status = 0
elif demo == 1 and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1: elif demo == 1 and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1:
counterpart_id = player.id counterpart_id = player.id
print(turn,counterpart_id)
counterpart_old_x , counterpart_old_y = Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y'] counterpart_old_x , counterpart_old_y = Axis.axis[counterpart_id]['old_x'],Axis.axis[counterpart_id]['old_y']
counterpart_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y'] counterpart_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y']
if counterpart_id == 1 and turn == 0: if counterpart_id == 1 and turn == 0:
@ -2134,6 +2133,9 @@ def main():
r_elephant.x , r_elephant.y = init.tran(counterpart_x,counterpart_y) r_elephant.x , r_elephant.y = init.tran(counterpart_x,counterpart_y)
turn = (1-turn) turn = (1-turn)
player.invalid = 0 player.invalid = 0
elif demo == 2:
pass
draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion, draw_window(l_elephant, l_eagle, l_wolf, l_lion, l_leopard, l_mouse, l_fox, r_elephant, r_eagle, r_wolf, r_lion,
r_leopard, r_mouse, r_fox, id, x, y, status, MAP, MAP1, turn) r_leopard, r_mouse, r_fox, id, x, y, status, MAP, MAP1, turn)

Loading…
Cancel
Save