【发布时间】:2016-11-07 07:21:38
【问题描述】:
我正在尝试为 connectfour 游戏编写 minimax 函数,这是我未完成的代码
minimax:: RT Board ->Int
minimax (Tree board subtrees) = case subtrees of
[] >evaluate board (get_turn board)
_ ->case get_turn board of
Player_X ->maximum (next_socres)
Player_O ->minimum (next_socres)
where next_socres = map evaluate (map get_board subtrees)
--get the node from sub trees
get_board:: RT Board -> Board
get_board (Tree board subtrees) = board
--evaluate moves(not finished)
evaluate :: Board -> Player -> Int
evaluate board me'
|[me,me,me,Blank] `isInfixOf_e` all_stone_lines = 10
|[opp,opp,opp,Blank] `isInfixOf_e` all_stone_lines = -10
|otherwise = 0
where
me = get_stone_of me'
opp = opponent' me
all_stone_lines = combine_list stones_from_rows (combine_list stones_from_cols (combine_list stones_from_left_dias stones_from_right_dias))
stones_from_rows = map (get_from_row board) [1..board_size]
stones_from_cols = map (get_from_column board) [1..board_size]
stones_from_left_dias = map (get_from_left_diagonal board) [-(board_size-1)..(board_size-1)]
stones_from_right_dias = map (get_from_right_diagonal board) [2..(2*board_size)]
我想在计算整个树之前使用 map 来评估每个子树,但我不知道如何在这里使用 map...而且我意识到如果我的代码编译,它不会是递归。谁能教我怎么做?
【问题讨论】:
-
我会尝试使 minimax 成为递归函数。即在 minimax 上映射而不评估。