#include <iostream>
#include <iomanip>
#include <cstddef>
#include <fstream>
#include"squirrel.h"
#include"tree.h"
#include"hoard.h"
#include"nut.h"
usingnamespace std;
int main()
{
int num_of_squirrels;
int num_of_trees;
int skip_factor;
int total_nuts;
Squirrel squirrel;
Tree nut;
cout << "Please enter the number of squirrels: ";
cin >> num_of_squirrels;
cout << "Please enter the number of trees: ";
cin >> num_of_trees;
//Creating the correct amount
Squirrel *squirrels = new Squirrel[num_of_squirrels];
Hoard *hoards = new Hoard [num_of_squirrels];
Tree *trees = new Tree[num_of_trees];
//Getting and setting skip factor
//assigning hoard owners
for(int i=0;i<num_of_squirrels;++i)
{
cout << "Please enter the skip factor for squirrel # "<<(1+i)<<": ";
cin >> skip_factor;
while (skip_factor > num_of_trees)
{
skip_factor = skip_factor - num_of_trees;
}
if (skip_factor == 0)
{
skip_factor = 1;
}
squirrels[i].set_skip_factor(skip_factor);
squirrels[i].set_location(skip_factor);
//Sets the owners of the hoards to each squirrel
hoards[i].set_owner(squirrels);
}
int round = 1;
total_nuts = 0;
while(total_nuts < 100)
{
cout << endl;
cout << "Round " << round << ":" << endl;
if(round % 2 != 0)
{
for(int i = 0; i < num_of_trees; i++)
{
cout << "Tree " << i+1 << " has " << trees[i].get_nuts_left() << endl;
}
for(int i = 0; i < num_of_squirrels; i++)
{
cout << "Squirrel " << i+1 << " is at Tree " << squirrels[i].get_location()+1 << endl;
}
for(int i = 0; i < num_of_squirrels; i++)
{
// This is where we should determine if they fight. Idk how to go about that.
int myvar;
int myvar7;
cout << "Squirrel " << i+1 << " collects a nut from Tree " << squirrels[i].get_location()+1 << endl;
myvar = squirrels[i].get_location();
trees[myvar].remove_nut();
squirrels[i].move_location(myvar, skip_factor, num_of_trees);
// Not sure how to take the nut from the tree because of location issues
myvar7 = myvar +1;
squirrels[i].take_nut();
}
}
if(round % 2 == 0)
{
// Not sure if any of this works because we need to figure out what is wrong with location
for(int i = 0; i < num_of_squirrels; i++)
{
if(squirrels[i].has_nut()==true)
{
hoards[i].add_nut();
cout << "Squirrel " << i+1 << " deposited a nut into its hoard." << endl;
}
else
{
cout << "Squirrel " << i+1 << " had no nut to deposit." << endl;
}
}
for(int i = 0; i < num_of_squirrels; i++)
{
cout << "Squirrel " << i+1 << "'s Hoard contains " << hoards[i].get_number_of_nuts() << " nuts." << endl;
}
}
round++;
// This will be moved higher up once we figure out how to see if the squirrels are fighting
total_nuts++;
if (round==100){
getchar();
}
}
}
#pragma once
#include <iostream>
#include "hoard.h"
#include "nut.h"
#include "squirrel.h"
class Tree;
class Nut;
class Squirrel;
class Hoard;
class Tree{
Nut *nuts;
public:
int remove_nut();
int get_nuts_left();
int nuts_left;
~Tree();
Tree();
};
#pragma once
#include <iostream>
#include "tree.h"
#include "nut.h"
#include "squirrel.h"
class Hoard;
class Squirrel;
class Tree;
class Nut;
class Hoard{
Squirrel* owner;
Nut *nuts;
int number_of_nuts;
public:
int add_nut();
int get_number_of_nuts();
Hoard();
~Hoard();
void set_owner(Squirrel* name);
};
nut.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#pragma once
#include <iostream>
#include "hoard.h"
#include "tree.h"
#include "squirrel.h"
class Nut;
class Nut
{
public:
Nut();
};