From c9cfd6321d090c62ee8dcb2c61f9e1938f3391e5 Mon Sep 17 00:00:00 2001 From: huangjielun <2872405629@qq.com> Date: Sat, 8 Oct 2022 12:33:19 +0800 Subject: [PATCH] No more --- src/a_b_Tree.py | 41 +++++++++++++++++++++++++++++++++++++++++ src/main.py | 4 +++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/a_b_Tree.py diff --git a/src/a_b_Tree.py b/src/a_b_Tree.py new file mode 100644 index 0000000..fa1e3ea --- /dev/null +++ b/src/a_b_Tree.py @@ -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) + + + diff --git a/src/main.py b/src/main.py index 43bd26b..fd4cc8c 100644 --- a/src/main.py +++ b/src/main.py @@ -2005,7 +2005,6 @@ def main(): status = 0 elif demo == 1 and player.id and turn != player.side and player.invalid == 1 and player.status_2 == -1: 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_x ,counterpart_y = Axis.axis[counterpart_id]['x'],Axis.axis[counterpart_id]['y'] 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) turn = (1-turn) 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, r_leopard, r_mouse, r_fox, id, x, y, status, MAP, MAP1, turn)