[explorer] A bunch of random changes to this binary
Too many changes mixed up together to tease apart.
This commit is contained in:
parent
00c4aa38f0
commit
d67c2cfb99
1 changed files with 13 additions and 14 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
// Eryn Wells <eryn@erynwells.me>
|
// Eryn Wells <eryn@erynwells.me>
|
||||||
|
|
||||||
use chessfriend_core::{Color, Piece, PlacedPiece, Shape, Square};
|
use chessfriend_board::{fen::FromFenStr, Board};
|
||||||
|
use chessfriend_core::{Color, Piece, Shape, Square};
|
||||||
use chessfriend_moves::Builder as MoveBuilder;
|
use chessfriend_moves::Builder as MoveBuilder;
|
||||||
use chessfriend_position::{fen::ToFen, MakeMoveBuilder, Position, PositionBuilder};
|
use chessfriend_position::{fen::ToFenStr, PlacePieceStrategy, Position, ValidateMove};
|
||||||
use clap::{Arg, Command};
|
use clap::{Arg, Command};
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
use rustyline::DefaultEditor;
|
use rustyline::DefaultEditor;
|
||||||
|
|
@ -22,7 +23,6 @@ impl Default for CommandResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
builder: PositionBuilder,
|
|
||||||
position: Position,
|
position: Position,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,7 +87,7 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
|
||||||
"{}",
|
"{}",
|
||||||
state
|
state
|
||||||
.position
|
.position
|
||||||
.to_fen()
|
.to_fen_str()
|
||||||
.map_err(|_| "error: Unable to generate FEN for current position")?
|
.map_err(|_| "error: Unable to generate FEN for current position")?
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -132,10 +132,12 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
|
||||||
let square = Square::from_algebraic_str(square)
|
let square = Square::from_algebraic_str(square)
|
||||||
.map_err(|_| "Error: invalid square specifier")?;
|
.map_err(|_| "Error: invalid square specifier")?;
|
||||||
|
|
||||||
let piece = PlacedPiece::new(Piece::new(color, shape), square);
|
let piece = Piece::new(color, shape);
|
||||||
|
|
||||||
state.builder.place_piece(piece);
|
state
|
||||||
state.position = state.builder.build();
|
.position
|
||||||
|
.place_piece(piece, square, PlacePieceStrategy::default())
|
||||||
|
.map_err(|err| format!("Error: could not place piece: {err:?}"))?;
|
||||||
}
|
}
|
||||||
Some(("sight", matches)) => {
|
Some(("sight", matches)) => {
|
||||||
let square = matches
|
let square = matches
|
||||||
|
|
@ -167,7 +169,6 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
|
||||||
}
|
}
|
||||||
Some(("starting", _matches)) => {
|
Some(("starting", _matches)) => {
|
||||||
let starting_position = Position::starting();
|
let starting_position = Position::starting();
|
||||||
state.builder = PositionBuilder::from_position(&starting_position);
|
|
||||||
state.position = starting_position;
|
state.position = starting_position;
|
||||||
}
|
}
|
||||||
Some((name, _matches)) => unimplemented!("{name}"),
|
Some((name, _matches)) => unimplemented!("{name}"),
|
||||||
|
|
@ -178,12 +179,10 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), String> {
|
fn main() -> Result<(), String> {
|
||||||
let mut editor = DefaultEditor::new().map_err(|err| format!("Error: {}", err.to_string()))?;
|
let mut editor = DefaultEditor::new().map_err(|err| format!("Error: {err}"))?;
|
||||||
|
|
||||||
let starting_position = Position::starting();
|
let starting_position = Position::starting();
|
||||||
let builder = PositionBuilder::from_position(&starting_position);
|
|
||||||
let mut state = State {
|
let mut state = State {
|
||||||
builder,
|
|
||||||
position: starting_position,
|
position: starting_position,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -192,7 +191,7 @@ fn main() -> Result<(), String> {
|
||||||
loop {
|
loop {
|
||||||
if should_print_position {
|
if should_print_position {
|
||||||
println!("{}", &state.position);
|
println!("{}", &state.position);
|
||||||
println!("{} to move.", state.position.player_to_move());
|
println!("{} to move.", state.position.board.active_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
let readline = editor.readline("\n? ");
|
let readline = editor.readline("\n? ");
|
||||||
|
|
@ -210,7 +209,7 @@ fn main() -> Result<(), String> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(message) => println!("{}", message),
|
Err(message) => println!("{message}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ReadlineError::Interrupted) => {
|
Err(ReadlineError::Interrupted) => {
|
||||||
|
|
@ -222,7 +221,7 @@ fn main() -> Result<(), String> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("Error: {:?}", err);
|
println!("Error: {err}");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue