Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <pair>
- using namespace std;
- class neuron
- {
- public:
- neuron(int beta);
- float SNNfunc(float input);
- private:
- float beta;
- };
- neuron::neuron(int beta)
- {
- this->beta = beta;
- }
- float neuron::SNNfunc(float input)
- {
- input = input*2.0f-1.0f;
- float y=1.0f/(1.0f+exp(-beta*input));
- return y;
- }
- float scale(float oldvalue,float oldmin, float oldmax, float newmin, float newmax)
- {
- float oldrange = oldmax-oldmin;
- float newrange = newmax-newmin;
- return (((oldvalue-oldmin)*newrange )/oldrange)+newmin;
- }
- class AImob
- {
- public:
- AImob();
- bool attack(float my_hp, float creature_hp,float my_hp_later, float creature_hp_later); // hp = health/max_health. Zakres: 0 - 1.0f
- bool attack();
- private:
- int health;
- int maxhealth;
- int maxdamage;
- int enemyhealth;
- int enemymaxhealth;
- int enemymaxdamage;
- };
- AImob::AImob()
- {
- //to tak testowo tylko...
- health = 100;
- maxhealth = 200;
- maxdamage = 40;
- enemyhealth = 100;
- enemymaxhealth = 200;
- enemymaxdamage = 40;
- }
- bool AImob::attack()
- {
- //wyliczam procenty i skaluje na floata
- float me_health1 = (float)this->health/(float)this->maxhealth;
- float me_health2 = ((float)this->health-(float)enemymaxdamage)/(float)this->maxhealth;
- float en_health1 = (float)this->enemyhealth/(float)this->enemymaxhealth;
- float en_health2 = ((float)this->enemyhealth-(float)this->maxdamage)/(float)this->enemymaxhealth;
- if(me_health2<0.0f) me_health2=0.0f;
- if(en_health2<0.0f) en_health2=0.0f;
- return attack(me_health1,me_health2,en_health1,en_health2);
- }
- bool AImob::attack(float my_hp, float creature_hp,float my_hp_later, float creature_hp_later) // hp = health/max_health. Zakres: 0 - 1.0f
- {
- float result;
- neuron hp(3.0f); // wartosci do dobrania
- neuron hp_later(3.0f);
- neuron creaturehp(3.0f);
- neuron creaturehp_later(3.0f);
- cout << "myhp:" << my_hp << " ehp: " << creature_hp << "\t";
- cout << hp.SNNfunc(my_hp) << " : " << creaturehp.SNNfunc(creature_hp) << "\t";
- cout << hp_later.SNNfunc(my_hp_later) << " : " << creaturehp_later.SNNfunc(creature_hp_later) << "\t";
- result = creaturehp.SNNfunc(creature_hp)+
- creaturehp_later.SNNfunc(creature_hp_later)-
- hp.SNNfunc(my_hp)-
- hp_later.SNNfunc(my_hp_later);
- result = scale(result,-4.0f,4.0f,0.0f,1.0f);
- cout << result*100 << "% \n";
- if(result>=0.5f)
- return 1; // attack
- return 0; //heal
- }
- int main(int argc, char** argv)
- {
- AImob* mob = new AImob;
- if(mob->attack())
- cout << endl << "ATTACK!";
- else
- cout << endl << "DEFENCE!";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement