Crate curses_game_wrapper [−] [src]
This crate is wrapper of curses games like rogue and nethack, for AI making.
What this crate provie is spawning CUI game as child process and emulation of vt100 control sequence(helped by vte crate).
To run AI, You have to implement Reactor
trait to your AI object.
The result of vt100 emulation are stored as Vec<Vec<u8>>
and AI recieves it as
Changed(Vec<Vec<u8>>)
.
Examples
extern crate curses_game_wrapper as cgw; use cgw::{Reactor, ActionResult, AsciiChar, GameSetting, Severity}; use std::time::Duration; fn main() { struct EmptyAI { loopnum: usize, }; impl Reactor for EmptyAI { fn action(&mut self, _screen: ActionResult, turn: usize) -> Option<Vec<u8>> { let mut res = Vec::new(); match turn { val if val == self.loopnum - 1 => res.push(AsciiChar::CarriageReturn.as_byte()), val if val == self.loopnum - 2 => res.push(b'y'), val if val == self.loopnum - 3 => res.push(b'Q'), _ => { let c = match (turn % 4) as u8 { 0u8 => b'h', 1u8 => b'j', 2u8 => b'k', _ => b'l', }; res.push(c); } }; Some(res) } } let loopnum = 50; let gs = GameSetting::new("rogue") .env("ROGUEUSER", "EmptyAI") .lines(24) .columns(80) .debug_file("debug.txt") .max_loop(loopnum + 1) .draw_on(Duration::from_millis(200)); let game = gs.build(); let mut ai = EmptyAI { loopnum: loopnum }; game.play(&mut ai); }
Structs
GameEnv |
This is for spawning curses game as child process. |
GameSetting |
Game process builder, providing control over how a new process should be spawned. |
Enums
ActionResult |
Result of the game action.
|
AsciiChar |
An ASCII character. It wraps a |
Severity |
The severity of a log record. |
Traits
Reactor |
You have to implement |