diff options
Diffstat (limited to 'src/consulter.rs')
| -rw-r--r-- | src/consulter.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/consulter.rs b/src/consulter.rs new file mode 100644 index 0000000..1f27124 --- /dev/null +++ b/src/consulter.rs @@ -0,0 +1,24 @@ +use std::fs::File; +use std::io::{Error, ErrorKind, Result, Write}; +use std::process::Command; + +use crate::game::*; +use crate::parser::*; + +const FILE_NAME: &str = "/tmp/takwrap_ptn_consult.ptn"; + +pub fn consult_next_action(game: &Game, proc: &str) -> Result<Action> { + let file = File::create(FILE_NAME)?; + + write!(&file, "{}", game)?; + + let output = Command::new(proc).args(&[FILE_NAME]).output()?; + + match String::from_utf8(output.stdout) { + Err(e) => Err(Error::new(ErrorKind::InvalidData, e)), + Ok(string) => match parse_action(game, &string) { + Err(string) => Err(Error::new(ErrorKind::InvalidData, string)), + Ok(action) => Ok(action), + }, + } +} |
