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
impl GameEnv
Sourcepub fn play<R: Reactor>(self, ai: &mut R)
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§
impl Freeze for GameEnv
impl RefUnwindSafe for GameEnv
impl Send for GameEnv
impl !Sync for GameEnv
impl Unpin for GameEnv
impl UnwindSafe for GameEnv
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more