triango a game of go in triangles

28
TrianGO TrianGO A Game of GO in A Game of GO in Triangles Triangles Qingzhe Huang Qingzhe Huang Comp6711 project demo Comp6711 project demo

Upload: tahir

Post on 18-Jan-2016

38 views

Category:

Documents


0 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: TrianGO A Game of GO in Triangles

TrianGOTrianGOA Game of GO in TrianglesA Game of GO in Triangles

Qingzhe HuangQingzhe Huang

Comp6711 project demoComp6711 project demo

Page 2: TrianGO A Game of GO in Triangles

OutlineOutline

• Brief introduction of game GO as Brief introduction of game GO as motivation of projectmotivation of project

• Introduce algorithm used in projectIntroduce algorithm used in project (nested convex hull, triangulation between (nested convex hull, triangulation between

convex hull, range searching, DFS in game convex hull, range searching, DFS in game board etc.)board etc.)

• Introduce game ruleIntroduce game rule• Playing gamePlaying game• ResourcesResources

Page 3: TrianGO A Game of GO in Triangles

What is GO?What is GO?Go is... an ancient board game which takes simple elements -- line and circle, black and white, 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 stone and wood -- combines them with simple rules and generates subtleties which have enthralled players for millennia. enthralled players for millennia.

Page 4: TrianGO A Game of GO in Triangles

GO is a game for controlsGO is a game for controls

Before the play Black captures After the play

Before the play Black captures three stones After the play

Page 5: TrianGO A Game of GO in Triangles

Why Not GO? Why Not GO?

• GO is too complicated. Theoretically 3GO is too complicated. Theoretically 3361 361

combinations. The best computer combinations. The best computer software player cannot even beat good software player cannot even beat good amateur player.amateur player.

• What if we use triangle as chess board?What if we use triangle as chess board?

Page 6: TrianGO A Game of GO in Triangles

How to draw chess board?How to draw chess board?

• Triangulation by nested convex hull.Triangulation by nested convex hull.

Page 7: TrianGO A Game of GO in Triangles

How to create nested convex How to create nested convex hull?hull?

• How Simple is the algorithm?How Simple is the algorithm?

• while (!inputPointSet.empty())while (!inputPointSet.empty())• {{• createConvexHull(inputPointSet, convexHull);createConvexHull(inputPointSet, convexHull);

• outputConvexHull(convexHull);outputConvexHull(convexHull);• removePoints(inputPointSet, convexHull);removePoints(inputPointSet, convexHull);

• }}

• The time complexity is just O(nlogn) because of sorting of points. The time complexity is just O(nlogn) because of sorting of points. All rests are just linear. All rests are just linear.

Page 8: TrianGO A Game of GO in Triangles

How to triangulate?How to triangulate?

• Zigzag between external and internal convex hull.Zigzag between external and internal convex hull.

Page 9: TrianGO A Game of GO in Triangles

When to terminate?When to terminate?

• Just count the number of vertex in both convex Just count the number of vertex in both convex hull. hull.

Page 10: TrianGO A Game of GO in Triangles

What about degenerated cases?What about degenerated cases?

• The function to determine the sides of vertex The function to determine the sides of vertex WRT line also works when the line degenerates to WRT line also works when the line degenerates to points. points.

• It also works when triangle degenerates to line or It also works when triangle degenerates to line or point.point.

• But we have to take care with no internal convex But we have to take care with no internal convex hull.hull.

Page 11: TrianGO A Game of GO in Triangles

What about the total time What about the total time complexity?complexity?

• The total time complexity is still O(nlogn) because The total time complexity is still O(nlogn) because triangulation is just linear. The following is 10000 points triangulation is just linear. The following is 10000 points and it takes 16 seconds for nested convex hull.and it takes 16 seconds for nested convex hull.

Page 12: TrianGO A Game of GO in Triangles

What about the total time What about the total time complexity?complexity?

• The triangulation is really fast because it is linear. The The triangulation is really fast because it is linear. The following triangulation of 10000vertices only takes about following triangulation of 10000vertices only takes about one second.one second.

Page 13: TrianGO A Game of GO in Triangles

Do we really need DCEL?Do we really need DCEL?

• In the project proposal, I mentioned about In the project proposal, I mentioned about implementing DCEL data structure. However, I implementing DCEL data structure. However, I give it up during project because it is not very give it up during project because it is not very useful for my purpose. useful for my purpose.

• DCEL is ideal for dynamic changing of elements DCEL is ideal for dynamic changing of elements while my chess board only needs searching and it while my chess board only needs searching and it is static.is static.

Page 14: TrianGO A Game of GO in Triangles

The game playingThe game playing• How to check if a point is inside a triangle?How to check if a point is inside a triangle?• A more general way is to count the number of intersections A more general way is to count the number of intersections

between all edges and the cast ray from the point. If the number between all edges and the cast ray from the point. If the number is even, the point is outside polygon. is even, the point is outside polygon.

• My way is just check which side the point is on for each edge. If 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 the sign for all edges are the same, the point is inside the triangle. This is only workable for convex polygons.triangle. This is only workable for convex polygons.

Page 15: TrianGO A Game of GO in Triangles

When the triangle can killWhen the triangle can kill• If red clicks “next” triangle, the neighbour blue triangle will be removed 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 because of all its neighbours are either red or boundary. This can also happen when multiple blue neighbour might be removed.happen when multiple blue neighbour might be removed.

Page 16: TrianGO A Game of GO in Triangles

When the triangle can killWhen the triangle can kill• More complicated case is when the searching might be infinite loop if we 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 don’t keep track our searching path. The right picture is the result when red click the triangle.red click the triangle.

Page 17: TrianGO A Game of GO in Triangles

When the triangle is a deadendWhen the triangle is a deadend

• When the triangle cannot kill, the blue is forbidden to place its triangle in a When the triangle cannot kill, the blue is forbidden to place its triangle in a dead end. dead end.

Page 18: TrianGO A Game of GO in Triangles

When does game end?When does game end?• After every move, the program check if there is any possible move for next 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 player. If no possible move can be made by next player, the program begins count triangles for both players and declare the winner. count triangles for both players and declare the winner.

• Actually the counting is not correct because those empty triangle may be 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 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.best move for red is also labelled. And there is no end.

Page 19: TrianGO A Game of GO in Triangles

Onion TriangulationOnion Triangulation• When I finished this slides, I checked with Google and find out that the When I finished this slides, I checked with Google and find out that the

official name for this algorithm is called Onion Triangulation.official name for this algorithm is called Onion Triangulation.• http://cgm.cs.mcgill.ca/~orm/ontri.htmlhttp://cgm.cs.mcgill.ca/~orm/ontri.html• The region between two nested convex hulls is called an annulus. The region between two nested convex hulls is called an annulus.

Toussaint (1986) presents a simple algorithm for triangulating an Toussaint (1986) presents a simple algorithm for triangulating an annulus, using the Rotating Calipers.annulus, using the Rotating Calipers.

• Their algorithms are essentially same as I did. Only that my way is more Their algorithms are essentially same as I did. Only that my way is more intuitive for understanding. And their way may generate less skinny intuitive for understanding. And their way may generate less skinny triangles.triangles.

Page 20: TrianGO A Game of GO in Triangles

Onion TriangulationOnion Triangulation• Insert the edges of the hulls as edges in the triangulation. Insert the edges of the hulls as edges in the triangulation. • Compute the points with minimum Compute the points with minimum xx coordinate for both coordinate for both PP and and QQ, calling , calling

them them xmin(P)xmin(P) and and xmin(Q)xmin(Q). . • Construct two vertical lines of support (the calipers) at Construct two vertical lines of support (the calipers) at xmin(P)xmin(P) and and

xmin(Q)xmin(Q); call them ; call them LPLP and and LQLQ. . • Insert (Insert (xmin(P)xmin(P), , xmin(Q)xmin(Q)) as an edge in the triangulation. ) as an edge in the triangulation. • The "current" points The "current" points pp and and qq for for LPLP and and LQLQ are are xmin(P)xmin(P) and and xmin(Q)xmin(Q), ,

respectively. respectively. • Rotate the lines clockwise until one coincides with an edge. A new vertex Rotate the lines clockwise until one coincides with an edge. A new vertex

has therefore been "hit" by one of the lines. has therefore been "hit" by one of the lines. – If it belongs to If it belongs to PP (call it (call it p'p'), insert (), insert (p'p', , qq) into the triangulation. ) into the triangulation.

Update the "current" points to Update the "current" points to p'p' and and qq. . – If it belongs to If it belongs to QQ (call it q'), insert ( (call it q'), insert (pp, , q'q') into the triangulation. ) into the triangulation.

Update the "current" points to Update the "current" points to pp and and q'q'. . – In case of parallel edges, both lines of support coincide with edges, In case of parallel edges, both lines of support coincide with edges,

and two new vertices are "hit" (call them and two new vertices are "hit" (call them p'p' and and q'q'). Then, insert (). Then, insert (p'p', , q'q'), and either (), and either (pp, , q'q') or () or (p'p', , qq) into the triangulation. Update the ) into the triangulation. Update the "current" points to "current" points to p'p' and and q'q'..

• Repeat the previous step until the starting minimum points are reached. Repeat the previous step until the starting minimum points are reached.

Page 21: TrianGO A Game of GO in Triangles

Summary of the gameSummary of the game

• I searched Google and find no clue I searched Google and find no clue that anybody connected triangle that anybody connected triangle and game Go together because it is and game Go together because it is too far from each other. Therefore I too far from each other. Therefore I think it is a kind of original idea to think it is a kind of original idea to play chess GO in a kind of reduced play chess GO in a kind of reduced complexity. Maybe we can discover complexity. Maybe we can discover more general principles of GO when more general principles of GO when complexity of game is reduced.complexity of game is reduced.

Page 22: TrianGO A Game of GO in Triangles

Why GO? Why GO? Top Ten Reasons to Play GoTop Ten Reasons to Play Go

• 1. Go is the simplest of all games.1. Go is the simplest of all games.• 2. Go is the most complex of all games.2. Go is the most complex of all games.• 3. Go is the most popular game in the world today.3. Go is the most popular game in the world today.• 4. Go is the oldest game still played in its original 4. Go is the oldest game still played in its original

form.form.• 5. Every game has a winner.5. Every game has a winner.• 6. All players are equal.6. All players are equal.• 7. You always know where you fit in.7. You always know where you fit in.• 8. It's easy to learn from mistakes.8. It's easy to learn from mistakes.• 9. Ancient rituals impart important values.9. Ancient rituals impart important values.• 10. Go is about building, not destroying.10. Go is about building, not destroying.

Page 23: TrianGO A Game of GO in Triangles

Why not STL?Why not STL?

1. STL is efficient. 1. STL is efficient.

2. It is template.2. It is template.

3. It is platform, compiler 3. It is platform, compiler independent.independent.

4. All program know about it and 4. All program know about it and free of bugs.free of bugs.

Page 24: TrianGO A Game of GO in Triangles

The beauty of STLThe beauty of STL

What I need is just fast searching and binary search What I need is just fast searching and binary search tree is ideal for this purpose.tree is ideal for this purpose.

The internal implementation of “set” is a binary The internal implementation of “set” is a binary

search tree.search tree.

template<class Key, class Pred = less<Key>, class A = template<class Key, class Pred = less<Key>, class A = allocator<Key> > class set {…}allocator<Key> > class set {…}

All you need is just the comparison function. As long as All you need is just the comparison function. As long as your comparison function is a strict order, you are done.your comparison function is a strict order, you are done.

Page 25: TrianGO A Game of GO in Triangles

The comparison functionThe comparison function

• The vertex compares its x,y coordinate.The vertex compares its x,y coordinate.• The edge uses vertex comparison for its two The edge uses vertex comparison for its two

vertices.vertices.• The triangle uses edge comparison for its The triangle uses edge comparison for its

three edges.three edges.

• By storing vertices, edges, triangles in By storing vertices, edges, triangles in set<Vertex>, set<Edge>, set<Triangle>, set<Vertex>, set<Edge>, set<Triangle>, we can achieve O(logn) searching efficiency.we can achieve O(logn) searching efficiency.

Page 26: TrianGO A Game of GO in Triangles

The vertex compares x,yThe vertex compares x,y• struct PrevPointstruct PrevPoint• {{• bool operator()(const TPoint& first, const TPoint& second)bool operator()(const TPoint& first, const TPoint& second)• {{• if (first.x==second.x)if (first.x==second.x)• {{• return first.y>second.y;return first.y>second.y;• }}• elseelse• {{• return first.x<second.x;return first.x<second.x;• }}• }}• };};

Page 27: TrianGO A Game of GO in Triangles

The edge compares verticesThe edge compares vertices• struct PrevEdgestruct PrevEdge• {{• bool operator()(TEdge* first, TEdge* second)bool operator()(TEdge* first, TEdge* second)• {{• for (int i=0; i<2; i++)for (int i=0; i<2; i++)• {{• if (prevPoint(first->pairPoint[i], second->pairPoint[i]))if (prevPoint(first->pairPoint[i], second->pairPoint[i]))• {{• return true;return true;• }}• if (prevPoint(second->pairPoint[i], first->pairPoint[i]))if (prevPoint(second->pairPoint[i], first->pairPoint[i]))• {{• return false;return false;• }}• }}• return false;return false;• }}• };};

Page 28: TrianGO A Game of GO in Triangles

The triangle compares edgesThe triangle compares edges• struct PrevFacestruct PrevFace• {{• bool operator()(TFace* first, TFace* second)bool operator()(TFace* first, TFace* second)• {{• for (int i=0; i<3; i++)for (int i=0; i<3; i++)• {{• if (prevEdge(first->edges[i], second->edges[i]))if (prevEdge(first->edges[i], second->edges[i]))• {{• return true;return true;• }}• if (prevEdge(second->edges[i], first->edges[i]))if (prevEdge(second->edges[i], first->edges[i]))• {{• return false;return false;• }}• }}• return false;return false;• }}• };};