mirror of
https://github.com/Noratrieb/minmax.git
synced 2026-01-14 15:25:08 +01:00
Fixes
This commit is contained in:
parent
d3d7011c43
commit
53bd5cdfde
1 changed files with 8 additions and 5 deletions
|
|
@ -3,7 +3,7 @@ use std::{
|
||||||
ops::{Index, IndexMut},
|
ops::{Index, IndexMut},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{minmax::Score, Game, GamePlayer, Player, State};
|
use crate::{minmax::Score, Game, Player, State};
|
||||||
|
|
||||||
type Position = Option<Player>;
|
type Position = Option<Player>;
|
||||||
|
|
||||||
|
|
@ -55,7 +55,7 @@ impl Connect4 {
|
||||||
fn check_rows(&self) -> State {
|
fn check_rows(&self) -> State {
|
||||||
for row_start in 0..HEIGTH {
|
for row_start in 0..HEIGTH {
|
||||||
for offset in 0..4 {
|
for offset in 0..4 {
|
||||||
let start = row_start + offset;
|
let start = (row_start * WIDTH) + offset;
|
||||||
self.check_four(start, start + 1, start + 2, start + 3)?;
|
self.check_four(start, start + 1, start + 2, start + 3)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +152,7 @@ impl Game for Connect4 {
|
||||||
|
|
||||||
if self[next].is_some() {
|
if self[next].is_some() {
|
||||||
self[prev] = Some(player);
|
self[prev] = Some(player);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,8 +181,11 @@ impl Display for Connect4 {
|
||||||
for j in 0..WIDTH {
|
for j in 0..WIDTH {
|
||||||
let index = (i * WIDTH) + j;
|
let index = (i * WIDTH) + j;
|
||||||
match self[index] {
|
match self[index] {
|
||||||
Some(player) => {
|
Some(Player::X) => {
|
||||||
write!(f, "\x1B[33m {player}\x1B[0m ")?;
|
write!(f, "\x1B[31m X\x1B[0m ")?;
|
||||||
|
}
|
||||||
|
Some(Player::O) => {
|
||||||
|
write!(f, "\x1B[34m O\x1B[0m ")?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
write!(f, "\x1B[35m{index:3 }\x1B[0m ")?;
|
write!(f, "\x1B[35m{index:3 }\x1B[0m ")?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue