2026 · BASIC · Z80

Artificial Intelligence for the Z80

Understand artificial intelligence by programming it from scratch in BASIC. A practical journey through algorithms, data and neural networks on 8-bit computers.

12 chaptersTwo editions: Spanish / English
Inteligencia Artificial para el Z80Artificial Intelligence for the Z80
THE BOOK

Understanding AI, one program at a time

What happens when we bring the foundations of artificial intelligence to an 8-bit machine? This book takes a learning-by-building approach: write the algorithms, observe their results and understand the decisions behind each program. BASIC turns ideas into instructions that can be followed, changed and run on a Spectrum, a Spectrum Next or an emulator.

The journey begins with AI history and a practical question: how to make the most of a computer with limited memory and speed. Comparing sorting algorithms and measuring their execution times prepares the ground for expert systems, an ELIZA-inspired chatbot and a tic-tac-toe player using Minimax and alpha-beta pruning.

Knowledge then moves from rules to data. Linear regression works with real CO₂ measurements; k-NN and Naive Bayes classify role-playing characters; k-means discovers groups without labels. The perceptron and multilayer networks take learning as far as digit recognition, explaining weights, errors, activation functions and backpropagation.

The Game of Life closes the book with another kind of complexity: behavior emerging from simple rules, without training. Complete listings and experiments invite readers to change parameters and see what happens. The narrative can be followed from beginning to end, with the code available whenever a closer look is useful; the programs are also available in the book’s repository.

THE JOURNEY

Twelve chapters to build and experiment

A look at each chapter, with images from the book. Select an image to enlarge it.

Diagram of the main branches of artificial intelligence
Diagram of the main branches of artificial intelligence
CHAPTER 01

From Artificial Intelligence to BASIC

A journey through AI history, its main branches and our working laboratory: the Z80, the Spectrum and the Spectrum Next. The starting point for understanding what we will build and why BASIC is a useful way to explore it.

Spectrum performance chart comparing three sorting algorithms
Spectrum performance chart comparing three sorting algorithms
CHAPTER 02

The Battle Against Complexity

Timing Bubble sort, Shell sort and Quicksort makes algorithmic complexity visible. Performance plots show why increasing the clock speed cannot replace choosing an efficient algorithm.

BASIC expert system diagnosing a tape-loading problem
BASIC expert system diagnosing a tape-loading problem
CHAPTER 03

Expert Systems

Facts, rules and an inference engine form a small diagnostic system. Separating knowledge from the reasoning mechanism makes it possible to extend the rules and explain how a conclusion was reached.

Conversation with ELIZA running on a ZX Spectrum
Conversation with ELIZA running on a ZX Spectrum
CHAPTER 04

Symbolic AI

An implementation of ELIZA transforms text through patterns and responses. Normalization, keywords and substitutions build a conversation while revealing the difference between simulating dialogue and understanding it.

Tic-tac-toe game from the search chapter
Tic-tac-toe game from the search chapter
CHAPTER 05

Heuristic Search

Tic-tac-toe provides a way to represent states and explore decision trees. Depth-first search, Minimax and alpha-beta pruning show how to look ahead and reduce the work required to choose a move.

Spectrum plot of a regression line fitted to CO₂ data
Spectrum plot of a regression line fitted to CO₂ data
CHAPTER 06

Linear Regression

The move from rules to data begins by fitting a line and measuring error. An example using Mauna Loa CO₂ data applies least squares to a real problem, calculated and plotted in BASIC.

BASIC program classifying a character with k-NN
BASIC program classifying a character with k-NN
CHAPTER 07

Supervised Classification: k-NN

Wizards, warriors and rangers become feature vectors. A classifier decides from the nearest examples, showing how distance, data representation and the choice of k affect the result.

Naive Bayes classification result on the Spectrum screen
Naive Bayes classification result on the Spectrum screen
CHAPTER 08

Probabilistic Classification: Bayes

The same world of characters is now explored through counts and probabilities. Naive Bayes contrasts a decision based on proximity with one based on evidence and assumptions about independence.

Four stages of k-means clustering plotted in BASIC
Four stages of k-means clustering plotted in BASIC
CHAPTER 09

k-means Clustering

Without predefined labels, the program looks for groups in a cloud of points. Assigning examples and moving centroids makes it possible to follow the iterative process visually until convergence.

Training a perceptron to distinguish horizontal and vertical lines
Training a perceptron to distinguish horizontal and vertical lines
CHAPTER 10

The Perceptron

An artificial neuron combines inputs, weights and a threshold, then corrects its mistakes during training. Experiments with lines and digits introduce generalization and the limits of a linear boundary, including XOR.

Diagram of a neural network with inputs, hidden layers and output
Diagram of a neural network with inputs, hidden layers and output
CHAPTER 11

Neural Networks

Specialized perceptrons lead to hidden layers, the sigmoid function and backpropagation. A digit-recognition project on a 6 × 6 grid brings training, weights and prediction together.

The Game of Life running in BASIC on a 20 by 20 board
The Game of Life running in BASIC on a 20 by 20 board
CHAPTER 12

The Game of Life

The final chapter explores how simple local rules produce complex behavior. A toroidal 20 × 20 universe, two arrays and a visual editor make it possible to experiment with patterns, oscillators and moving structures.

Watch the video ↓
FROM PAGE TO SCREEN / CHAPTER 12

The Game of Life, in motion

Each cell lives or dies according to its eight neighbors. A living cell survives with two or three neighbors; a dead cell is born with exactly three. All cells change at the same time. These rules produce stable structures, oscillators and moving patterns.

The book’s example uses a toroidal 20 × 20 board: opposite edges connect. Two arrays keep the current generation separate from the next so the calculation order cannot change the result.

Game of Life demonstration. Use the controls to play the video.
Open the MP4 video ↗
ES / EN

One book, two editions

Choose your preferred edition. Both are collected on this page.

The programs from the book

The examples are organized by chapter in the AI_Z80 repository. Study the listings and experiment on real hardware or in an emulator.