|
|
|
@ -510,7 +510,7 @@ impl Board {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
info!("Remaining moves: {:?}", self.moves);
|
|
|
|
debug!("Remaining moves: {:?}", self.moves);
|
|
|
|
return moves;
|
|
|
|
return moves;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -1105,7 +1105,7 @@ pub(crate) fn update_board(
|
|
|
|
match to {
|
|
|
|
match to {
|
|
|
|
// If we are moving on the board...
|
|
|
|
// If we are moving on the board...
|
|
|
|
Some(to_idx) => {
|
|
|
|
Some(to_idx) => {
|
|
|
|
info!("Moving piece {:?} {:?} -> {:?}", entity, from, to_idx);
|
|
|
|
debug!("Moving piece {:?} {:?} -> {:?}", entity, from, to_idx);
|
|
|
|
// Update the piece's index
|
|
|
|
// Update the piece's index
|
|
|
|
*index = *to_idx;
|
|
|
|
*index = *to_idx;
|
|
|
|
// Play audio sfx
|
|
|
|
// Play audio sfx
|
|
|
|
@ -1125,7 +1125,7 @@ pub(crate) fn update_board(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let ns = !*curr_state.get();
|
|
|
|
let ns = !*curr_state.get();
|
|
|
|
info!("Piece moved, switching sides: {:?}", ns);
|
|
|
|
debug!("Piece moved, switching sides: {:?}", ns);
|
|
|
|
next_state.set(ns);
|
|
|
|
next_state.set(ns);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1133,7 +1133,7 @@ pub(crate) fn update_board(
|
|
|
|
None => {
|
|
|
|
None => {
|
|
|
|
match move_type {
|
|
|
|
match move_type {
|
|
|
|
MoveType::Capture => {
|
|
|
|
MoveType::Capture => {
|
|
|
|
info!("Capturing piece {:?}", entity);
|
|
|
|
debug!("Capturing piece {:?}", entity);
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.entity(entity)
|
|
|
|
.entity(entity)
|
|
|
|
.remove::<BoardIndex>()
|
|
|
|
.remove::<BoardIndex>()
|
|
|
|
@ -1390,7 +1390,7 @@ fn handle_selection(
|
|
|
|
.iter()
|
|
|
|
.iter()
|
|
|
|
.filter(|(_, this_index)| *this_index == index)
|
|
|
|
.filter(|(_, this_index)| *this_index == index)
|
|
|
|
.for_each(|(piece, piece_index)| {
|
|
|
|
.for_each(|(piece, piece_index)| {
|
|
|
|
info!("Selecting {:?} at {:?}", piece, piece_index);
|
|
|
|
debug!("Selecting {:?} at {:?}", piece, piece_index);
|
|
|
|
commands.entity(piece).insert(Selected);
|
|
|
|
commands.entity(piece).insert(Selected);
|
|
|
|
if !(*done) {
|
|
|
|
if !(*done) {
|
|
|
|
audio_event.send(audio::AudioEvent::PickUp);
|
|
|
|
audio_event.send(audio::AudioEvent::PickUp);
|
|
|
|
@ -1409,7 +1409,7 @@ fn handle_selection(
|
|
|
|
match board.move_piece(*current_index, *index) {
|
|
|
|
match board.move_piece(*current_index, *index) {
|
|
|
|
Ok(moves) => {
|
|
|
|
Ok(moves) => {
|
|
|
|
// De-select the piece
|
|
|
|
// De-select the piece
|
|
|
|
info!("Applying moves {:?}", moves);
|
|
|
|
debug!("Applying moves {:?}", moves);
|
|
|
|
if !(*done) {
|
|
|
|
if !(*done) {
|
|
|
|
moves.iter().for_each(|m| {
|
|
|
|
moves.iter().for_each(|m| {
|
|
|
|
move_events.send(m.clone());
|
|
|
|
move_events.send(m.clone());
|
|
|
|
@ -1417,9 +1417,9 @@ fn handle_selection(
|
|
|
|
*done = true;
|
|
|
|
*done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(GameError::NullMove) => warn!("Null move!"),
|
|
|
|
Err(GameError::NullMove) => debug!("Null move!"),
|
|
|
|
Err(GameError::InvalidIndex) | Err(GameError::InvalidMove) => {
|
|
|
|
Err(GameError::InvalidIndex) | Err(GameError::InvalidMove) => {
|
|
|
|
warn!("Invalid index/move!");
|
|
|
|
debug!("Invalid index/move!");
|
|
|
|
if !(*done) {
|
|
|
|
if !(*done) {
|
|
|
|
audio_event.send(AudioEvent::Invalid);
|
|
|
|
audio_event.send(AudioEvent::Invalid);
|
|
|
|
*done = true;
|
|
|
|
*done = true;
|
|
|
|
@ -1442,7 +1442,7 @@ fn asserts<T: Component>(
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if selected_pieces.iter().len() > 2 {
|
|
|
|
if selected_pieces.iter().len() > 2 {
|
|
|
|
selected_pieces.iter().for_each(|e| {
|
|
|
|
selected_pieces.iter().for_each(|e| {
|
|
|
|
info!("Too many pieces selected, one of which is: {:?}", e);
|
|
|
|
debug!("Too many pieces selected, one of which is: {:?}", e);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
panic!(
|
|
|
|
panic!(
|
|
|
|
"More than two pieces selected {:?}",
|
|
|
|
"More than two pieces selected {:?}",
|
|
|
|
@ -1475,7 +1475,7 @@ fn show_valid_moves(
|
|
|
|
// Iterate over all ValidMove entities
|
|
|
|
// Iterate over all ValidMove entities
|
|
|
|
// For each one with a ValidMove index, make it visible
|
|
|
|
// For each one with a ValidMove index, make it visible
|
|
|
|
let valid_moves = board.valid_moves(*idx);
|
|
|
|
let valid_moves = board.valid_moves(*idx);
|
|
|
|
info!("Showing valid moves for {:?}: {:?}", idx, valid_moves);
|
|
|
|
debug!("Showing valid moves for {:?}: {:?}", idx, valid_moves);
|
|
|
|
indicators.iter_mut().for_each(|(i, mut vis)| {
|
|
|
|
indicators.iter_mut().for_each(|(i, mut vis)| {
|
|
|
|
if valid_moves.contains(i) {
|
|
|
|
if valid_moves.contains(i) {
|
|
|
|
*vis = Visibility::Inherited;
|
|
|
|
*vis = Visibility::Inherited;
|
|
|
|
@ -1539,7 +1539,7 @@ fn assert_piece_consistency(
|
|
|
|
let active_count = active.iter().len();
|
|
|
|
let active_count = active.iter().len();
|
|
|
|
let being_captured_count = being_captured.iter().len();
|
|
|
|
let being_captured_count = being_captured.iter().len();
|
|
|
|
let captured_count = captured.iter().len();
|
|
|
|
let captured_count = captured.iter().len();
|
|
|
|
info!("Active: {} | being captured: {} | captured: {}", active_count, being_captured_count, captured_count);
|
|
|
|
debug!("Active: {} | being captured: {} | captured: {}", active_count, being_captured_count, captured_count);
|
|
|
|
let total_count = active_count + being_captured_count + captured_count;
|
|
|
|
let total_count = active_count + being_captured_count + captured_count;
|
|
|
|
assert_eq!(total_count, 18, "Pieces does does not add up!");
|
|
|
|
assert_eq!(total_count, 18, "Pieces does does not add up!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -1565,8 +1565,10 @@ fn undo_move(
|
|
|
|
side = !turn.get().0;
|
|
|
|
side = !turn.get().0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
info!("Reverting move {:?} {:?} -> {:?}", epoch, from, to);
|
|
|
|
debug!("Reverting move {:?} {:?} -> {:?}", epoch, from, to);
|
|
|
|
match to { Some(to_idx) => { info!("Moving piece back from {:?}", to_idx);
|
|
|
|
match to { Some(to_idx) => {
|
|
|
|
|
|
|
|
debug!("Moving piece back from {:?}", to_idx);
|
|
|
|
|
|
|
|
|
|
|
|
// Find piece currently at "to_idx" and update it's position to "from"
|
|
|
|
// Find piece currently at "to_idx" and update it's position to "from"
|
|
|
|
active_pieces
|
|
|
|
active_pieces
|
|
|
|
.iter_mut()
|
|
|
|
.iter_mut()
|
|
|
|
|