[explorer] A bunch of random changes to this binary

Too many changes mixed up together to tease apart.
This commit is contained in:
Eryn Wells 2025-05-19 08:41:48 -07:00
parent 00c4aa38f0
commit d67c2cfb99

View file

@ -1,8 +1,9 @@
// 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_position::{fen::ToFen, MakeMoveBuilder, Position, PositionBuilder};
use chessfriend_position::{fen::ToFenStr, PlacePieceStrategy, Position, ValidateMove};
use clap::{Arg, Command};
use rustyline::error::ReadlineError;
use rustyline::DefaultEditor;
@ -22,7 +23,6 @@ impl Default for CommandResult {
}
struct State {
builder: PositionBuilder,
position: Position,
}
@ -87,7 +87,7 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
"{}",
state
.position
.to_fen()
.to_fen_str()
.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)
.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.position = state.builder.build();
state
.position
.place_piece(piece, square, PlacePieceStrategy::default())
.map_err(|err| format!("Error: could not place piece: {err:?}"))?;
}
Some(("sight", matches)) => {
let square = matches
@ -167,7 +169,6 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
}
Some(("starting", _matches)) => {
let starting_position = Position::starting();
state.builder = PositionBuilder::from_position(&starting_position);
state.position = starting_position;
}
Some((name, _matches)) => unimplemented!("{name}"),
@ -178,12 +179,10 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, 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 builder = PositionBuilder::from_position(&starting_position);
let mut state = State {
builder,
position: starting_position,
};
@ -192,7 +191,7 @@ fn main() -> Result<(), String> {
loop {
if should_print_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? ");
@ -210,7 +209,7 @@ fn main() -> Result<(), String> {
break;
}
}
Err(message) => println!("{}", message),
Err(message) => println!("{message}"),
}
}
Err(ReadlineError::Interrupted) => {
@ -222,7 +221,7 @@ fn main() -> Result<(), String> {
break;
}
Err(err) => {
println!("Error: {:?}", err);
println!("Error: {err}");
break;
}
}