From 46be26af768e1686e6e151ba5defb17d937b78f1 Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Mon, 1 May 2023 00:05:50 +0300 Subject: [PATCH] Horizotnal score checking :D --- src/gamedata/score_checkers.rs | 59 ++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/src/gamedata/score_checkers.rs b/src/gamedata/score_checkers.rs index 25a08c8..8956f7b 100644 --- a/src/gamedata/score_checkers.rs +++ b/src/gamedata/score_checkers.rs @@ -2,11 +2,66 @@ use array2d::Array2D; use super::Disk; -pub fn one_direction(board: &Array2D, index: &(usize, usize)) -> i32 { +pub fn one_direction(board: &Array2D, index: &(usize, usize), direction: Direction) -> i32 { let current_disk = board.get(index.0, index.1); - unimplemented!() + let mut current_index = *index; + let mut in_a_row = 0; + loop { + dbg!(in_a_row, current_index); + match board.get(current_index.0, current_index.1) { + Some(_disk) => { + if matches!(current_disk, _disk) && !matches!(_disk, Disk::EMPTY) { + // add in a row by 1 + in_a_row += 1; + //go to next element + match direction { + Direction::BACKWARD => { + if current_index.0 == 0 { + break; + } + current_index.0 -= 1; + } + Direction::FORWARD => { + if current_index.0 == board.num_rows() - 1 { + break; + } + current_index.0 += 1; + } + } + } else { + break; + } + } + + None => break, + } + } + if in_a_row == 4 { + //score added + return 1; + } else { + return 0; + } + //+-3 } +// board[(2,3)]; + pub fn two_direction(board: &Array2D, index: &(usize, usize)) -> i32 { let current_disk = board.get(index.0, index.1); unimplemented!() + //+-1 -+2 +} +//1 == number +//dbg!() +//println!() +//matches!() +//assert!() + +// for _num 0..n {} +pub enum Direction { + UP, + DOWN, + FORWARD, + BACKWARD, + //TODO add more directions for diagonals }