This repository has been archived by the owner on Jul 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvironment.h
executable file
·154 lines (133 loc) · 3.03 KB
/
Environment.h
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#pragma once
#include <iostream>
#include <math.h>
enum Objects : int
{
Nothing = 0,
Line,
End
};
enum LineTypes : int
{
Horizontal = 0,
Vertical
};
typedef struct {
int x;
int y;
} Point;
class Environment
{
private:
int AreaWidth;
int AreaHeight;
int* content;
void clrEnv();
public:
Environment(int width, int height, int* env);
~Environment();
int getWidth();
int getHeight();
float getReward(int _x, int _y, int* _done);
void NakresliHernySvet(int _x, int _y);
int getState(int _x, int _y);
Objects getContent(int _x, int _y);
};
Environment::Environment(int width, int height, int* env)
{
this->AreaWidth = width;
this->AreaHeight = height;
this->content = env;
}
int Environment::getWidth()
{
return this->AreaWidth;
}
int Environment::getHeight()
{
return this->AreaHeight;
}
void Environment::clrEnv()
{
for (int i = 0; i < (this->AreaWidth * this->AreaHeight); i++)
this->content[i] = Objects::Nothing;
}
float Environment::getReward(int _x, int _y, int* _done)
{
float reward;
switch (this->content[getState(_x, _y)])
{
case Objects::Nothing:
// ak strati ciaru
reward = -0.55;
// end of game
*_done = 0;
break;
case Objects::End:
// nasiel vychod z bludiska
reward = +1.0;
// end of game
*_done = 1;
break;
default:
// pre najdenie najkratsej trasy
reward = -0.17;
*_done = 0;
break;
}
return reward;
}
void Environment::NakresliHernySvet(int _x, int _y)
{
// Vycisti konzolu
system("clear");
for (int j = 0; j < AreaHeight; j++)
{
std::cout << "|";
for (int i = 0; i < AreaWidth; i++)
{
if (_x == i && _y == j)
{
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (BACKGROUND_RED|FOREGROUND_INTENSITY));
std::cout << "\033[0;41m A \033[0m";
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (0|FOREGROUND_INTENSITY));
}
else
{
switch (this->content[(j * AreaWidth) + i])
{
case (int)Objects::Nothing:
//Console.ResetColor();
std::cout << "\033[0m ";
break;
case (int)Objects::Line:
//Console.BackgroundColor = ConsoleColor.White;
std::cout << "\033[0;47;30m + \033[0m";
//Console.ResetColor();
break;
case (int)Objects::End:
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (BACKGROUND_GREEN));
//Console.BackgroundColor = ConsoleColor.Green;
//Console.ForegroundColor = ConsoleColor.Black;
std::cout << "\033[0;42;30m E \033[0m";
//SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (0|FOREGROUND_INTENSITY));
//Console.ResetColor();
break;
}
}
}
std::cout << "|" << std::endl;
}
std::cout << std::endl;
}
int Environment::getState(int _x, int _y)
{
return ((_y * this->AreaWidth) + _x);
}
Objects Environment::getContent(int _x, int _y)
{
return (Objects) this->content[getState(_x, _y)];
}
Environment::~Environment()
{
}