Module chillow.service.ai.random_ai
Expand source code
import time
from multiprocessing import Value
from chillow.service.ai.artificial_intelligence import ArtificialIntelligence
from chillow.model.action import Action
from chillow.model.game import Game
class RandomAI(ArtificialIntelligence):
"""AI that randomly chooses an action ignoring the state of the game.
Attributes:
player: The player associated with this AI.
"""
def create_next_action(self, game: Game, return_value: Value):
"""See base class."""
self._turn_ctr += 1
action = Action.get_random_action()
return_value.value = action.get_index()
def get_information(self) -> str:
"""See base class."""
return ""
class RandomWaitingAI(RandomAI):
"""AI that randomly chooses an action ignoring the state of the game and waits five seconds.
Attributes:
player: The player associated with this AI.
"""
def create_next_action(self, game: Game, return_value: Value):
time.sleep(5)
super().create_next_action(game, return_value)
Classes
class RandomAI (player: Player, max_speed: int = 10)
-
AI that randomly chooses an action ignoring the state of the game.
Attributes
player
- The player associated with this AI.
Creates a new object of an AI.
Args
player
- The player assigned to the AI.
max_speed
- The maximum speed the AI can reach.
Expand source code
class RandomAI(ArtificialIntelligence): """AI that randomly chooses an action ignoring the state of the game. Attributes: player: The player associated with this AI. """ def create_next_action(self, game: Game, return_value: Value): """See base class.""" self._turn_ctr += 1 action = Action.get_random_action() return_value.value = action.get_index() def get_information(self) -> str: """See base class.""" return ""
Ancestors
Subclasses
Methods
def create_next_action(self, game: Game, return_value:
>) -
See base class.
Expand source code
def create_next_action(self, game: Game, return_value: Value): """See base class.""" self._turn_ctr += 1 action = Action.get_random_action() return_value.value = action.get_index()
def get_information(self) ‑> str
-
See base class.
Expand source code
def get_information(self) -> str: """See base class.""" return ""
class RandomWaitingAI (player: Player, max_speed: int = 10)
-
AI that randomly chooses an action ignoring the state of the game and waits five seconds.
Attributes
player
- The player associated with this AI.
Creates a new object of an AI.
Args
player
- The player assigned to the AI.
max_speed
- The maximum speed the AI can reach.
Expand source code
class RandomWaitingAI(RandomAI): """AI that randomly chooses an action ignoring the state of the game and waits five seconds. Attributes: player: The player associated with this AI. """ def create_next_action(self, game: Game, return_value: Value): time.sleep(5) super().create_next_action(game, return_value)
Ancestors
Inherited members