# [WSS17] Pure Functional Games

GROUPS:

## Introduction

For the 2017 Wolfram Summer School, my project was to design and implement a game based on functions. The intention of the project was to design a game that would be easy for new programmers to understand and strategically deep enough for experienced programmers to remain entertained. Originally, the title "functional scrabble" was used to describe the project as scrabble is a well known game that requires using basic components to build more complex structures. Scrabble also features a random element where players draw letters from the bag and must use creativity and skill to work with what they have in order to accomplish their goal. Scrabble is also a multiplayer game where there is no direct way to attack the opponent. However, players can interfere indirectly with one another by placing words on the board at locations that block their opponent.

## Design

First I began drawing parallels between the elements of scrabble, and the game I wanted to create. I decided that letters would correspond to function heads, and the board would be represented by a matrix of elements. Players would draw function heads from a virtual bag and use them to effect the board in some way. The game board underwent several revisions during this project, starting out rather complicated but eventually becoming simple.

### Game Board

Originally, I designed the board to be a matrix of elements where each element was an arbitrary argument to a function or an expression. My intent was to allow players to place functions from their "hand" on the board with the constraint that the function placed had to be a valid expression when applied to the argument. However, this strategy soon revealed a problem, which I continuously faced during development of this project. Functions in Mathematica take many different arguments and generate many different outputs, and, it is often the case, an invalid expression will assume symbolic form; for example, the following expression returns the symbolic form of itself:

Sin[Rectangle[]]


This behaviour may be desirable; however, for my purposes, it means each function included in the game requires manually entered meta-data that can be used to verify the validity of the input and output from expressions. To work around this issue, I redesigned the board. The second version of the board included only lists and integers. The concept was to have players attempt to remove the lists by employing functions like "Fold" in order to obtain a matrix of only integers which when summed would give their score. However, lists could get arbitrary large and gameplay slowed due to players having to closely examine a complex matrix in order to make a smart move. The final version of the board removed the lists and had success by using only integers as matrix elements. Additionally, integers in the matrix are always mod ten to prevent them from getting too large. An image of the final board is shown below. Eights are highlighted as players receive one point for each eight on their board:

### Game Functions and Interface

Once the board was finished, functions were designed to allow players to manipulate the board. Originally, players had to enter strictly formatted code in order to select which function they wanted to apply to the matrix. However, buttons were later introduced to allow players to select a function by clicking on it which increased the pace of the game and helped players fully realize all the actions available to them.

In order to give players more flexibility during their turn, some pure functions take a "row" or "column" argument. The value of this argument is controlled by a set of selector widgets, shown below. Players can choose to apply these functions to the most strategically beneficial location on the board.

## Strategy

The resulting game has some interesting strategic properties. For example, some functions apply a single effect over the entire board; one such function counts all the even numbers on the board and sets every number to that number. If a player realizes they have eight even numbers on their board, they can turn their entire board into eights in one move, and win the game. If a player doesn't have the correct number of even numbers, they can attempt to get closer to the desired number by using row and column functions. Yet, the other player can interfere indirectly with this strategy by using functions during their turn which would be beneficial to their opponent. Thus, by keeping the board simple and making it intuitive for players to move, it was possible to create a game with some strategy and depth that was relatively accessible for beginners.

I'll also mention that as part of this project, I implemented two other games which explored cellular automata in a visual and interactive manner. These games are briefly discussed below.

### Cellular Surfer

Players "surf" over an animated grid generated by cellular automata by adjusting controls which modify the behaviour of the player, red square, in order to collect gems, blue squares. The intent of the game is to demonstrate the behaviour that arises when CA and Turing machines interact.

### Bomber-man Clone

This was a light weight clone of a game called Bomber-man that uses Rule 30 to generate an interesting playing field. Players can move around in the grid and place bombs which destroy the environment upon detonation. The goal is to catch the other player in the path of a detonation.

## Conclusions

My conclusions from undertaking this project are that function-based games of a moderate entertainment value can be constructed by allowing players some finite choice over what function to use on a given turn. However, a function-based game could be much more entertaining if a robust system was designed to allow players to directly enter code in order to effect game state. However, such a system would have to prevent players from entering code that would break the game, and the game objective would have to be stated very clearly, so players could understand what code was expected. I believe the optimal version of a function based game would give players nearly all the creative freedom programming languages allow for while maintaining the ability to enforce a set of game rules. There is also value in interactive visualization style games as these types of interaction have the potential to inspire players and allow them to view systems like CA and Turing machines from a different perspective.

View this project on Github

Attachments: