Skip to content

hurrja/ib-cs-tower-of-hanoi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solving Tower of Hanoi

The purpose of this repository

This repository contains model, view and controller classes for solving Tower of Hanoi.

Installation in IDEA

To install the application in IDEA, do the following:

  1. Clone the repository.
  2. Right click on class TOHApp.
  3. Select Run TOHApp.main()

You are now able to make changes to the project and run it again.

Alternative installation method

  1. Clone repository.
  2. Run ant default target (builds and runs the application).

Programming your solution

Class TOHApp contains method

static void solve (TowerOfHanoi toh, int numDiscs, Peg from, Peg to)

which you need to modify to solve the problems. The main() of this class calls method solve() with correct parameters for solving the problem, that is, moving all discs from rod A to rod C.

The version of solve() in this repository is a feeble attempt to solve this problem, and you need to replace it with your own version. Still, the feeble version demonstrates the only external methods you need to use:

  • class TowerOfHanoi contains method
    move (Peg from, Peg to)
        

    which moves top disc of rod from to rod to. This may throw an exception if the move breaks the rules of Tower of Hanoi, but this exception is caught by the program. Possible exceptions are printed into console.

License

Copyright (C) 2020–2023 Jarmo Hurri, Aleksei Terin

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/.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages