Skip to content
This repository
Browse code

Moving headers into the root. Fixing polygon detecting algorithm.

- Removing emty *.cpp files
- Adding exceptions when an edge index is beyond the limit
- Adding the cmake file for finding the old LibKDEGames
- Removing inline attributes.
  • Loading branch information...
commit 19ea385174d0503ef2f1266a8c8c16bcae4ed05a 1 parent 0ff2f1b
Minh Ngo authored August 30, 2012

Showing 35 changed files with 240 additions and 188 deletions. Show diff stats Hide diff stats

  1. 57  CMakeLists.txt
  2. 2  brushcombo.cpp
  3. 0  {include → }/brushcombo.hpp
  4. 2  brushcombodelegate.cpp
  5. 0  {include → }/brushcombodelegate.hpp
  6. 49  cmake/FindLibKDEGames.cmake
  7. 9  {include → }/constants.hpp
  8. 70  dottable.cpp
  9. 7  {include → }/dottable.hpp
  10. 20  {include → }/edgelist.hpp
  11. 0  {include → }/gameconfig.hpp
  12. 12  {include → }/graph.hpp
  13. 26  graphpoint.cpp
  14. 11  {include → }/graphpoint.hpp
  15. 4  interface/irival.hpp
  16. 2  mainwindow.cpp
  17. 0  {include → }/mainwindow.hpp
  18. 2  newgamedialog.cpp
  19. 0  {include → }/newgamedialog.hpp
  20. 2  newgamewidget.cpp
  21. 0  {include → }/newgamewidget.hpp
  22. 4  {include → }/plugincontainer.hpp
  23. 2  pluginmanagerwidget.cpp
  24. 0  {include → }/pluginmanagerwidget.hpp
  25. 6  plugins/ipconnect/rival.cpp
  26. 8  plugins/simpleai/prioritymap.hpp
  27. 12  plugins/simpleai/rival.cpp
  28. 35  {include → }/point.hpp
  29. 26  polygon.cpp
  30. 6  {include → }/polygon.hpp
  31. 29  polygonfinder.cpp
  32. 1  {include → }/polygonfinder.hpp
  33. 22  {include → }/stepqueue.hpp
  34. 2  tablewidget.cpp
  35. 0  {include → }/tablewidget.hpp
57  CMakeLists.txt
... ...
@@ -1,6 +1,11 @@
1 1
 CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
2 2
 PROJECT (kdots)
3 3
 
  4
+SET (CMAKE_MODULE_PATH
  5
+	${CMAKE_MODULE_PATH}
  6
+	${CMAKE_CURRENT_SOURCE_DIR}/cmake
  7
+)
  8
+
4 9
 FIND_PACKAGE (Qt4 REQUIRED)
5 10
 FIND_PACKAGE (KDE4 REQUIRED)
6 11
 
@@ -10,18 +15,10 @@ IF (KDEGAMES_FOUND)
10 15
 	ADD_DEFINITIONS(-DOLD_LIBKDEGAMES)
11 16
 ELSE (KDEGAMES_FOUND)
12 17
 	FIND_PACKAGE (KDEGames REQUIRED)
  18
+	MESSAGE(STATUS "Found KDEGames")
13 19
 	ADD_DEFINITIONS (-DNEW_LIBKDEGAMES)
14 20
 ENDIF (KDEGAMES_FOUND)
15 21
 
16  
-#IF (KDEGAMES_LIBRARY)
17  
-#    MESSAGE(STATUS "FOUND ${KDEGAMES_LIBRARY}")
18  
-#    ADD_DEFINITIONS (-DNEW_LIBKDEGAMES)
19  
-#ELSE (KDEGAMES_LIBRARY)
20  
-#    MESSAGE(STATUS "NOT FOUND")
21  
-#    FIND_PACKAGE (LibKDEGames REQUIRED)
22  
-#    ADD_DEFINITIONS (-DOLD_LIBKDEGAMES)
23  
-#ENDIF (KDEGAMES_LIBRARY)
24  
-
25 22
 INCLUDE (KDE4Defaults)
26 23
 
27 24
 OPTION (KDE4_BUILD_TESTS "Enable test units" OFF)
@@ -47,7 +44,7 @@ INCLUDE_DIRECTORIES (
47 44
 	${QT_INCLUDES}
48 45
 )
49 46
 
50  
-SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
  47
+SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -fexceptions")
51 48
 
52 49
 SET (PLUGIN_BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}/plugins)
53 50
 SET (KDOTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
@@ -60,7 +57,6 @@ ENDIF (UNIX)
60 57
 
61 58
 SET (SRCS
62 59
 	brushcombo.cpp
63  
-	graphpoint.cpp
64 60
 	graph.cpp
65 61
 	dottable.cpp
66 62
 	stepqueue.cpp
@@ -69,7 +65,6 @@ SET (SRCS
69 65
 	newgamedialog.cpp
70 66
 	mainwindow.cpp
71 67
 	polygonfinder.cpp
72  
-	polygon.cpp
73 68
 	plugincontainer.cpp
74 69
 	pluginmanagerwidget.cpp
75 70
 	gameconfig.cpp
@@ -79,24 +74,24 @@ SET (SRCS
79 74
 )
80 75
 
81 76
 SET (HEADERS
82  
-	include/brushcombo.hpp
83  
-	include/graphpoint.hpp
84  
-	include/graph.hpp
85  
-	include/dottable.hpp
86  
-	include/stepqueue.hpp
87  
-	include/tablewidget.hpp
88  
-	include/edgelist.hpp
89  
-	include/point.hpp
90  
-	include/newgamedialog.hpp
91  
-	include/newgamewidget.hpp
92  
-	include/mainwindow.hpp
93  
-	include/constants.hpp
94  
-	include/polygonfinder.hpp
95  
-	include/polygon.hpp
96  
-	include/plugincontainer.hpp
97  
-	include/pluginmanagerwidget.hpp
98  
-	include/gameconfig.hpp
99  
-	include/brushcombodelegate.hpp
  77
+	brushcombo.hpp
  78
+	graphpoint.hpp
  79
+	graph.hpp
  80
+	dottable.hpp
  81
+	stepqueue.hpp
  82
+	tablewidget.hpp
  83
+	edgelist.hpp
  84
+	point.hpp
  85
+	newgamedialog.hpp
  86
+	newgamewidget.hpp
  87
+	mainwindow.hpp
  88
+	constants.hpp
  89
+	polygonfinder.hpp
  90
+	polygon.hpp
  91
+	plugincontainer.hpp
  92
+	pluginmanagerwidget.hpp
  93
+	gameconfig.hpp
  94
+	brushcombodelegate.hpp
100 95
 )
101 96
 
102 97
 SET (INTERFACE_HEAD
@@ -170,4 +165,4 @@ ADD_CUSTOM_TARGET (uninstall
170 165
 ADD_SUBDIRECTORY (plugins)
171 166
 
172 167
 #INCLUDE (MacroOptionalAddSubdirectory)
173  
-#MACRO_OPTIONAL_ADD_SUBDIRECTORY (po)
  168
+#MACRO_OPTIONAL_ADD_SUBDIRECTORY (po)
2  brushcombo.cpp
@@ -62,4 +62,4 @@ namespace KDots
62 62
 	}
63 63
 }
64 64
 
65  
-#include "include/brushcombo.moc"
  65
+#include "brushcombo.moc"
0  include/brushcombo.hpp → brushcombo.hpp
File renamed without changes
2  brushcombodelegate.cpp
@@ -109,4 +109,4 @@ namespace KDots
109 109
 	}
110 110
 }
111 111
 
112  
-#include "include/brushcombodelegate.moc"
  112
+#include "brushcombodelegate.moc"
0  include/brushcombodelegate.hpp → brushcombodelegate.hpp
File renamed without changes
49  cmake/FindLibKDEGames.cmake
... ...
@@ -0,0 +1,49 @@
  1
+# - Try to find the kdegames library
  2
+# Once done this will define
  3
+#
  4
+#  KDEGAMES_FOUND - system has the kdegames library
  5
+#  KDEGAMES_INCLUDE_DIRS - a list of the relevant libkdegames include dirs. Allows the use of forwarding header, e.g. #include <KGameDifficulty>
  6
+#  KDEGAMES_INCLUDE_DIR - the kdegames include directory
  7
+#  KDEGAMES_LIBRARY - Link this to use the kdegames library
  8
+#
  9
+include(CheckLibraryExists)
  10
+
  11
+if (KDEGAMES_INCLUDE_DIR AND KDEGAMES_LIBRARY)
  12
+    # in cache already
  13
+    SET(KDEGAMES_FOUND TRUE)
  14
+
  15
+else (KDEGAMES_INCLUDE_DIR AND KDEGAMES_LIBRARY)
  16
+
  17
+        # reset vars
  18
+        set(KDEGAMES_INCLUDE_DIRS)
  19
+        set(KDEGAMES_INCLUDE_DIR)
  20
+        set(KDEGAMES_LIBRARY)
  21
+        FIND_PATH(KDEGAMES_INCLUDE_DIR kgamedifficulty.h
  22
+                ${INCLUDE_INSTALL_DIR}
  23
+                ${KDE4_INCLUDE_DIR} 
  24
+                ${GNUWIN32_DIR}/include
  25
+        )
  26
+        set(KDEGAMES_INCLUDE_DIR ${KDEGAMES_INCLUDE_DIR})
  27
+
  28
+        set(CMAKE_LIBRARY_PATH ${LIB_INSTALL_DIR})
  29
+        find_library(KDEGAMES_LIBRARY NAMES kdegames
  30
+                PATHS
  31
+                ${LIB_INSTALL_DIR}
  32
+                ${KDE4_LIB_DIR}
  33
+                ${GNUWIN32_DIR}/lib
  34
+        )
  35
+        set(KDEGAMES_LIBRARY ${KDEGAMES_LIBRARY})
  36
+
  37
+        include(FindPackageHandleStandardArgs)
  38
+        FIND_PACKAGE_HANDLE_STANDARD_ARGS(KDEGAMES DEFAULT_MSG KDEGAMES_INCLUDE_DIR KDEGAMES_LIBRARY )
  39
+
  40
+        MARK_AS_ADVANCED(KDEGAMES_INCLUDE_DIR KDEGAMES_LIBRARY)
  41
+ENDIF(KDEGAMES_INCLUDE_DIR AND KDEGAMES_LIBRARY)
  42
+
  43
+#The ${KDEGAMES_INCLUDE_DIR}/KDE addition is for the forwarding includes
  44
+IF(NOT KDEGAMES_INCLUDE_DIRS)
  45
+    SET(KDEGAMES_INCLUDE_DIRS ${KDEGAMES_INCLUDE_DIR} ${KDEGAMES_INCLUDE_DIR}/KDE ${KDEGAMES_INCLUDE_DIR}/KDE/KGame)
  46
+    MARK_AS_ADVANCED(KDEGAMES_INCLUDE_DIRS)
  47
+ENDIF(NOT KDEGAMES_INCLUDE_DIRS)
  48
+
  49
+
9  include/constants.hpp → constants.hpp
@@ -27,6 +27,7 @@
27 27
 #define KDOTS_CONSTANTS_HPP
28 28
 #include <QString>
29 29
 #include <kdemacros.h>
  30
+#include "point.hpp"
30 31
 #ifndef KDOTS_EXPORT
31 32
 # if defined(MAKE_KDOTS_LIB)
32 33
    // We are building this library
@@ -55,10 +56,12 @@ namespace KDots
55 56
 		FIRST,
56 57
 		SECOND
57 58
 	};
  59
+	
  60
+	const int DIRECTION_COUNT = 8;
58 61
 
59  
-	const int GRAPH_DX[8] = {0, 1, 1, 1, 0, -1, -1, -1};
60  
-	const int GRAPH_DY[8] = {1, 1, 0, -1, -1, -1, 0, 1};
61  
-
  62
+	const int GRAPH_DX[DIRECTION_COUNT] = {0, 1, 1, 1, 0, -1, -1, -1};
  63
+	const int GRAPH_DY[DIRECTION_COUNT] = {1, 1, 0, -1, -1, -1, 0, 1};
  64
+	
62 65
 	const QString PLUGIN_SUFFIX = "kdots_";
63 66
 }
64 67
 
70  dottable.cpp
@@ -26,6 +26,7 @@
26 26
 #include "dottable.hpp"
27 27
 #include <KMessageBox>
28 28
 #include <KLocalizedString>
  29
+#include <KDebug>
29 30
 #include "graph.hpp"
30 31
 #include "polygonfinder.hpp"
31 32
 #include "stepqueue.hpp"
@@ -95,6 +96,9 @@ namespace KDots
95 96
 					++itr;
96 97
 					continue;
97 98
 				}
  99
+				
  100
+				if (itr->x () == point.x ())
  101
+					return true;	
98 102
 
99 103
 				const Point& prevPoint = getPrevPoint (polygon, itr);
100 104
 				const Point& nextPoint = getNextPoint (polygon, shift, itr);
@@ -107,12 +111,6 @@ namespace KDots
107 111
 
108 112
 			return i % 2;
109 113
 		}
110  
-		
111  
-		int doubleTriangleArea (const Point& a, const Point& b, const Point& c)
112  
-		{
113  
-			return std::abs ((b.x () - a.x ()) * (c.y () - a.y ())
114  
-					- (c.x () - a.x ()) * (b.y () - a.y ()));
115  
-		}
116 114
 	}
117 115
 
118 116
 	void DotTable::pushPoint (const Point& point)
@@ -225,6 +223,62 @@ namespace KDots
225 223
 		for (const Point& point : points)
226 224
 			pushPoint (point);
227 225
 	}
  226
+	
  227
+	namespace
  228
+	{
  229
+		Polygon::iterator next (Polygon& polygon, Polygon::iterator current)
  230
+		{
  231
+			if (current == --polygon.end ())
  232
+				return polygon.begin ();
  233
+			else
  234
+				return ++current;
  235
+		}
  236
+		
  237
+		int sqrLength (const Point& first, const Point& second)
  238
+		{
  239
+			const int dx = second.x () - first.x ();
  240
+			const int dy = second.y () - first.y ();
  241
+			return dx * dx + dy * dy;
  242
+		}
  243
+	}
  244
+	
  245
+	void DotTable::resizePolygon (Polygon_ptr polygon)
  246
+	{
  247
+		const Owner current = m_steps->getCurrentOwner ();
  248
+		
  249
+		for (Polygon::iterator itr = polygon->begin (), endItr = polygon->end ();
  250
+				 itr != endItr; ++itr)
  251
+		{
  252
+			for (int i = 0; i < DIRECTION_COUNT; ++i)
  253
+			{
  254
+				const int tempx = itr->x () + GRAPH_DX[i];
  255
+				const int tempy = itr->y () + GRAPH_DY[i];
  256
+
  257
+				if (tempx < 0 || tempy < 0
  258
+						|| static_cast<std::size_t> (tempx) >= m_graph->width ()
  259
+						|| static_cast<std::size_t> (tempy) >= m_graph->height ())
  260
+					continue;
  261
+				
  262
+				const Point newPoint (tempx, tempy);
  263
+				const GraphPoint& graphPoint = (*m_graph)[newPoint];
  264
+
  265
+				if (graphPoint.owner () != current || graphPoint.isCaptured ())
  266
+					continue;
  267
+				
  268
+				Polygon::iterator nextItr = next (*polygon, itr);
  269
+				
  270
+				const int sum = sqrLength (newPoint, *itr) + sqrLength (newPoint, *nextItr);
  271
+				
  272
+				if (sum != 2 && sum != 3)
  273
+					continue;
  274
+				
  275
+				if (isInPolygon (polygon, newPoint))
  276
+					continue;
  277
+				
  278
+				polygon->insert (nextItr, newPoint);
  279
+			}
  280
+		} 
  281
+	}
228 282
 
229 283
 	void DotTable::drawPolygon (PolyList polygons)
230 284
 	{
@@ -233,6 +287,8 @@ namespace KDots
233 287
 			if (!polygon->isFilled ())
234 288
 				continue;
235 289
 			
  290
+			resizePolygon (polygon);
  291
+			
236 292
 			polygon->setOwner (m_steps->getCurrentOwner ());
237 293
 			m_polygons.push_back (polygon);
238 294
 			
@@ -247,4 +303,4 @@ namespace KDots
247 303
 	}
248 304
 }
249 305
 
250  
-#include "include/dottable.moc"
  306
+#include "dottable.moc"
7  include/dottable.hpp → dottable.hpp
@@ -49,17 +49,17 @@ namespace KDots
49 49
 
50 50
 		void pushPoint (const Point& point);
51 51
 		
52  
-		inline std::vector<Polygon_ptr> polygons ()
  52
+		std::vector<Polygon_ptr> polygons ()
53 53
 		{
54 54
 			return m_polygons;
55 55
 		}
56 56
 
57  
-		inline Graph& graph () const
  57
+		Graph& graph () const
58 58
 		{
59 59
 			return *m_graph;
60 60
 		}
61 61
 
62  
-		inline std::shared_ptr<StepQueue> stepQueue ()
  62
+		std::shared_ptr<StepQueue> stepQueue ()
63 63
 		{
64 64
 			return m_steps;
65 65
 		}
@@ -69,6 +69,7 @@ namespace KDots
69 69
 		void nextPlayer (const Point& lastPoint);
70 70
 	private:
71 71
 		void drawPolygon (PolyList polygons);
  72
+		void resizePolygon (Polygon_ptr polygon);
72 73
 		
73 74
 		void continueStep ();
74 75
 	};
20  include/edgelist.hpp → edgelist.hpp
@@ -25,6 +25,7 @@
25 25
  */
26 26
 #ifndef KDOTS_EDGELIST_HPP
27 27
 #define KDOTS_EDGELIST_HPP
  28
+#include <stdexcept>
28 29
 #include "point.hpp"
29 30
 
30 31
 namespace KDots
@@ -35,11 +36,11 @@ namespace KDots
35 36
 		int m_count;
36 37
 		Point m_pointList[SIZE];
37 38
 	public:
38  
-		inline EdgeList()
  39
+		EdgeList()
39 40
 			: m_count (0)
40 41
 		{}
41 42
 
42  
-		inline bool addEdge (const Point& point)
  43
+		bool addEdge (const Point& point)
43 44
 		{
44 45
 			if (m_count == SIZE || hasPoint (point))
45 46
 				return false;
@@ -48,12 +49,12 @@ namespace KDots
48 49
 			return true;
49 50
 		}
50 51
 
51  
-		inline int size () const
  52
+		int size () const
52 53
 		{
53 54
 			return m_count;
54 55
 		}
55 56
 
56  
-		inline bool hasPoint (const Point& point)
  57
+		bool hasPoint (const Point& point)
57 58
 		{
58 59
 			for (int i = 0;  i < m_count; ++i)
59 60
 			{
@@ -64,18 +65,19 @@ namespace KDots
64 65
 			return false;
65 66
 		}
66 67
 
67  
-		inline Point& operator[] (int index)
  68
+		Point& operator[] (int index)
68 69
 		{
69 70
 			return const_cast<EdgeList<SIZE>&> (static_cast<const EdgeList<SIZE>&> (*this) [index]);
70 71
 		}
71 72
 
72  
-		inline const Point& operator[] (int index) const
  73
+		const Point& operator[] (int index) const
73 74
 		{
74  
-			Point def;
75  
-			return index >= 0 && index < m_count ? m_pointList[index] : def;
  75
+			if (index >= 0 && index < m_count)
  76
+				throw std::runtime_error ("beyond the limit of the array");
  77
+			return m_pointList[index];
76 78
 		}
77 79
 
78  
-		inline bool removeEdge (const Point& toPoint)
  80
+		bool removeEdge (const Point& toPoint)
79 81
 		{
80 82
 			for (int i = 0; i < m_count; ++i)
81 83
 			{
0  include/gameconfig.hpp → gameconfig.hpp
File renamed without changes
12  include/graph.hpp → graph.hpp
@@ -120,32 +120,32 @@ namespace KDots
120 120
 		iterator end ();
121 121
 		const_iterator end () const;
122 122
 
123  
-		inline std::size_t width () const
  123
+		std::size_t width () const
124 124
 		{
125 125
 			return m_graph.size ();
126 126
 		}
127 127
 
128  
-		inline std::size_t height () const
  128
+		std::size_t height () const
129 129
 		{
130 130
 			return m_graph.front ().size ();
131 131
 		}
132 132
 
133  
-		inline GraphPoint& operator[] (const Point& index)
  133
+		GraphPoint& operator[] (const Point& index)
134 134
 		{
135 135
 			return m_graph[index.x ()][index.y ()];
136 136
 		}
137 137
 
138  
-		inline const GraphPoint& operator[] (const Point& index) const
  138
+		const GraphPoint& operator[] (const Point& index) const
139 139
 		{
140 140
 			return m_graph[index.x ()][index.y ()];
141 141
 		}
142 142
 
143  
-		inline std::vector<GraphPoint>& operator[] (int index)
  143
+		std::vector<GraphPoint>& operator[] (int index)
144 144
 		{
145 145
 			return m_graph[index];
146 146
 		}
147 147
 
148  
-		inline const std::vector<GraphPoint>& operator[] (int index) const
  148
+		const std::vector<GraphPoint>& operator[] (int index) const
149 149
 		{
150 150
 			return m_graph[index];
151 151
 		}
26  graphpoint.cpp
... ...
@@ -1,26 +0,0 @@
1  
-/*
2  
- * KDots
3  
- * Copyright (c) 2011-2012 Minh Ngo <nlminhtl@gmail.com>
4  
- * 
5  
- * Redistribution and use in source and binary forms, with or without
6  
- * modification, are permitted provided that the following conditions
7  
- * are met:
8  
- *
9  
- * 1. Redistributions of source code must retain the above copyright
10  
- *    notice, this list of conditions and the following disclaimer.
11  
- * 2. Redistributions in binary form must reproduce the above copyright
12  
- *    notice, this list of conditions and the following disclaimer in the
13  
- *    documentation and/or other materials provided with the distribution.
14  
- *
15  
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  
- */
26  
-#include "graphpoint.hpp"
11  include/graphpoint.hpp → graphpoint.hpp
@@ -33,7 +33,7 @@ namespace KDots
33 33
 	class KDOTS_EXPORT GraphPoint
34 34
 	{
35 35
 	public:
36  
-		typedef EdgeList<8> GraphEdges;
  36
+		typedef EdgeList<DIRECTION_COUNT> GraphEdges;
37 37
 
38 38
 	private:
39 39
 		bool m_captured;
@@ -41,29 +41,28 @@ namespace KDots
41 41
 		GraphEdges m_edges;
42 42
 
43 43
 	public:
44  
-		inline
45 44
 		GraphPoint (Owner owner = NONE)
46 45
 			: m_captured (false)
47 46
 			, m_owner (owner)
48 47
 		{
49 48
 		}
50 49
 
51  
-		inline bool isCaptured () const
  50
+		bool isCaptured () const
52 51
 		{
53 52
 			return m_captured;
54 53
 		}
55 54
 
56  
-		inline void capture ()
  55
+		void capture ()
57 56
 		{
58 57
 			m_captured = true;
59 58
 		}
60 59
 
61  
-		inline void setOwner (Owner owner)
  60
+		void setOwner (Owner owner)
62 61
 		{
63 62
 			m_owner = owner;
64 63
 		}
65 64
 
66  
-		inline Owner owner () const
  65
+		Owner owner () const
67 66
 		{
68 67
 			return m_owner;
69 68
 		}
4  interface/irival.hpp
@@ -26,7 +26,8 @@
26 26
 #ifndef KDOTS_IRIVAL_HPP
27 27
 #define KDOTS_IRIVAL_HPP
28 28
 #include <QObject>
29  
-#include <include/newgamewidget.hpp>
  29
+#include <newgamewidget.hpp>
  30
+#include <point.hpp>
30 31
 
31 32
 class QStatusBar;
32 33
 
@@ -34,7 +35,6 @@ namespace KDots
34 35
 {
35 36
 	class DotTable;
36 37
 	class IConfigurationWidget;
37  
-	class Point;
38 38
 	
39 39
 	class IRival : public QObject
40 40
 	{
2  mainwindow.cpp
@@ -255,4 +255,4 @@ namespace KDots
255 255
 	}
256 256
 }
257 257
 
258  
-#include "include/mainwindow.moc"
  258
+#include "mainwindow.moc"
0  include/mainwindow.hpp → mainwindow.hpp
File renamed without changes
2  newgamedialog.cpp
@@ -148,4 +148,4 @@ namespace KDots
148 148
 	
149 149
 }
150 150
 
151  
-#include "include/newgamedialog.moc"
  151
+#include "newgamedialog.moc"
0  include/newgamedialog.hpp → newgamedialog.hpp
File renamed without changes
2  newgamewidget.cpp
@@ -81,4 +81,4 @@ namespace KDots
81 81
 	
82 82
 }
83 83
 
84  
-#include "include/newgamewidget.moc"
  84
+#include "newgamewidget.moc"
0  include/newgamewidget.hpp → newgamewidget.hpp
File renamed without changes
4  include/plugincontainer.hpp → plugincontainer.hpp
@@ -44,12 +44,12 @@ namespace KDots
44 44
 
45 45
 		static PluginContainer& instance ();
46 46
 
47  
-		inline const PluginMap& plugins () const
  47
+		const PluginMap& plugins () const
48 48
 		{
49 49
 			return m_pluginMap;
50 50
 		}
51 51
 
52  
-		inline IPlugin* plugin (const QString& name)
  52
+		IPlugin* plugin (const QString& name)
53 53
 		{
54 54
 			PluginMap::const_iterator itr = m_pluginMap.find (name);
55 55
 			return itr != m_pluginMap.end () ? *itr : NULL;
2  pluginmanagerwidget.cpp
@@ -63,4 +63,4 @@ namespace KDots
63 63
 	}
64 64
 }
65 65
 
66  
-#include "include/pluginmanagerwidget.moc"
  66
+#include "pluginmanagerwidget.moc"
0  include/pluginmanagerwidget.hpp → pluginmanagerwidget.hpp
File renamed without changes
6  plugins/ipconnect/rival.cpp
@@ -32,9 +32,9 @@
32 32
 #else
33 33
 # include <KGameDifficulty>
34 34
 #endif
35  
-#include <include/dottable.hpp>
36  
-#include <include/stepqueue.hpp>
37  
-#include <include/graph.hpp>
  35
+#include <dottable.hpp>
  36
+#include <stepqueue.hpp>
  37
+#include <graph.hpp>
38 38
 #include "connectdialog.hpp"
39 39
 #include "configurationwidget.hpp"
40 40
 
8  plugins/simpleai/prioritymap.hpp
@@ -27,8 +27,8 @@
27 27
 #define KDOTS_PLUGINS_SIMPLEAI_PRIORITY_HPP
28 28
 #include <list>
29 29
 #include <vector>
30  
-#include <include/constants.hpp>
31  
-#include <include/point.hpp>
  30
+#include <constants.hpp>
  31
+#include <point.hpp>
32 32
 
33 33
 struct stat;
34 34
 namespace KDots
@@ -55,11 +55,11 @@ namespace KDots
55 55
 			Point m_current;
56 56
 			float m_priority;
57 57
 
58  
-			inline MapData ()
  58
+			MapData ()
59 59
 			{
60 60
 			}
61 61
 			
62  
-			inline MapData (const MapType& map, const Point& current, float priority)
  62
+			MapData (const MapType& map, const Point& current, float priority)
63 63
 				: m_map (map)
64 64
 				, m_current (current)
65 65
 				, m_priority (priority)
12  plugins/simpleai/rival.cpp
@@ -33,11 +33,11 @@
33 33
 #else
34 34
 # include <KGameDifficulty>
35 35
 #endif
36  
-#include <include/point.hpp>
37  
-#include <include/dottable.hpp>
38  
-#include <include/stepqueue.hpp>
39  
-#include <include/constants.hpp>
40  
-#include <include/graph.hpp>
  36
+#include <point.hpp>
  37
+#include <dottable.hpp>
  38
+#include <stepqueue.hpp>
  39
+#include <constants.hpp>
  40
+#include <graph.hpp>
41 41
 #include "prioritymap.hpp"
42 42
 
43 43
 namespace KDots
@@ -239,7 +239,7 @@ namespace KDots
239 239
 			float max_imp =  -m_iterations;
240 240
 			
241 241
 			int i = 0;
242  
-			for (; i < 8; ++i)
  242
+			for (; i < DIRECTION_COUNT; ++i)
243 243
 			{
244 244
 				const int tempx = point.x () + GRAPH_DX[i];
245 245
 				const int tempy = point.y () + GRAPH_DY[i];
35  include/point.hpp → point.hpp
@@ -30,11 +30,11 @@
30 30
 
31 31
 namespace KDots
32 32
 {
33  
-	class KDOTS_EXPORT Point
  33
+	class Point
34 34
 	{
35 35
 		int m_x, m_y;
36 36
 	public:
37  
-		inline Point ()
  37
+		Point ()
38 38
 			: m_x (-1)
39 39
 			, m_y (-1)
40 40
 		{}
@@ -44,27 +44,28 @@ namespace KDots
44 44
 			return m_x < 0 || m_y < 0;
45 45
 		}
46 46
 		
47  
-		inline Point (int x, int y)
  47
+		Point (int x, int y)
48 48
 			: m_x (x)
49 49
 			, m_y (y)
50  
-		{}
  50
+		{
  51
+		}
51 52
 
52  
-		inline int x () const
  53
+		int x () const
53 54
 		{
54 55
 			return m_x;
55 56
 		}
56 57
 
57  
-		inline int y () const
  58
+		int y () const
58 59
 		{
59 60
 			return m_y;
60 61
 		}
61 62
 
62  
-		inline void setX (int x)
  63
+		void setX (int x)
63 64
 		{
64 65
 			m_x = x;
65 66
 		}
66 67
 
67  
-		inline void setY (int y)
  68
+		void setY (int y)
68 69
 		{
69 70
 			m_y = y;
70 71
 		}
@@ -79,30 +80,28 @@ namespace KDots
79 80
 			return Point (m_x + val, m_y + val);
80 81
 		}
81 82
 
82  
-		inline bool operator== (const Point& a) const
  83
+		bool operator== (const Point& a) const
83 84
 		{
84 85
 			return m_x == a.m_x && m_y == a.m_y;
85 86
 		}
86 87
 
87  
-		inline bool operator!= (const Point& a) const
  88
+		bool operator!= (const Point& a) const
88 89
 		{
89  
-			return ! (*this == a);
  90
+			return !(*this == a);
90 91
 		}
91 92
 
92  
-		inline bool empty () const
  93
+		bool empty () const
93 94
 		{
94 95
 			return m_x == -1 || m_y == -1;
95 96
 		}
96 97
 		
97  
-		
98  
-		
99  
-		friend QDataStream& operator<< (QDataStream& out, const KDots::Point& obj);
100  
-		friend QDataStream& operator>> (QDataStream& in, KDots::Point& obj);
  98
+		friend QDataStream& operator<< (QDataStream& out, const Point& obj);
  99
+		friend QDataStream& operator>> (QDataStream& in, Point& obj);
101 100
 	};
102 101
 	
103  
-	QDataStream& operator<< (QDataStream& out, const KDots::Point& obj);
  102
+	QDataStream& operator<< (QDataStream& out, const Point& obj);
104 103
 
105  
-	QDataStream& operator>> (QDataStream& in, KDots::Point& obj);
  104
+	QDataStream& operator>> (QDataStream& in, Point& obj);
106 105
 }
107 106
 
108 107
 Q_DECLARE_METATYPE (KDots::Point);
26  polygon.cpp
... ...
@@ -1,26 +0,0 @@
1  
-/*
2  
- * KDots
3  
- * Copyright (c) 2011-2012 Minh Ngo <nlminhtl@gmail.com>
4  
- * 
5  
- * Redistribution and use in source and binary forms, with or without
6  
- * modification, are permitted provided that the following conditions
7  
- * are met:
8  
- *
9  
- * 1. Redistributions of source code must retain the above copyright
10  
- *    notice, this list of conditions and the following disclaimer.
11  
- * 2. Redistributions in binary form must reproduce the above copyright
12  
- *    notice, this list of conditions and the following disclaimer in the
13  
- *    documentation and/or other materials provided with the distribution.
14  
- *
15  
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  
- */
26  
-#include "polygon.hpp"
6  include/polygon.hpp → polygon.hpp
@@ -38,7 +38,7 @@ namespace KDots
38 38
 	{
39 39
 		bool m_filled;
40 40
 		Owner m_owner;
41  
-		float m_area;
  41
+		int m_area;
42 42
 	public:
43 43
 		Polygon ()
44 44
 			: PolygonContainer ()
@@ -52,12 +52,12 @@ namespace KDots
52 52
 		{
53 53
 		}
54 54
 		
55  
-		void setArea (float area)
  55
+		void setArea (int area)
56 56
 		{
57 57
 			m_area = area;
58 58
 		}
59 59
 		
60  
-		float area () const
  60
+		int area () const
61 61
 		{
62 62
 			return m_area;
63 63
 		}
29  polygonfinder.cpp
@@ -41,27 +41,27 @@ namespace KDots
41 41
 	
42 42
 	namespace
43 43
 	{
44  
-		float area (const Polygon& polygon)
  44
+		int doubleArea (const Polygon& polygon)
45 45
 		{
46  
-			float res = 0;
  46
+			int res = 0;
47 47
 			Point prevPoint = polygon.back ();
48 48
 			for (Polygon::const_iterator itr = polygon.begin (), itrEnd = polygon.end ();
49 49
 					 itr != itrEnd; ++itr)
50 50
 			{
51  
-				res += (itr->x () - prevPoint.x ()) * float (itr->y () + prevPoint.y ()) / 2; 
  51
+				res += (itr->x () - prevPoint.x ()) * (itr->y () + prevPoint.y ()); 
52 52
 				prevPoint = *itr;
53 53
 			} 
54 54
 			
55 55
 			return std::abs (res);
56 56
 		}
57 57
 		
58  
-		float maxSize (const PolyList& polygonList)
  58
+		int maxSize (const PolyList& polygonList)
59 59
 		{
60  
-			float max = 0;
  60
+			int max = 0;
61 61
 
62 62
 			for (const Polygon_ptr& ptr : polygonList)
63 63
 			{
64  
-				const float currArea = area (*ptr);
  64
+				const int currArea = doubleArea (*ptr);
65 65
 				ptr->setArea (currArea);
66 66
 				if (currArea > max)
67 67
 					max = currArea;
@@ -75,7 +75,7 @@ namespace KDots
75 75
 	{
76 76
 		findPolygons (point);
77 77
 
78  
-		const float max = maxSize (m_polygons);
  78
+		const int max = maxSize (m_polygons);
79 79
 		m_polygons.erase (std::remove_if (m_polygons.begin (), m_polygons.end (),
80 80
 						[&max] (const Polygon_ptr& ptr)
81 81
 						{
@@ -88,11 +88,6 @@ namespace KDots
88 88
 
89 89
 	void PolygonFinder::findPolygons (const Point& point)
90 90
 	{
91  
-		const GraphPoint& graphPoint = m_graph[point];
92  
-
93  
-		if (graphPoint.isCaptured () || graphPoint.owner () != m_current)
94  
-			return;
95  
-
96 91
 		if (m_cache.size () > 3 && point == m_cache.front ())
97 92
 		{
98 93
 			m_polygons.push_back (Polygon_ptr (new Polygon (m_cache)));
@@ -105,7 +100,7 @@ namespace KDots
105 100
 		m_cache.push_back (point);
106 101
 		m_stepMap[point.x ()][point.y ()] = true;
107 102
 
108  
-		for (int i = 0; i < 8; ++i)
  103
+		for (int i = 0; i < DIRECTION_COUNT; ++i)
109 104
 		{
110 105
 			const int tempx = point.x () + GRAPH_DX[i];
111 106
 			const int tempy = point.y () + GRAPH_DY[i];
@@ -114,8 +109,14 @@ namespace KDots
114 109
 					|| static_cast<std::size_t> (tempx) >= m_graph.width ()
115 110
 					|| static_cast<std::size_t> (tempy) >= m_graph.height ())
116 111
 				continue;
  112
+			
  113
+			const Point newPoint (tempx, tempy);
  114
+			const GraphPoint& graphPoint = m_graph[newPoint];
117 115
 
118  
-			findPolygons (Point (tempx, tempy));
  116
+			if (graphPoint.isCaptured () || graphPoint.owner () != m_current)
  117
+				continue;
  118
+			
  119
+			findPolygons (newPoint);
119 120
 		}
120 121
 
121 122
 		m_cache.pop_back ();
1  include/polygonfinder.hpp → polygonfinder.hpp
@@ -32,7 +32,6 @@
32 32
 
33 33
 namespace KDots
34 34
 {
35  
-	class Point;
36 35
 	struct Graph;
37 36
 
38 37
 	class PolygonFinder
22  include/stepqueue.hpp → stepqueue.hpp
@@ -42,17 +42,17 @@ namespace KDots
42 42
 		StepQueue (Owner firstPlayer);
43 43
 		virtual ~StepQueue () {}
44 44
 		
45  
-		inline Owner firstOwner () const
  45
+		Owner firstOwner () const
46 46
 		{
47 47
 			return m_firstOwner;
48 48
 		}
49 49
 		
50  
-		inline Point lastPoint () const
  50
+		Point lastPoint () const
51 51
 		{
52 52
 			return m_points.empty () ? Point () : m_points.back ();
53 53
 		}
54 54
 		
55  
-		inline void clear ()
  55
+		void clear ()
56 56
 		{
57 57
 			m_first = m_second = m_emptyCaptured = 0;
58 58
 			m_owner  = m_firstOwner;
@@ -65,42 +65,42 @@ namespace KDots
65 65
 		void addPoint (const Point& point);
66 66
 		void addCaptured ();
67 67
 		
68  
-		inline void addEmptyCaptured ()
  68
+		void addEmptyCaptured ()
69 69
 		{
70 70
 			++m_emptyCaptured;
71 71
 		}
72 72
 		
73  
-		inline std::size_t emtyCapturedCount () const
  73
+		std::size_t emtyCapturedCount () const
74 74
 		{
75 75
 			return m_emptyCaptured;
76 76
 		}
77 77
 
78  
-		inline Owner getCurrentOwner () const
  78
+		Owner getCurrentOwner () const
79 79
 		{
80 80
 			return m_owner;
81 81
 		}
82 82
 
83  
-		inline std::size_t getMarks (Owner owner) const
  83
+		std::size_t getMarks (Owner owner) const
84 84
 		{
85 85
 			return owner == FIRST ? m_first : m_second;
86 86
 		}
87 87
 
88  
-		inline std::vector<Point> getPoints (Owner owner) const
  88
+		std::vector<Point> getPoints (Owner owner) const
89 89
 		{
90 90
 			return owner == SECOND ? m_secondPoints : m_firstPoints;
91 91
 		}
92 92
 		
93  
-		inline std::vector<Point> getAllPoints () const
  93
+		std::vector<Point> getAllPoints () const
94 94
 		{
95 95
 			return m_points;
96 96
 		}
97 97
 
98  
-		inline static Owner other (Owner player)
  98
+		static Owner other (Owner player)
99 99
 		{
100 100
 			return player == FIRST ? SECOND : FIRST;
101 101
 		}
102 102
 
103  
-		virtual Owner nextStep ()
  103
+		Owner nextStep ()
104 104
 		{
105 105
 			m_captured = false;
106 106
 			return (m_owner = other (m_owner));
2  tablewidget.cpp
@@ -238,4 +238,4 @@ namespace KDots
238 238
 	}
239 239
 }
240 240
 
241  
-#include "include/tablewidget.moc"
  241
+#include "tablewidget.moc"
0  include/tablewidget.hpp → tablewidget.hpp
File renamed without changes

0 notes on commit 19ea385

Please sign in to comment.
Something went wrong with that request. Please try again.