Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Representations/Perception/PlayersPercept.cpp

Go to the documentation of this file.

    00001 /**
    00002  * @file PlayersPercept.cpp
    00003  *
    00004  * Implementation of class PlayersPercept.
    00005  */
    00006
    00007 #include "PlayersPercept.h"
    00008
    00009
    00010 void PlayersPercept::reset(unsigned long frameNumber)
    00011 {
    00012   this->frameNumber = frameNumber;
    00013   numberOfRedPlayers=0;
    00014   numberOfBluePlayers=0;
    00015 }
    00016
    00017
    00018 void PlayersPercept::addRedPlayer(const SinglePlayerPercept& percept)
    00019 {
    00020   if(numberOfRedPlayers < maxNumberOfRedPlayerPercepts)
    00021     redPlayers[numberOfRedPlayers++] = percept;
    00022 }
    00023
    00024
    00025 void PlayersPercept::addBluePlayer(const SinglePlayerPercept& percept)
    00026 {
    00027   if(numberOfRedPlayers < maxNumberOfBluePlayerPercepts)
    00028     bluePlayers[numberOfBluePlayers++] = percept;
    00029 }
    00030
    00031
    00032 In& operator>>(In& stream,PlayersPercept& playersPercept)
    00033 {
    00034   stream >> playersPercept.frameNumber;
    00035   int i;
    00036   stream >> playersPercept.numberOfBluePlayers;
    00037   stream >> playersPercept.numberOfRedPlayers;
    00038   for(i=0; i<playersPercept.numberOfBluePlayers; i++)
    00039   {
    00040     stream.read(&playersPercept.bluePlayers[i], sizeof(SinglePlayerPercept));
    00041   }
    00042   for(i=0; i<playersPercept.numberOfRedPlayers; i++)
    00043   {
    00044     stream.read(&playersPercept.redPlayers[i], sizeof(SinglePlayerPercept));
    00045   }
    00046
    00047   return stream;
    00048 }
    00049
    00050
    00051 Out& operator<<(Out& stream, const PlayersPercept& playersPercept)
    00052 {
    00053   stream << playersPercept.frameNumber;
    00054   int i;
    00055   stream << playersPercept.numberOfBluePlayers;
    00056   stream << playersPercept.numberOfRedPlayers;
    00057   for(i=0; i<playersPercept.numberOfBluePlayers; i++)
    00058   {
    00059     stream.write(&playersPercept.bluePlayers[i], sizeof(SinglePlayerPercept));
    00060   }
    00061   for(i=0; i<playersPercept.numberOfRedPlayers; i++)
    00062   {
    00063     stream.write(&playersPercept.redPlayers[i], sizeof(SinglePlayerPercept));
    00064   }
    00065
    00066   return stream;
    00067 }