Skip to content

Commit 8204460

Browse files
committed
fix filter of Edge::Draw in Path Vec<Edge> bijection
1 parent d956bf3 commit 8204460

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

src/mccfr/blueprint.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,12 @@ impl Solver {
116116
/// continuing Edge Actions.
117117
/// fn explore(&mut self, tree: &mut Tree,node: &Node) -> Vec<Branch> {
118118
fn explore(&mut self, node: &Node) -> Vec<Branch> {
119-
use crate::gameplay::ply::Ply;
120-
// INCORRECT
121119
let branches = self.sampler.branches(node);
122120
let walker = self.profile.walker();
123121
let chance = Player::chance();
124122
let player = node.player();
125123
match (branches.len(), player) {
126-
(0, p) => {
127-
// INCORRECT
128-
assert!(p.0 == Ply::Terminal);
124+
(0, _) => {
129125
vec![] //
130126
}
131127
(_, p) if p == chance => {

src/mccfr/node.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,6 @@ impl<'tree> Node<'tree> {
6666

6767
// Navigational methods
6868

69-
/// if we were to play this edge, what would the
70-
/// history: Vec<Edge> of the resulting Node be?
71-
#[allow(dead_code)]
72-
fn chained(&self, edge: &Edge) -> Vec<Edge> {
73-
self.history()
74-
.into_iter()
75-
.rev()
76-
.chain(std::iter::once(edge))
77-
.rev()
78-
.take_while(|e| e.is_choice())
79-
.copied()
80-
.collect()
81-
}
8269
pub fn history(&self) -> Vec<&'tree Edge> {
8370
if let (Some(edge), Some(head)) = (self.incoming(), self.parent()) {
8471
let mut history = head.history();
@@ -138,8 +125,9 @@ impl<'tree> Node<'tree> {
138125
Bucket::from((subgame, present, choices))
139126
}
140127

141-
/// TODO
142-
/// compare to self::futures()
128+
/// determine the set of branches that could be taken from this node
129+
/// this determines what Bucket we end up in since Tree::attach()
130+
/// uses this to assign Buckets to Data upon insertion
143131
pub fn branches(&self) -> Vec<(Edge, Game)> {
144132
self.stale_continuations()
145133
.into_iter()
@@ -233,6 +221,19 @@ impl<'tree> Node<'tree> {
233221
.copied()
234222
.collect()
235223
}
224+
/// if we were to play this edge, what would the
225+
/// history: Vec<Edge> of the resulting Node be?
226+
#[allow(dead_code)]
227+
fn chained(&self, edge: &Edge) -> Vec<Edge> {
228+
self.history()
229+
.into_iter()
230+
.rev()
231+
.chain(std::iter::once(edge))
232+
.rev()
233+
.take_while(|e| e.is_choice())
234+
.copied()
235+
.collect()
236+
}
236237
}
237238

238239
impl std::fmt::Display for Node<'_> {

src/mccfr/path.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ impl Arbitrary for Path {
1515
/// we (un)pack the byte representation of the edges in a Path(u64) sequence
1616
impl From<Path> for Vec<Edge> {
1717
fn from(path: Path) -> Self {
18-
(0..16)
19-
.map(|i| ((path.0 >> (i * 4)) & 0xF) as u8)
20-
.filter(|&bits| bits != 0)
18+
(0..)
19+
.map(|i| i * 4)
20+
.map(|b| 0xF & (path.0 >> b))
21+
.map(|bits| bits as u8)
22+
.take_while(|bits| bits != &0)
2123
.map(Edge::from)
22-
.take_while(|e| e.is_choice())
2324
.collect()
2425
}
2526
}
@@ -28,10 +29,12 @@ impl From<Vec<Edge>> for Path {
2829
assert!(edges.len() <= 16);
2930
edges
3031
.into_iter()
32+
.map(u8::from)
33+
.map(|byte| byte as u64)
3134
.enumerate()
32-
.map(|(i, edge)| (i, u8::from(edge)))
33-
.map(|(i, byte)| (byte as u64) << (i * 4))
34-
.fold(Self::default(), |Self(acc), bits| Self(acc | bits))
35+
.map(|(i, byte)| byte << (i * 4))
36+
.fold(0u64, |acc, bits| acc | bits)
37+
.into()
3538
}
3639
}
3740

src/mccfr/profile.rs

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ pub struct Profile {
4040
}
4141

4242
impl Profile {
43+
/// count of Buckets visited so far
44+
pub fn size(&self) -> usize {
45+
self.strategies.len()
46+
}
4347
/// increment Epoch counter
4448
/// and return current count
4549
pub fn next(&mut self) -> usize {

0 commit comments

Comments
 (0)