elo: fix types
This commit is contained in:
parent
cb00b28166
commit
7863e0324f
26
src/elo.rs
26
src/elo.rs
@ -14,6 +14,8 @@ use skillratings::{
|
|||||||
};
|
};
|
||||||
use std::num::NonZero;
|
use std::num::NonZero;
|
||||||
|
|
||||||
|
type AgentMaker = Box<dyn Fn(Piece) -> Box<dyn Agent>>;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
const FMV_BASE: FutureMoveConfig = FutureMoveConfig {
|
const FMV_BASE: FutureMoveConfig = FutureMoveConfig {
|
||||||
@ -93,16 +95,14 @@ pub fn run() {
|
|||||||
.collect()
|
.collect()
|
||||||
});
|
});
|
||||||
|
|
||||||
let vec: Vec<(String, Box<dyn Fn(Piece) -> Box<dyn Agent>>)> = configs
|
let vec: Vec<(String, AgentMaker)> = configs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(
|
.map(move |config| -> (String, AgentMaker) {
|
||||||
move |config| -> (String, Box<dyn Fn(Piece) -> Box<dyn Agent>>) {
|
(
|
||||||
(
|
format!("{}", config),
|
||||||
format!("{}", config),
|
Box::new(move |piece| Box::new(ComplexAgent::new(piece, config))),
|
||||||
Box::new(move |piece| Box::new(ComplexAgent::new(piece, config))),
|
)
|
||||||
)
|
})
|
||||||
},
|
|
||||||
)
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let mut arena = PlayerArena::new(vec);
|
let mut arena = PlayerArena::new(vec);
|
||||||
@ -114,7 +114,7 @@ pub fn run() {
|
|||||||
|
|
||||||
pub struct PlayerArena {
|
pub struct PlayerArena {
|
||||||
/// Name, Creator Function, Elo
|
/// Name, Creator Function, Elo
|
||||||
players: Vec<(String, Box<dyn Fn(Piece) -> Box<dyn Agent>>, EloRating)>,
|
players: Vec<(String, AgentMaker, EloRating)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for PlayerArena {
|
impl std::fmt::Display for PlayerArena {
|
||||||
@ -136,7 +136,7 @@ impl std::fmt::Display for PlayerArena {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PlayerArena {
|
impl PlayerArena {
|
||||||
pub fn new(players: Vec<(String, Box<dyn Fn(Piece) -> Box<dyn Agent>>)>) -> Self {
|
pub fn new(players: Vec<(String, AgentMaker)>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
players: players
|
players: players
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -259,8 +259,8 @@ impl PlayerArena {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn create_agents(
|
fn create_agents(
|
||||||
player_1_fn: &dyn Fn(Piece) -> Box<dyn Agent>,
|
player_1_fn: &AgentMaker,
|
||||||
player_2_fn: &dyn Fn(Piece) -> Box<dyn Agent>,
|
player_2_fn: &AgentMaker,
|
||||||
) -> (Box<dyn Agent>, Box<dyn Agent>) {
|
) -> (Box<dyn Agent>, Box<dyn Agent>) {
|
||||||
(player_1_fn(Piece::Black), player_2_fn(Piece::White))
|
(player_1_fn(Piece::Black), player_2_fn(Piece::White))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user