Elixir Quiz

Weekly programming problems to help you learn Elixir

Problems

2048 Game

Welcome to the seventeenth edition of Elixir Quiz. This week we will be creating our own version of the game, 2048.

The 2048 Game

2048 is a game that was created in 2014 by developer Gabriele Cirulli, and is reminiscent of Sliding Puzzle games.

The game is played on a 4x4 grid, which is initially empty except for 2 randomly selected tiles, which have either a 2 or a 4 value in it. Players play the game by pushing all of the tiles in a specified direction; up, down, left or right.

When tiles with matching values come into contact, they merge into one (the one furthest in the direction that was specified). The value of this new tile is the combined value of the tiles. After each turn, a new tile (either a 2 or a 4) is generated in one of the free spaces.

The player wins by creating a tile with the value 2048, and loses if the board is filled with tiles and no more moves are available.

The problem

Create the game of 2048. You can simply use the command line for output, or build a web application if you’re feeling ambitious.

How do I enter?

The 2048 quiz runs from Saturday December 13th 2014 until Friday December 19th, 2014.

To enter, just complete the problem and post a link to the code on Twitter, and mention @elixir_quiz. As always, you can host your code anywhere (like Github Gists).

Example solutions

After the quiz period ends on December 19th, I will update this section and talk about some interesting solutions that were posted on Twitter.


Tic Tac Toe part 3: Multiplayer

Welcome to the sixteenth edition of Elixir Quiz. This week we will be finialising our multiplayer tic tac toe game.

Last week we built made it possible for our application to handle multiple games at once. This week we’ll extend that to allow many human players to play.

Communication

There are several ways that we can build our networking system.

We could build a TCP server or use Phoenix websockets

Taking ideas from the talk on game servers at ElixirConf 2014, it may be a good idea to have your networking code in a separate OTP application to the game code.

The problem

Continuing on from last week, create a networking system that will allow multiple human players to connect to and play your game at once.

How do I enter?

Part 3 of the Tic Tac Toe quiz runs from Saturday December 6th 2014 until Friday December 12th, 2014.

To enter, just complete the problem and post a link to the code on Twitter, and mention @elixir_quiz. As always, you can host your code anywhere (like Github Gists), or post your solution directly into the subreddit post.

Example solutions

After the quiz period ends on December 12th, I will update this section and talk about some interesting solutions that were posted on Twitter.


Tic Tac Toe part 2: The Application

Welcome to the fifteenth edition of Elixir Quiz. This week we will be continuing our multi-week Tic Tac Toe project.

Last week we built a game that could be played by a human and a computer player. This week we will be continuing that game, and making it possible for a game server to manage several games at once.

Supervision Trees

The official Erlang documentation describes supervisors as:

a process which supervises other processes called child processes. A child process can either be another supervisor or a worker process.

Supervisors are used to build an hierarchical process structure called a supervision tree, a nice way to structure a fault tolerant application.

For more information, see the OTP design principles document.

The problem

Create an OTP application that manages several games of tic-tac-toe. The games should be monitored by a supervisor, and recover if they crash for any reason.

Next week we’ll create an interface for the game so that people can connect to it and play against other people.

Like last week, a good reference on how a multiplayer game can hang together in an OTP application, check out Martin Schurrer’s talk at ElixirConf 2014.

How do I enter?

Part 2 of the Tic Tac Toe quiz runs from Saturday November 29th 2014 until Friday December 5th, 2014.

To enter, just complete the problem and post a link to the code on Twitter, and mention @elixir_quiz. As always, you can host your code anywhere (like Github Gists), or post your solution directly into the subreddit post.

Example solutions

After the quiz period ends on December 5th, I will update this section and talk about some interesting solutions that were posted on Twitter.