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.
22 #include "LevelLights.h"
23 #include "ComputerPlayer.h"
28 //#define WAIT_TIME ( GC_STEPS_PER_SECOND * 10 )
30 bool ComputerPlayer::lost
;
31 ComputerPlayerAI
*ComputerPlayer::ai
;
33 void ComputerPlayer::gameStart()
35 if (!(MetaState::mode
& CM_AI
))
37 //queue = new GarbageQueue();
39 if ((MetaState::mode
& CM_AI_EASY
))
41 if ((MetaState::mode
& CM_AI_MEDIUM
))
43 if ((MetaState::mode
& CM_AI_HARD
))
47 ai->garbageQueue(queue);
54 static void show_element (GarbageQueueElement
*e
) {
56 printf("Element: %p h %d w %d f %d\n",
64 int ComputerPlayer::gameFinish()
66 return ai
->determineLoss() ? GS_WON
: GS_LOST
;
69 void ComputerPlayer::timeStep()
71 static bool first_time
= true;
72 if (!(MetaState::mode
& CM_AI
))
79 LevelLights::handleAI();
81 ComputerPlayerAI
&localAi
= *ai
;
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");
87 if (Game::time_step
>= localAi
.alarm()) {
88 //localAi.garbageQueue(queue);
89 localAi
.garbageAmount()->sendToGenerator();//garbage_queue);
91 cout
<< "init pop: " << GC_INITIAL_POP_DELAY
<< endl
;
92 cout
<< "steps per second: " << GC_STEPS_PER_SECOND
<< endl
;
93 cout
<< "Height: " << ai
->garbageQueue()->height() << endl
;
98 MESSAGE("AI will drop again in " << ((localAi
.alarm() - Game::time_step
) / GC_STEPS_PER_SECOND
) << " seconds");
99 LOG("AI will drop again in " << ((localAi
.alarm() - Game::time_step
) / GC_STEPS_PER_SECOND
) << " seconds");
101 if(localAi
.determineLoss()) {
102 Game::aiPlayerLoss();
106 void ComputerPlayer::addGarbage ( int height
, int width
, int flavor
) {
108 MESSAGE("Adding garbage to queue");
109 ai
->garbageQueue()->add(height
, width
, flavor
);
112 bool ComputerPlayer::checkLevelLightDying()
114 int height
= ai
->garbageQueue()->height();
115 int ninety
= ai
->lossHeight() * .9;
116 //MESSAGE("ninety " << ninety);
117 if (ninety
== ai
->lossHeight())
118 ninety
= ai
->lossHeight() - 1;
119 if (height
>= ninety
)
124 bool ComputerPlayer::checkLevelLightBlue(int n
)
126 double max
= LL_NUMBER_LEVEL_LIGHTS
;
127 double lh
= ai
->lossHeight();
128 //MESSAGE("lh " << lh << " max " << max);
129 double partition
= lh
/ max
;
130 double colorh
= n
* partition
;
131 //MESSAGE("n " << n << " partition " << partition << " colorh " << colorh << " height " << ai->garbageQueue()->height());
132 if (colorh
>= ai
->garbageQueue()->height())