From 21e2d05e93843c931bce3a80ec247850ee435e3c Mon Sep 17 00:00:00 2001 From: Jeff Wu Date: Wed, 30 Mar 2016 02:42:03 -0700 Subject: [PATCH] better partitioning, fix card table bug with extra 0 entries --- README.md | 2 +- src/info.rs | 4 +++- src/strategies/information.rs | 33 ++++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d3202c1..407be27 100644 --- a/README.md +++ b/README.md @@ -53,5 +53,5 @@ Currently, on seeds 0-9999, we have: | 2p | 3p | 4p | 5p | ----------|---------|---------|---------|---------| cheating | 24.8600 | 24.9781 | 24.9715 | 24.9583 | -info | 17.136 | 23.181 | 24.63 | 24.805 | +info | 17.147 | 23.357 | 24.76 | 24.824 | diff --git a/src/info.rs b/src/info.rs index 22140ec..9d5cd00 100644 --- a/src/info.rs +++ b/src/info.rs @@ -313,7 +313,9 @@ impl <'a> From<&'a CardCounts> for CardPossibilityTable { for &value in VALUES.iter() { let card = Card::new(color, value); let count = counts.remaining(&card); - possible.insert(card, count); + if count > 0 { + possible.insert(card, count); + } } } CardPossibilityTable { diff --git a/src/strategies/information.rs b/src/strategies/information.rs index 5aae85f..e3dc06d 100644 --- a/src/strategies/information.rs +++ b/src/strategies/information.rs @@ -165,18 +165,37 @@ struct CardPossibilityPartition { } impl CardPossibilityPartition { fn new( - index: usize, n_partitions: u32, card_table: &CardPossibilityTable, view: &T + index: usize, max_n_partitions: u32, card_table: &CardPossibilityTable, view: &T ) -> CardPossibilityPartition where T: GameView { let mut cur_block = 0; let mut partition = HashMap::new(); + let mut n_partitions = 0; + + let has_dead = card_table.probability_is_dead(view.get_board()) != 0.0; + + let effective_max = if has_dead { + max_n_partitions - 1 + } else { + max_n_partitions + }; + for card in card_table.get_possibilities() { - let mut block = cur_block; - if view.get_board().is_dead(&card) { - block = n_partitions - 1; - } else { - cur_block = (cur_block + 1) % (n_partitions - 1); + if !view.get_board().is_dead(&card) { + partition.insert(card.clone(), cur_block); + cur_block = (cur_block + 1) % effective_max; + if n_partitions < effective_max { + n_partitions += 1; + } } - partition.insert(card.clone(), block); + } + + if has_dead { + for card in card_table.get_possibilities() { + if view.get_board().is_dead(&card) { + partition.insert(card.clone(), n_partitions); + } + } + n_partitions += 1; } CardPossibilityPartition {