major algo improvements again
This commit is contained in:
@@ -32,7 +32,10 @@ impl Move {
|
||||
fn value(&self, agent_color: Piece, depth: usize) -> i64 {
|
||||
let mut captured_value = self.captured as i64;
|
||||
|
||||
if agent_color != self.color {
|
||||
if self.board.game_over() && self.board.get_winner() != Some(!agent_color) {
|
||||
// if this board results in the opponent winning, MAJORLY negatively weigh this move
|
||||
captured_value = i64::MIN;
|
||||
} else if agent_color != self.color {
|
||||
captured_value = -captured_value;
|
||||
}
|
||||
|
||||
@@ -133,6 +136,8 @@ impl Agent for ComplexAgent {
|
||||
.into_iter()
|
||||
.max_by_key(|m| m.value(self.color, 1));
|
||||
|
||||
assert!(self.curr_move.is_some(), "ComplexAgent didn't make a move");
|
||||
|
||||
self.curr_move.as_ref().map(Move::coords)
|
||||
}
|
||||
|
||||
|
||||
31
src/game.rs
31
src/game.rs
@@ -67,8 +67,37 @@ impl Game {
|
||||
|
||||
println!("{}", self);
|
||||
|
||||
// Check if the game is over
|
||||
// TODO! what if the board isn't full, but one player cannot win as
|
||||
// they don't have any moves to play?
|
||||
// Example::
|
||||
// Player 1 placed at (1, 0)
|
||||
// Players: Complex Agent (□) and Manual Agent (■)
|
||||
// 0 1 2 3 4 5 6 7
|
||||
// -----------------
|
||||
// 0|□|□|□|□|□|□|□|□|
|
||||
// -----------------
|
||||
// 1|■|■|■|□|□|□| |□|
|
||||
// -----------------
|
||||
// 2|■|■|□|■|□|□|□|□|
|
||||
// -----------------
|
||||
// 3|■|■|□|□|■|□|□|□|
|
||||
// -----------------
|
||||
// 4|■|■|□|□|■|□|□|□|
|
||||
// -----------------
|
||||
// 5|□|□|■|□|■|□|□|□|
|
||||
// -----------------
|
||||
// 6| |□|□|□|□|□|□|□|
|
||||
// -----------------
|
||||
// 7| | | |■|■| |■| |
|
||||
// -----------------
|
||||
// White Score: 17
|
||||
// Black Score: 40
|
||||
|
||||
// (depth: 5) possible board states: 0
|
||||
// thread 'main' panicked at src/complexagent.rs:139:9:
|
||||
// ComplexAgent didn't make a move
|
||||
if self.board.game_over() {
|
||||
// end the game
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ mod piece;
|
||||
|
||||
fn main() {
|
||||
let player1 = complexagent::ComplexAgent::new(Piece::Black);
|
||||
let player2 = complexagent::ComplexAgent::new(Piece::White);
|
||||
// let player2 = agent::ManualAgent::new(Piece::White);
|
||||
// let player2 = complexagent::ComplexAgent::new(Piece::White);
|
||||
let player2 = agent::ManualAgent::new(Piece::White);
|
||||
// let player2 = agent::RandomAgent::new(Piece::White);
|
||||
let mut game = Game::new(Box::new(player1), Box::new(player2));
|
||||
game.game_loop();
|
||||
|
||||
Reference in New Issue
Block a user