All work

ARTIFICIALLY INTELLIGENT GAME / REINFORCEMENT LEARNING

A small grid.
A learning agent.

Exploring how an agent can choose its next move through rewards, a structured view of the board and a neural Q-function.

REPOSITORY PUBLISHED
2019
MY WORK
Environment representation, reward design & neural Q-function
PROJECT TYPE
Early machine-learning exploration
PUBLIC ARCHIVE
Design diagrams & source excerpts
8 × 8GRID ENVIRONMENT
256STATE INPUT VALUES
4ACTION VALUES
3HIDDEN LAYERS

Based on the public README and Python source · reviewed 25 September 2026.

01 / THE IDEA

Learning a route,
one decision at a time.

This project explores Q-learning through a small grid-world game. The agent has to reach a goal while avoiding a pit and navigating around a wall. The central idea is to learn how valuable each move is from the state of the board and the reward that follows.

I used a neural network to represent the Q-function. It takes the board as input and estimates four action values, turning the problem into a connection between state representation, reward design and decision-making.

A learning agent, in motionThe original README animation illustrates a 4 × 4 grid. The Python project implements an 8 × 8 environment; this is a concept illustration, not a recorded training run. Open the original GIF ↗
PythonNumPyKerasQ-learning

02 / THE ENVIRONMENT

A board the network
can read.

The implemented state is an 8 × 8 × 4 NumPy array. Each channel records a different object: goal, pit, wall or player. Flattening that array gives the network 256 input values.

The supplied code starts the player at row 0, column 1, places the pit at (1, 1), the wall at (2, 2) and the goal at (7, 7). A separate display function converts the internal representation into a readable grid.

Four stacked grids representing player, wall, pit and goal positions.
Representing the board in separate channelsOriginal illustration from the project README. The code uses an 8 × 8 board with four channels.

Rewards give each move a consequence.

+10REACH THE GOAL
−10ENTER THE PIT
−1AN ORDINARY STEP

The step penalty encourages shorter routes, while the terminal rewards distinguish success from failure. Those choices make reward design a central part of the learning problem.

03 / THE ENGINEERING

One state.
Four action values.

The Keras model uses three dense hidden layers with ReLU activations and 20% dropout, followed by a linear output layer. The output values can therefore represent both positive and negative expected rewards.

256INPUT VALUES
512HIDDEN 1
256HIDDEN 2
128HIDDEN 3
4ACTION VALUES

The model is configured with mean squared error and RMSprop. The test routine predicts the four values, selects the largest with argmax, and calls the movement function before checking the new reward. It also includes a move limit to stop an unsuccessful run.

Concept diagram passing a game state through an input vector and hidden layers to four directional Q-values.
The state-to-action sequenceOriginal README concept diagram. Its 64-value input illustrates a smaller board; the published Python code uses 256 input values.
Original neural-network diagram with layer widths marked 512, 256 and 128, ending in four directional outputs.
The original network sketchFrom the README’s detailed design. The sketch labels 512 as the input; the code defines a 256-value input followed by a 512-unit hidden layer.

The original figures are retained as published. The architecture described here follows the Python implementation where their dimensions differ.

04 / WHAT THE REPOSITORY SHOWS

The design and
the implementation excerpts.

The archive contains the grid and reward functions, the neural-network definition, and a greedy test routine in Q_NN_2.01.py. A second file loads the saved model and repeats the environment setup.

The main file explicitly identifies itself as a partial source sample. The movement function, full training loop and trained model are not included. The README describes goal-reaching behaviour, but the archive does not provide the runs needed to reproduce or measure shortest-path performance.

05 / LOOKING BACK

Small environments make
the decisions visible.

This project connects three practical parts of reinforcement learning: how a state is encoded, what a reward means, and how the model’s output becomes an action. A simple grid makes those decisions easier to inspect.

A fuller evaluation would compare the learned policy with the shortest valid route, report success rates and path lengths across repeated runs, and test different starting positions. Publishing the complete training setup and saved weights would make those comparisons reproducible.

The useful question is how the policy behaves.

A network definition explains the model. Repeated runs, a baseline and a complete environment establish whether its decisions achieve the intended goal.

NEXT PROJECT

Botnet detection

↗