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 36 37 38 39 40 41 42 43 44 45 46 47 48
|
class challenge {
public:
enum context { // context
SMALL_REWARD=0, LARGE_REWARD=1, PUNISHMENT=2, NONE=3
};
enum position { // position
CX0Y3=0, CX1Y3=1,CX2Y3=2,CX3Y3=3,CX4Y3=4,CX5Y3=5,CX0Y2=6, CX1Y2=7,CX2Y2=8,CX3Y2=9,CX4Y2=10
};
enum time_step{ // time
TIME_STEP_1=0, TIME_STEP_2=1, TIME_STEP_3=2, TIME_STEP_4 = 3,TIME_STEP_5=4, TIME_STEP_6=5
};
// ...
};
namespace multipliers { // multipliers to form the integer id
constexpr int context = 1 ;
constexpr int position = 100 ;
constexpr int time_step = 10'000 ;
}
constexpr int make_state_id( challenge::context c, challenge::position p, challenge::time_step t )
{
// returns an integer of the form ttppcc (two digits for each of the enum values)
// eg, if c == 3, p == 10, t = 4, returns 041003
return c * multipliers::context + p * multipliers::position + t * multipliers::time_step ;
}
challenge::context context_from_id( int id ) {
if( id < 0 || id >= multipliers::time_step * 10 ) throw "bad id" ; // check validity
const int value = id % multipliers::position ; // gets the last two digits
if( value > challenge::NONE ) throw "bad id" ; // check validity
return challenge::context(value) ;
}
challenge::position position_from_id( int id ) {
if( id < 0 || id >= multipliers::time_step * 10 ) throw "bad id" ; // check validity
int value = id % multipliers::time_step ; // pick up the last four digits
value = id / multipliers::position ; // knock off the last two digits
if( value > challenge::CX4Y2 ) throw "bad id" ; // check validity
return challenge::position(value) ;
}
// and likewise for time_step
|