Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jacobsapps/fffa5bca0aeb50757871b52801fdd687 to your computer and use it in GitHub Desktop.
Save jacobsapps/fffa5bca0aeb50757871b52801fdd687 to your computer and use it in GitHub Desktop.
import Distributed
public distributed actor BotPlayer: Identifiable {
typealias ActorSystem = LocalTestingDistributedActorSystem
var ai: RandomPlayerBotAI
var gameState: GameState
public init(team: CharacterTeam, actorSystem: ActorSystem) {
self.actorSystem = actorSystem // first, initialize the implicitly synthesized actor system property
self.gameState = .init()
self.ai = RandomPlayerBotAI(playerID: self.id, team: team) // use the synthesized `id` property
}
public distributed func makeMove() throws -> GameMove {
return try ai.decideNextMove(given: &gameState)
}
public distributed func opponentMoved(_ move: GameMove) async throws {
try gameState.mark(move)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment