-
Notifications
You must be signed in to change notification settings - Fork 37
/
StateTable.cpp
35 lines (30 loc) · 1.38 KB
/
StateTable.cpp
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
#include "StateTable.hpp"
uint8_t StateTable::getNextState(uint8_t const state, const int y) {
return stateTable[state][y];
}
uint8_t StateTable::getNextState(uint8_t const oldState, const int y, Random &rnd) {
const uint8_t newState = stateTable[oldState][y];
if (newState >= 205 && newState >= oldState + 4) {
// Apply probabilistic increment for contexts with strong trend of 0s or 1s.
// Applicable to states 149 and above, but we'll start applying it from states (205-208).
// That means...
// For states 205..208, 209..212, ... 249..252 a group of 4 states is not represented by
// the counts indicated in the state table. An exponential scale is used instead.
// The highest group (249..252) represents the top of this scale, where we can not increment anymore.
// Reaching the highest states (249-252) from states (201-204) takes 12 steps.
// thus the probability of reaching the highest states (249-252) is ~ 1/2048
if (rnd(1) != 0) { // random bit: p()=1/2 -> the probability to advance to a higher state is 1/2
return oldState; // don't advance
}
}
return newState;
}
void StateTable::update(uint8_t *const state, const int y, Random &rnd) {
*state = getNextState(*state, y, rnd);
}
uint8_t StateTable::group(const uint8_t state) {
return stateGroup[state];
}
uint8_t StateTable::prio(const uint8_t state) {
return statePrio[state];
}