From 48fe3799d152aa76ba9d2f2503608d3d5c0832fb Mon Sep 17 00:00:00 2001 From: lorien420 Date: Mon, 28 Mar 2005 21:11:00 +0000 Subject: [PATCH] Implement flashing to remove warning --- src/ComputerPlayer.cxx | 48 +++++++++++++++++++++++++++++++++--------------- src/ComputerPlayer.h | 6 ++++++ src/LevelLights.cxx | 4 +++- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/ComputerPlayer.cxx b/src/ComputerPlayer.cxx index 59f6a52..a771178 100644 --- a/src/ComputerPlayer.cxx +++ b/src/ComputerPlayer.cxx @@ -29,13 +29,13 @@ using namespace std; //#define WAIT_TIME ( GC_STEPS_PER_SECOND * 10 ) bool ComputerPlayer::lost; +bool ComputerPlayer::_impact; ComputerPlayerAI *ComputerPlayer::ai; void ComputerPlayer::gameStart() { if (!(MetaState::mode & CM_AI)) return; - //queue = new GarbageQueue(); if ((MetaState::mode & CM_AI_EASY)) ai = new EasyAI(); @@ -43,10 +43,7 @@ void ComputerPlayer::gameStart() ai = new MediumAI(); if ((MetaState::mode & CM_AI_HARD)) ai = new HardAI(); - /* - if (ai) - ai->garbageQueue(queue); - */ + assert(ai != NULL); lost = false; @@ -86,15 +83,12 @@ void ComputerPlayer::timeStep() first_time = false; } if (Game::time_step >= localAi.alarm()) { - //localAi.garbageQueue(queue); - localAi.garbageAmount()->sendToGenerator();//garbage_queue); + localAi.garbageAmount()->sendToGenerator(); #ifndef NDEBUG cout << "init pop: " << GC_INITIAL_POP_DELAY << endl; cout << "steps per second: " << GC_STEPS_PER_SECOND << endl; cout << "Height: " << ai->garbageQueue()->height() << endl; #endif - //delete tmp; - //queue->reset(); localAi.resetAlarm(); MESSAGE("AI will drop again in " << ((localAi.alarm() - Game::time_step) / GC_STEPS_PER_SECOND) << " seconds"); LOG("AI will drop again in " << ((localAi.alarm() - Game::time_step) / GC_STEPS_PER_SECOND) << " seconds"); @@ -108,13 +102,13 @@ void ComputerPlayer::addGarbage ( int height, int width, int flavor ) { assert(ai != NULL); MESSAGE("Adding garbage to queue"); ai->garbageQueue()->add(height, width, flavor); + _impact = true; } bool ComputerPlayer::checkLevelLightDying() { int height = ai->garbageQueue()->height(); int ninety = ai->lossHeight() * .9; - //MESSAGE("ninety " << ninety); if (ninety == ai->lossHeight()) ninety = ai->lossHeight() - 1; if (height >= ninety) @@ -122,16 +116,40 @@ bool ComputerPlayer::checkLevelLightDying() return false; } -bool ComputerPlayer::checkLevelLightBlue(int n) +double ComputerPlayer::lightPartition (int n) { - double max = LL_NUMBER_LEVEL_LIGHTS; + static double max = LL_NUMBER_LEVEL_LIGHTS; double lh = ai->lossHeight(); - //MESSAGE("lh " << lh << " max " << max); double partition = lh / max; double colorh = n * partition; - //MESSAGE("n " << n << " partition " << partition << " colorh " << colorh << " height " << ai->garbageQueue()->height()); - if (colorh >= ai->garbageQueue()->height()) + return colorh; +} + +bool ComputerPlayer::checkLevelLightBlue(int n) +{ + if (lightPartition(n) >= ai->garbageQueue()->height()) return true; else return false; } + +int ComputerPlayer::findTopRed() +{ + for (int i=0; i < LL_NUMBER_LEVEL_LIGHTS; ++i) { + if (lightPartition(i) >= ai->garbageQueue()->height()) + return i; + } +} + +int ComputerPlayer::levelLightImpact ( ) +{ + if (impact(true)) + return findTopRed(); +} + +bool ComputerPlayer::impact (bool reset) +{ + bool ret = _impact; + if (reset) _impact = false; + return ret; +} diff --git a/src/ComputerPlayer.h b/src/ComputerPlayer.h index 81aff4c..357ae80 100644 --- a/src/ComputerPlayer.h +++ b/src/ComputerPlayer.h @@ -30,8 +30,12 @@ using namespace std; /* static */ class ComputerPlayer { private: static bool lost; + static bool _impact; static ComputerPlayerAI *ai; + static int findTopRed ( ); + static double lightPartition ( int block ); + public: static void gameStart ( ); static void timeStep ( ); @@ -42,6 +46,8 @@ public: // lights static bool checkLevelLightDying ( ); static bool checkLevelLightBlue ( int block ); + static bool impact ( bool reset = false ); + static int levelLightImpact ( ); }; #endif diff --git a/src/LevelLights.cxx b/src/LevelLights.cxx index cb36d95..02b3628 100644 --- a/src/LevelLights.cxx +++ b/src/LevelLights.cxx @@ -111,6 +111,8 @@ void LevelLights::handleAI () if (!ComputerPlayer::checkLevelLightBlue(n)) setRed(lights[LL_OPPONENT_LIGHTS][n]); } -#warning Doesn't handle flashing! + if (ComputerPlayer::impact()) { + setFlashing(lights[LL_OPPONENT_LIGHTS][ComputerPlayer::levelLightImpact()]); + } } } -- 2.11.4.GIT