The Science of Complexity 
by David Lamper and Neil F. Johnson

Listing One
if(win==strategy_prediction)
    Si=1;
else
    Si=0;
S += Si - baS->GetBit(iSindex); //# strategy points
if(Si==1);
    baS->SetBit(iSindex);
else
    baS->ClearBit(iSindex);
if( ++iSindex == T)            //update index
    iSindex = 0;

Listing Two
nas=0;      //number of active strategies (<=q)
max=0;      //maximum number of strategy points
for(i=0;i<q;i++) {
    S=pStrats[i]->points();     //# points 
    if(S>=r) {                  //determine if strategy is active
        if(S>max) {             //check if it's the best
            nas=1;
            max=S;
            work[0]=i;          //temp array to record strategy
        }
        else if(S==max) {       //we have a tied situation
            work[nas]=i;
            nas++;
        }
    }
}
if(nas==0)                     //no active strategy
    return -1; 
else if(nas==1)                //a distinct active strategy
    return work[0];
else {                         //tie-break situation
    i=(int)(nas*random());
    return work[i];
}

Listing Three
m_iQ = (int)pow(2,m_iM+1);
d = 1;
//m_SSpace[history bit]->[strategy number]
m_SSpace = new CBitArray*[m_iP];
for(i=0;i<m_iP;i++)
    m_SSpace[i] = new CBitArray(m_iQ);
m_SSpace[1]->SetBit(1);
for(i=1;i<m_iM;i++) {
    d *= 2;
    for(j=0;j<d;j++) {
        for(k=0;k<d;k++) {
            if(m_SSpace[j]->GetBit(k)==1) {
                m_SSpace[j+d]->SetBit(k);
                m_SSpace[j+d]->SetBit(k+d);
            }
            else 
            m_SSpace[j]->SetBit(k+d);
        }
    }
}
d *= 2;
for(i=0;i<d;i++)        //and mirror into bottom half
    for(j=0;j<d;j++)
        if(m_SSpace[i]->GetBit(j)==0)
            m_SSpace[i]->SetBit(j+d);


Listing Four
if(i<P) {
    strat_prediction = m_SSpace[mu]->GetBit(i);
    strat_points = S[i]; }
else { 
    i = anticorr(i);
    strat_prediction = 1 - m_SSpace[mu]->GetBit(i);
    strat_points = T - S[i]; }


Listing Five
int anticorr(int i) {
    return 2*P - 1 - i;
    }


 


1


