/**
 * \file PlaygroundStatistics.h
 * \date 06.03.2005
 * \author Marian Tines
 *
 * Interface for the PlaygroundStatistics class
 */

#include "Coach/SquareZoneStatistic.h"
#include "Common/Protocol/ParseStructs.h"
#include <iostream>

#ifndef PLAYGROUND_STATISTICS_H
#define PLAYGROUND_STATISTICS_H

#define X_LENGTH 105.0f
#define Y_LENGTH 68.0f

#define X_ZONES_NUMBER 105
#define Y_ZONES_NUMBER 68


/**
 * \class SquareZoneStatistics
 * \author Marian Tines
 * \brief Zone statistics interface
 * 
 * Square zone statistics store statistics about the position
 * of the player (friend and enemy) and ball on the playground.
 */
class PlaygroundStatistics
{
private:
	int		xZoneNumber;
	int		yZoneNumber;
	float	xZoneLength;
	float	yZoneLength;
	SquareZoneStatistic* zoneStatistic;

public:
	// Construction and destruction
	PlaygroundStatistics(int xZoneNumber, int yZoneNumber);
	~PlaygroundStatistics();

	int		GetXZoneNumber() const { return xZoneNumber; }
	int		GetYZoneNumber() const { return yZoneNumber; }
	float	GetXZoneLength() const { return xZoneLength; }
	float	GetYZoneLength() const { return yZoneLength; }
	const SquareZoneStatistic* GetSquareZoneStatistic(int xIndex, int yIndex) const;

	// Serialization and deserialization of the class
	void SerializeYourself(std::ofstream &fs);
	void DeserializeYourself(std::ifstream &fs);

	void SerializeYourself(char *fileName, char *path);

	const SquareZoneStatistic* GetZoneStatistic() const { return zoneStatistic; }

#ifndef MOVABLE_OBJECT_DENSITY
	/// Updates statistics for the zones according to received visual info
	void OnReceiveVisualInfo(const COACH_VISUAL_INFO& vi);
#endif // MOVABLE_OBJECT_DENSITY

private:
	// Gets the index of the square zone which contains specified point
	int GetZoneIndex(float x, float y);
};

class BitPlaygroundObjectStat
{
private:
	float	procent;
	int		topLevel;
	int		xZoneNumber;
	int		yZoneNumber;
	bool	*bitPlaygroundStat;

public:
	BitPlaygroundObjectStat(): bitPlaygroundStat(NULL) {};

	float	GetProcet() { return procent; }
	int		GetXZoneNumber() { return xZoneNumber; }
	int		GetYZoneNumber() { return yZoneNumber; }
	int		GetTopLevel() { return topLevel; }

	bool	GetBitPlaygroundStat(int xIndex, int yIndex);

	void	LoadByFloodAlgorithm(const PlaygroundStatistics *stat, float toProcent, StatisticsType type);
	void	LoadByPeakAlgorithm(const PlaygroundStatistics *stat, float toProcent, StatisticsType type);
	void	LoadByLocalMaximumAlgorithm(const PlaygroundStatistics *stat, StatisticsType type);
	void	Clear();

protected:
	void	SetBitPlaygroundStat(int xIndex, int yIndex, bool value);
};

#endif // PLAYGROUND_STATISTICS_H
