know.OpenHardware

erduino...

computers "gumsticks"

psp screens available... {{{

// Specify the way to modify my pattern when I receive another pattern
void combinePats(int rcvdPattern)
{
    //g_MyPattern ^=  rcvdPattern;       // bitwise XOR (~add) the patterns
    return combinePats_GiftEconomy(rcvdPattern);
    //return combinePats_InfoCommons(rcvdPattern);
    //return combinePats_InfoNeighborhood(rcvdPattern);
} // combinePats()


void combinePats_GiftEconomy(int rcvdPattern)
{
    g_MyPattern = rcvdPattern;         // adopt the pattern you just received, no matter what
    g_CurrentEnergyLevel += g_EnergyGainPerMsgAffectedBy;
} // combinePats_GiftEconomy()


void combinePats_InfoCommons(int rcvdPattern)
{
    if(g_MyPattern != rcvdPattern)
    {
        g_MyPattern = rcvdPattern;     // adopt the pattern you just received, unless you already hold it
        g_CurrentEnergyLevel += g_EnergyGainPerMsgAffectedBy;
    }
} // combinePats_InfoCommons()


// Only be affected by a pattern that I've not held in the last N changes.
void combinePats_InfoNeighborhood(int rcvdPattern)
{
    static const int neighborhoodSize = 4;
    static int lastOne = 0;
    static int numPats = 0;
    static int recentlySeen[neighborhoodSize];

    int p = 0;
    while(p < numPats  &&  p < neighborhoodSize  &&  recentlySeen[p++] != rcvdPattern);
    if (p == neighborhoodSize  ||  p == numPats)   // if rcvdPattern not found in recent list
    {
        g_MyPattern = rcvdPattern;      
        g_CurrentEnergyLevel += g_EnergyGainPerMsgAffectedBy;
    }

    recentlySeen[lastOne++] = rcvdPattern;
    lastOne %= neighborhoodSize;       // wrap around
    ++numPats;
} // combinePats_InfoCommons()

}}}


Edit Rename Changes History Upload Download Back to Top