//-*-c++-*-
#ifndef INCLUDED_MapBuilderCount_h_
#define INCLUDED_MapBuild
#include "Behaviors/Leapers.h"
#include <sstream>
#include <string>
using namespace std;

template <class T>
inline std::string to_string (const T& t)
{
   std::stringstream ss;
   ss << t;
   return ss.str();
} 


#nodeclass MapBuilderCount: VisualRoutinesStateNode

	#shortnodeclass FindBlobs : MapBuilderNode($,MapBuilderRequest::localMap) : constructor
		NEW_SHAPE(gazePoly, PolygonData, new PolygonData(localShS, Lookout::groundSearchPoints(), false));
		mapreq.searchArea = gazePoly;
		mapreq.motionSettleTime = 2000;
		mapreq.maxDist = 1e6;
		mapreq.clearShapes = true;
		mapreq.pursueShapes = false;
		mapreq.rawY = true;
		mapreq.addObjectColor(blobDataType, "blue");
		mapreq.addObjectColor(blobDataType, "green");


	#shortnodeclass GetHowManyBlueBlobs : VisualRoutinesStateNode : DoStart
		NEW_SHAPEVEC(blobs, BlobData, select_type<BlobData>(localShS));
		NEW_SHAPEVEC(blue_blobs, BlobData, subset(blobs, IsColor("blue"))); 
		if(blue_blobs.empty())
			postStateFailure();
		postStateSignal<string>("I saw " + to_string(blue_blobs.size())+ " blue blobs and" ); 

	#shortnodeclass GetHowManyGreenBlobs : VisualRoutinesStateNode : DoStart
		NEW_SHAPEVEC(blobs, BlobData, select_type<BlobData>(localShS));
		NEW_SHAPEVEC(green_blobs, BlobData, subset(blobs, IsColor("green"))); 
		if(green_blobs.empty())
			postStateFailure();
		postStateSignal<string>("I saw " + to_string(green_blobs.size())+ " green blobs" );


	#shortnodemethod setup
		#statemachine
			startnode: FindBlobs
			howmanyblue : GetHowManyBlueBlobs
			howmanygreen : GetHowManyGreenBlobs


			startnode =MAP=> howmanyblue =F=> Speak($, "I did not find any blue blobs")
			howmanyblue =S<string>=> Speak =T(2000)=> howmanygreen =S<string>=> Speak =B(ChiaraInfo::RedButOffset)=> startnode
			howmanygreen =F=> Speak($, "I did not find any green blobs")
		#endstatemachine

#endnodeclass
#endif

