-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.h
More file actions
117 lines (105 loc) · 2.46 KB
/
Object.h
File metadata and controls
117 lines (105 loc) · 2.46 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#pragma once
class Object
{
public:
int score;
int stepA;
bool life;
sf::Sprite obj;
nndx::neuronet net;
Object(sf::Texture&, nndx::dy_tpl&&, int);
void mA(::std::vector<double>&&);
};
class Wall
{
public:
sf::Sprite wall;
Wall(sf::Texture&, float, float);
};
class TimeGet
{
public:
TimeGet() {}
~TimeGet();
bool restart();
inline int operator*();
void operator()();
private:
sf::Clock *c = new sf::Clock();
};
Object::Object(sf::Texture& t, nndx::dy_tpl&& tpl, int i)
: score(0), stepA(def_STEPA_), life(true), obj(t), net(::std::move(tpl), []() -> double { return static_cast<double>(WEIGHT_FUNC); }, nndx::neuron::_func::_fnTANH)
{
//if (i != 0) net.SPECinit(topology);
//net.setParams(0.5, 0.35); // just for U, moment is unnecessary (FOR callFuncHebb ONLY)
obj.setTextureRect(sf::IntRect(0, def_TEXTURE_OBJ_Y * i, def_TEXTURE_OBJ_X, def_TEXTURE_OBJ_Y));
obj.setPosition(static_cast<float>(def_POSX), static_cast<float>(def_POSY));
obj.setOrigin(sf::Vector2f(def_TEXTURE_OBJ_X / 2.0f, def_TEXTURE_OBJ_Y / 2.0f));
}
void Object::mA(::std::vector<double>&& args)
{
bool step_forward = true;
if ((args[0] < def_KF_X) || (args[0] > -def_KF_X))
{
obj.move(static_cast<float>(def_TEXTURE_OBJ_X), 0.f);
score += 20;
stepA = def_STEPA_;
}
else
{
step_forward = false;
}
if (args[1] > def_KF_Y)
{
if (obj.getPosition().y < def_POSY_WALL + def_TEXTURE_WLL_Y + def_TEXTURE_WLL_Y * def__NUM_ACTIVE_WALL)
{
obj.move(0.f, static_cast<float>(def_TEXTURE_OBJ_Y));
score += 5;
if (!step_forward) --stepA;
}
else
{
--stepA;
}
}
else if (args[1] < -def_KF_Y)
{
if (obj.getPosition().y > def_POSY_WALL)
{
obj.move(0.f, static_cast<float>(-def_TEXTURE_OBJ_Y));
score += 5;
if (!step_forward) --stepA;
}
else
{
--stepA;
}
}
else
{
if (!step_forward) --stepA;
}
}
Wall::Wall(sf::Texture& t, float x, float y) : wall(t)
{
wall.setTextureRect(sf::IntRect(def_TEXTURE_OBJ_X, 0, def_TEXTURE_OBJ_X, def_TEXTURE_OBJ_Y));
wall.setPosition(x, y);
wall.setOrigin(sf::Vector2f(def_TEXTURE_OBJ_X / 2.0f, def_TEXTURE_OBJ_Y / 2.0f));
}
TimeGet::~TimeGet()
{
delete c;
}
bool TimeGet::restart()
{
c->restart();
return true;
}
inline int TimeGet::operator*()
{
return static_cast<int>(c->getElapsedTime().asMilliseconds());
}
void TimeGet::operator()()
{
::std::cout << c->getElapsedTime().asMicroseconds() << ::std::endl;
}