Develop a simple game consisting of a rectangular grid (of size height x width) where each cell has a random value between 0 and n.

Python programming and analysis.

Test your Python skills and capacity to plan a statistical analysis. You need to develop a simple game consisting of a rectangular grid (of size height x width) where each cell has a random value between 0 and n.

An agent starts at the upper-left corner of the grid and must reach the lower-right corner of the grid as fast as possible. Accordingly, the task consists of finding the shortest path.
Start position
End position

There are two game modes:
The time spent on a cell is the number on this cell
The time spent on a cell is the absolute of the difference between the previous cell the agent was on and the current cell it is on

The task is divided in the following parts:

Implementation of the game. Implement the game in a structured and flexible way to allow the selection of game modes and parameters. Build a method to build and visualize the grid filled with random numbers. Build a method to visualise a path. (30%)

Develop your own heuristic algorithm. Identify simple criteria and strategies to find short paths. This algorithm should be taken as a baseline. It does not have to be optimized to perform fast or well, but should be better than random movements. Implement this part without searching for standard algorithms to find short paths. (10%)

Implement the Dijkstra’s algorithm to find the shortest path between two points. There are many refined versions of this algorithm that you can find in the literature. Implement a simple version close to the original algorithm, using a simple priority queue.

Write your own code as much as possible and provide detailed comments of each step. Relying on more sophisticated implementations available online is not the objective of the task, but to be able to write your own code. (30%)

Plan and implement a statistical analysis to characterize the length of the shortest path in dependence of several parameters of the grid and comparing the two game modes. Relevant parameters are size of the grid, distribution from which cell numbers are generated, etc. (30%)

You can use the built-in libraries of python (math, random, …), numpy, and matplotlib.

An agent can move from cell to cell (U, D, L, R).
Each time it enters a cell, it spends some time in this cell.

2 game modes:
The number on the cell indicates time spent on the cell
The absolute difference between origin cell and destination cell indicates the time spent on the cell.

The goal is to move from top-left to bottom-right position as fast as possible.

Game: creating the environment:
Implementation of the game (30%)

Think which is the optimal architecture for your code:                                               Subclasses for the 2 modes of the game?
If so, which methods are subclass specific, or not? Explain and justify your selection.

Create attributes and methods to:
Generate any rectangular size of the grid
Populate the cells with random numbers
Select specific distributions of the random numbers
Visualize the game
Compute and visualize the cost of specific paths

Game: finding the shortest path:
Propose a naïve approach (not too naïve) (10%):
Look for neighbours
Build a tree

Explain your heuristics. , think these simple criteria and strategies before learning the Dijkstra algorithm

Implement Dijkstra’s algorithm to find the shortest path between 2 points (30%)

How the algorithm maps to the game setting? How it varies for the two game modes?

Do not copy/paste an implementation from online code. Comment the code so that it is clear that you understand what does what.

Use a version of the algorithm close to the original one

Game: analyze factors affecting the shortest path:

Design and implement an analysis of factors that affect the length of the shortest path.

It does not have to be a complete list of factors. Just think of interesting factors that you can systematically study how they affect the length:

Obviously, the size of the grid.
Distribution of the random numbers: e.g Uniform distribution between 0 and N.
Different types of distributions:
Discrete: Poisson, Negative binomial
Continuous: Gamma, log-normal, etc.
How the shortest paths depend on the parameters of these distributions
Characterize the mean and variance of the shortest path
Think some other factor for analysis you come up with

Develop a simple game consisting of a rectangular grid (of size height x width) where each cell has a random value between 0 and n.
Scroll to top