|
|
|
@ -208,7 +208,7 @@ pub(crate) struct BoardIndex {
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component, PartialEq, Clone, Default, Copy, Eq, Hash)]
|
|
|
|
#[derive(Debug, Component, PartialEq, Clone, Default, Copy, Eq, Hash)]
|
|
|
|
pub(crate) struct Previous {
|
|
|
|
pub(crate) struct Previous {
|
|
|
|
board_index: BoardIndex
|
|
|
|
board_index: BoardIndex,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component, PartialEq, Clone, Copy)]
|
|
|
|
#[derive(Debug, Component, PartialEq, Clone, Copy)]
|
|
|
|
@ -240,21 +240,27 @@ impl Board {
|
|
|
|
match side {
|
|
|
|
match side {
|
|
|
|
Side::A => {
|
|
|
|
Side::A => {
|
|
|
|
// X: 0..3, Y: 0..3
|
|
|
|
// X: 0..3, Y: 0..3
|
|
|
|
(0..=3).flat_map(|x| {
|
|
|
|
(0..=3)
|
|
|
|
(0..=3).map(move |y| {
|
|
|
|
.flat_map(|x| {
|
|
|
|
self.at(BoardIndex { x, y }).map(|p| (p, BoardIndex { x, y }))
|
|
|
|
(0..=3).map(move |y| {
|
|
|
|
|
|
|
|
self.at(BoardIndex { x, y })
|
|
|
|
|
|
|
|
.map(|p| (p, BoardIndex { x, y }))
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}).filter_map(|r| r)
|
|
|
|
.filter_map(|r| r)
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Side::B => {
|
|
|
|
Side::B => {
|
|
|
|
// X: 4..7, Y: 0..3
|
|
|
|
// X: 4..7, Y: 0..3
|
|
|
|
(4..=7).flat_map(|x| {
|
|
|
|
(4..=7)
|
|
|
|
(0..=3).map(move |y| {
|
|
|
|
.flat_map(|x| {
|
|
|
|
self.at(BoardIndex { x, y }).map(|p| (p, BoardIndex { x, y }))
|
|
|
|
(0..=3).map(move |y| {
|
|
|
|
|
|
|
|
self.at(BoardIndex { x, y })
|
|
|
|
|
|
|
|
.map(|p| (p, BoardIndex { x, y }))
|
|
|
|
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}).filter_map(|r| r)
|
|
|
|
.filter_map(|r| r)
|
|
|
|
.collect()
|
|
|
|
.collect()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -582,20 +588,14 @@ fn track_previous_move(
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
struct Endgame;
|
|
|
|
struct Endgame;
|
|
|
|
|
|
|
|
|
|
|
|
fn check_endgame(
|
|
|
|
fn check_endgame(board: Res<Board>, mut next_state: ResMut<NextState<GameState>>) {
|
|
|
|
board: Res<Board>,
|
|
|
|
|
|
|
|
mut next_state: ResMut<NextState<GameState>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if board.on(Side::A).is_empty() || board.on(Side::B).is_empty() {
|
|
|
|
if board.on(Side::A).is_empty() || board.on(Side::B).is_empty() {
|
|
|
|
warn!("The game is over!");
|
|
|
|
warn!("The game is over!");
|
|
|
|
next_state.set(GameState::Endgame);
|
|
|
|
next_state.set(GameState::Endgame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn set_endgame(
|
|
|
|
fn set_endgame(score: Res<Score>, mut commands: Commands) {
|
|
|
|
score: Res<Score>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.spawn((
|
|
|
|
.spawn((
|
|
|
|
Endgame,
|
|
|
|
Endgame,
|
|
|
|
@ -642,10 +642,7 @@ fn set_endgame(
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn clear_endgame(
|
|
|
|
fn clear_endgame(query: Query<Entity, With<Endgame>>, mut commands: Commands) {
|
|
|
|
query: Query<Entity, With<Endgame>>,
|
|
|
|
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
query.iter().for_each(|e| {
|
|
|
|
query.iter().for_each(|e| {
|
|
|
|
commands.entity(e).despawn_recursive();
|
|
|
|
commands.entity(e).despawn_recursive();
|
|
|
|
})
|
|
|
|
})
|
|
|
|
@ -695,7 +692,6 @@ fn handle_selection(
|
|
|
|
mut latest: Local<Option<BoardIndex>>, // Tracks the last one worked on
|
|
|
|
mut latest: Local<Option<BoardIndex>>, // Tracks the last one worked on
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
selections.read().for_each(|Selection(index)| {
|
|
|
|
selections.read().for_each(|Selection(index)| {
|
|
|
|
|
|
|
|
|
|
|
|
// Skip indexes already processed
|
|
|
|
// Skip indexes already processed
|
|
|
|
if Some(*index) != *latest {
|
|
|
|
if Some(*index) != *latest {
|
|
|
|
// Set the latest index to the current index
|
|
|
|
// Set the latest index to the current index
|
|
|
|
|