Struct GameEnv

Source
pub struct GameEnv { /* private fields */ }
Expand description

This is for spawning curses game as child process.

It stores inputs from the game and sends result to AI when its input handler timeouts.

The only usage is

§Example

extern crate curses_game_wrapper as cgw;
use cgw::{Reactor, ActionResult, AsciiChar, GameSetting};
use std::time::Duration;
fn main() {
    struct EmptyAI;
    impl Reactor for EmptyAI {
        fn action(&mut self, _screen: ActionResult, _turn: usize) -> Option<Vec<u8>> {
             None
        }
    }
    let gs = GameSetting::new("rogue")
        .env("ROGUEUSER", "EmptyAI")
        .lines(24)
        .columns(80)
        .debug_file("debug.txt")
        .max_loop(10)
        .draw_on(Duration::from_millis(200));
    let game = gs.build();
    let mut ai = EmptyAI { };
    game.play(&mut ai);
}

Implementations§

Source§

impl GameEnv

Source

pub fn play<R: Reactor>(self, ai: &mut R)

Start process and run AI.

Examples found in repository?
examples/rogue.rs (line 38)
4fn main() {
5    struct EmptyAI {
6        loopnum: usize,
7    };
8    impl Reactor for EmptyAI {
9        fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> {
10            let mut res = Vec::new();
11            match turn {
12                val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()),
13                val if val == self.loopnum - 2 => res.push(b'y'),
14                val if val == self.loopnum - 3 => res.push(b'Q'),
15                _ => {
16                    let c = match (turn % 4) as u8 {
17                        0u8 => b'h',
18                        1u8 => b'j',
19                        2u8 => b'k',
20                        _ => b'l',
21                    };
22                    res.push(c);
23                }
24            };
25            Some(res)
26        }
27    }
28    let loopnum = 50;
29    let gs = GameSetting::new("rogue")
30        .env("ROGUEUSER", "EmptyAI")
31        .lines(24)
32        .columns(80)
33        .debug_file("debug.txt")
34        .max_loop(loopnum + 1)
35        .draw_on(Duration::from_millis(100));
36    let game = gs.build();
37    let mut ai = EmptyAI { loopnum: loopnum };
38    game.play(&mut ai);
39}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.