Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Rules Class Reference

#include <rules.h>

List of all members.

Public Methods

 Rules (void)
int SpyCaught (void)
void NewTurn (void)
void UpdateSpyPos (PosType locus)
int NumTurns (void)
int CurrentTurn (void)
MoveListGetLegalMoves (Player &dude)
PosType ShowSpy (void)
preyass GameOver (void)
PosType RandomPos (void)
int SpyLastX (void)
int SpyLastY (void)
int StartingTokens (TokenType identity)

Private Methods

bool NoTurnsLeft (void)
bool DetectivesTrapped (void)
MoveRules::CanGo (int taxi, int bus, int subway, PosType source, PosType dest)
bool Occupato (PosType birdsplat)

Private Attributes

int turn
int tachymetabolic
int endothermy


Constructor & Destructor Documentation

Rules::Rules void    [inline]
 

Definition at line 32 of file rules.h.

References endothermy, tachymetabolic, and turn.

00033      {
00034       turn = 0;
00035       tachymetabolic = theMap.max_x () / 2;
00036       endothermy = theMap.max_y () / 2;
00037      }


Member Function Documentation

int Rules::CurrentTurn void    [inline]
 

Definition at line 43 of file rules.h.

References turn.

Referenced by main().

00043 { return turn; }      // Turn, turn, turn

bool Rules::DetectivesTrapped void    [private]
 

Definition at line 14 of file rules.c.

References False, GetLegalMoves(), MoveList::Length(), and True.

Referenced by GameOver().

00015   {
00016    int counter;
00017    MoveList *steinBrenner;       // YOU got a better name?
00018 
00019    for (counter = 1; counter < NumPlayers; counter++)
00020      {
00021       steinBrenner = GetLegalMoves (*thePlayers [counter]);
00022       if (steinBrenner->Length ()) return False;
00023      }
00024    return True;
00025   }

preyass Rules::GameOver void   
 

Definition at line 168 of file rules.c.

References DetectivesTrapped(), NoTurnsLeft(), preyass, SpyCaught(), and spyWins.

Referenced by main().

00169   {
00170    preyass sleuth;
00171 
00172    /* All right. Here's the deal with the return value of this
00173       function. First, it's called "prey ass" because it describes
00174       the game's end. Get it? I tought you would.
00175 
00176       Now, if the spy wins, it returns -1. Why? Because I said so,
00177       that's why! If the game isn't done yet it returns "notYet"
00178       (duh). If a detective wins, it returns his number in the
00179       array (so, if detective 3 wins, it returns 3. It's amazing). */
00180 
00181     if (NoTurnsLeft ()) return spyWins;
00182     if (DetectivesTrapped ()) return spyWins;
00183     return (preyass) SpyCaught ();
00184    }

MoveList * Rules::GetLegalMoves Player   dude
 

Definition at line 113 of file rules.c.

References Bus, Player::GetPosition(), Player::NumTokens(), Occupato(), PosType, Subway, and Taxi.

Referenced by DetectivesTrapped().

00114   {
00115    Move *nextMove;              // These get added into the list
00116    MoveList *congaLine;         // Nuke () works on empty list?
00117    PosType position;            // Where is our frothing fiend?
00118    int busTokens;               // How many taxi tokens this guy has
00119    int taxiTokens;              // Duh, I wonder what she's
00120    int subwayTokens;            // talking about, Norm!
00121    int counter, city, limit;    // Austin City Limits :-)
00122    bool blocked;                // Cannot stack detectives in cities
00123 
00124    congaLine = new MoveList;
00125    position = dude.GetPosition ();
00126    taxiTokens = dude.NumTokens (Taxi);
00127    busTokens = dude.NumTokens (Bus);
00128    subwayTokens = dude.NumTokens (Subway);
00129    limit = theMap.num_connections (position);
00130    for (counter = 0; counter < limit; counter++)
00131      {
00132       city = theMap.connected_to (position, counter);
00133       nextMove = CanGo (taxiTokens, busTokens, subwayTokens, position, city);
00134       blocked = Occupato (city);
00135       if (blocked)                   // Oh, no. We gotta go, me-oh-my-oo.
00136   {
00137    delete nextMove;
00138    nextMove = NULL;
00139   }
00140       if (nextMove) congaLine -> Append (nextMove);
00141      }
00142    return congaLine;
00143   }

void Rules::NewTurn void    [inline]
 

Definition at line 40 of file rules.h.

References turn.

Referenced by main().

00040 { turn++; }              // Use Gritto, radio friends

bool Rules::NoTurnsLeft void    [inline, private]
 

Definition at line 24 of file rules.h.

References bool, MAXTURNS, and turn.

Referenced by GameOver().

00024 { return (bool (turn > MAXTURNS)); }

int Rules::NumTurns void    [inline]
 

Definition at line 42 of file rules.h.

References MAXTURNS.

00042 { return MAXTURNS; }     // To everything

bool Rules::Occupato PosType    birdsplat [private]
 

Definition at line 100 of file rules.c.

References False, PosType, and True.

Referenced by GetLegalMoves().

00101   {
00102    int counter;
00103    PosType windshield;
00104 
00105    for (counter = 1; counter < NumPlayers; counter++)
00106      {
00107       windshield = thePlayers [counter] -> GetPosition ();
00108       if (windshield == birdsplat) return True; // and kill the damned bird!
00109      }
00110    return False;
00111   }

PosType Rules::RandomPos void   
 

Definition at line 41 of file rules.c.

References False, max(), MAXPLAYERS, PosType, and True.

00042   {
00043    static playPosition [MAXPLAYERS];
00044    static int nextPlayer = 0;
00045    int min, max, counter, ok = False;
00046    PosType randPos;
00047 
00048    max = theMap.num_nodes ();
00049    while (!ok)
00050      {
00051       randPos = (Random * max) + 1;
00052       ok = True;
00053       while ((ok) && (counter < nextPlayer))
00054   if (randPos == playPosition [counter++]) ok = False;
00055       if (ok) playPosition [nextPlayer++] = randPos;
00056      }
00057    return randPos;
00058   }

Move* Rules::Rules::CanGo int    taxi,
int    bus,
int    subway,
PosType    source,
PosType    dest
[private]
 

PosType Rules::ShowSpy void   
 

Definition at line 151 of file rules.c.

References PosType, theSpy, and UpdateSpyPos().

00152   {
00153    PosType serve;
00154 
00155    switch (turn)
00156      {
00157       case 2  :
00158       case 7  :
00159       case 12 :
00160       case 17 :
00161       case 22 : serve = thePlayers [theSpy] -> GetPosition ();
00162             UpdateSpyPos (serve);
00163             return serve;     // tennis, anyone?
00164       default: return 0;
00165      }
00166   }

int Rules::SpyCaught void   
 

Definition at line 27 of file rules.c.

References False, PosType, and theSpy.

Referenced by GameOver(), and main().

00028   {
00029    PosType spyPos, sleuthPos;
00030    int counter;
00031 
00032    spyPos = thePlayers [theSpy] -> GetPosition ();
00033    for (counter = 1; counter < NumPlayers; counter++)
00034      {
00035       sleuthPos = thePlayers [counter] -> GetPosition ();
00036       if (spyPos == sleuthPos) return counter;
00037      }
00038    return False;
00039   }

int Rules::SpyLastX void    [inline]
 

Definition at line 48 of file rules.h.

References tachymetabolic.

00048 {return tachymetabolic;} // And a time to every

int Rules::SpyLastY void    [inline]
 

Definition at line 49 of file rules.h.

References endothermy.

00049 { return endothermy; }   // Purpose under Heaven

int Rules::StartingTokens TokenType    identity
 

Definition at line 60 of file rules.c.

References Bus, NUM_BUS_TOKENS, NUM_SUBWAY_TOKENS, NUM_TAXI_TOKENS, Subway, Taxi, and TokenType.

00061   {
00062    switch (identity)
00063      {
00064       case Subway: return NUM_SUBWAY_TOKENS;
00065       case Taxi: return NUM_TAXI_TOKENS;
00066       case Bus: return NUM_BUS_TOKENS;
00067       default : return 0;   // F---ing compiler!!!!!!!!!
00068      }
00069   }

void Rules::UpdateSpyPos PosType    locus
 

Definition at line 145 of file rules.c.

References endothermy, PosType, and tachymetabolic.

Referenced by ShowSpy().

00146   {
00147    tachymetabolic = theMap.x (locus);
00148    endothermy = theMap.y (locus);
00149   }


Member Data Documentation

int Rules::endothermy [private]
 

Definition at line 22 of file rules.h.

Referenced by Rules(), SpyLastY(), and UpdateSpyPos().

int Rules::tachymetabolic [private]
 

Definition at line 22 of file rules.h.

Referenced by Rules(), SpyLastX(), and UpdateSpyPos().

int Rules::turn [private]
 

Definition at line 21 of file rules.h.

Referenced by CurrentTurn(), NewTurn(), NoTurnsLeft(), and Rules().


The documentation for this class was generated from the following files:
Generated on Sun Jul 6 23:07:18 2003 for Scotland Yard by doxygen1.2.15