Menu

1 / 5

A Double DQN agent that plays Snake, written entirely in KingCobra

DEV Community: machinelearning·Divyanshu Sinha·15 days ago
#EVQ8F1cZ
Long article (1057 words) — no AI summary yet.
Reading 0:00
15s threshold

I built a Double DQN agent that learns to play Snake , and every part of it is written in KingCobra , my programming language: the game, the replay buffer, the neural-network training, the HTTP server and a live web dashboard. It uses only KingCobra's standard library ( std.nn , std.http , std.json and std.system ). There is no Python and there are no external dependencies.

Repo: https://github.com/DivyanshuSinha136/KingCobra-Snake-DQN

The dashboard, captured from the real app: the trained agent playing, what it sees and wants, and how it learned.

The result

Score mean 33.1 (best game 50 ) over 100 greedy games on a 10×10 board

Training about 2 minutes on one CPU core

Agent Double DQN, 3-step returns, Huber loss, gradient clipping, soft target updates, optional prioritized replay

Network 19 → 96 → 96 → 3, 11,523 parameters

Reproducible one seed controls everything, and two runs with the same seed give bit-identical models

The model is small on purpose.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.