Skip to content

Terminal-based mapping tool for exploring movement vectors in a 2d grid

License

Notifications You must be signed in to change notification settings

paulpls/knight-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

banner

Knight Map

version: 1.0.0
author: Paul Clayberg
license: GPL 3.0

PURPOSE

Generates a map based on the movements of the knight piece in chess.

Given coordinates (x,y), the knight can move to squares within the following set:

N(x,y)  =  ( x ± a, y ± b )  ∪  ( x ± b, y ± a )
        for a=1, b=2

The knight's complex movement gives rise to many interesting patterns and scenarios. Because the vector is not a pair of even or odd numbers, the knight is forced to change color each time it moves. Due to this, it can only attack squares of an opposite color to its own. Moreover, once the knight moves, it will be able to attack only the same colored squares as that from which it came.

This color-swapping compulsion makes some squares quickly reachable, but can be unforgiving in other cases. By making these movement patterns both visible and configurable, this tool aims to help to provide a better understanding of how the knight maneuvers around its environment. The movement vector (a,b) can also be changed to allow the study of other jumping pieces. The default value is (1,2), but it can be set to any pair of positive, non-zero integers.

Output settings can be changed by modifying the parameters in knight.py. By placing more knights, friendly pieces, or changing the grid dimensions, countless scenarios can be studied.

SYNOPSIS

python knight.py

DEPENDENCIES

  • python (3.8.10)
  • color terminal emulator (eg xterm)

LICENSE

Copyright (C) 2022 Paul Clayberg

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

SCREENSHOTS

[1] Knight in the center, no labels

knight1

[2] Knight unable to reach corner due to being blocked by friendlies

knight2

[3] Knight unable to leave corner due to being blocked by friendlies

knight3

[4] Two knights in opposite corners with some friendlies

knight4

[5] Knight with only one escape path

knight5

[6] Knight in corner, unblocked

knight6