Browse Source

jsais pu ca fait longtemps

master
DemiSel 3 years ago
parent
commit
3d1b681526

+ 7
- 2
lib/Agents/Agent.hpp View File

@@ -1,12 +1,14 @@
1 1
 #ifndef AGENT_H
2 2
 #define AGENT_H
3 3
 #include <Agents/Perception/Perception.hpp>
4
+
4 5
 #include <Environment/PictureEnvironment.hpp>
5 6
 
6 7
 class Agent
7 8
 {
8 9
 public:
9 10
 	Perception fCurrentPerception;
11
+
10 12
 	PictureEnvironment* fEnvironment;
11 13
 	sf::Color fColor;
12 14
 	int fDotSize;
@@ -29,12 +31,15 @@ public:
29 31
 	std::vector<std::vector<int>> fMovements;
30 32
 	std::vector<int> fValidMovementIndexes;
31 33
 	std::vector<int> fCurrentMovement;
34
+	int fTolerance;
32 35
 
33
-	RepaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize);
36
+	RepaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize, int iTolerance);
34 37
 	virtual void loop();
35 38
 	virtual void move();
36 39
 	virtual void paint();
37 40
 
41
+	bool colorCloseEnough(sf::Uint32 iColor);
42
+
38 43
 protected:
39 44
 	virtual void init();
40 45
 };
@@ -42,7 +47,7 @@ protected:
42 47
 class StraightPaintAgent : public RepaintAgent
43 48
 {
44 49
 public:
45
-	StraightPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize);
50
+	StraightPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize, int iTolerance);
46 51
 
47 52
 protected:
48 53
 	virtual void init();

+ 12
- 0
lib/Control/EnvInputs.hpp View File

@@ -0,0 +1,12 @@
1
+
2
+#ifndef ENVINPUTS_H
3
+#define ENVINPUTS_H
4
+
5
+class EnvInputs
6
+{
7
+public:
8
+	EnvInputs();
9
+	void loop();
10
+};
11
+
12
+#endif //ENVINPUTS_H

+ 4
- 2
lib/Environment/PictureEnvironment.hpp View File

@@ -2,6 +2,7 @@
2 2
 #define PICTURE_ENVIRONMENT_H
3 3
 #include "Platform/Platform.hpp"
4 4
 #include <Agents/Perception/Perception.hpp>
5
+#include <Control/EnvInputs.hpp>
5 6
 
6 7
 class Agent;
7 8
 
@@ -15,6 +16,7 @@ public: // Access specifier
15 16
 	sf::Vector2f fInitialSize;
16 17
 	sf::Event fEvent;
17 18
 	sf::RectangleShape fShape;
19
+	EnvInputs fInputs;
18 20
 
19 21
 	sf::Texture fTextureImage;
20 22
 	sf::Image fImage;
@@ -26,9 +28,9 @@ public: // Access specifier
26 28
 	PictureEnvironment(std::string& iFilePath, sf::RenderWindow* iWindow, util::Platform* iPlatform, bool iDisplayOriginal);
27 29
 	void getPerception(Perception* ioPercept, int iX, int iY);
28 30
 	void makeAgents(int iNumber, int iDotSize, int iMoveSize);
29
-	void makeRepaintAgents(int iNumber, int iDotSize, int iMoveSize);
31
+	void makeRepaintAgents(int iNumber, int iDotSize, int iMoveSize, int iTolerance);
30 32
 	void makePullPaintAgents(int iNumber, int iDotSize, int iMoveSize);
31
-	void makeStraightRepaintAgents(int iNumber, int iDotSize, int iMoveSize);
33
+	void makeStraightRepaintAgents(int iNumber, int iDotSize, int iMoveSize, int iTolerance);
32 34
 	bool paint(int iX, int iY, const sf::Color Color);
33 35
 
34 36
 	sf::Uint32 getCell(int iX, int iY);

+ 1
- 1
src/Agents/PullPaintAgent.cpp View File

@@ -2,7 +2,7 @@
2 2
 #include <Environment/PictureEnvironment.hpp>
3 3
 
4 4
 PullPaintAgent::PullPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize) :
5
-	RepaintAgent(iEnvironment, iDotSize, iMoveSize)
5
+	RepaintAgent(iEnvironment, iDotSize, iMoveSize, 0)
6 6
 {
7 7
 	int vWidth = fEnvironment->getWidth();
8 8
 	int vHeight = fEnvironment->getHeight();

+ 15
- 11
src/Agents/RepaintAgent.cpp View File

@@ -1,11 +1,11 @@
1 1
 #include <Agents/Agent.hpp>
2 2
 #include <Environment/PictureEnvironment.hpp>
3 3
 
4
-RepaintAgent::RepaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize) :
4
+RepaintAgent::RepaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize, int iTolerance) :
5 5
 	Agent(iEnvironment, iDotSize, iMoveSize)
6 6
 {
7 7
 	init();
8
-
8
+	fTolerance = iTolerance;
9 9
 	//Initalize list of possible movement vectors
10 10
 	fMovements = std::vector<std::vector<int>>();
11 11
 	fValidMovementIndexes = std::vector<int>();
@@ -33,17 +33,12 @@ void RepaintAgent::move()
33 33
 {
34 34
 	//Only move on cells having a sufficiently close color
35 35
 	fValidMovementIndexes.clear();
36
-	int tolerance = 5;
37 36
 	for (int i = 0; i < static_cast<int>(fMovements.size()); i++)
38 37
 	{
39
-		sf::Uint32 va = fEnvironment->getCellOriginal(fXPos + fMovements.at(i).at(0), fYPos + fMovements.at(i).at(1));
40
-		sf::Uint32 vb = (int)fColor.toInteger();
41
-		bool vcomp =
42
-			abs((int)(va >> 24) - (int)(vb >> 24)) <= tolerance &&			 //R
43
-			abs((int)(va << 8 >> 24) - (int)(vb << 8 >> 24)) <= tolerance && //G
44
-			abs((int)(va << 16 >> 24) - (int)(vb << 16 >> 24)) <= tolerance; //B
45
-
46
-		if (vcomp)
38
+		int vXMove = fMovements.at(i).at(0);
39
+		int vYMove = fMovements.at(i).at(1);
40
+		if (
41
+			colorCloseEnough(fEnvironment->getCellOriginal(fXPos + vXMove, fYPos + vYMove)) && fEnvironment->getCell(fXPos + vXMove, fYPos + vYMove) != fColor.toInteger())
47 42
 		{
48 43
 			fValidMovementIndexes.push_back(i);
49 44
 		}
@@ -61,6 +56,15 @@ void RepaintAgent::move()
61 56
 	}
62 57
 }
63 58
 
59
+bool RepaintAgent::colorCloseEnough(sf::Uint32 iColor)
60
+{
61
+	sf::Uint32 va = iColor;
62
+	sf::Uint32 vb = (int)fColor.toInteger();
63
+	return abs((int)(va >> 24) - (int)(vb >> 24)) <= fTolerance &&		  //R
64
+		abs((int)(va << 8 >> 24) - (int)(vb << 8 >> 24)) <= fTolerance && //G
65
+		abs((int)(va << 16 >> 24) - (int)(vb << 16 >> 24)) <= fTolerance; //B
66
+}
67
+
64 68
 void RepaintAgent::paint()
65 69
 {
66 70
 	int vHalfBrush = fDotSize / 2;

+ 2
- 2
src/Agents/StraightPaintAgent.cpp View File

@@ -1,8 +1,8 @@
1 1
 #include <Agents/Agent.hpp>
2 2
 #include <Environment/PictureEnvironment.hpp>
3 3
 
4
-StraightPaintAgent::StraightPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize) :
5
-	RepaintAgent(iEnvironment, iDotSize, iMoveSize)
4
+StraightPaintAgent::StraightPaintAgent(PictureEnvironment* iEnvironment, int iDotSize, int iMoveSize, int iTolerance) :
5
+	RepaintAgent(iEnvironment, iDotSize, iMoveSize, iTolerance)
6 6
 {
7 7
 	init();
8 8
 }

+ 9
- 0
src/Control/EnvInputs.cpp View File

@@ -0,0 +1,9 @@
1
+#include <Control/EnvInputs.hpp>
2
+
3
+EnvInputs::EnvInputs()
4
+{
5
+}
6
+
7
+void EnvInputs::loop()
8
+{
9
+}

+ 7
- 4
src/Environment/PictureEnvironment.cpp View File

@@ -1,6 +1,7 @@
1 1
 #include "Platform/Platform.hpp"
2 2
 #include <Agents/Agent.hpp>
3 3
 #include <Agents/Perception/Perception.hpp>
4
+#include <Control/EnvInputs.hpp>
4 5
 #include <Environment/PictureEnvironment.hpp>
5 6
 
6 7
 const sf::Vector2f DEFAUMT_SIMZE = sf::Vector2f(800, 600);
@@ -53,6 +54,7 @@ PictureEnvironment::PictureEnvironment(std::string& iFilePath, sf::RenderWindow*
53 54
 	fPlatform->setIcon(fWindow->getSystemHandle());
54 55
 
55 56
 	//fShape = sf::RectangleShape(fSize);
57
+	fInputs = EnvInputs();
56 58
 	fShape = sf::RectangleShape(fInitialSize);
57 59
 	fAgents = std::vector<std::unique_ptr<Agent>>();
58 60
 	fShape.setFillColor(sf::Color::White);
@@ -92,6 +94,7 @@ bool PictureEnvironment::loop()
92 94
 			if (fEvent.type == sf::Event::Closed)
93 95
 				fWindow->close();
94 96
 		}
97
+		fInputs.loop();
95 98
 		// fAgentsIterator = fAgents.begin();
96 99
 		std::vector<std::unique_ptr<Agent>>::iterator vAgentsIterator = fAgents.begin();
97 100
 		while (vAgentsIterator != fAgents.end())
@@ -154,11 +157,11 @@ void PictureEnvironment::makeAgents(int iNumber, int iDotSize, int iMoveSize)
154 157
 	}
155 158
 }
156 159
 
157
-void PictureEnvironment::makeRepaintAgents(int iNumber, int iDotSize, int iMoveSize)
160
+void PictureEnvironment::makeRepaintAgents(int iNumber, int iDotSize, int iMoveSize, int iTolerance)
158 161
 {
159 162
 	for (int i = 0; i < iNumber; i++)
160 163
 	{
161
-		fAgents.push_back(std::make_unique<RepaintAgent>(this, iDotSize, iMoveSize));
164
+		fAgents.push_back(std::make_unique<RepaintAgent>(this, iDotSize, iMoveSize, iTolerance));
162 165
 	}
163 166
 }
164 167
 
@@ -170,11 +173,11 @@ void PictureEnvironment::makePullPaintAgents(int iNumber, int iDotSize, int iMov
170 173
 	}
171 174
 }
172 175
 
173
-void PictureEnvironment::makeStraightRepaintAgents(int iNumber, int iDotSize, int iMoveSize)
176
+void PictureEnvironment::makeStraightRepaintAgents(int iNumber, int iDotSize, int iMoveSize, int iTolerance)
174 177
 {
175 178
 	for (int i = 0; i < iNumber; i++)
176 179
 	{
177
-		fAgents.push_back(std::make_unique<StraightPaintAgent>(this, iDotSize, iMoveSize));
180
+		fAgents.push_back(std::make_unique<StraightPaintAgent>(this, iDotSize, iMoveSize, iTolerance));
178 181
 	}
179 182
 }
180 183
 

+ 10
- 4
src/Main.cpp View File

@@ -11,7 +11,8 @@ int main()
11 11
 #endif
12 12
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\dickbutt.jpg";
13 13
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\caisseenre.png";
14
-	std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA315024.jpg";
14
+	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA315024.jpg";
15
+	std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\14.jpg";
15 16
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA304995.jpg";
16 17
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\P6224671.jpg";
17 18
 	//std::string filepath = "content/sfml.png";
@@ -26,9 +27,14 @@ int main()
26 27
 	PictureEnvironment vEnvironment(filepath, &window, &platform, vDisplayOriginal);
27 28
 
28 29
 	//vEnvironment.makeAgents(10000, 1, 10);
29
-	vEnvironment.makeRepaintAgents(50, 30, 10);
30
-	vEnvironment.makeStraightRepaintAgents(250, 20, 15);
31
-	vEnvironment.makePullPaintAgents(50, 20, 10);
30
+	//vEnvironment.makeRepaintAgents(50, 50, 25, 15);
31
+
32
+	//vEnvironment.makeRepaintAgents(50, 50, 25, 15);
33
+	//vEnvironment.makeStraightRepaintAgents(1000, 25, 15, 50);
34
+
35
+	vEnvironment.makeRepaintAgents(50, 15, 8, 15);
36
+	vEnvironment.makeStraightRepaintAgents(1000, 15, 8, 50);
37
+	//vEnvironment.makePullPaintAgents(50, 20, 10);
32 38
 	//int i = 0;
33 39
 	while (vEnvironment.loop())
34 40
 	{

Loading…
Cancel
Save