本文介绍了使用列表上的 max()/min() 获取返回的最大或最小项的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在列表上使用 Python 的 max 和 min 函数来实现极大极小算法,我需要 max() 或 min().换句话说,我需要知道哪个移动产生了最大值(在第一个玩家的回合)或最小值(第二个玩家).
I'm using Python's max and min functions on lists for a minimax algorithm, and I need the index of the value returned by max() or min(). In other words, I need to know which move produced the max (at a first player's turn) or min (second player) value.
for i in range(9): new_board = current_board.new_board_with_move([i / 3, i % 3], player) if new_board: temp = min_max(new_board, depth + 1, not is_min_level) values.append(temp) if is_min_level: return min(values) else: return max(values)我需要能够返回最小值或最大值的实际索引,而不仅仅是值.
I need to be able to return the actual index of the min or max value, not just the value.
推荐答案 if is_min_level: return values.index(min(values)) else: return values.index(max(values))更多推荐
使用列表上的 max()/min() 获取返回的最大或最小项的索引
发布评论