We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0f66abb commit 6e2afc4Copy full SHA for 6e2afc4
minesweeper/src/minesweeper_logic/table.rs
@@ -290,18 +290,13 @@ fn get_neighbor_fields(
290
row: SizeType,
291
col: SizeType,
292
) -> HashSet<(SizeType, SizeType)> {
293
- fn add(u: SizeType, i: i8) -> Option<SizeType> {
294
- if i.is_negative() {
295
- u.checked_sub(i.abs() as u8 as SizeType)
296
- } else {
297
- u.checked_add(i as SizeType)
298
- }
299
- };
300
-
301
let mut neighbors = HashSet::new();
302
303
for offset in &NEIGHBOR_OFFSETS {
304
- match (add(row, offset.0), add(col, offset.1)) {
+ match (
+ row.checked_add(offset.0 as i64),
+ col.checked_add(offset.1 as i64),
+ ) {
305
(Some(r), Some(c)) if r >= 0 && r < height && c >= 0 && c < width => {
306
neighbors.insert((r, c));
307
}
0 commit comments