better partitioning, fix card table bug with extra 0 entries

This commit is contained in:
Jeff Wu 2016-03-30 02:42:03 -07:00
parent 79051b51fc
commit 21e2d05e93
3 changed files with 30 additions and 9 deletions

View file

@ -53,5 +53,5 @@ Currently, on seeds 0-9999, we have:
| 2p | 3p | 4p | 5p | | 2p | 3p | 4p | 5p |
----------|---------|---------|---------|---------| ----------|---------|---------|---------|---------|
cheating | 24.8600 | 24.9781 | 24.9715 | 24.9583 | 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 |

View file

@ -313,9 +313,11 @@ impl <'a> From<&'a CardCounts> for CardPossibilityTable {
for &value in VALUES.iter() { for &value in VALUES.iter() {
let card = Card::new(color, value); let card = Card::new(color, value);
let count = counts.remaining(&card); let count = counts.remaining(&card);
if count > 0 {
possible.insert(card, count); possible.insert(card, count);
} }
} }
}
CardPossibilityTable { CardPossibilityTable {
possible: possible, possible: possible,
} }

View file

@ -165,18 +165,37 @@ struct CardPossibilityPartition {
} }
impl CardPossibilityPartition { impl CardPossibilityPartition {
fn new<T>( fn new<T>(
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 { ) -> CardPossibilityPartition where T: GameView {
let mut cur_block = 0; let mut cur_block = 0;
let mut partition = HashMap::new(); let mut partition = HashMap::new();
for card in card_table.get_possibilities() { let mut n_partitions = 0;
let mut block = cur_block;
if view.get_board().is_dead(&card) { let has_dead = card_table.probability_is_dead(view.get_board()) != 0.0;
block = n_partitions - 1;
let effective_max = if has_dead {
max_n_partitions - 1
} else { } else {
cur_block = (cur_block + 1) % (n_partitions - 1); max_n_partitions
};
for card in card_table.get_possibilities() {
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 { CardPossibilityPartition {