Giter Club home page Giter Club logo

codingame-ai's Introduction

Using a Neural Network in a Bot Game on Codingame

After competing in multiple challenges on Codingame with bots using simple heuristics, it's time for something new: the goal is to learn and advance to the Gold league in an upcoming challenge.

Important

"Codingame doesn't have NN specific libraries. For Codingame people mostly train locally using NN libraries, and just copy the learned weights and implement the forward propagation themselves in their language." - jacek from Codingame

git clone https://github.com/tonigineer/nn-codingame.git ~/journey && cd ~/journey

# Optional, but recommended
python -m venv .venv
source .venv/bin/activate

pip install -r requirements.txt

1️⃣ Check feasibility with Python

Using the MNIST dataset to train a simple Neural Network with TensorFlow and then transferring the parameters to a Neural Network implemented from scratch.

python feasibility/example_ann_tf.py

...
Epoch 10/10
1875/1875 ━━━━━━━━━━━━━━━━━━━━ 1s 531us/step - accuracy: 0.9960 - loss: 0.0140
313/313 - 0s - 459us/step - accuracy: 0.9794 - loss: 0.0787

The weights and biases have been exported. The ANN, implemented in example_ann_scratch.py, also includes backpropagation and gradient descent, which are not necessary for this task.

python feasibility/ann_with_tf_param.py

...
Accuracy with test data: 97.94%

✔️ Both evaluations yield the same accuracy on the test data from mnist = tf.keras.datasets.mnist. Therefore, transferring weights and biases to a custom implementation from scratch proves to be effective.

Lessons learned for the next parts:

  • Adapt sizes to TensorFlow conventions from the outset
  • Implement a dynamic architecture based on weights and biases

2️⃣ Implemented Neural Network in Rust

Todo

Keep in mind

  • 100k limit on characters from Codingame
  • plain text export of weights to use on Codingame
  • Reduce size of numbers

codingame-ai's People

Contributors

tonigineer avatar

Watchers

Kostas Georgiou avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.