当使用GKMinmaxStrategist和2名玩家(人类与AI)时,策略师会调用score(for player: GKGameModelPlayer) -> Int
每次可能的动作一次。 (这是正确的行为)。
然而,如果我将玩家提升到3(例如人类对AI与AI对比),则战略家每次可能的移动连续3次调用相同的得分函数,而不是每次移动1次。 (这是对计算周期的极大不必要的浪费)。
任何想法如何防止策略师浪费时间在同一个功能上?
3个玩家定义如下:class Player:NSObject,GKGameModelPlayer
static var allPlayers = [
Player(.player1),
Player(.player2),
Player(.player3)
]
评论第3位玩家会产生当前score()
次来电
玩家将传递给游戏模型:class Board:NSObject,GKGameModel
public var players: [GKGameModelPlayer]? {
return Player.allPlayers
}
预期:
apply selected move.option (8, 5)
score(for player: "Test1")
score 0
apply selected move.option (5, 4)
score(for player: "Test1")
score 10
问题:
apply selected move.option (8, 5)
score(for player: "Test1")
score 0
score(for player: "Test1")
score 0 <- unnecessary re-call of score()
score(for player: "Test1")
score 0 <- unnecessary re-call of score()
apply selected move.option (5, 4)
score(for player: "Test1")
score 10
score(for player: "Test1")
score 10 <- unnecessary re-call of score()
score(for player: "Test1")
score 10 <- unnecessary re-call of score()
我无法发布我的整个代码,但您可以通过从Razeware下载这个功能齐全的tutorial来轻松复制此问题。
On Board.swift将这些直接添加到各自的功能中:
print("apply(_ gameModelUpdate:")
print("score(for: player) -> Int ")
运行,你会看到每个可能的移动只有两行:
apply(_ gameModelUpdate:
score(for: player)
然后,在Player.swift上添加第3个玩家,使用这些行在各自的位置:
case test
case .test:
return "test"
Player(. test)
现在,您将看到以下可能的移动:
apply(_ gameModelUpdate:
score(for: player)
score(for: player)
score(for: player)