Alexander Martinez-Marchese's Home Page

Recursive C program

This program is a part of bigger program that was an assignment for a C programming course. This part of the program is supposed to play a game of Zig Zag by itself. Although there are more optimal ways of writing this program I though I’ll apply recursion to write the program and this is what I came up with: program.c.

One advantage of this program is that it can be smaller than other programs that do not use recursion. The program basically works by starting a function in a cell and then making more functions that move to all adjacent cells. The functions 'die' if they are not in an empty space or if they reached a cell with the same value as the original one. Otherwise they keep 'replicating'. The functions carry information (the amount of replications) from previous functions and this number is used to determine the distance from two cells of the same type. Every time a cell reaches a cell of the same value the number of replications is 'reported' and the highest reported value is used to decide which two cells can be deleted while yielding the most points.

Here’s a sample board: board.txt.