Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing exception

  • Loading branch information...
commit cb95ecf07f1cd81c7d0458cfb135c7080d5129ff 1 parent a73e8f0
@Ignotus authored
View
9 dottable.cpp
@@ -233,13 +233,6 @@ namespace KDots
else
return ++current;
}
-
- int sqrLength (const Point& first, const Point& second)
- {
- const int dx = second.x () - first.x ();
- const int dy = second.y () - first.y ();
- return dx * dx + dy * dy;
- }
}
void DotTable::resizePolygon (Polygon_ptr polygon)
@@ -267,7 +260,7 @@ namespace KDots
Polygon::iterator nextItr = next (*polygon, itr);
- const int sum = sqrLength (newPoint, *itr) + sqrLength (newPoint, *nextItr);
+ const int sum = Point::sqrLength (newPoint, *itr) + Point::sqrLength (newPoint, *nextItr);
if (sum != 2 && sum != 3)
continue;
View
2  edgelist.hpp
@@ -72,7 +72,7 @@ namespace KDots
const Point& operator[] (int index) const
{
- if (index >= 0 && index < m_count)
+ if (index < 0 || index >= m_count)
throw std::runtime_error ("beyond the limit of the array");
return m_pointList[index];
}
View
4 mainwindow.cpp
@@ -236,10 +236,6 @@ namespace KDots
connect (m_table,
SIGNAL (updateStatusBar (const QString&)),
statusBar (),
- SLOT (clearMessage ()));
- connect (m_table,
- SIGNAL (updateStatusBar (const QString&)),
- statusBar (),
SLOT (showMessage (const QString&)));
setCentralWidget (m_table);
View
26 plugins/simpleai/rival.cpp
@@ -33,6 +33,7 @@
#else
# include <KGameDifficulty>
#endif
+#include <KDebug>
#include <point.hpp>
#include <dottable.hpp>
#include <stepqueue.hpp>
@@ -223,8 +224,33 @@ namespace KDots
}
}
+ /*
+ auto maxSize = [&points] (const Point& lastPoint) {
+ int distance = 10000;
+ int id = 0;
+ int index = 0;
+ for (const Point& point : points)
+ {
+ const int sqrDistance = Point::sqrLength (point, lastPoint);
+ if (sqrDistance < distance)
+ {
+ distance = sqrDistance;
+ index = id;
+ }
+
+ ++id;
+ }
+
+ return index;
+ };
+ */
+
if (!points.empty ())
+ {
+ //const int index = maxSize (point);
+ //kDebug () << "index: " << index;
m_table->pushPoint (points[rand () % points.size ()]);
+ }
}
void Rival::calcImportanceTree (float& importance, const Point& point, int iteration)
View
7 point.hpp
@@ -95,6 +95,13 @@ namespace KDots
return m_x == -1 || m_y == -1;
}
+ static int sqrLength (const Point& first, const Point& second)
+ {
+ const int dx = second.x () - first.x ();
+ const int dy = second.y () - first.y ();
+ return dx * dx + dy * dy;
+ }
+
friend QDataStream& operator<< (QDataStream& out, const Point& obj);
friend QDataStream& operator>> (QDataStream& in, Point& obj);
};
View
22 tablewidget.cpp
@@ -78,6 +78,23 @@ namespace KDots
}
}
+ void TableWidget::mouseMoveEvent (QMouseEvent *event)
+ {
+ QWidget::mouseMoveEvent (event);
+ /*
+ if (!m_rival->isAllow ())
+ return;
+
+ const Point& res = calculatePoint (event);
+ if (!res.isInitialized ())
+ return;
+
+ if (res.x () >= m_width - 1 || res.x () < 0
+ || res.y () < 0 || res.y () >= m_height - 1)
+ return;
+ */
+ }
+
void TableWidget::onStatusMessage ()
{
emit updateStatusBar (QString ("First:\t")
@@ -120,8 +137,9 @@ namespace KDots
return;
else if (dy < firstPart)
--y;
-
- if (x >= m_width - 1 || x < 0 || y < 0 || y >= m_height - 1)
+
+ if (x >= m_width - 1 || x < 0
+ || y < 0 || y >= m_height - 1)
return;
m_table->pushPoint (Point (x, y));
View
1  tablewidget.hpp
@@ -50,6 +50,7 @@ namespace KDots
void undo ();
protected:
void mousePressEvent (QMouseEvent *event);
+ void mouseMoveEvent (QMouseEvent *event);
void paintEvent (QPaintEvent *event);
private slots:
void onStatusMessage ();
Please sign in to comment.
Something went wrong with that request. Please try again.