uncommented hardwork :(

This commit is contained in:
LinlyBoi
2023-05-02 02:20:18 +03:00
parent 70c0827205
commit 21f8976e5e

View File

@@ -1,111 +1,141 @@
use array2d::Array2D; use array2d::Array2D;
use super::Disk; use super::{dec_col, get_indices, inc_col, Disk};
pub fn one_direction(board: &Array2D<Disk>, index: &(usize, usize), direction: Direction) -> i32 { pub fn one_direction(board: &Array2D<Disk>, index: &(usize, usize), direction: Direction) -> i32 {
// let current_disk: &Disk;
// match board.get(index.0, index.1) {
// Some(disk) => current_disk = disk,
// None => return 0,
// };
// let mut current_index = *index;
// let mut in_a_row = 0;
// for _num in 0..4 {
// match board.get(current_index.0, current_index.1) {
// Some(_disk) => {
// if variant_eq(current_disk, _disk) && !matches!(_disk, Disk::EMPTY) {
// // add in a row by 1
// in_a_row += 1;
// //go to next element
// match direction {
// Direction::DOWN => {
// if current_index.0 == 0 {
// break;
// }
// current_index.0 -= 1;
// }
// Direction::UP => {
// if current_index.0 == board.num_columns() - 1 {
// break;
// }
// current_index.0 += 1;
// }
// Direction::BACKWARD => {
// if current_index.1 == 0 {
// break;
// }
// current_index.1 -= 1;
// }
// Direction::FORWARD => {
// if current_index.1 == board.num_rows() - 1 {
// break;
// }
// current_index.1 += 1;
// }
// Direction::UPFORW => {
// if current_index.0 == board.num_columns() - 1
// || current_index.1 == board.num_rows() - 1
// {
// break;
// }
// current_index.1 += 1;
// current_index.0 += 1;
// }
// Direction::UPBACK => {
// if current_index.0 == board.num_columns() - 1 || current_index.1 == 0 {
// break;
// }
// current_index.1 -= 1;
// current_index.0 += 1;
// }
// Direction::DOWNFORW => {
// if current_index.0 == 0 || current_index.1 == board.num_columns() - 1 {
// break;
// }
// current_index.1 += 1;
// current_index.0 -= 1;
// }
// Direction::DOWNBACK => {
// if current_index.0 == 0 || current_index.1 == 0 {
// break;
// }
// current_index.1 -= 1;
// current_index.0 -= 1;
// }
// }
// } else {
// break;
// }
// }
//
// None => break,
// }
// }
// if in_a_row == 4 {
// //score added
// return 1;
// } else {
// return 0;
// }
// //+-3
todo!()
}
// board[(2,3)];
pub fn two_direction(board: &Array2D<Disk>, index: &(usize, usize), direction: Direction) -> i32 {
let mut added_score = 0;
let current_disk: &Disk; let current_disk: &Disk;
match board.get(index.0, index.1) { match board.get(index.0, index.1) {
Some(disk) => current_disk = disk, Some(disk) => current_disk = disk,
None => return 0, None => return 0,
}; };
let mut current_index = *index;
let mut in_a_row = 0;
loop {
match board.get(current_index.0, current_index.1) {
Some(_disk) => {
if variant_eq(current_disk, _disk) && !matches!(_disk, Disk::EMPTY) {
// add in a row by 1
in_a_row += 1;
//go to next element
match direction { match direction {
Direction::DOWN => { Direction::HORIZONTAL => {
if current_index.0 == 0 { //get values to increase/decrease by
break; let two = vec![1, 2];
} let one = vec![1];
current_index.0 -= 1; //get surrounding indices
} let mut indices: Vec<(usize, usize)> = vec![];
Direction::UP => { indices.append(&mut get_indices(index, inc_col, two));
if current_index.0 == board.num_columns() - 1 { indices.append(&mut get_indices(index, dec_col, one));
break; dbg!(indices.clone());
} let mut neighbours: Vec<Disk> = vec![];
current_index.0 += 1; //get neighbours
} for index in indices {
Direction::BACKWARD => { match board.get(index.0, index.1) {
if current_index.1 == 0 { Some(disk) => neighbours.push(*disk),
break;
}
current_index.1 -= 1;
}
Direction::FORWARD => {
if current_index.1 == board.num_rows() - 1 {
break;
}
current_index.1 += 1;
}
Direction::UPFORW => {
if current_index.0 == board.num_columns() - 1
|| current_index.1 == board.num_rows() - 1
{
break;
}
current_index.1 += 1;
current_index.0 += 1;
}
Direction::UPBACK => {
if current_index.0 == board.num_columns() - 1 || current_index.1 == 0 {
break;
}
current_index.1 -= 1;
current_index.0 += 1;
}
Direction::DOWNFORW => {
if current_index.0 == 0 || current_index.1 == board.num_columns() - 1 {
break;
}
current_index.1 += 1;
current_index.0 -= 1;
}
Direction::DOWNBACK => {
if current_index.0 == 0 || current_index.1 == 0 {
break;
}
current_index.1 -= 1;
current_index.0 -= 1;
}
}
} else {
break;
}
}
None => break, None => break,
} }
} }
if in_a_row == 4 { let in_a_row = neighbours
//score added .iter()
return 1; .filter(|&a| variant_eq(a, current_disk))
} else { .count();
return 0; if in_a_row == 3 {
added_score += 1;
} }
//+-3
}
// board[(2,3)];
pub fn two_direction(board: &Array2D<Disk>, index: &(usize, usize)) -> i32 { added_score
let current_disk = board.get(index.0, index.1); }
unimplemented!() Direction::VERTICAL => todo!(),
//+-1 -+2 Direction::DIAGONAL => todo!(),
}
} }
pub enum Direction { pub enum Direction {
UP, HORIZONTAL,
DOWN, VERTICAL,
FORWARD, DIAGONAL,
BACKWARD,
UPFORW,
UPBACK,
DOWNFORW,
DOWNBACK,
//TODO add more directions for diagonals
} }
// serves nothing except do what matches!() should have done all along // serves nothing except do what matches!() should have done all along
fn variant_eq<T>(a: &T, b: &T) -> bool { fn variant_eq<T>(a: &T, b: &T) -> bool {