Skip to main content

LEX --- Learning EX-a-pawn

A game written by Mattia Monga for a 'Coding for lawyers' course. Copyright 2020-25 - Free to distribute, use, and modify according to the terms of GPLv3.

The code is simplistic but this version uses an OOP style; see branch master for an even simpler approach.

Installation

pip install lex_game

lex_game -h gives help on command line arguments.

A web app version can be installed with

pip install lex_game[web]

then python -m lexweb.app serves on localhost:5000

Rules of the game

Pawns move and capture as in chess, but there are neither two-step moves nor en-passant captures. Players win by reaching the last row or by blocking the opponent. Moves are given by two letters: the starting column and the ending one.

Machine learning

Automatic players can learn to play better by memorizing its experience in Excel files (the format was chosen as an example of using Python with spreadsheets).

With the command:

lex_game -e2 exapawn-empty.xlsx exapawn-001.xlsx

player 2 plays with the experience found in exapawn-empty.xlsx, at the end of the match, all the learned experience is saved in exapawn-001.xlsx.

It is possibile to make two automatic player play one against the other, see learn1vs2.sh for a match with several games. After a dozen of games, player2 becomes unbeatable. This is a typical trend for a match with 30 games.

game Player 1 Player 2
1 1
2 2
3 3
4 3 1
5 3 2
6 3 3
7 3 4
8 3 5
9 4 5
10 4 6
11 5 6
12 5 7
13 6 7
14 6 8
15 6 9
16 6 10
17 6 11
18 6 12
19 6 13
20 6 14
21 6 15
22 6 16
23 6 17
24 7 17
25 7 18
26 7 19
27 7 20
28 7 21
29 7 22
30 7 23

The game can also be solved deterministically. See tree-solved (cyan is player 1, magenta is player 2) for a spoiler of the three pawns version. With four or five paws for each player the game tree is much bigger, but nevertheless it can be produced by the program in a few minutes.

References

See: https://www.gwern.net/docs/rl/1991-gardner-ch8amatchboxgamelearningmachine.pdf

Metadata

Release files for lex-game 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lex-game 0.2.3
File Size Uploaded
lex_game-0.2.3.tar.gz 37.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lex-game 0.2.3
File Interpreter ABI Platform
lex_game-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 73.4 kB

Release files / lex_game-0.2.3.tar.gz

Download URL lex_game-0.2.3.tar.gz
Size 37.3 kB
Tags Source
SHA-256 checksum
How to use checksums
13b96e305ac9c431cbf1ac6b6a5a656484f9e6bfe5d493c660b57d2f63c023e3
BLAKE2b-256 checksum
How to use checksums
cd3e62e45cad4b77e2420eada1895275b1f15ae3285ec6ddaac557e6d88f3d0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.13.12

Release files / lex_game-0.2.3-py3-none-any.whl

Download URL lex_game-0.2.3-py3-none-any.whl
Size 36.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8133f565a4ef1b2e45cb11444f4a3c657055bca9ab9b8f5d225152d79d57c90
BLAKE2b-256 checksum
How to use checksums
ed204efb2f3881a24bfdc9c5060d3b2c2c871314c03546f3a3a266d18785da58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.2.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page