PlanetAI

Trait PlanetAI 

Source
pub trait PlanetAI: Send {
    // Required methods
    fn handle_sunray(
        &mut self,
        state: &mut PlanetState,
        generator: &Generator,
        combinator: &Combinator,
        sunray: Sunray,
    );
    fn handle_asteroid(
        &mut self,
        state: &mut PlanetState,
        generator: &Generator,
        combinator: &Combinator,
    ) -> Option<Rocket>;
    fn handle_internal_state_req(
        &mut self,
        state: &mut PlanetState,
        generator: &Generator,
        combinator: &Combinator,
    ) -> DummyPlanetState;
    fn handle_explorer_msg(
        &mut self,
        state: &mut PlanetState,
        generator: &Generator,
        combinator: &Combinator,
        msg: ExplorerToPlanet,
    ) -> Option<PlanetToExplorer>;

    // Provided methods
    fn on_explorer_arrival(
        &mut self,
        state: &mut PlanetState,
        generator: &Generator,
        combinator: &Combinator,
        explorer_id: ID,
    ) { ... }
    fn on_explorer_departure(
        &mut self,
        state: &mut PlanetState,
        generator: &Generator,
        combinator: &Combinator,
        explorer_id: ID,
    ) { ... }
    fn on_start(
        &mut self,
        state: &PlanetState,
        generator: &Generator,
        combinator: &Combinator,
    ) { ... }
    fn on_stop(
        &mut self,
        state: &PlanetState,
        generator: &Generator,
        combinator: &Combinator,
    ) { ... }
}
Expand description

The trait that defines the behavior of a planet, meaning how it reacts to messages coming from the orchestrator and explorers. This is done through trait methods acting as handlers for the messages.

Structs implementing this trait are intended to be passed to the Planet constructor, so that the handlers (methods of the trait) can be invoked by the planet default logic when certain messages are received on the planet channels.

The handlers can alter the planet state by accessing the state parameter, which is passed to the methods as a mutable borrow. The Generator and Combinator of the planet are also passed as parameters.

Required Methods§

Source

fn handle_sunray( &mut self, state: &mut PlanetState, generator: &Generator, combinator: &Combinator, sunray: Sunray, )

This handler will be invoked when a OrchestratorToPlanet::Sunray message is received. The sunray parameter is the actual Sunray struct used to charged energy cells.

Source

fn handle_asteroid( &mut self, state: &mut PlanetState, generator: &Generator, combinator: &Combinator, ) -> Option<Rocket>

This handler will be invoked when a OrchestratorToPlanet::Asteroid message is received. It’s important to handle Asteroid messages correctly, as this will the determine the planet survival.

§Returns

In order to survive, an owned Rocket must be returned from this method; if None is returned instead, the planet will (or should) be destroyed by the orchestrator

Source

fn handle_internal_state_req( &mut self, state: &mut PlanetState, generator: &Generator, combinator: &Combinator, ) -> DummyPlanetState

This handler will be invoked when a OrchestratorToPlanet::InternalStateRequest message is received.

§Returns

A DummyPlanetState instance that should represent the current state of the planet.

Source

fn handle_explorer_msg( &mut self, state: &mut PlanetState, generator: &Generator, combinator: &Combinator, msg: ExplorerToPlanet, ) -> Option<PlanetToExplorer>

Handler for all messages received by explorers (receiving end of the ExplorerToPlanet channel). The id of the sender explorer is part of the msg struct.

§Returns

This method can return an optional response to the message, which will be delivered to the explorer that sent the message.

Provided Methods§

Source

fn on_explorer_arrival( &mut self, state: &mut PlanetState, generator: &Generator, combinator: &Combinator, explorer_id: ID, )

This method will be invoked when an explorer (identified by the explorer_id parameter) lands on the planet.

Source

fn on_explorer_departure( &mut self, state: &mut PlanetState, generator: &Generator, combinator: &Combinator, explorer_id: ID, )

This method will be invoked when an explorer (identified by the explorer_id parameter) leaves the planet.

Source

fn on_start( &mut self, state: &PlanetState, generator: &Generator, combinator: &Combinator, )

This method will be invoked when a OrchestratorToPlanet::StartPlanetAI is received, but only if the planet is currently in a stopped state.

Start messages received when planet is already running are ignored.

Source

fn on_stop( &mut self, state: &PlanetState, generator: &Generator, combinator: &Combinator, )

This method will be invoked when a OrchestratorToPlanet::StopPlanetAI is received, but only if the planet is currently in a running state.

Stop messages received when planet is already stopped are ignored.

Implementors§