more iterator stuff
This commit is contained in:
10
src/board.rs
10
src/board.rs
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
misc::{diag, split_from},
|
||||
misc::{diag_raw, split_from},
|
||||
piece::Piece,
|
||||
};
|
||||
use std::{cmp::Ordering, fmt};
|
||||
@@ -148,17 +148,19 @@ impl Board {
|
||||
|
||||
chains.extend(
|
||||
i_chain
|
||||
.clone()
|
||||
.map(|range| range.map(move |i| (i, j)))
|
||||
.map(Iterator::collect),
|
||||
);
|
||||
chains.extend(
|
||||
j_chain
|
||||
.clone()
|
||||
.map(|range| range.map(move |j| (i, j)))
|
||||
.map(Iterator::collect),
|
||||
);
|
||||
|
||||
// handle diagonals
|
||||
chains.extend(diag(i, j, 0, 0, BOARD_SIZE - 1, BOARD_SIZE - 1).map(Iterator::collect));
|
||||
chains.extend(diag_raw(i_chain, j_chain).map(Iterator::collect));
|
||||
|
||||
// Longest chain is (BOARD_SIZE - 2) as there needs to be the two pieces containing it
|
||||
let mut fill: Vec<(usize, usize)> = Vec::with_capacity((BOARD_SIZE - 2) * chains.len());
|
||||
@@ -214,7 +216,9 @@ impl Board {
|
||||
match white_score.cmp(&black_score) {
|
||||
Ordering::Greater => Some(Piece::White), // White win
|
||||
Ordering::Less => Some(Piece::Black), // Black win
|
||||
Ordering::Equal => None, // Tie
|
||||
|
||||
// TODO! this will end up being parsed the same as a "no winner", it should be a seperate type
|
||||
Ordering::Equal => None, // Tie
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user