Skip to content

Commit

Permalink
Changed colors to match my beads, added PDFs, and wrote the README.
Browse files Browse the repository at this point in the history
  • Loading branch information
kyp44 committed Mar 7, 2022
1 parent 3d6f35c commit a8b1347
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 14 deletions.
20 changes: 17 additions & 3 deletions Board.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from enum import Enum
from dataclasses import dataclass, replace, field
from Config import Config
import itertools as it
from os import linesep as endl
from typing import Optional, Tuple, List, Set, Dict
import math
from Config import Config

class Player(Enum) :
WHITE = "White"
Expand Down Expand Up @@ -164,8 +165,21 @@ def draw(self) -> str :
out += r"\draw[thick] " + pt_units(x*s, y*s) + " rectangle " + pt_units((x+1)*s, (y+1)*s) + ";" + endl

# Draw available moves
for move, color in zip(self.legal_moves(), self.config.colors) :
out += r"\draw [line width=0.6mm, " + color + ", -{Stealth[scale=1]}] " + center(move.pawn.x, move.pawn.y) + " -- " + center(move.x, move.y) + ";" + endl
moves = self.legal_moves()
assert len(moves) <= len(self.config.colors), "Need at least " + str(len(moves)) + " colors, but only " + str(len(self.config.colors)) + " are defined!"
for move, color in zip(moves, self.config.colors) :
#out += r"\draw [line width=1mm, " + color + ", -{Stealth[scale=1]}] " + center(move.pawn.x, move.pawn.y) + " -- " + center(move.x, move.y) + ";" + endl
#out += r"\node[single arrow, draw=blue, very thick, fill=green, minimum width = 10pt, single arrow head extend=3pt, inner xsep=0pt, fit=" + center(move.pawn.x, move.pawn.y) + " " + center(move.x, move.y) + "] {};" + endl
# Draw a nice thick arrow
dx = (move.x - move.pawn.x) * s
dy = (move.y - move.pawn.y) * s
theta = math.atan2(dy, dx)
mag = math.hypot(dx, dy)*0.6
center = ((move.pawn.x + 0.5)*s + dx/2, (move.pawn.y + 0.5)*s + dy/2)

out += (r"\node[single arrow, draw=black, fill=" + color + ", inner sep=" + self.config.units(1)
+ ", single arrow head extend=3pt, minimum height=" +
self.config.units(mag) + ", shift={" + pt_units(*center) +"}, rotate=" + str(math.degrees(theta)) + "] {};" + endl)

# Draw turn number
out += r"\draw " + pt_units(self.config.width/2, -3) + " node {Move: " + str(self.turn_num) + "};" + endl
Expand Down
8 changes: 4 additions & 4 deletions Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ def __init__(self) :
Parses the config file.
"""
# Width of each board (in mm).
self.width = 30
self.width = 34
# Colors to use for the moves, only 4 are needed.
# These can be any LaTeX colors including mixes using xcolor.
# For more info see: https://en.wikibooks.org/wiki/LaTeX/Colors
self.colors = ["red", "green!50!black", "blue", "black"]
# Space between boards (in mm).
self.colors = ["violet!80!white", "green!50!black", "yellow", "pink"]
# Space between boards (in mm) on the page.
self.board_spacing = 8
# Number of boards to show per row.
# Number of boards to show per row on the page.
self.boards_per_row = 4

# Calculated sizes
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ help:
@echo "all: Build the manual from the LaTeX source code."
@echo "clean: Remove all of the build files for the PDFs."
@echo "board: Build game board PDF."
@echo "her: Build the positions and moves for a HER, the black player."
@echo "him: Build the positions and moves for a HIM, the white player."

#==============================================================================
board:
Expand Down
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
Just notes for now:
1. Requirement of the chessfss LaTeX package, in package texlive-games in Ubuntu.
2. Python packages: anytree
# Hexapawn Positions for the HER and HIM Learning Computers

TODO:
1. Comment everything using nice docstrings.
## Introduction

This project will generate all the black positions and moves for a Hexapawn Educable Robot (HER) and the white positions for a Hexapawn Instructable Matchboxes (HIM) machine.

Inspired by the [MENACE](https://www.mscroggs.co.uk/blog/94) Tic-Tac-Toe (i.e. Noughts and Crossses if you aren't American) engine, these are the positions for the simpler game hexapawn, which was devised by Martin Gardner in his [1962 article](http://cs.williams.edu/~freund/cs136-073/GardnerHexapawn.pdf).
Unlike MENACE for tic-tac-toe, which requires 304 matchboxes, HER and HIM for hexapawn requires only 19 matchboxes for the black player (HER) and 18 for the white player (HIM) once symmetry is taken into account.
The PDFs for [HER]() and [HIM]() are in the repository along with a printable [game board]().

## Requirements

The project is a combination of Python and LaTeX, with a Python program generating LaTeX code that is then compiled, which was developed in a Linux environment.
Python 3 and a working LaTeX installation are required along with the [`anytree`](https://pypi.org/project/anytree/) Python module to build the game tree, and the [`chessfss`](https://ctan.org/pkg/chessfss?lang=en) LaTeX package to render the pawn symbols.

## Building

Everything above can be built by simply running `make`, or run `make help` for information about just building individual components.
Currently things are configured for my needs, but `Config.py` contains a configuration object with some parameters that can be adjusted to meet other user's specific needs.
Namely this includes changing the board sizes (for different sized matchboxes or other containers), move colors (which will depend on what color beads one has available), and parameters relating to position boards layout on the PDF pages.
See `Config.py` for more details on these paramters.
2 changes: 1 addition & 1 deletion base.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
\documentclass{article}
\usepackage{tikz}
\usepackage{chessfss}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{fit, shapes.arrows}
\usepackage[top=2cm,left=1.5cm,right=1.5cm,bottom=2cm]{geometry}
\begin{document}
\noindent
Expand Down
3 changes: 2 additions & 1 deletion board.tex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
\noindent

% Draw 3 x 3 board
\def\size{2cm}
% Size of a single space
\def\size{26mm}
\setboardfontsize{\size}
\begin{center}
\begin{tikzpicture}
Expand Down
Binary file added output/board.pdf
Binary file not shown.
Binary file added output/her.pdf
Binary file not shown.
Binary file added output/him.pdf
Binary file not shown.

0 comments on commit a8b1347

Please sign in to comment.