literally copy pasted the heuristic scan function here with some minor adjustments

This commit is contained in:
LinlyBoi
2023-05-10 08:15:54 +03:00
parent 4d1c11594a
commit 9f88e6d99e

View File

@@ -58,32 +58,34 @@ impl Board {
Some(disk) => match disk { Some(disk) => match disk {
Disk::P1 => { Disk::P1 => {
for _move in moves { for _move in moves {
let mut consecutive = scan(&self.columns, &index, _move.clone(), 4); let mut consecutive = scan(&self.columns, &index, _move.clone(), 4, *disk);
if consecutive < 4 { if consecutive < 4 {
consecutive += scan( consecutive += scan(
&self.columns, &self.columns,
&index, &index,
flip_direction(_move), flip_direction(_move.clone()),
4 - consecutive + 1, 4 - consecutive,
) *disk,
) - 1;
} }
if consecutive - 1 == 4 { if consecutive == 4 {
self.p1_score += 1 self.p1_score += 1
} }
} }
} }
Disk::P2 => { Disk::P2 => {
for _move in moves { for _move in moves {
let mut consecutive = scan(&self.columns, &index, _move.clone(), 4); let mut consecutive = scan(&self.columns, &index, _move.clone(), 4, *disk);
if consecutive < 4 { if consecutive < 4 {
consecutive += scan( consecutive += scan(
&self.columns, &self.columns,
&index, &index,
flip_direction(_move), flip_direction(_move.clone()),
4 - consecutive + 1, 4 - consecutive,
) *disk,
) - 1;
} }
if consecutive - 1 == 4 { if consecutive == 4 {
self.p2_score += 1 self.p2_score += 1
} }
} }