3 * Andrew Sayman - 3/27/05
5 * Copyright (C) 2005 Andrew Sayman
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "LevelLights.h"
24 #include "ComputerPlayer.h"
29 //#define WAIT_TIME ( GC_STEPS_PER_SECOND * 10 )
31 bool ComputerPlayer::lost
;
32 bool ComputerPlayer::_impact
;
33 ComputerPlayerAI
*ComputerPlayer::ai
;
35 void ComputerPlayer::gameStart()
37 if (!(MetaState::mode
& CM_AI
))
40 if ((MetaState::mode
& CM_AI_EASY
))
42 if ((MetaState::mode
& CM_AI_MEDIUM
))
44 if ((MetaState::mode
& CM_AI_HARD
))
52 int ComputerPlayer::gameFinish()
54 return ai
->determineLoss() ? GS_WON
: GS_LOST
;
57 void ComputerPlayer::timeStep()
59 static bool first_time
= true;
60 if (!(MetaState::mode
& CM_AI
))
67 LevelLights::handleAI();
69 ComputerPlayerAI
&localAi
= *ai
;
71 MESSAGE("AI will drop again in " << ((localAi
.alarm() - Game::time_step
) / GC_STEPS_PER_SECOND
) << " seconds");
72 LOG("AI will drop again in " << ((localAi
.alarm() - Game::time_step
) / GC_STEPS_PER_SECOND
) << " seconds");
75 if (Game::time_step
>= localAi
.alarm()) {
76 localAi
.garbageAmount()->sendToGenerator();
78 cout
<< "init pop: " << GC_INITIAL_POP_DELAY
<< endl
;
79 cout
<< "steps per second: " << GC_STEPS_PER_SECOND
<< endl
;
80 cout
<< "Height: " << ai
->garbageQueue()->height() << endl
;
83 MESSAGE("AI will drop again in " << ((localAi
.alarm() - Game::time_step
) / GC_STEPS_PER_SECOND
) << " seconds");
84 LOG("AI will drop again in " << ((localAi
.alarm() - Game::time_step
) / GC_STEPS_PER_SECOND
) << " seconds");
86 if(localAi
.determineLoss()) {
91 void ComputerPlayer::addGarbage ( int height
, int width
, int flavor
) {
93 MESSAGE("Adding garbage to queue");
94 ai
->garbageQueue()->add(height
, width
, flavor
);
98 bool ComputerPlayer::checkLevelLightDying()
100 int height
= ai
->garbageQueue()->height();
101 int ninety
= (int)(ai
->lossHeight() * .9);
102 if (ninety
== ai
->lossHeight())
103 ninety
= ai
->lossHeight() - 1;
104 if (height
>= ninety
)
109 double ComputerPlayer::lightPartition (int n
)
111 static double max
= LL_NUMBER_LEVEL_LIGHTS
;
112 double lh
= ai
->lossHeight();
113 double partition
= lh
/ max
;
114 double colorh
= n
* partition
;
118 bool ComputerPlayer::checkLevelLightBlue(int n
)
120 if (lightPartition(n
) >= ai
->garbageQueue()->height())
126 int ComputerPlayer::findTopRed()
128 for (int i
=0; i
< LL_NUMBER_LEVEL_LIGHTS
; ++i
) {
129 if (lightPartition(i
) >= ai
->garbageQueue()->height())
135 int ComputerPlayer::levelLightImpact ( )
143 bool ComputerPlayer::impact (bool reset
)
146 if (reset
) _impact
= false;