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

ComputerSpy Class Reference

#include <players.h>

Inheritance diagram for ComputerSpy:

Computer Spy Player Player List of all members.

Public Methods

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

Protected Methods

Move ChooseMove (void)
MoveFindFarthest (int x, int y, MoveList *moves)

Constructor & Destructor Documentation

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

Definition at line 156 of file players.h.

00156 : Player (name, color) { }

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

Definition at line 157 of file players.h.

References PosType.

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


Member Function Documentation

Move ComputerSpy::ChooseMove void    [protected, virtual]
 

Reimplemented from Player.

Definition at line 211 of file players.c.

References FindFarthest(), and Move::Next.

00212   {
00213    MoveList *ml;
00214    Move *shalowitz, theMove;
00215    int ira, barry;                         // If it was us, could you eat?
00216 
00217    ml = theRules.GetLegalMoves (*this);
00218    ira = ml -> Length ();
00219    if (ira == 0)                           // Dooh!
00220      theMove = UI.NoLegalMoves (*this);
00221    else                                    // Our AI routine
00222      {
00223       ira = theRules.SpyLastX ();
00224       barry = theRules.SpyLastY ();
00225       shalowitz = FindFarthest (ira, barry, ml);
00226 
00227       theMove = *shalowitz;                // Rum raisin! Woof!
00228       theMove.Next = NULL;
00229      }
00230    delete ml;                              // Let's try Smalltalk
00231    return theMove;
00232   }

Move * ComputerSpy::FindFarthest int    x,
int    y,
MoveList   moves
[protected]
 

Definition at line 186 of file players.c.

Referenced by ChooseMove().

00187   {
00188    Move *best, *temp;
00189    int deltaX, deltaY;
00190    double dist, farthest = 0;
00191 
00192    moves -> Reset ();
00193    best = moves -> GetCurrent ();
00194    while (moves -> Next ())
00195      {
00196       temp = moves -> GetCurrent ();
00197       deltaX = x - theMap.x (temp -> Node);
00198       deltaY = y - theMap.y (temp -> Node);
00199       dist = deltaX * deltaX;
00200       dist += deltaY * deltaY;
00201       dist = sqrt (dist);
00202       if (dist > farthest)
00203   {
00204    best = temp;
00205    farthest = dist;
00206   }
00207      }
00208    return best;
00209   }


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