#include<string.h>
#include<iostream>
#include<vector>
#include<Town.h>
#include<Agent.h>
using namespace std;                       //to use vector

class Group
{
public:     
			int GroupDec(int agent_choice,int agent_fortune);        // agent should contain these attributes
			void addAgent(int agent_num);                    //not sure!!!!
			void ModGroup(void);

private:    int group_choice;
	        vector <int> member;
};

Group::Group(void)
{
    group_choice=0;
}

void Group::addAgent(int agent_num)
{
	member.push_back(agent_num);
}


int Group::GroupDec(int agent_choice,int agent_fortune)
{
	long sum=0,sum_fortune=0;
	int  i,decision;
	for (i=0;i<member.size();i++)
	{
		        sum += agentPter[Group.member[i]].agent_choice * agentPter[Group.member[i]].agent_fortune;
		sum_fortune += agentPter[Group.member[i]].agent_fortune;
	}
	if ((double)sum/(double)sum_fortune < 0.5)
		group_choice=0;
	else
		group_choice=1;
	return (group_choice);
}


void Group::ModGroup (void)
{
	int i,j,k,l,m,tmp,individual_num=0;
	int group_num,group_min,group_min_index;     // group_num是个全局变量 groupIndex全局变量
	
	/*********** find the poorest agent **********/
	group_min= agentPter[Group.member[0]].agent_fortune;
	group_min_index=0;

	for (i=0;i<member.size();i++)
	{   
		if (agentPter[Group.member[i]].fortune < group_min)
			 {
				group_min = agentPter[Group.member[i]].fortune;
		        group_min_index=i;
		     }
	}

	/***** find an individual to get in group *****/
	int j=0;
	while (j=0)
	{
		for (i=0;i<agent_num;i++)
		{
			if (agentPter[i].groupIndex == -1)
			{
				Group.member[group_min_index]=i;
				j++;
			}
		}
	}
}