LEX is Martin Gardner's Hexapawn where matchboxes are Excel files
Project description
LEX --- Learning EX-a-pawn
A game written by Mattia Monga for a 'Coding for lawyers' course. Copyright 2020 - 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.
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 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lex_game-0.0.3.tar.gz.
File metadata
- Download URL: lex_game-0.0.3.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
caac43bcc52f59e0694884e5bd82097297b45bbcd4adc98067a795913e7b9219
|
|
| MD5 |
3aab8681305f03721af8702613eda3b1
|
|
| BLAKE2b-256 |
f74b85c761af03860a1226939fc6422b021619a3a373615c562d1519e57313c6
|
File details
Details for the file lex_game-0.0.3-py3-none-any.whl.
File metadata
- Download URL: lex_game-0.0.3-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a58d84b597858f38ff938d31ccfe0252abcdc1ac2c543850b783a085498886e4
|
|
| MD5 |
9ae3ea98a1bc019087ff8e4ce17048f0
|
|
| BLAKE2b-256 |
d85afe1dc14fad685a861aa472389d672e67c7f62f2e09054740b5d30667f1a4
|