#include "stdafx.h"
#include "general.h"
#include "stateaction.h"

//IMPLEMENT_SERIAL(CStateValue, CObject, 1)
/////////////////////////////////////////////////////////////////
//class CStateAction implementation

/*CStateAction::CStateAction(int conf ,int hour , int nextConfig ):
	m_nJunctionConfig(conf),      //This is set to a start configuration.
	m_nHour(hour),
	m_nNextConfig(nextConfig)
{
	for(int i = 0;i < NUM_OF_LANES;i++)
		m_NumOfCarsArray[i] = 0;
}*/

/*CStateAction::CStateAction(const CStateAction& stateAction)
{
	*this = stateAction;
}
const CStateAction& CStateAction::operator=(const CStateAction& stateAction)
{
	m_nJunctionConfig = stateAction.m_nJunctionConfig;
	for(int i = 0;i < NUM_OF_LANES;i++)
		m_NumOfCarsArray[i] = stateAction.m_NumOfCarsArray[i];	
	m_nHour = stateAction.m_nHour;
	m_nNextConfig = stateAction.m_nNextConfig; //action taken
	return *this;
}


bool CStateAction::operator==(const CStateAction& stateAction) const
{
	bool isArrEq = true;

	for(int i = 0;i < NUM_OF_LANES;i++)
		if( m_NumOfCarsArray[i] != stateAction.m_NumOfCarsArray[i])
			isArrEq = false;

	return( m_nJunctionConfig == stateAction.m_nJunctionConfig &&
					isArrEq &&
					m_nHour == 	stateAction.m_nHour &&
					m_nNextConfig == stateAction.m_nNextConfig);
}*/
bool CStateAction::operator==( const CStateAction& rightState) const
{
	return( m_nJunctionConfig == rightState.m_nJunctionConfig &&
			m_nNumOfCarsNorth == rightState.m_nNumOfCarsNorth &&
			m_nNumOfCarsEast == rightState.m_nNumOfCarsEast &&
			m_nNumOfCarsSouth == rightState.m_nNumOfCarsSouth &&
			m_nNumOfCarsWest == rightState.m_nNumOfCarsWest &&
			m_nHour == 	rightState.m_nHour &&
			m_nNextConfig == rightState.m_nNextConfig);
}

int CStateAction::GetLaneTraffic(int numOfCars)
{
	//this is the case that the traffic goes beyond the
	//junction "sensors" range.
	if (numOfCars > MAX_NUM_OF_CARS_IN_JUNC)
		return MAX_JUNCTION_TRAFFIC;
	else
		if (numOfCars == 0)
			return 0;
		return (numOfCars/NUM_OF_CARS_IN_SEGMENT)+1;
} 
void CStateAction::NormalizeTrafficValues()
{
	m_nNumOfCarsEast = GetLaneTraffic(m_nNumOfCarsEast);
	m_nNumOfCarsWest = GetLaneTraffic(m_nNumOfCarsWest);
	m_nNumOfCarsSouth= GetLaneTraffic(m_nNumOfCarsSouth);
	m_nNumOfCarsNorth = GetLaneTraffic(m_nNumOfCarsNorth);
}
///////////////////////////////////////////////////////////
//class CStateValue 
/*void CStateValue::Serialize(CArchive& archive)
{
	if (archive.IsStoring())
	{
		archive<<m_value;
		archive<<m_nTimesVisited;
	}
	else
	{
		archive>>m_value;
		archive>>m_nTimesVisited;
	}
}
*/
