0xCUB3 / Modified-Dots-and-Boxes

Wheel Graph Dots and Boxes: A strategic Python Pygame challenge adapted from the classic game

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Modified Dots and Boxes

A strategic turn-based game for two players, implemented with Pygame. Players take turns selecting an edge on a wheel graph. Once all edges around a vertex are selected, it becomes isolated and is owned by the player. The player with the most vertices when all edges are selected wins the game.

In the algorithm file, a recursive method is used to determine outcomes for various classes of graphs. A summary of these findings can be found below.

Features

  • Dynamic generation of the wheel graph based on the number of spokes.
  • Colorful interactive GUI with undo and redo functionalities.
  • Simple and intuitive gameplay ideal for quick sessions and strategy enthusiasts.

Discoveries

Complete Graphs

In a complete graph, player 1 wins for 1 & 2 (mod 4) and player 2 wins for 3 & 4 (mod 4) vertices. (Proof TBD) K_5 Example of the complete graph K_5

Number of Vertices Winner Score
1 N/A N/A
2 P1 (2 - 0)
3 P2 (0 - 3)
4 P2 (0 - 4)
5 P1 (4 - 1)
6 P1 (5 - 1)
7 P2 (2 - 5)
8 P2 (2 - 6)
9 P1 (7 - 2)
10 P1 (7 - 3)

Wheel Graphs

A wheel graph is one where there is a center vertex connected to n outer vertices which are all connected via a cycle, analogous to spokes in a wheel. In this graph family, player 2 wins with an even number of spokes and player 1 wins with an odd number of spokes. (Proof TBD) Wheel graph with 5 spokes Example of the wheel graph with 5 spokes

Number of Spokes Winner Score
1 N/A N/A
2 N/A N/A
3 P2 (0 - 4)
4 P1 (4 - 1)
5 P2 (2 - 4)
6 P1 (5 - 2)
7 P2 (2 - 6)
8 P1 (5 - 4)
9 P2 (4 - 6)
10 P1 (6 - 5)
11 P2 (5 - 7)
12 P1 (7 - 6)
  • Observation: A pattern seems to appear at 8 spokes...

Hanging Stars

The next discovery came in a graph family that we defined as hanging stars. These graphs are similar to star graphs, but each outer vertex has an extra edge connecting to itself. In this graph family, player 1 wins for odd spokes and player 2 wins for even spokes. (Proven) Hanging Tree with 5 spokes Example of a hanging tree with 5 spokes

Number of Spokes Winner Score
1 P1 (2 - 0)
2 P2 (0 - 3)
3 P1 (3 - 1)
4 P2 (1 - 4)
5 P1 (4 - 2)
6 P2 (2 - 5)
7 P1 (5 - 3)
8 P2 (3 - 6)
9 P1 (6 - 4)
10 P2 (4 - 7)
11 P1 (7 - 5)
12 P2 (5 - 8)

Afterward, we were interested if the same pattern continued when extra vertices were added to certain "spokes" of hanging trees. We found this to be the case. (Proven) Extended Hanging Star Example of a hanging tree with 5 spokes and 2 extra vertices on one of the spokes

In a "normal" hanging star with 2 outer loops, player 2 always wins, but they win by 2 for odd spokes and they win by 3 for even spokes. (Proven)

Number of Spokes Winner Score
1 Tie (1 - 1)
2 P2 (1 - 2)
3 P2 (1 - 3)
4 P2 (1 - 4)
5 P2 (2 - 4)
6 P2 (2 - 5)
7 P2 (3 - 5)
8 P2 (3 - 6)
9 P2 (4 - 6)
10 P2 (4 - 7)
11 P2 (5 - 7)
12 P2 (5 - 8)

In a hanging star with 1 spokes and n outer loops, player 1 wins for odd loops, and it is a tie for even loops. (Proven)

Number of Loops Winner Score
1 P1 (2 - 0)
2 Tie (1 - 1)
3 P1 (2 - 0)
4 Tie (1 - 1)
5 P1 (2 - 0)
...and so on

In a hanging star with 2 spokes and n outer loops, player 2 always wins. (Proven)

Number of Loops Winner Score
1 P2 (0 - 3)
2 P2 (1 - 2)
3 P2 (1 - 2)
4 P2 (1 - 2)
5 P2 (1 - 2)
...and so on

For more complicated hanging star revelations, please see hanging_trees.md

Petersen graph

The Petersen graph is a common graph used to prove or disprove a lot of graph theory-related theorems. Player 1 wins on Petersen with a score of (9 - 1) (Proof TBD).

Friendship graphs

A friendship graph is one with a center vertex and n triangles around it. Player 1 wins by 1 for odd n and player 2 wins by 3 for even n (Proof TBD). F_3

Number of Triangles Winner Score
1 P2 (0 - 3)
2 P1 (3 - 2)
3 P2 (2 - 5)
4 P1 (5 - 4)
5 P2 (4 - 7)
6 P1 (7 - 6)
7 P2 (6 - 9)
8 P1 (9 - 8)

But now I hear you ask, what about friendship graphs with squares instead of triangles? You asked that, right? RIGHT?????

Number of Squares Winner Score
1 P2 (0 - 4)
2 P2 (2 - 5)
3 P2 (4 - 6)
4 P2 (6 - 7)
5 P2 (7 - 9)
6 P2 (9 - 10)
7 P2 (10 - 12)
8 P2 (12 - 13)

Balloon Path graphs

The naming is getting a bit vain, but balloon paths and ferris wheel graphs have potential to help us solve wheels. For balloon paths, P1 wins for odd n and there is a tie for even n (Proven) BP_5

Number of Vertices Winner Score
3 P1 (3 - 0)
4 Tie (2 - 2)
5 P1 (3 - 2)
6 Tie (3 - 3)
7 P1 (5 - 2)
8 Tie (4 - 4)
9 P1 (5 - 4)
10 Tie (5 - 5)
11 P1 (6 - 5)
12 Tie (6 - 6)
13 P1 (7 - 6)

Ferris Wheel graphs

Similar to a balloon path but with the nodes connected in a cycle. BP_10

Number of Vertices Winner Score
3 P2 (0 - 3)
4 P1 (3 - 1)
5 P2 (2 - 3)
6 P1 (4 - 2)
7 P2 (2 - 5)
8 Tie (4 - 4)
9 P2 (4 - 5)
10 Tie (5 - 5)
11 P2 (5 - 6)

Hypercubes

An interesting thing to look at. HC_3

Number of Dimensions Winner Score
1 P1 (2 - 0)
2 P2 (0 - 4)
3 P2 (2 - 6)
4 P2 (6 - 10)

Double N-gons

DN_3

Size of N-gon Winner Score
3 P1 (5 - 1)
4 P2 (2 - 6)
5 P1 (8 - 2)
6 P2 (4 - 8)
7 P1 (8 - 6)
8 P2 (7 - 9)
9 Tie (9 - 9)
10 P2 (9 - 11)

How to Play

  1. Enter the desired number of spokes at the start screen.
  2. Players take turns to click on the active (brighter color) edges of the graph to select them.
  3. Try to isolate vertices by selecting all edges around them. They will change color to indicate your ownership.
  4. If you isolate a vertex, you get another turn.
  5. Use the 'Undo' and 'Redo' buttons as necessary.
  6. The game ends when all edges are selected, and the player with the most vertices wins.

Gameplay Example

CleanShot.202024-01-11.20at.2015.24.28.mp4

License

Distributed under the MIT License. See LICENSE for more information.

About

Wheel Graph Dots and Boxes: A strategic Python Pygame challenge adapted from the classic game

License:MIT License


Languages

Language:Python 71.0%Language:Rust 29.0%