fixed the score check bug that burnt out me couldn't fix
This commit is contained in:
@@ -9,21 +9,22 @@ pub fn scan(
|
|||||||
index: &(usize, usize),
|
index: &(usize, usize),
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
depth: i32,
|
depth: i32,
|
||||||
|
player_disk: Disk,
|
||||||
) -> i32 {
|
) -> i32 {
|
||||||
let current_disk: &Disk = match board.get(index.0, index.1) {
|
match board.get(index.0, index.1) {
|
||||||
Some(disk) => disk,
|
Some(_) => {}
|
||||||
None => return 0,
|
None => return 0,
|
||||||
};
|
};
|
||||||
let mut current_index = *index;
|
let mut current_index = *index;
|
||||||
let mut in_a_row = 0;
|
let mut in_a_row: Vec<Disk> = vec![];
|
||||||
// dbg!("Starting new thing", &direction);
|
// dbg!("Starting new thing", &direction);
|
||||||
for _num in 0..depth {
|
for _num in 0..depth {
|
||||||
match board.get(current_index.0, current_index.1) {
|
match board.get(current_index.0, current_index.1) {
|
||||||
Some(_disk) => {
|
Some(_disk) => {
|
||||||
// dbg!(_disk, current_disk, in_a_row);
|
// 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
|
// add in a row by 1
|
||||||
in_a_row += 1;
|
in_a_row.push(*_disk);
|
||||||
// dbg!(current_index);
|
// dbg!(current_index);
|
||||||
//go to next element
|
//go to next element
|
||||||
match direction {
|
match direction {
|
||||||
@@ -44,14 +45,12 @@ pub fn scan(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current_index = dec_col(¤t_index, 1);
|
current_index = dec_col(¤t_index, 1);
|
||||||
// current_index.1 -= 1;
|
|
||||||
}
|
}
|
||||||
Direction::Right => {
|
Direction::Right => {
|
||||||
if current_index.1 == board.num_columns() - 1 {
|
if current_index.1 == board.num_columns() - 1 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current_index = inc_col(¤t_index, 1);
|
current_index = inc_col(¤t_index, 1);
|
||||||
// current_index.1 += 1;
|
|
||||||
}
|
}
|
||||||
Direction::UpRight => {
|
Direction::UpRight => {
|
||||||
if current_index.0 == board.num_rows() - 1
|
if current_index.0 == board.num_rows() - 1
|
||||||
@@ -60,16 +59,12 @@ pub fn scan(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current_index = inc_both(¤t_index, 1);
|
current_index = inc_both(¤t_index, 1);
|
||||||
// current_index.1 += 1;
|
|
||||||
// current_index.0 += 1;
|
|
||||||
}
|
}
|
||||||
Direction::UpLeft => {
|
Direction::UpLeft => {
|
||||||
if current_index.0 == board.num_columns() - 1 || current_index.1 == 0 {
|
if current_index.0 == board.num_columns() - 1 || current_index.1 == 0 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// current_index.1 -= 1;
|
|
||||||
// current_index.0 += 1;
|
|
||||||
current_index = inc_dec(¤t_index, 1);
|
current_index = inc_dec(¤t_index, 1);
|
||||||
}
|
}
|
||||||
Direction::DownRight => {
|
Direction::DownRight => {
|
||||||
@@ -77,8 +72,6 @@ pub fn scan(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
current_index = dec_inc(¤t_index, 1);
|
current_index = dec_inc(¤t_index, 1);
|
||||||
// current_index.1 += 1;
|
|
||||||
// current_index.0 -= 1;
|
|
||||||
}
|
}
|
||||||
Direction::DownLeft => {
|
Direction::DownLeft => {
|
||||||
if current_index.0 == 0 || current_index.1 == 0 {
|
if current_index.0 == 0 || current_index.1 == 0 {
|
||||||
@@ -95,28 +88,27 @@ pub fn scan(
|
|||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in_a_row
|
in_a_row.len() as i32
|
||||||
// //+-3
|
|
||||||
}
|
}
|
||||||
// board[(2,3)];
|
// board[(2,3)];
|
||||||
pub fn get_legal_moves(
|
pub fn get_legal_moves(
|
||||||
(row, col): &(usize, usize),
|
(row, col): &(usize, usize),
|
||||||
(nrow, ncol): (usize, usize),
|
(nrow, ncol): (usize, usize),
|
||||||
) -> Vec<Direction> {
|
) -> Vec<Direction> {
|
||||||
let _max_col = nrow - 1;
|
let _max_col = ncol - 1;
|
||||||
let _max_row = ncol - 1;
|
let _max_row = nrow - 1;
|
||||||
let mut moves: Vec<Direction> = vec![];
|
let mut moves: Vec<Direction> = vec![];
|
||||||
match *col {
|
match *row {
|
||||||
0 => moves.push(Direction::Up),
|
0 => moves.push(Direction::Up),
|
||||||
_max_row => moves.push(Direction::Down),
|
_max_rows => moves.push(Direction::Down),
|
||||||
_ => {
|
_ => {
|
||||||
moves.push(Direction::Up);
|
moves.push(Direction::Up);
|
||||||
moves.push(Direction::Down);
|
moves.push(Direction::Down);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match *row {
|
match *col {
|
||||||
0 => moves.push(Direction::Right),
|
0 => moves.push(Direction::Right),
|
||||||
_max_row => moves.push(Direction::Left),
|
_max_col => moves.push(Direction::Left),
|
||||||
_ => {
|
_ => {
|
||||||
moves.push(Direction::Left);
|
moves.push(Direction::Left);
|
||||||
moves.push(Direction::Right)
|
moves.push(Direction::Right)
|
||||||
|
|||||||
Reference in New Issue
Block a user