the start of sth cool in gamedata
This commit is contained in:
@@ -1,9 +1,20 @@
|
|||||||
|
mod score_checkers;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
sync::mpsc::{self, Receiver, Sender},
|
||||||
|
thread,
|
||||||
|
};
|
||||||
|
|
||||||
|
use array2d::Array2D;
|
||||||
|
|
||||||
|
use self::score_checkers::{one_direction, two_direction};
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Board {
|
pub struct Board {
|
||||||
p1_score: i32,
|
p1_score: i32,
|
||||||
p2_score: i32,
|
p2_score: i32,
|
||||||
columns: Vec<Vec<i32>>,
|
columns: Vec<Vec<Disk>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Board {
|
impl Default for Board {
|
||||||
@@ -19,3 +30,41 @@ impl Default for Board {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Board {
|
||||||
|
fn getscore(&self) -> (i32, i32) {
|
||||||
|
(self.p1_score, self.p2_score)
|
||||||
|
}
|
||||||
|
fn play(&mut self, disk: Disk, col: i32) {
|
||||||
|
match self.columns.get_mut(col as usize) {
|
||||||
|
Some(column) => {
|
||||||
|
if column.len() != column.capacity() {
|
||||||
|
column.push(disk)
|
||||||
|
} else {
|
||||||
|
println!("Column full")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => println!("column not exist"), //TODO properly handle this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fn score_check(&mut self, index: (usize, usize)) {
|
||||||
|
let _board = Array2D::from_columns(&self.columns);
|
||||||
|
match _board {
|
||||||
|
Ok(board) => {
|
||||||
|
// thread::scope(|scope| {
|
||||||
|
// let (tx, rx): (Sender<i32>, Receiver<i32>) = mpsc::channel();
|
||||||
|
// let one = scope.spawn(|| tx.clone().send(one_direction(&board, &index)));
|
||||||
|
// let two = scope.spawn(|| two_direction(&board, &index));
|
||||||
|
// one.join();
|
||||||
|
// two.join();
|
||||||
|
// }); //ignore this is threading for later TODO
|
||||||
|
}
|
||||||
|
Err(_err) => println!("Error parsing the thing"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub enum Disk {
|
||||||
|
RED,
|
||||||
|
BLUE,
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user