-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27a3460
commit e071034
Showing
6 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use mcts::strategies::human::HumanAgent; | ||
use mcts::strategies::mcts::select; | ||
use mcts::strategies::mcts::util; | ||
use mcts::strategies::mcts::SearchConfig; | ||
use mcts::strategies::mcts::TreeSearch; | ||
use mcts::util::battle_royale; | ||
|
||
fn main() { | ||
use mcts::games::gonnect::Gonnect; | ||
|
||
type TS = TreeSearch<Gonnect<7>, util::Ucb1Grave>; | ||
let mut ts = TS::default() | ||
.config( | ||
SearchConfig::default() | ||
.select(select::Ucb1Grave { | ||
exploration_constant: 1.32, | ||
threshold: 700, | ||
bias: 430., | ||
current_ref_id: None, | ||
}) | ||
.max_iterations(300000) | ||
// .max_time(Duration::from_secs(10)) | ||
.expand_threshold(1), | ||
) | ||
.verbose(true); | ||
|
||
let mut human = HumanAgent::new(); | ||
|
||
_ = battle_royale(&mut human, &mut ts); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::io; | ||
use std::io::Write; | ||
use std::marker::PhantomData; | ||
|
||
use crate::{game::Game, strategies::Search}; | ||
|
||
pub struct HumanAgent<G: Game> { | ||
name: String, | ||
marker: PhantomData<G>, | ||
} | ||
|
||
impl<G: Game> Default for HumanAgent<G> { | ||
fn default() -> Self { | ||
Self::new() | ||
} | ||
} | ||
|
||
impl<G: Game> HumanAgent<G> { | ||
pub fn new() -> Self { | ||
Self { | ||
name: "human".into(), | ||
marker: PhantomData, | ||
} | ||
} | ||
} | ||
|
||
impl<G: Game> Search for HumanAgent<G> | ||
where | ||
G::S: std::fmt::Display, | ||
{ | ||
type G = G; | ||
|
||
fn choose_action(&mut self, state: &<Self::G as Game>::S) -> <Self::G as Game>::A { | ||
print!("State is:\n{}", state); | ||
let mut input = String::new(); | ||
loop { | ||
input.clear(); | ||
print!("> "); | ||
io::stdout().flush().expect("Failed to flush stdout"); | ||
match io::stdin().read_line(&mut input) { | ||
Ok(_) => match G::parse_action(state, input.as_str()) { | ||
None => eprintln!("Error parsing input: >{}<", input), | ||
Some(action) => return action, | ||
}, | ||
Err(error) => { | ||
eprintln!("Error reading input: {}", error); | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn friendly_name(&self) -> String { | ||
self.name.clone() | ||
} | ||
|
||
fn set_friendly_name(&mut self, name: &str) { | ||
self.name = name.to_string(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub mod flat_mc; | ||
pub mod human; | ||
pub mod mcts; | ||
pub mod random; | ||
|
||
|