Add "best" subcommand to CLI to invoke AI core
This commit is contained in:
parent
90dcc2555a
commit
f76cc06bc9
|
@ -72,7 +72,7 @@ fn main() -> anyhow::Result<()> {
|
|||
let args = <Args as clap::Parser>::parse();
|
||||
match args.cmd {
|
||||
Cmd::List(_) => list_moves(),
|
||||
Cmd::Best(_) => Err(anyhow!("'best' command is not implemented")),
|
||||
Cmd::Best(cmd) => print_best_move(cmd.settings),
|
||||
Cmd::Play(_) => Err(anyhow!("'play' command is not implemented")),
|
||||
}
|
||||
}
|
||||
|
@ -102,3 +102,41 @@ fn list_moves() -> anyhow::Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn print_best_move(_settings: Settings) -> anyhow::Result<()> {
|
||||
let input: fish::io::InputState =
|
||||
serde_json::from_reader(std::io::stdin()).context("error parsing input state")?;
|
||||
|
||||
let mut mat = input.matrix.to_mat();
|
||||
mat.clear_lines();
|
||||
|
||||
// TODO: ai init config, e.g. personality
|
||||
let mut ai = fish::Ai::new();
|
||||
|
||||
// TODO: hold
|
||||
// TODO: attack state
|
||||
ai.start(&mat, &input.queue.previews, input.queue.hold);
|
||||
|
||||
// TODO: resource limits (cycles,nodes,time)
|
||||
loop {
|
||||
if ai.think_1_cycle() {
|
||||
break;
|
||||
}
|
||||
// TODO: proper logging
|
||||
// eprintln!("thinking...");
|
||||
}
|
||||
|
||||
// print suggestions trace
|
||||
let mut output = fish::io::OutputMoves::default();
|
||||
for pc in ai.suggestion() {
|
||||
output.moves.push(fish::io::OutputMove {
|
||||
location: pc.into(),
|
||||
// TODO: spin suggestions
|
||||
spin: fish::io::Spin::None,
|
||||
});
|
||||
}
|
||||
|
||||
serde_json::to_writer(std::io::stdout(), &output).context("error writing output state")?;
|
||||
println!();
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue