Browse Source

jsais pu ca fait longtemps

master
DemiSel 3 years ago
parent
commit
3d1b681526

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

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

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

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

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

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

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

1
 #include <Agents/Agent.hpp>
1
 #include <Agents/Agent.hpp>
2
 #include <Environment/PictureEnvironment.hpp>
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
 	Agent(iEnvironment, iDotSize, iMoveSize)
5
 	Agent(iEnvironment, iDotSize, iMoveSize)
6
 {
6
 {
7
 	init();
7
 	init();
8
-
8
+	fTolerance = iTolerance;
9
 	//Initalize list of possible movement vectors
9
 	//Initalize list of possible movement vectors
10
 	fMovements = std::vector<std::vector<int>>();
10
 	fMovements = std::vector<std::vector<int>>();
11
 	fValidMovementIndexes = std::vector<int>();
11
 	fValidMovementIndexes = std::vector<int>();
33
 {
33
 {
34
 	//Only move on cells having a sufficiently close color
34
 	//Only move on cells having a sufficiently close color
35
 	fValidMovementIndexes.clear();
35
 	fValidMovementIndexes.clear();
36
-	int tolerance = 5;
37
 	for (int i = 0; i < static_cast<int>(fMovements.size()); i++)
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
 			fValidMovementIndexes.push_back(i);
43
 			fValidMovementIndexes.push_back(i);
49
 		}
44
 		}
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
 void RepaintAgent::paint()
68
 void RepaintAgent::paint()
65
 {
69
 {
66
 	int vHalfBrush = fDotSize / 2;
70
 	int vHalfBrush = fDotSize / 2;

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

1
 #include <Agents/Agent.hpp>
1
 #include <Agents/Agent.hpp>
2
 #include <Environment/PictureEnvironment.hpp>
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
 	init();
7
 	init();
8
 }
8
 }

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

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
 #include "Platform/Platform.hpp"
1
 #include "Platform/Platform.hpp"
2
 #include <Agents/Agent.hpp>
2
 #include <Agents/Agent.hpp>
3
 #include <Agents/Perception/Perception.hpp>
3
 #include <Agents/Perception/Perception.hpp>
4
+#include <Control/EnvInputs.hpp>
4
 #include <Environment/PictureEnvironment.hpp>
5
 #include <Environment/PictureEnvironment.hpp>
5
 
6
 
6
 const sf::Vector2f DEFAUMT_SIMZE = sf::Vector2f(800, 600);
7
 const sf::Vector2f DEFAUMT_SIMZE = sf::Vector2f(800, 600);
53
 	fPlatform->setIcon(fWindow->getSystemHandle());
54
 	fPlatform->setIcon(fWindow->getSystemHandle());
54
 
55
 
55
 	//fShape = sf::RectangleShape(fSize);
56
 	//fShape = sf::RectangleShape(fSize);
57
+	fInputs = EnvInputs();
56
 	fShape = sf::RectangleShape(fInitialSize);
58
 	fShape = sf::RectangleShape(fInitialSize);
57
 	fAgents = std::vector<std::unique_ptr<Agent>>();
59
 	fAgents = std::vector<std::unique_ptr<Agent>>();
58
 	fShape.setFillColor(sf::Color::White);
60
 	fShape.setFillColor(sf::Color::White);
92
 			if (fEvent.type == sf::Event::Closed)
94
 			if (fEvent.type == sf::Event::Closed)
93
 				fWindow->close();
95
 				fWindow->close();
94
 		}
96
 		}
97
+		fInputs.loop();
95
 		// fAgentsIterator = fAgents.begin();
98
 		// fAgentsIterator = fAgents.begin();
96
 		std::vector<std::unique_ptr<Agent>>::iterator vAgentsIterator = fAgents.begin();
99
 		std::vector<std::unique_ptr<Agent>>::iterator vAgentsIterator = fAgents.begin();
97
 		while (vAgentsIterator != fAgents.end())
100
 		while (vAgentsIterator != fAgents.end())
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
 	for (int i = 0; i < iNumber; i++)
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
 	}
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
 	for (int i = 0; i < iNumber; i++)
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
 #endif
11
 #endif
12
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\dickbutt.jpg";
12
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\dickbutt.jpg";
13
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\caisseenre.png";
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
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA304995.jpg";
16
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\PA304995.jpg";
16
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\P6224671.jpg";
17
 	//std::string filepath = "C:\\Users\\VroumVroumMachine\\Pictures\\RepAgents\\P6224671.jpg";
17
 	//std::string filepath = "content/sfml.png";
18
 	//std::string filepath = "content/sfml.png";
26
 	PictureEnvironment vEnvironment(filepath, &window, &platform, vDisplayOriginal);
27
 	PictureEnvironment vEnvironment(filepath, &window, &platform, vDisplayOriginal);
27
 
28
 
28
 	//vEnvironment.makeAgents(10000, 1, 10);
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
 	//int i = 0;
38
 	//int i = 0;
33
 	while (vEnvironment.loop())
39
 	while (vEnvironment.loop())
34
 	{
40
 	{

Loading…
Cancel
Save