rust port

- draw board
- legal move checks
This commit is contained in:
Uğur Küpeli
2022-05-06 22:48:24 +03:00
parent 3e8b3901d7
commit e89b7128b6
4 changed files with 127 additions and 0 deletions

34
72_Queen/rust/src/util.rs Normal file
View File

@@ -0,0 +1,34 @@
pub fn is_move_legal(loc: u8, mov: u8) -> bool {
let dt: i32 = (mov - loc).into();
if dt.is_negative() {
return false;
}
if (dt % 21) == 0 || (dt % 10) == 0 || (dt % 11) == 0 {
return true;
}
false
}
pub fn is_legal_start(loc: u8) -> bool {
let mut legal_spots = Vec::new();
let start: u8 = 11;
legal_spots.push(start);
for i in 1..=7 {
legal_spots.push(start + (10 * i));
}
for i in 1..=7 {
legal_spots.push(start + (11 * i));
}
if legal_spots.contains(&loc) {
true
} else {
false
}
}