Description


Line War is a remake of a classic small console game made entirely adhering to functional programming principles using C# and LanguageExt.

The goal of the game is to send units from your castle at one end of the line to destroy the opponents castle on the other end. Units will fight enemy units when in range, and are bought with the currency earned each turn and when regained after a unit dies in combat.

There are three unit types:

  • A warrior that is strong but short range
  • A ranger with middling strength but can engage at range
  • A cleric that is weak with a high range but can heal allies

Turns have a purchase phase where one unit purchase is allowed, then a resolve phase where all units do their action in order of closest to furthest from the enemy castle. Each unit has a hireachry of preferred actions according to what is currently possible that goes as such:

  • Heal an ally (for the cleric only)
  • Attack the weakest enemy unit in range
  • Move forward into unblocked space
  • Swap spaces with a weaker allied unit one space ahead

Line War Gameplay

Download


The project can be downloaded here:

Goals and Achievements


Functional Programming

This was created as an exercise in functional programming and it’s application within video games. All functions are either made pure where possible, or marked as effectful where not. Data structures are immutable and everything is type safe. Code that can fail will return either the output wrapped in Option, or wrapped in Either with an error code as the second data type.

For unit testing and greater function isolation, a runtime environment is injected into effectful functions. A few unit tests were created along with this both to ensure the concept and execution were fully understood, as well as for their own aid in testing the relevant code.

Match Exacting Rules

This game was created using a strict rule-set made by Artūras Šlajus. This rule set is useful for testing many aspects of functional programming, as well as problem solving how to apply functional programming to a given scenario.

An example of this would be the inclusion of an AI player, which I have implemented in two types - fast and slow, which will re-render the scene differently for either speed of play or clarity of moves taken. This forced proper separation of player actions from turn logic and scene rendering.

Project Details


Role: Programmer

Group Size: 1

Code Language: C#/LanguageExt

Project Purpose: Education