Skip to content
PeterJ68663Public

About

Code for playing Legends of Code and Magic, and for automatically running games via CodeInGame for ML training.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Legends of Code and Magic

Repo containing code for playing LOCAM on the CodeInGame platform, as well as automated data-gathering to enable training machine learning models.

locam.py

This script actually plays LOCAM. All code must exist in a single script due to the constraints of the CodeinGame platform.

Game Algorithm:

On each of my turns, the code works out a list of possible ending states for the borad. A neural network is used to evaluate the quality of each board state and the set of plays that produces the highest-scoring board state are executed.

TODO: This times-out in games where board states get sufficiently large. Implement early-stopping for non-promising branches, or alpha-go style move suggester + state evaluator networks (needs some thought, and probably RL training rather than supervised as environment of each network will evolve during training).

Neural Network Implementation:

The environment in which the code must run on the CodeInGame platform has no machine learning libraries available. Therefore I hard-code the nerual network weights and implement feed-forward using numpy.

The network is trained offline to predict probablilty of winning from a given board-state in a supervised-learning fashion.

Data Recording:

In addition to playing the game, this code prints formatted strings to stdout, which can be extracted from the json game summaries to determine the state of the game at each step.

Get Game Data:

This script submits POST requests to CodeInGame to run games and records the results from the json object returned. This is used to generate data for training the neural network. The POST requests were reversed-engineered by inspecting browser traffic whilst manually submitting games on the site.

To work the script needs some keys and cookies which are stored in secrets.py (not tracked in the repo).

Testing:

saved_games.txt contains the random seeds used to produce historical games which the code has lost, either due to direct bugs or poor play. These can be used as regression tests.

About

Code for playing Legends of Code and Magic, and for automatically running games via CodeInGame for ML training.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages