Created
July 8, 2025 11:26
-
-
Save jacobsapps/fffa5bca0aeb50757871b52801fdd687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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