You may have heard of the game GraphWar. It pits you against one or more components, giving you spaceships as lives and asteroids to avoid on a Cartesian plane.
You must then write mathematical functions which shoot beams from your ships, to hopefully strike and destroy your opponents ships.
In this project, I produced a Python script which automatically create the perfect function to win in one turn.

All the code produced can be downloaded here:

Download ZIP File


Explaining the algorithm

The algorithm works by your clicking on points on your screen sequentially, from left to right. Then the program produces a function which draws straight lines between those points. This is done using a combination of absolute value functions, the maths of which is straight forward enough to not write explicitly.

In the graphWarMind.py file, all functions are defined. They are then called with the graphWarMain.py file.
Before destroying the enemies, one must calibrate their screen with the calibrate() function, which stores important location information in the calibc.pk and calibd.pk files. Following this, the fire() command allows you to identify and destroy your opponents!