Skip to content

Commit

Permalink
rename some methods of AdjoinedField
Browse files Browse the repository at this point in the history
  • Loading branch information
zbrachinara committed Jan 5, 2023
1 parent e45de59 commit c5086b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/area_attack/client_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ pub fn request_reveal(
if !puppet_table.contains_key(player) {
// counts both flags and known mines
let marked_count = field
.iter_neighbors(position)
.neighbor_cells(position)
.filter(|tile| matches!(tile, ClientTile::Flag | ClientTile::Mine))
.count() as u8;

if marked_count == *num_neighbors {
for (position, tile) in field.iter_neighbors_enumerated(position) {
for (position, tile) in field.neighbors(position) {
if !matches!(tile, ClientTile::Flag) {
sock.send_logged(ClientMessage::Ingame {
data: rmp_serde::to_vec(&AreaAttackRequest::Reveal(
Expand Down
6 changes: 3 additions & 3 deletions src/area_attack/server_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ pub fn reveal_tiles(
ServerTile::Empty => {
*tile = ServerTile::Owned { player };
let mine_count = field
.iter_neighbors(position)
.neighbor_cells(position)
.filter(|tile| matches!(tile, ServerTile::Mine | ServerTile::HardMine))
.count() as u8;

if mine_count == 0 {
request_buffer.extend(field.iter_neighbor_positions(position).map(|position| {
request_buffer.extend(field.neighbor_positions(position).map(|position| {
RevealTile {
position,
player,
Expand Down Expand Up @@ -221,7 +221,7 @@ fn send_tiles<'a>(
player: owner,
num_neighbors: if player_id == owner {
minefield
.iter_neighbors(position)
.neighbor_cells(position)
.filter(|tile| matches!(tile, ServerTile::Mine | ServerTile::HardMine))
.count() as u8
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/minefield/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ where
});
}

pub fn iter_neighbors_enumerated(
pub fn neighbors(
&self,
position: Position,
) -> impl Iterator<Item = (Position, ROQueryItem<Tile>)> {
Expand All @@ -127,15 +127,15 @@ where
})
}

pub fn iter_neighbor_positions(
pub fn neighbor_positions(
&self,
position: Position,
) -> impl Iterator<Item = Position> + '_ {
self.minefield.iter_neighbor_positions(position)
}

pub fn iter_neighbors(&self, position: Position) -> impl Iterator<Item = ROQueryItem<Tile>> {
self.iter_neighbors_enumerated(position)
pub fn neighbor_cells(&self, position: Position) -> impl Iterator<Item = ROQueryItem<Tile>> {
self.neighbors(position)
.map(|(_, tile)| tile)
}

Expand Down

0 comments on commit c5086b6

Please sign in to comment.