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

ComputerDetective Class Reference

#include <players.h>

Inheritance diagram for ComputerDetective:

Computer Detective Player Player List of all members.

Public Methods

 ComputerDetective (char *name, int color)
 ComputerDetective (char *name, int color, PosType pos)

Protected Methods

Move ChooseMove (void)
byte NumNodeTypes (int node)
bool CanLeave (Move *duh)
MoveFindNearest (int x, int y, MoveList *moves)

Constructor & Destructor Documentation

ComputerDetective::ComputerDetective char *    name,
int    color
[inline]
 

Definition at line 140 of file players.h.

00140 : Player (name, color) { }

ComputerDetective::ComputerDetective char *    name,
int    color,
PosType    pos
[inline]
 

Definition at line 141 of file players.h.

References PosType.

00142     : Player (name, color, pos) { }


Member Function Documentation

bool ComputerDetective::CanLeave Move   duh [protected]
 

Definition at line 104 of file players.c.

References Bus, False, NumNodeTypes(), Detective::NumTokens(), Subway, Taxi, and True.

Referenced by FindNearest().

00105   {
00106    bool taxi, bus, subway, ok = False;
00107    int vertex;
00108 
00109    vertex = duh -> Node;
00110    if (NumNodeTypes (vertex) > 1) return True;
00111 
00112    bus = theMap.bus (vertex);
00113    taxi = theMap.taxi (vertex);
00114    subway = theMap.subway (vertex);
00115 
00116    if (bus)
00117      {
00118       bus &= (bool) (NumTokens (Bus) - 1);    // Just one token left...
00119       if (!bus) return False;
00120      }
00121 
00122    if (taxi)
00123      {
00124       bus &= (bool) (NumTokens (Taxi) - 1);   // Just one token left...
00125       if (!bus) return False;
00126      }
00127 
00128    if (subway)
00129      {
00130       bus &= (bool) (NumTokens (Subway) - 1); // Just one token left...
00131       if (!bus) return False;
00132      }
00133 
00134    return True;         // He has more than one token
00135   }

Move ComputerDetective::ChooseMove void    [protected, virtual]
 

Reimplemented from Player.

Definition at line 163 of file players.c.

References FindNearest(), and Move::Next.

00164   {
00165    MoveList *ml;
00166    Move *shalowitz, theMove;
00167    int ira, barry;                         // If it was us, could you eat?
00168 
00169    ml = theRules.GetLegalMoves (*this);
00170    ira = ml -> Length ();
00171    if (ira == 0)                           // Dooh!
00172      theMove = UI.NoLegalMoves (*this);
00173    else                                    // Our AI routine
00174      {
00175       ira = theRules.SpyLastX ();
00176       barry = theRules.SpyLastY ();
00177       shalowitz = FindNearest (ira, barry, ml);
00178 
00179       theMove = *shalowitz;                // Rum raisin! Woof!
00180       theMove.Next = NULL;
00181      }
00182    delete ml;                              // Let's try Smalltalk
00183    return theMove;
00184   }

Move * ComputerDetective::FindNearest int    x,
int    y,
MoveList   moves
[protected]
 

Definition at line 137 of file players.c.

References CanLeave().

Referenced by ChooseMove().

00138   {
00139    Move *best, *temp;
00140    int deltaX, deltaY;
00141    double dist, nearest;
00142 
00143    nearest = MAXINT;
00144    moves -> Reset ();
00145    best = moves -> GetCurrent ();
00146    while (moves -> Next ())
00147      {
00148       temp = moves -> GetCurrent ();
00149       deltaX = x - theMap.x (temp -> Node);
00150       deltaY = y - theMap.y (temp -> Node);
00151       dist = deltaX * deltaX;
00152       dist += deltaY * deltaY;
00153       dist = sqrt (dist);
00154       if ((dist < nearest) && CanLeave (temp))  // Will he get stuck?
00155   {
00156    best = temp;
00157    nearest = dist;
00158   }
00159      }
00160    return best;
00161   }

byte ComputerDetective::NumNodeTypes int    node [protected]
 

Definition at line 94 of file players.c.

References byte.

Referenced by CanLeave().

00095   {
00096    byte me = 0;
00097 
00098    me += theMap.bus (node);
00099    me += theMap.taxi (node);
00100    me += theMap.subway (node);
00101    return me;
00102   }


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