-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcube.rs
35 lines (32 loc) · 1.1 KB
/
cube.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use engine::probabilities::Probabilities;
#[cfg(feature = "web")]
use serde::Serialize;
#[cfg(feature = "web")]
use utoipa::ToSchema;
#[cfg_attr(feature = "web", derive(Serialize, ToSchema))]
/// Information about proper cube decisions. Currently quick and dirty calculations.
pub struct CubeInfo {
/// `true` if the player `x` should double, `false` if no double yet or too good.
double: bool,
/// `true` if the opponent should take the cube, `false` if they should reject.
accept: bool,
}
impl From<&Probabilities> for CubeInfo {
fn from(value: &Probabilities) -> Self {
// This is just a very simple calculation so that we can implement the cube API.
// Later we want better cube decisions, helpful could be the article:
// https://bkgm.com/articles/Janowski/cubeformulae.pdf
let equity = value.equity();
let double = equity > 0.4 && equity < 0.6;
let accept = equity < 0.5;
Self { double, accept }
}
}
impl CubeInfo {
pub fn double(&self) -> bool {
self.double
}
pub fn accept(&self) -> bool {
self.accept
}
}