Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #include <SFML/Graphics.hpp>
  2. #include <list>
  3. #include <map>
  4.  
  5. class Node {
  6. public:
  7. float cout_g, cout_h, cout_f;
  8. sf::Vector2i parent;
  9. };
  10.  
  11. class Pathfinding
  12. {
  13. public:
  14. Pathfinding(sf::Vector2i);
  15. std::list<sf::Vector2i> searchPath(sf::Vector2i endpoint,sf::Vector2i startpoint);
  16.  
  17. private:
  18. std::map<sf::Vector2i,Node> closedList;
  19. std::map<sf::Vector2i,Node> openList;
  20. };
  21.  
  22. #include "Pathfinding.h"
  23.  
  24. Pathfinding::Pathfinding(sf::Vector2i coords)
  25. {
  26. }
  27.  
  28. std::list<sf::Vector2i> Pathfinding::searchPath(sf::Vector2i endpoint, sf::Vector2i startpoint)
  29. {
  30. Node startNode;
  31. startNode.parent.x = 0;
  32. startNode.parent.y = 0;
  33. openList[startpoint] = startNode;
  34. std::list<sf::Vector2i> list;
  35. return list;
  36. }
  37.  
  38. #include "Pathfinding.h"
  39.  
  40. int main()
  41. {
  42. sf::RenderWindow window(sf::VideoMode(800,600),"A* Test");
  43. Pathfinding pathfinder(sf::Vector2i(800,600));
  44. while(window.isOpen())
  45. {
  46. sf::Event event;
  47. while(window.pollEvent(event))
  48. {
  49. if(event.type == sf::Event::Closed) window.close();
  50. }
  51. std::list<sf::Vector2i> path = pathfinder.searchPath(sf::Vector2i(3,3),sf::Vector2i(45,55));
  52. window.clear(sf::Color::White);
  53. window.display();
  54. }
  55. return 0;
  56. }
  57.  
  58. openList[startpoint] = startNode;
  59.  
  60. namespace std
  61. {
  62. template <class T>
  63. struct hash<sf::Vector2<T>>
  64. {
  65. std::size_t operator()(const sf::Vector2<T>& v) const
  66. {
  67. using std::hash;
  68.  
  69. // Compute individual hash values for first
  70. // and second. Combine them using the Boost-func
  71.  
  72. std::size_t tmp0 = hash<T>()(v.x);
  73. std::size_t tmp1 = hash<T>()(v.y);
  74.  
  75. tmp0 ^= tmp1 + 0x9e3779b9 + (tmp0 << 6) + (tmp0 >> 2);
  76. }
  77. };
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement