Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <cmath>
  5. #include <vector>
  6. #include <pair>
  7.  
  8. using namespace std;
  9. class neuron
  10. {
  11.     public:
  12.         neuron(int beta);
  13.         float SNNfunc(float input);
  14.     private:
  15.         float beta;
  16. };
  17. neuron::neuron(int beta)
  18. {
  19.     this->beta = beta;
  20. }
  21. float neuron::SNNfunc(float input)
  22. {
  23.     input = input*2.0f-1.0f;
  24.     float y=1.0f/(1.0f+exp(-beta*input));
  25.     return y;
  26. }
  27. float scale(float oldvalue,float oldmin, float oldmax, float newmin, float newmax)
  28. {
  29.     float oldrange = oldmax-oldmin;
  30.     float newrange = newmax-newmin;
  31.     return (((oldvalue-oldmin)*newrange )/oldrange)+newmin;
  32. }
  33. class AImob
  34. {
  35.     public:
  36.         AImob();
  37.         bool attack(float my_hp, float creature_hp,float my_hp_later, float creature_hp_later); // hp = health/max_health. Zakres: 0 - 1.0f
  38.         bool attack();
  39.     private:
  40.         int health;
  41.         int maxhealth;
  42.         int maxdamage;
  43.         int enemyhealth;
  44.         int enemymaxhealth;
  45.         int enemymaxdamage;
  46. };
  47. AImob::AImob()
  48. {
  49.     //to tak testowo tylko...
  50.     health = 100;
  51.     maxhealth = 200;
  52.     maxdamage = 40;
  53.     enemyhealth = 100;
  54.     enemymaxhealth = 200;
  55.     enemymaxdamage = 40;
  56. }
  57. bool AImob::attack()
  58. {
  59.     //wyliczam procenty i skaluje na floata
  60.     float me_health1 = (float)this->health/(float)this->maxhealth;
  61.     float me_health2 = ((float)this->health-(float)enemymaxdamage)/(float)this->maxhealth;
  62.     float en_health1 = (float)this->enemyhealth/(float)this->enemymaxhealth;
  63.     float en_health2 = ((float)this->enemyhealth-(float)this->maxdamage)/(float)this->enemymaxhealth;
  64.     if(me_health2<0.0f) me_health2=0.0f;
  65.     if(en_health2<0.0f) en_health2=0.0f;
  66.     return attack(me_health1,me_health2,en_health1,en_health2);
  67. }
  68. 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
  69. {
  70.     float result;
  71.     neuron hp(3.0f); // wartosci do dobrania
  72.     neuron hp_later(3.0f);
  73.     neuron creaturehp(3.0f);
  74.     neuron creaturehp_later(3.0f);
  75.     cout << "myhp:" << my_hp << " ehp: " << creature_hp << "\t";
  76.     cout << hp.SNNfunc(my_hp) << " : " << creaturehp.SNNfunc(creature_hp) << "\t";
  77.     cout << hp_later.SNNfunc(my_hp_later) << " : " << creaturehp_later.SNNfunc(creature_hp_later) << "\t";
  78.     result = creaturehp.SNNfunc(creature_hp)+
  79.         creaturehp_later.SNNfunc(creature_hp_later)-
  80.         hp.SNNfunc(my_hp)-
  81.         hp_later.SNNfunc(my_hp_later);
  82.     result = scale(result,-4.0f,4.0f,0.0f,1.0f);
  83.     cout << result*100 << "% \n";
  84.     if(result>=0.5f)
  85.         return 1; // attack
  86.     return 0; //heal
  87. }
  88. int main(int argc, char** argv)
  89. {
  90.     AImob* mob = new AImob;
  91.     if(mob->attack())
  92.         cout << endl << "ATTACK!";
  93.     else
  94.         cout << endl << "DEFENCE!";
  95.     return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement