fixed the score check bug that burnt out me couldn't fix

This commit is contained in:
LinlyBoi
2023-05-10 08:16:19 +03:00
parent 9f88e6d99e
commit bdfb102122

View File

@@ -9,21 +9,22 @@ pub fn scan(
index: &(usize, usize),
direction: Direction,
depth: i32,
player_disk: Disk,
) -> i32 {
let current_disk: &Disk = match board.get(index.0, index.1) {
Some(disk) => disk,
match board.get(index.0, index.1) {
Some(_) => {}
None => return 0,
};
let mut current_index = *index;
let mut in_a_row = 0;
let mut in_a_row: Vec<Disk> = vec![];
// dbg!("Starting new thing", &direction);
for _num in 0..depth {
match board.get(current_index.0, current_index.1) {
Some(_disk) => {
// dbg!(_disk, current_disk, in_a_row);
if variant_eq(current_disk, _disk) && !variant_eq(_disk, &Disk::EMPTY) {
if variant_eq(&player_disk, _disk) && !variant_eq(_disk, &Disk::EMPTY) {
// add in a row by 1
in_a_row += 1;
in_a_row.push(*_disk);
// dbg!(current_index);
//go to next element
match direction {
@@ -44,14 +45,12 @@ pub fn scan(
break;
}
current_index = dec_col(&current_index, 1);
// current_index.1 -= 1;
}
Direction::Right => {
if current_index.1 == board.num_columns() - 1 {
break;
}
current_index = inc_col(&current_index, 1);
// current_index.1 += 1;
}
Direction::UpRight => {
if current_index.0 == board.num_rows() - 1
@@ -60,16 +59,12 @@ pub fn scan(
break;
}
current_index = inc_both(&current_index, 1);
// current_index.1 += 1;
// current_index.0 += 1;
}
Direction::UpLeft => {
if current_index.0 == board.num_columns() - 1 || current_index.1 == 0 {
break;
}
// current_index.1 -= 1;
// current_index.0 += 1;
current_index = inc_dec(&current_index, 1);
}
Direction::DownRight => {
@@ -77,8 +72,6 @@ pub fn scan(
break;
}
current_index = dec_inc(&current_index, 1);
// current_index.1 += 1;
// current_index.0 -= 1;
}
Direction::DownLeft => {
if current_index.0 == 0 || current_index.1 == 0 {
@@ -95,28 +88,27 @@ pub fn scan(
None => break,
}
}
in_a_row
// //+-3
in_a_row.len() as i32
}
// board[(2,3)];
pub fn get_legal_moves(
(row, col): &(usize, usize),
(nrow, ncol): (usize, usize),
) -> Vec<Direction> {
let _max_col = nrow - 1;
let _max_row = ncol - 1;
let _max_col = ncol - 1;
let _max_row = nrow - 1;
let mut moves: Vec<Direction> = vec![];
match *col {
match *row {
0 => moves.push(Direction::Up),
_max_row => moves.push(Direction::Down),
_max_rows => moves.push(Direction::Down),
_ => {
moves.push(Direction::Up);
moves.push(Direction::Down);
}
};
match *row {
match *col {
0 => moves.push(Direction::Right),
_max_row => moves.push(Direction::Left),
_max_col => moves.push(Direction::Left),
_ => {
moves.push(Direction::Left);
moves.push(Direction::Right)