C++功能的时间限制
C++ time limit for function
>im 试图为我的 negamax alpha beta 算法实现时间限制,但我似乎无法弄清楚。 我试图实现的是: 开始计算移动,如果在 5 秒内未完成计算,则此时返回最佳移动。
我该怎么做?NEGAMAX甚至可能吗?
负极的伪代码:
01 function negamax(node, depth, α, β, color)
02 if depth = 0 or node is a terminal node
03 return color * the heuristic value of node
04 childNodes := GenerateMoves(node)
05 childNodes := OrderMoves(childNodes)
06 bestValue := −∞
07 foreach child in childNodes
08 v := −negamax(child, depth − 1, −β, −α, −color)
09 bestValue := max( bestValue, v )
10 α := max( α, v )
11 if α ≥ β
12 break
13 return bestValue
如果需要,我可以添加 negamax 算法的 C++ 实现
我能看到的唯一困难是递归,但这不是真正的问题,只需使用当前时间调用它,并在每次调用开始时检查经过的时间是否大于 5 秒:
01 function negamax(node, depth, α, β, color, startTime)
02 if (currentTime - startTime > 5sec) or depth = 0 or node is a terminal node
03 return color * the heuristic value of node
为方便起见,您可以使用包装器:
function negamaxWrap(node, depth, α, β, color)
return negamax(node, depth, α, β, color, currentTime)
如何确保您获得最佳价值?当堆栈展开时,返回值仍将通过测试:
bestValue := max( bestValue, v )
因此,您将获得到目前为止找到的值的max
。
相关文章:
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 控制台打印时间功能产生1
- 不同C++功能的编译时间
- 以小于一毫秒的精度计算时间的功能
- 如何实现声明功能-C 11,编译时间
- 如何在 python 交易模型中创建功能时间条件
- C++功能的时间限制
- 功能执行时间很奇怪
- TIM6,基本时间生成功能不起作用
- 特定时间后打破功能.(C )
- 是否有任何挂钩接口在编译时间内更换功能
- 使用SFINAE检测编译时间是否存在过载的独立式功能
- 在Visual Studio Enterprise 2017(C )中测量功能执行时间
- C++ 在特定时间激活功能而无需中断
- 如果将功能的非常简单的定义移动到.cpp,则编译时间的减少是多少
- 两个功能并没有花时间我期望的,因为它们的复杂性很大,任何人都可以解释原因
- 如何在QT中测量功能运行时间
- 示例功能处理时间装饰器在C 11中
- 该功能检测循环链接列表的时间复杂性是什么?
- 在编译时间(或运行时)获取C 功能的名称