SPYSpheres
ZeroRoboticsGame Class Reference

The class of the game object that you will use. More...

#include <ZRGame.h>

List of all members.

Public Member Functions

float getFuelRemaining ()
void sendMessage (unsigned char inputMsg)
unsigned char receiveMessage ()
bool isFacingOther ()
 Check if the camera is pointed towards the other satellite.
float takePic ()
 Attempts to take a picture in the current position.
float getPicPoints ()
 Determines how many points a picture would give if taken immediately.
int getMemoryFilled () const
 Returns how many memory slots are currently in use.
int getMemorySize ()
 Returns the total number of memory slots available to the satellite.
float uploadPics (void)
 Attempts to upload pictures taken to Earth.
bool isCameraOn ()
 Makes sure the camera is on.
float getEnergy ()
 Tells how much energy the player has.
float getOtherEnergy ()
 Tells how much energy the opponent has, at a cost of 0 energy.
bool posInLight (float pos[])
 Returns true if the given coordinate is in the light zone.
bool posInDark (float pos[])
 Returns true if the given coordinate is in the dark zone.
bool posInGrey (float pos[])
 Returns true if the given coordinate is in a grey zone.
int posInArea (float pos[])
 Returns 1 if the given coordinate is in the light, -1 if in the dark, and 0 otherwise.
float getLightInterfacePosition ()
 Determines where the center of the grey zone at the tail end of the light zone is.
float getDarkGreyBoundary ()
 Determines where the boundary between the dark zone and the grey zone is.
float getLightGreyBoundary ()
 Determines where the boundary between the light zone and the grey zone is.
float getLightSwitchTime ()
 Determines how long until the light and dark zones next switch (2D/3D).
int getNumItem ()
 Returns the number of total items in play, whether they have been picked up yet or not.
bool useMirror ()
 Uses a held mirror item.
int getMirrorTimeRemaining ()
 Returns the amount of time left on your current mirror.
int getNumMirrorsHeld ()
 Returns the number of mirrors currently held and available for use.
void getItemLoc (float pos[], int itemID)
 Copies the location of a given item into the given array.
int hasItem (int itemID)
 Tells who has a given item.
int getItemType (int itemID)
 Returns what the item does.
float getScore ()
 Returns the player's current score.
float getOtherScore ()
 Returns the opponent's current score.
int getCurrentTime ()
 Returns the time.
 ZeroRoboticsGame (ZeroRoboticsGameImpl &impl, ZeroRoboticsAPIImpl &apiImpl)
 Constructor for the game. The provided references should be singleton instances.

Static Public Member Functions

static ZeroRoboticsGameinstance ()

Private Attributes

ZeroRoboticsGameImplpimpl
 REQUIRED: reference to the game implementation, do not delete!
ZeroRoboticsAPIImpl & apiImpl

Detailed Description

The class of the game object that you will use.

Contains publicly available member functions.

Definition at line 34 of file ZRGame.h.


Constructor & Destructor Documentation

ZeroRoboticsGame::ZeroRoboticsGame ( ZeroRoboticsGameImpl impl,
ZeroRoboticsAPIImpl &  apiImpl 
)

Constructor for the game. The provided references should be singleton instances.

Definition at line 51 of file ZRGameInternal.cpp.

                                                                                          : pimpl(impl), apiImpl(apiImpl)
{
  impl.game = this;
}

Member Function Documentation

Returns the time.

Definition at line 460 of file ZRGameInternal.cpp.

Determines where the boundary between the dark zone and the grey zone is.

Returns:
The y-coordinate of the plane between the dark zone and the grey zone.

Definition at line 122 of file ZRLight.cpp.

Tells how much energy the player has.

Returns:
Amount of energy the player satellite currently has.

Definition at line 46 of file ZREnergy.cpp.

                                  {
  return pimpl.challInfo.me.energy;
}

Tells the player how much fuel remains.

Returns:
float indicating how many seconds of fuel remain.

Definition at line 451 of file ZRGameInternal.cpp.

{
  ZeroRoboticsGameImpl::ChallengeInfo& challInfo = pimpl.challInfo;
  float total = PROP_ALLOWED_SECONDS-challInfo.me.fuelUsed;
  total = MIN_FUEL(total, 0.0f); //~Prevents fuel from being less than 0.0f
  total = MAX_FUEL(total, PROP_ALLOWED_SECONDS); //~Prevents fuel from being greater than MAX fuel in tank
  return total;
}
void ZeroRoboticsGame::getItemLoc ( float  pos[],
int  itemID 
)

Copies the location of a given item into the given array.

Parameters:
posA pointer to an array of size 3 which will be overwritten by the item location.
itemIDThe integer identifier of a given item.

Definition at line 101 of file ZRItems.cpp.

                                                         {
  memcpy(pos, pimpl.challInfo.mpLoc[itemID], 3 * sizeof(float));
}
int ZeroRoboticsGame::getItemType ( int  itemID)

Returns what the item does.

Possible Item Types:

  • ITEM_TYPE_ADD_SCORE
  • ITEM_TYPE_ADD_ENERGY
  • ITEM_TYPE_MIRROR
Parameters:
itemIDThe integer identifier of a given item.
Returns:
The corresponding item type to the given identifier.

Definition at line 105 of file ZRItems.cpp.

                                            {
  if (itemID < NUM_ITEMS) return ITEM_TYPES[itemID];
  return -1; // Error
}

Determines where the boundary between the light zone and the grey zone is.

Returns:
The y-coordinate of the plane between the light zone and the grey zone.

Definition at line 118 of file ZRLight.cpp.

Determines where the center of the grey zone at the tail end of the light zone is.

The tail end is at the lower Y-coordinate of the light zone, disregarding any portion that has wrapped around.

Returns:
The y-coordinate of the light interface plane.

Definition at line 114 of file ZRLight.cpp.

Determines how long until the light and dark zones next switch (2D/3D).

Returns:
Number of seconds until the light switches.

Definition at line 111 of file ZRLight.cpp.

Returns how many memory slots are currently in use.

Returns:
The number of memory slots used.

Definition at line 43 of file ZRCamera.cpp.

Returns the total number of memory slots available to the satellite.

This includes both used and unused slots.

Returns:
Number of memory slots available.

Definition at line 48 of file ZRCamera.cpp.

Returns the amount of time left on your current mirror.

Returns:
remaining time with a mirror up, zero if no mirror is up.

Definition at line 120 of file ZRItems.cpp.

{
  int mirrorEnd = pimpl.challInfo.me.mirrorTime + ITEM_MIRROR_DURATION;
  int timeLeft = mirrorEnd - pimpl.challInfo.currentTime;
  if(timeLeft > 0 && pimpl.challInfo.me.mirrorTime != 0)
    return timeLeft;
  return 0;
}

Returns the number of total items in play, whether they have been picked up yet or not.

Returns:
Number of total items.

Definition at line 97 of file ZRItems.cpp.

                                 {
  return NUM_ITEMS;
}

Returns the number of mirrors currently held and available for use.

Returns:
number of mirrors held by the player.

Definition at line 129 of file ZRItems.cpp.

{
  return pimpl.challInfo.me.mirrors;
}

Tells how much energy the opponent has, at a cost of 0 energy.

Returns:
Amount of energy the opponent satellite currently has.

Definition at line 49 of file ZREnergy.cpp.

                                      {
  bool energyUsed = pimpl.tryToUseEnergy(ENERGY_COST_GET_OTHER_ENERGY);
  if(energyUsed)
    return pimpl.challInfo.other.energy;
  return 0;
}

Returns the opponent's current score.

Definition at line 443 of file ZRGameInternal.cpp.

{
  return pimpl.challInfo.other.score;
}

Determines how many points a picture would give if taken immediately.

Does not actually take a picture. Costs 0.1 energy.

Returns:
The amount of points that the picture is worth.

Definition at line 61 of file ZRCamera.cpp.

{
  if(!pimpl.challInfo.camera.cameraOn) {
        return 0;
    }

  if (!pimpl.tryToUseEnergy(ENERGY_COST_GET_PIC_POINTS)) {
    return 0;
  }

  return pimpl.picPointsImpl();
}

Returns the player's current score.

Returns:
Player satellite score.

Definition at line 438 of file ZRGameInternal.cpp.

{
  return pimpl.challInfo.me.score;
}
int ZeroRoboticsGame::hasItem ( int  itemID)

Tells who has a given item.

Parameters:
itemIDThe integer identifier of a given item.
Returns:
0 if you have picked up the specified item, 1 if the other player has, or -1 if no one has.

Definition at line 88 of file ZRItems.cpp.

                                       {
  int a = -1;
  if (pimpl.challInfo.me.mpTime[itemID] != MP_EMPTY)
    a = 0;
  if (pimpl.challInfo.other.mpTime[itemID] != MP_EMPTY)
    a = 1;
  return a;
}

Retrieves the singleton instance of the game API. Users are not allowed to construct a game instance, so the API must be retrieved through this interface.

Returns:
singleton of the game API

Definition at line 43 of file ZRGameInternal.cpp.

                                             {
  static ZeroRoboticsGame gameInstance(ZeroRoboticsGameImpl::instance(), ZeroRoboticsAPIImpl::instance());
  return gameInstance;
}

Makes sure the camera is on.

Returns:
true if the camera is usable, false if not.

Definition at line 74 of file ZRCamera.cpp.

Check if the camera is pointed towards the other satellite.

Returns:
true if the camera is facing the other satellite, false otherwise.

Definition at line 192 of file ZRCamera.cpp.

                                    {
  return pimpl.isFacingOther();
}
int ZeroRoboticsGame::posInArea ( float  pos[])

Returns 1 if the given coordinate is in the light, -1 if in the dark, and 0 otherwise.

Parameters:
posAn array of three floats in (x, y, z) order.
Returns:
1 if the given coordinate is in the light, -1 if in the dark, and 0 else.

Definition at line 127 of file ZRLight.cpp.

                                               {
  #ifdef ALLIANCE
  return pimpl.sphereInMovingArea(position);
  #else
  return pimpl.sphereInSwitchingArea(position);
  #endif  
}
bool ZeroRoboticsGame::posInDark ( float  pos[])

Returns true if the given coordinate is in the dark zone.

Parameters:
posAn array of three floats in (x, y, z) order.
Returns:
true if the coordinate is in dark, false else.

Definition at line 139 of file ZRLight.cpp.

                                                {
  return pimpl.sphereInDark(position);
}
bool ZeroRoboticsGame::posInGrey ( float  pos[])

Returns true if the given coordinate is in a grey zone.

Parameters:
posAn array of three floats in (x, y, z) order.
Returns:
true if the coordinate is in grey, false else.

Definition at line 143 of file ZRLight.cpp.

                                                {
  return !pimpl.sphereInDark(position) && !pimpl.sphereInLight(position);
}
bool ZeroRoboticsGame::posInLight ( float  pos[])

Returns true if the given coordinate is in the light zone.

Parameters:
posAn array of three floats in (x, y, z) order.
Returns:
true if the coordinate is in light, false else.

Definition at line 135 of file ZRLight.cpp.

                                                  {
  return pimpl.sphereInLight(position);
}

Recieve value from 0-255 from other satellite.

Returns:
An unsigned char containing a value from 0-255.

Definition at line 470 of file ZRGameInternal.cpp.

{
  return (unsigned char)pimpl.challInfo.other.message;
}
void ZeroRoboticsGame::sendMessage ( unsigned char  inputMsg)

Send a value from 0-255 to the other satellite.

Parameters:
inputMsgUnsigned Char to be sent to other satellite.

Definition at line 465 of file ZRGameInternal.cpp.

{
  pimpl.challInfo.me.message = (short)inputMsg;
}

Attempts to take a picture in the current position.

The camera will be disabled for 3 seconds after an attempt, whether successful or not. Costs 1.0 energy.

Returns:
The amount of points that the picture taken is worth.

Definition at line 53 of file ZRCamera.cpp.

{
  if(!pimpl.challInfo.camera.cameraOn) {
    return 0;
  }
  return pimpl.takePicImpl();
}
float ZeroRoboticsGame::uploadPics ( void  )

Attempts to upload pictures taken to Earth.

Will fail if not facing Earth (3D/Alliance). Disables camera for three seconds upon sucessful upload. Costs 1.0 energy.

Returns:
The total score over the course of the game so far.

Definition at line 202 of file ZRCamera.cpp.

                                  {
  float totalScore = 0.0;
  if(!pimpl.tryToUseEnergy(ENERGY_COST_UPLOAD_PICTURES)) return 0.0;

  GAME_TRACE(("[%d] trying to upload... ", apiImpl.api->getTime()));

  // Need to check that the SPHERE isn't going too fast to upload.
  float speed = mathVecMagnitude(&pimpl.challInfo.me.zrState[9],3);
  if (speed>UPLOAD_ANG_VEL)
  {
    GAME_TRACE(("Rotating too fast, Upload Failed. Speed=%2.4f",speed));
    return 0.0;
  }

// Need to check if the SPHERE is pointing towards earth before running the code to upload pictures.
#ifndef ZR2D
  if (!pimpl.isFacingEarth())
  {
  return totalScore;
  GAME_TRACE(("Not Facing Earth, Upload Failed. "));
  }
#endif
  pimpl.challInfo.camera.uploadedPictures = true;
  pimpl.disableCamera();            // For only three seconds.
  for (unsigned int i = 0; i < pimpl.challInfo.camera.memoryFilled; i++)
    {
  if (pimpl.challInfo.camera.memory[i].picStored == true)
  {
    pimpl.challInfo.camera.memory[i].picStored = false;
          pimpl.challInfo.me.score += pimpl.challInfo.camera.memory[i].value;
    totalScore  += pimpl.challInfo.camera.memory[i].value;
          GAME_TRACE(("uploaded picture for %4.2f points | ", pimpl.challInfo.camera.memory[i].value));
       }
    }
  pimpl.challInfo.camera.memoryFilled = 0;


  return totalScore;
}

Uses a held mirror item.

Returns:
true if the item existed and was used, false otherwise.

Definition at line 110 of file ZRItems.cpp.

{
  if(pimpl.challInfo.me.mirrors > 0){
    pimpl.challInfo.me.mirrors -= 1;
    pimpl.challInfo.me.mirrorTime = pimpl.challInfo.currentTime;
    return true;
  }
  return false;
}

Member Data Documentation

ZeroRoboticsAPIImpl& ZeroRoboticsGame::apiImpl [private]

Definition at line 292 of file ZRGame.h.

REQUIRED: reference to the game implementation, do not delete!

Definition at line 291 of file ZRGame.h.


The documentation for this class was generated from the following files: