-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnvironment.cs
More file actions
175 lines (134 loc) · 4.96 KB
/
Environment.cs
File metadata and controls
175 lines (134 loc) · 4.96 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System.Collections.Generic;
using System;
/*
L’environnement dans lequel évolue l’agent Aspirobot T-0.1 sera constitué d’une carte
contenant 25 pièces disposées telles qu’illustrées ci-dessous. Tel que défini au cours,
l’environnement devrait contenir tous les éléments passifs de votre programme (carte,
poussière, bijoux, etc.). L’environnement devrait aussi contenir minimalement une mesure de
performance que l’agent peut consulter (via ses capteurs). L’environnement devrait être une
boucle infinie (ou encore un événement programmé pour s’exécuter sporadiquement) qui
aléatoirement génère soit de la poussière dans une case aléatoire ou encore un bijou. C’est à
vous de décider des probabilités. Une case peut contenir à la fois de la poussière et un bijou.
*/
public static class Items {
//Apparemment enum ça n existe pas en C#
public const string Dirt = "DIRT";
public const string Jewel = "JEWEL";
public const string Robot = "ROBOT";
}
public class Environment
{
const int NUMBER_ROWS = 5;
const int NUMBER_COLUMNS = 5;
const double DIRT_PERCENTAGE = 0.5;
//jsp trop si on met la pos du robot ici?
private int robotPosX = 2;
private int robotPosY = 2;
private int performance = 0;
private int penalty = 0;
private int numberOfActions = 0;
private int iteration = 0;
private int numberOfIterationsForEachSearch = 1;
private bool learningTime = false;
private bool informedSearchTime = false;
private bool uninformedSearchTime = true;
private Map map;
public Environment(){
map = new Map(NUMBER_ROWS, NUMBER_COLUMNS, robotPosX, robotPosY);
}
//Choose which item to generate
public void Generate(){
Random rd = new Random();
bool cellChosen = false;
while(!cellChosen){
double i = rd.Next(100);
if(i<=DIRT_PERCENTAGE*100){
cellChosen = GenerateItems(Items.Dirt);
}
else{
cellChosen = GenerateItems(Items.Jewel);
}
}
}
//Generate item on map
public bool GenerateItems(String item){
Random rd = new Random();
int i;
int j;
i = rd.Next(NUMBER_ROWS);
j = rd.Next(NUMBER_COLUMNS);
bool value;
if(map.GetCell(i,j).TryGetValue(item, out value)){
if(!value){
map.SetMap(i,j,item,true);
Console.WriteLine("Environment : I've generated " + item + " at case (" + i + "," + j + ")");
//map.DisplayMap();
return true;
}
}
return false;
}
public void UpdatePerformance(){
performance = GetMap().CountNumberOfCleanCells() - numberOfActions - penalty;
}
public Map GetMap(){
return map;
}
public int GetRobotXPosition(){
return map.GetRobotXPosition();
}
public void SetRobotXPosition(int X){
robotPosX = X;
}
public int GetRobotYPosition(){
return map.GetRobotYPosition();
}
public void SetRobotYPosition(int Y){
robotPosY = Y;
}
public int GetPerformance(){
UpdatePerformance();
return performance;
}
public void SetPerformance(int performance){
this.performance = performance;
}
public int GetIteration(){
return iteration;
}
public void SetIteration(int iteration){
this.iteration = iteration;
if(iteration == numberOfIterationsForEachSearch){
if(uninformedSearchTime){
uninformedSearchTime = false;
informedSearchTime = true;
}
else if(informedSearchTime){
informedSearchTime = false;
learningTime = true;
}
this.iteration = 0;
}
}
public bool GetInformedSearchTime(){
return informedSearchTime;
}
public bool GetUninformedSearchTime(){
return uninformedSearchTime;
}
public bool GetLearningTime(){
return learningTime;
}
public int GetNumberOfActions(){
return numberOfActions;
}
public void SetNumberOfActions(int numberOfActions){
this.numberOfActions = numberOfActions;
}
public int GetPenalty(){
return penalty;
}
public void SetPenalty(int penalty){
this.penalty = penalty;
}
}