(board: &Vec<Vec<char>>, i: usize, j: usize)
| 28 | } |
| 29 | |
| 30 | pub fn valid(board: &Vec<Vec<char>>, i: usize, j: usize) -> bool { |
| 31 | // check column up |
| 32 | for idx in 0..i { |
| 33 | if board[idx][j] == 'Q' { return false } |
| 34 | } |
| 35 | // check diagonal \ up |
| 36 | let (mut idx, mut jdx) = (i as i32 - 1, j as i32 - 1); |
| 37 | while idx >= 0 && jdx >= 0 { |
| 38 | if board[idx as usize][jdx as usize] == 'Q' { return false } |
| 39 | idx -= 1; |
| 40 | jdx -= 1; |
| 41 | } |
| 42 | // check diagonal / up |
| 43 | let (mut idx, mut jdx) = (i as i32 - 1, j + 1); |
| 44 | while idx >= 0 && jdx < board.len() { |
| 45 | if board[idx as usize][jdx] == 'Q' { return false } |
| 46 | idx -= 1; |
| 47 | jdx += 1; |
| 48 | } |
| 49 | true |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | #[cfg(test)] |
nothing calls this directly
no outgoing calls
no test coverage detected