int main() { #ifdef DEBUG /* TODO: implement debugging Debug debug(DEBUG_FREQ); */ #endif // Set output pins: B0 (indicator), B1 (motor), B2 (lamp) DDRB |= BV(DDB0) | BV(DDB1) | BV(DDB2); // Initialize non-inverted pwm in pin OC0B (PB1) TCCR0A |= BV(WGM01) | BV(WGM00); TCCR0A |= BV(COM0B1); Attiny13::setTimer0Prescaler(Attiny13::PSV_64); // Initialize human as not doing anything. OCR0B = 0xff; bool indicatorLit = false; uint16_t counter = 0; while(true) { counter += 1; _delay_ms(LOOP_DELAY); // Read sensors and re-activate human if pig is detected if(pollSensors()) { humanInactivityDelay = HUMAN_DELAY; } runHuman(); if(counter % INDICATOR_HALF_PERIOD == 0) { indicatorLit = !indicatorLit; setIndicator(indicatorLit); } } }
bool BaseAI::startTurn() { int count = 0; count = getWallCount(); walls.clear(); walls.resize(count); for(int i = 0; i < count; i++) { walls[i] = Wall(getWalls()+i); } count = getCrateCount(); crates.clear(); crates.resize(count); for(int i = 0; i < count; i++) { crates[i] = Crate(getCrates()+i); } count = getWeaponCount(); weapons.clear(); weapons.resize(count); for(int i = 0; i < count; i++) { weapons[i] = Weapon(getWeapons()+i); } count = getHumanCount(); humans.clear(); humans.resize(count); for(int i = 0; i < count; i++) { humans[i] = Human(getHumans()+i); } count = getZombieCount(); zombies.clear(); zombies.resize(count); for(int i = 0; i < count; i++) { zombies[i] = Zombie(getZombies()+i); } count = getAirstrikeCount(); airstrikes.clear(); airstrikes.resize(count); for(int i = 0; i < count; i++) { airstrikes[i] = Airstrike(getAirstrikes()+i); } count = getSpawnzoneCount(); spawnzones.clear(); spawnzones.resize(count); for(int i = 0; i < count; i++) { spawnzones[i] = Spawnzone(getSpawnzones()+i); } if(turnNum() == 1) { init(); if(!isHuman()) { return true; } } if(isHuman()) { return runHuman(); } else { return runZombie(); } }