summaryrefslogtreecommitdiff
path: root/graphs/cpp/caste_or_cast/ant.hh
blob: 6a0a0ee7b3ab7715e8e8a9746b4bdc9b0128e92e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once

#include <memory>

//! forward declaration
class Colony;

/*
 * Enum Class representing the stage of life for
 * an ant
 */
enum class DevelopmentStage : unsigned int
{
    // from the youngest to the oldest stage
    EGG = 0,
    LARVA,
    COCOON,
    ADULT
};

/*
 *  Base Class for every ant caste
 */
class Ant
{
public:
    //! delete constructor
    Ant() = delete;
    //! constructor
    Ant(std::shared_ptr<Colony> colony,
        DevelopmentStage stage = DevelopmentStage::EGG);
    //! copy constructor
    Ant(const Ant&);
    //! copy assignement
    Ant& operator=(const Ant&);
    //! default virtual destructor
    virtual ~Ant() = default;
    //! communicate with another Ant
    virtual bool communicate(std::weak_ptr<Ant> wk_receiver);
    //! attack given Ant and check if it is dead
    bool attack(std::weak_ptr<Ant> wk_ant);

    //! getter for passport_pheromone_ of Colony class
    uint32_t get_passport_pheromone();
    //! getter for stage_
    DevelopmentStage get_stage() const;
    //! getter for hp_
    int get_hp() const;
    //! setter for hp_
    void set_hp(int hp);
    //! getter for food_level_
    float get_food_level() const;
    //! increment by value food_level_
    void increment_food_level_by(float value);

protected:
    //! return by value the colony shared_ptr if not expired else throw error
    std::shared_ptr<Colony> check_colony_access();
    //! development stage
    DevelopmentStage stage_;
    //! Colony of this Ant
    std::weak_ptr<Colony> colony_;
    //! health points
    int hp_ = 4;
    //! represent the energy / food the ant ate for its
    // current Development stage
    float food_level_ = 0;
    //! friend class
    friend class Colony;
};