Skip to content

A zero dependency playable TUI implementation of Towers of Hanoi in python

License

Notifications You must be signed in to change notification settings

Justaus3r/tonoi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tonoi

Screenshot

Overview

Introduction

Tonoi is a playable implementation of the classsical mathematical game called Towers of Hanoi. It is a console based implementation that uses ANSI Escape Sequences for implementing its own Textual User Interface(TUI) library.The game is responsive and only stdlib is used in this game.

Motivation

Not totally related but this Computerphile video. Since most github searches yeilded visualizers or solution for the puzzle, i thought, maybe i should implement a console based version thats actually playable. then i had the bright idea of implementing every thing from scratch using only stdlib. And BOY!, did i ever had more regrets. having no prior knowledge of how to work with ansi sequences, i had to binge search every resource. the current codebase is no way near perfect or good for that matter. But i am satisfied for now, and truth be told have lost motivation to work on this project anymore.

Installation

Using Source

You can install the game using the source. all you have to do is download this repo using your preferred method, be it may a git clone or directly downloading the Zip. after downloading the repo, you can use setup.py to install the game:

# if on *nix
$python3 setup.py install
# if on windows
$py setup.py install

From Pypi

You may install the game from Pypi also:

$python3 -m pip install tonoi==0.2.0

Compiled Binaries

x86_64 Binaries are compiled for Windows, for users not having python installed, using Nuitka. you can download the latest release from Releases Page. Though not necessayry, after downloading the zip, first time runners should run "tonoi.exe" from within cmd. As they will probably have to enable ANSI support from registry editor and the game provides the command for that.

Note: Since the game uses ANSI Escape Sequences, any terminal that supports it will run the game. Meanwhile the opposite is also true. also please note that even though tonoi supports the default windows terminal cmd.exe for systems that have "Windows Anniversary" update installed, it is still a better experience if you run it in Windows Terminal.

How to Play

Tonoi is a commandline based game. use your preferred terminal that supports ANSI to run the game.

# for help
$tonoi -h
# for simply running the game with defaults
$tonoi

Overview of the game

Playing it is pretty simple. tonoi uses commmand line interface(CLI) for interacting with the game. the three towers are labeled numerically in order. various commands are provided, which correspond to different actions. for example one can use the "move" command to move a disk from source tower/rod to destination tower/rod.i.e: "move 1 2" will move a disk from tower 1 to tower 2. The rules of the orignal game still apply. one cannot place a smaller disk onto a bigger one, doing so will deduct a life(not in orignal game). this behaviour, however can be disabled as mentioned below.

Changing modes

The game has two modes, the command-line mode: under which no terminal graphics are drawn. and the graphics mode: a responsive tui is drawn to the screen. you can use the "toggle-mode <mode>" command to change it. more info is provided in "list-commands" command. if you wish to use characters in ASCII charset for printing components, then use "--ascii" at the system commandline.

Registering a player name

A "Player name" can be registered through the interface, which will later be used to identify the player. all of "Best game runs" and "Perfect game runs" attributed to the player are stored in a config file and then later used. By default the player name is generated by using a seed value. if you wish to use a custom name, then use "register-player PLAYERNAME" command.

Using the cheat

By default tonoi has a additional component, the "life system". Whenever a player voilates the game rules, 1 life is deducted from the player. there are a total of 3 lives. If all 3 of them are lost, then the player looses.If you want to disable this system, then you can use the "icheat" command to do so. also the loosing message might be offensive for some people.For turning that off, use "butmymamainnocent" command.

Setting a time limit

Players can use a "time limit" system for setting a pseudo time limit for completing the game. the reason why its a "pseudo" time limit is because players can still complete the game after the time runs out. the time limit can only be set from commandline(not tonoi's but system's). use "--time-limit/-tl <value in seconds>" to set the time limit.

Checking a source file

One can use a source text file containing all the game moves for solving the puzzle for particular disks. this can be done by putting the disk count at the top of the file, and then all the moves. use the tower number for referencing it.for example:

3

1->3
1->2
3->2
1->3
2->1
2->3
1->3

the above source will solve the puzzle for 3 disks.

More

Much more is available in the game. use "list-commands" command to list all the commands.

Tonoi Configuration

Tonoi has a custom Markup language called "Konf" for configuration.it is used for storing both player game-data and configuration for tonoi. Most of the configuration(specifically the one's mentioned below) that is available at commandline can be specified in the configuration file.

" custom player config
<- END @meta

:: START -> tonoi_config
render_ascii = True
disk_capacity = 8
interface_type = graphics
" Always set this to false since
" debugger isn't complete and not available
debug = False
<- END tonoi_config

Implementation Details

Konf uses custom constructs called "Sections" and "Blocks" for organizing the datum. Sections live in higher hierarchy than Blocks.There may an arbitrary amount of Sections in a single Konf file.A Section may have an arbitrary amount of Blocks, but these Blocks may not be nested.There is a special Section called the "Meta" section which can be used to store states that are related to the Konf source file or are independent of Sections. It is the first Section that is parsed by the parser. The Special Meta Section variable "expression_delimiter" is used for modifying the assignment delimiter, which by default is "=". For example one may do something like:

" Use " for comments
some_another_var=some_val
expression_delimiter=>>
< END @meta

:: START -> a_section

: START -> a_block
some_number>>5
some_bool>>True
some_string>>i am a string
< END a_block

<- END a_section

:: START -> another_section
a_num>>4
a_string>>i am another string
<- END another_section

As you can see, Konf supports the three basic Datatypes,i.e strings,numbers,booleans.

Syntax Highlighting

There is a minimal syntax file at "syntax/konf.vim" provided for vim/nvim users to do simple syntax highlighting.

Issues

There is a single known issue at the time. First is after changing the terminal size, the cursor goes the right-end of the terminal.give an empty input(i.e: enter) to move it after the prompt. Don't know why this happens.Will hopefully be fixed someday.

Todos

  • Complete the debugger and logger
  • Use sockets for playing multiplayer
  • Do BugFixes
  • More Features?
  • Fix this README(i know its bad)

Future Updates

As i have mentioned above, i have lost motivation to work on this project for now.Consider this the first and the only release of the project. will comeback if my mind is changed.

Bug Reports

You can use the github issue tracker for reporting bugs.but know that fixes are not promised since the project is semi-abbandoned for now.

Support

Maybe star the project, if you like it.

Contribution

The codebase is kinda messy, but contributions are still welcomed. code formatting is done via "black".

License

This project is Licensed under GNU GPLV3 and can be distributed with later versions.