Nanothrones
Welcome to Nano Thrones
The Rules
The game takes place on a board of triangular tiles. Each player has a color and moves from tile to neighboring tile. Every time a player lands on a new tile, that tile becomes the color of the player. The objective is to keep as many tiles set to your color for as much time as possible. However, there are restrictions on which tiles you can move to — you can only move to adjacent unblocked tiles. If you are ever left without a place to move, you will be removed from the board for a finite amount of time.
My Role
The Artist: Control the color displayed by each tile depending on the player, and on the state of the game, and communicate the visual representation of the game to the Nanoleaf panels using their open API.
I worked with two other students; one took the role of the manager (implementing the rules of the game) and the other took the role of the strategist (choosing the next move).
The Tools
Python, JSON, Nanoleaf API
The Process
Defining the Code Architecture
In order to successfully execute the game, all three components needed to communicate with each other. As a result, our first step was illustrating the architecture of the game to determine what information we needed to share with each other.
Identifying and Extracting the Key Elements
I received the game state from the manager, which included the current position of each player as well as who was on each panel/tile, and for how long. The game state was structured as follows:
game_state = {'current_position': {'player1': position, 'player2': position, 'player3': position, ...}, 'panel': {panel_id: {'color': 'player', 'age': num}, {panel_id2: {'color': 'player', 'age': num}, ...}}
Within the artist component, I created a dictionary of RGB values for each player. Next, I went through the game state to create a list of panel ids. Then, I went through the game state using the panel id number to construct the list of bytes, based on whether a panel was occupied, and if so, the player’s RGB value. Finally, I sent the list of bytes to the Nanoleaf panels.
Showing Game States with Color
I adjusted the color of each panel based on the panel’s age. Per the rules, tiles with age 0 indicate current position. These tiles, along with those that are aged 1 or 2 are considered blocked. Tiles of age 3 and higher are unblocked, but still show the color of the player. The RGB values of each color were adjusted using the following formula:
val = round(val + ((255 - val) * .25))
To determine if a player is ejected, I stored the previous game state as an instance variable and compared it with the current game state. A player was considered ejected if their current position changed from an integer to a NoneType. To indicate a player’s ejection, I turned all panels into their color.
Connecting to the Nanoleaf Panels
For the final deliverable, our code came to life on the Nanoleaf Panels, as shown on the video below.
Concluding Remarks
This project highlighted the intersection of data and design, illuminating a wide field of new applications of Python. I am curious to explore the field of physical computing further, examining how we can share data in engaging and tangible ways.
Note: The instructor has asked that we do not publicly post our final code, as to preserve the experience for future students, however it can be shared upon request.