280 likes | 419 Views
TrianGO A Game of GO in Triangles. Qingzhe Huang Comp6711 project demo. Outline. Brief introduction of game GO as motivation of project Introduce algorithm used in project (nested convex hull, triangulation between convex hull, range searching, DFS in game board etc.) Introduce game rule
E N D
TrianGOA Game of GO in Triangles Qingzhe Huang Comp6711 project demo
Outline • Brief introduction of game GO as motivation of project • Introduce algorithm used in project (nested convex hull, triangulation between convex hull, range searching, DFS in game board etc.) • Introduce game rule • Playing game • Resources
What is GO?Go is... an ancient board game which takes simple elements -- line and circle, black and white, stone and wood -- combines them with simple rules and generates subtleties which have enthralled players for millennia.
GO is a game for controls Before the play Black capturesAfter the play Before the play Black captures three stones After the play
Why Not GO? • GO is too complicated. Theoretically 3361 combinations. The best computer software player cannot even beat good amateur player. • What if we use triangle as chess board?
How to draw chess board? • Triangulation by nested convex hull.
How to create nested convex hull? • How Simple is the algorithm? • while (!inputPointSet.empty()) • { • createConvexHull(inputPointSet, convexHull); • outputConvexHull(convexHull); • removePoints(inputPointSet, convexHull); • } • The time complexity is just O(nlogn) because of sorting of points. All rests are just linear.
How to triangulate? • Zigzag between external and internal convex hull.
When to terminate? • Just count the number of vertex in both convex hull.
What about degenerated cases? • The function to determine the sides of vertex WRT line also works when the line degenerates to points. • It also works when triangle degenerates to line or point. • But we have to take care with no internal convex hull.
What about the total time complexity? • The total time complexity is still O(nlogn) because triangulation is just linear. The following is 10000 points and it takes 16 seconds for nested convex hull.
What about the total time complexity? • The triangulation is really fast because it is linear. The following triangulation of 10000vertices only takes about one second.
Do we really need DCEL? • In the project proposal, I mentioned about implementing DCEL data structure. However, I give it up during project because it is not very useful for my purpose. • DCEL is ideal for dynamic changing of elements while my chess board only needs searching and it is static.
The game playing • How to check if a point is inside a triangle? • A more general way is to count the number of intersections between all edges and the cast ray from the point. If the number is even, the point is outside polygon. • My way is just check which side the point is on for each edge. If the sign for all edges are the same, the point is inside the triangle. This is only workable for convex polygons.
When the triangle can kill • If red clicks “next” triangle, the neighbour blue triangle will be removed because of all its neighbours are either red or boundary. This can also happen when multiple blue neighbour might be removed.
When the triangle can kill • More complicated case is when the searching might be infinite loop if we don’t keep track our searching path. The right picture is the result when red click the triangle.
When the triangle is a deadend • When the triangle cannot kill, the blue is forbidden to place its triangle in a dead end.
When does game end? • After every move, the program check if there is any possible move for next player. If no possible move can be made by next player, the program begins count triangles for both players and declare the winner. • Actually the counting is not correct because those empty triangle may be controlled by one player. The only good move for blue is labelled. Also the best move for red is also labelled. And there is no end.
Onion Triangulation • When I finished this slides, I checked with Google and find out that the official name for this algorithm is called Onion Triangulation. • http://cgm.cs.mcgill.ca/~orm/ontri.html • The region between two nested convex hulls is called an annulus. Toussaint (1986) presents a simple algorithm for triangulating an annulus, using the Rotating Calipers. • Their algorithms are essentially same as I did. Only that my way is more intuitive for understanding. And their way may generate less skinny triangles.
Onion Triangulation • Insert the edges of the hulls as edges in the triangulation. • Compute the points with minimum x coordinate for both P and Q, calling them xmin(P) and xmin(Q). • Construct two vertical lines of support (the calipers) at xmin(P) and xmin(Q); call them LP and LQ. • Insert (xmin(P), xmin(Q)) as an edge in the triangulation. • The "current" points p and q for LP and LQ are xmin(P) and xmin(Q), respectively. • Rotate the lines clockwise until one coincides with an edge. A new vertex has therefore been "hit" by one of the lines. • If it belongs to P (call it p'), insert (p', q) into the triangulation. Update the "current" points to p' and q. • If it belongs to Q (call it q'), insert (p, q') into the triangulation. Update the "current" points to p and q'. • In case of parallel edges, both lines of support coincide with edges, and two new vertices are "hit" (call them p' and q'). Then, insert (p', q'), and either (p, q') or (p', q) into the triangulation. Update the "current" points to p' and q'. • Repeat the previous step until the starting minimum points are reached.
Summary of the game • I searched Google and find no clue that anybody connected triangle and game Go together because it is too far from each other. Therefore I think it is a kind of original idea to play chess GO in a kind of reduced complexity. Maybe we can discover more general principles of GO when complexity of game is reduced.
Why GO? Top Ten Reasons to Play Go • 1. Go is the simplest of all games. • 2. Go is the most complex of all games. • 3. Go is the most popular game in the world today. • 4. Go is the oldest game still played in its original form. • 5. Every game has a winner. • 6. All players are equal. • 7. You always know where you fit in. • 8. It's easy to learn from mistakes. • 9. Ancient rituals impart important values. • 10. Go is about building, not destroying.
Why not STL? 1. STL is efficient. 2. It is template. 3. It is platform, compiler independent. 4. All program know about it and free of bugs.
The beauty of STL What I need is just fast searching and binary search tree is ideal for this purpose. The internal implementation of “set” is a binary search tree. template<class Key, class Pred = less<Key>, class A = allocator<Key> > class set {…} All you need is just the comparison function. As long as your comparison function is a strict order, you are done.
The comparison function • The vertex compares its x,y coordinate. • The edge uses vertex comparison for its two vertices. • The triangle uses edge comparison for its three edges. • By storing vertices, edges, triangles in set<Vertex>, set<Edge>, set<Triangle>, we can achieve O(logn) searching efficiency.
The vertex compares x,y • struct PrevPoint • { • bool operator()(const TPoint& first, const TPoint& second) • { • if (first.x==second.x) • { • return first.y>second.y; • } • else • { • return first.x<second.x; • } • } • };
The edge compares vertices • struct PrevEdge • { • bool operator()(TEdge* first, TEdge* second) • { • for (int i=0; i<2; i++) • { • if (prevPoint(first->pairPoint[i], second->pairPoint[i])) • { • return true; • } • if (prevPoint(second->pairPoint[i], first->pairPoint[i])) • { • return false; • } • } • return false; • } • };
The triangle compares edges • struct PrevFace • { • bool operator()(TFace* first, TFace* second) • { • for (int i=0; i<3; i++) • { • if (prevEdge(first->edges[i], second->edges[i])) • { • return true; • } • if (prevEdge(second->edges[i], first->edges[i])) • { • return false; • } • } • return false; • } • };