Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Importance calculation function

  • Loading branch information...
commit 46c91c444930d094c855549869b5f2a6f90bdeed 1 parent a8d8d18
@Ignotus authored
View
2  AUTHORS
@@ -1 +1 @@
-Minh Ngo <ignotusp@fedoraproject.org>
+Minh Ngo <nlminhtl@gmail.com>
View
2  COPYING
@@ -1,5 +1,5 @@
KDots
-Copyright (c) 2011 - 2012 Minh Ngo <ignotusp@fedoraproject.org>
+Copyright (c) 2011 - 2012 Minh Ngo <nlminhtl@gmail.com>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
View
2  include/graphpoint.hpp
@@ -63,7 +63,7 @@ namespace KDots
m_owner = owner;
}
- inline int owner () const
+ inline Owner owner () const
{
return m_owner;
}
View
67 plugins/simpleai/rival.cpp
@@ -26,6 +26,7 @@
#include "rival.hpp"
#include <include/point.hpp>
#include <include/dottable.hpp>
+#include <include/stepqueue.hpp>
#include "prioritymap.hpp"
namespace KDots
@@ -36,6 +37,7 @@ namespace KDots
: IRival (parent)
, m_table (NULL)
{
+ PriorityMap::instance ();
}
bool Rival::isAllow () const
@@ -45,9 +47,70 @@ namespace KDots
namespace
{
- int calcImportance (const DotTable *table, const Point& point)
+ float calcImportance(const Graph& graph, const Point& point)
{
- return 1;
+ float priority = -1;
+ const GraphPoint& thisPoint = graph[point];
+ const Owner currentOwner = thisPoint.owner ();
+ const Owner otherOwner = StepQueue::other (currentOwner);
+
+ for (const MapData& table : PriorityMap::instance ().priorityMap ())
+ {
+ const MapType& map = table.m_map;
+ const Point& currentPoint = table.m_current;
+
+ for (std::size_t j = 0, height = map.size (), i,
+ width = map.front ().size (); j < height; ++j)
+ {
+ for (i = 0; i < width; ++i)
+ {
+ const int dx = currentPoint.x () - i;
+ const int dy = currentPoint.y () - j;
+ const int newX = point.x () + dx;
+ const int newY = point.y () + dy;
+
+ if (newX < 0 || newY < 0 || newX >= graph.width ()
+ || newY >= graph.height ())
+ goto endloop;
+
+ const MapElement el = map[i][j];
+
+ const GraphPoint& graphPoint = graph[point.x () + dx][point.y () + dy];
+ const Owner own = graphPoint.owner ();
+ switch (el)
+ {
+ case EM: //Empty
+ if (own != NONE)
+ goto endloop;
+ break;
+ case FI: //First
+ if (own != currentOwner)
+ goto endloop;
+ break;
+ case SE: //Second
+ if (own != otherOwner)
+ goto endloop;
+ break;
+ case PF: // Possibly first
+ if (own == otherOwner)
+ goto endloop;
+ break;
+ case PS: // Possibly second
+ if (own == currentOwner)
+ goto endloop;
+ default:
+ break;
+ }
+ }
+ }
+
+ if (table.m_priority > priority)
+ priority = table.m_priority;
+endloop:
+ ;
+ }
+
+ return priority;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.