Skip to content

Advanced Examples

Shane McLean edited this page Oct 13, 2017 · 5 revisions

This section will contain the three advanced examples.

Getting started

The projecs use the nuget packages. Please update the dotSpace libraries to the latest version. Please note that the compiled versions might not run using mono, and running on Mac or Linux might require additional setup (See below).

Mac / Linux environment requirements

The terminal window size should be set to a minimum of 80 columns and 24 rows.


Custom Tuples

While the default Tuple class is versatile, it does not necessarily promote understanding of the domain its being used under. Developing more advanced programs than illustrated by the provided examples in sections Basic Examples and Networked Examples, it often usefull to create domain objects that relate to the domain more clearly. In dotSpace, it is possible to create custom Tuple's that allows one to wrap the required properties of a tuple as domain properties. Please see section ITupleFactory for an example.


Pong 2.0

alttext Pong 2.0 is a deriviation of the original PONG. The game only implements a simple AI that plays against itself, leaving you to implement a playercontroller. The rules are simple:

  • One point is awarded for getting the pong behind the opponent's pad.
  • The pong will change direction when hitting a surface.
  • When changing direction, the outbound angle is the inverse of the inbound angle.
  • Upon changing direction of the pong, a small random variation will be added.

The game can be run as either a local game or as a networked play with two opponents.

Syntax

The local version is found here.

  • Using .NET type the following in the command line: LocalPong.exe.
  • Using Mono type the following in the command line: mono LocalPongs.exe.

The networked version consists of a client found here, and a server found here.

  • Using .NET type the following in the command line: PongPlayer.exe <param> or PongServer.exe.
  • Using Mono type the following in the command line: mono PongPlayer.exe <param> or mono PongServer.exe


where <param> is either '1' or '2'.

Please note, that mono might have problems running this program.


Running the program:

LocalPong.exe

will show a similar view of the following:

alttext The red o represent the pong, while the green | represent the player pad.

Domain objects

The program(s) uses a class library Pong containing multiple classes:

Remarks

While the local version run both the visual presentation, the execution of the individual players and the pong, the networked version does not. In the networked version, the server is only responsible for the pong controller, while the clients both display the visual presentation and govern the AI player.


LifeForms

alttext Lifeforms is a small evolution game, based on the concept of John Conway's Game of Life. The concept is however expanded as each lifeform carries four genes, Life, Visual Range, Maximum number of children, and Speed that allows its offspring to evolve when mating. The rules are simple:

  • Gather food until a sufficient amount is reached, then find a mate.
  • A lifeform is only a valid mate if its not directly related.
  • A lifeform can only see other lifeforms and food within the Visual Range.
  • For every action consume one food. If all food has been consumed, then reduce Life by 1.
  • When Life is 0, the lifeform dies.
  • If no mate or food is within the Visual Range then roam randomly.
  • In order to eat food, the lifeform must be within a distance of 1.
  • In order to mate with another lifeform B, the lifeform A must be within a distance of 1 with B.
  • When mating with another lifeform, the offspring will derrive its genes from the parents paired with a mutation. This mutation can be either positive or negative.
  • A lifeform may only reproduce the number of times specified by Maximum number of children.

The game itself can be run as a local or distributed application.

Syntax

The local version is found here.

  • Using .NET type the following in the command line: LocalLifeforms.exe.
  • Using Mono type the following in the command line: mono LocalLifeforms.exe.

The networked version consists of a client found here, and a server found here.

  • Using .NET type the following in the command line: LifeformsClient.exe or LifeformsServer.exe.
  • Using Mono type the following in the command line: mono LifeformsClient.exe or mono LifeformsServer.exe.

Please note, that mono might have problems running this program.


Running the program:

LocalLifeforms.exe

will show a similar view of the following:

alttext The purple ¤ represent a lifeform, while the green @ represent food.

Domain objects

The program(s) uses a class library Lifeforms containing multiple classes:

Remarks

While the local version run both the visual presentation and the execution of the individual lifeforms, the networked version does not. In the networked version, the server is responsible for the visual presentation while the clients merely govern the underlying lifeforms AI.