Skip to content

Commit

Permalink
MaskToString method. Upd AI algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignotus committed Sep 5, 2012
1 parent e19cda3 commit 418503c
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 131 deletions.
46 changes: 23 additions & 23 deletions dottable.cpp
Expand Up @@ -81,36 +81,36 @@ namespace KDots
return *next;
}
}
}

bool isInPolygon (Polygon_ptr polygon, const Point& point)
{
// k - a count of points in the same line with "point" object
// i - crosses count
int i = 0, shift;
bool DotTable::isInPolygon (Polygon_ptr polygon, const Point& point)
{
// k - a count of points in the same line with "point" object
// i - crosses count
int i = 0, shift;

Polygon::const_iterator itr = polygon->begin (), itrEnd = polygon->end ();
while (itr != itrEnd)
Polygon::const_iterator itr = polygon->begin (), itrEnd = polygon->end ();
while (itr != itrEnd)
{
if (itr->y () != point.y ())
{
if (itr->y () != point.y ())
{
++itr;
continue;
}

if (itr->x () == point.x ())
return true;

const Point& prevPoint = getPrevPoint (polygon, itr);
const Point& nextPoint = getNextPoint (polygon, shift, itr);

if (itr->x () < point.x () && prevPoint.y () != nextPoint.y () && shift == 1)
++i;

++itr;
continue;
}

if (itr->x () == point.x ())
return true;

const Point& prevPoint = getPrevPoint (polygon, itr);
const Point& nextPoint = getNextPoint (polygon, shift, itr);

return i % 2;
if (itr->x () < point.x () && prevPoint.y () != nextPoint.y () && shift == 1)
++i;

++itr;
}

return i % 2;
}

void DotTable::pushPoint (const Point& point)
Expand Down
5 changes: 4 additions & 1 deletion dottable.hpp
Expand Up @@ -44,6 +44,9 @@ namespace KDots
std::vector<Polygon_ptr> m_polygons;
public:
DotTable (const GameConfig& config, QObject *parent = 0);

static bool isInPolygon (Polygon_ptr polygon, const Point& point);

virtual ~DotTable () {}
GameConfig gameConfig () const;

Expand Down Expand Up @@ -75,4 +78,4 @@ namespace KDots
};
}

#endif
#endif
45 changes: 45 additions & 0 deletions plugins/simpleai/prioritymap.hpp
Expand Up @@ -27,6 +27,7 @@
#define KDOTS_PLUGINS_SIMPLEAI_PRIORITY_HPP
#include <list>
#include <vector>
#include <KDebug>
#include <constants.hpp>
#include <point.hpp>

Expand Down Expand Up @@ -66,6 +67,50 @@ namespace KDots
{
}

QString toString() const
{
QString res;
for (std::size_t j = 0; j < m_map.size (); ++j)
{
res += "\n{ ";
for (std::size_t i = 0; i < m_map.front ().size (); ++i)
{
switch (m_map[j][i])
{
case EM: //Empty
res += "EM ";
break;
case NM: // Does not matter
res += "NM ";
break;
case FI: //First
res += "FI ";
break;
case SE: //Second
res += "SE ";
break;
case PF: // Possibly first
res += "PF ";
break;
case PS: // Possibly second
res += "PS ";
break;
case CU: // Current
res += "CU ";
break;
default:
kDebug () << "WTF?";
}
}
res += "}";

}

res += "\n";

return res;
}

bool operator== (const MapData& other) const;
bool operator!= (const MapData& other) const;
};
Expand Down

0 comments on commit 418503c

Please sign in to comment.