You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
948 B
PHTML

7 years ago
<?php
7 years ago
/*
* Hanoi towers ' resolver
* Copyright (C) 2017 Gnieark https://blog-du-grouik.tinad.fr/
* licensed under the terms of the GNU General Public V3. See License file.
*/
7 years ago
$discCount = 6;
7 years ago
//load the class
7 years ago
include("inc.php");
7 years ago
$tower = new Tower($discCount);
7 years ago
$steps = new Steps(array());
$steps->add_step($tower);
7 years ago
7 years ago
resolveHanoi($tower,$steps);
7 years ago
7 years ago
function resolveHanoi(Tower $tower, Steps $steps){
$result = false;
7 years ago
7 years ago
if($tower->is_won()){
7 years ago
echo "a winning suite was found:\n";
foreach($steps->steps as $oneTower){
echo $oneTower."\n";
}
7 years ago
return true;
7 years ago
}
7 years ago
$availablesMoves = $tower->list_moves_availables();
7 years ago
7 years ago
foreach($availablesMoves as $move){
7 years ago
$newTower = $tower->add_move($move);
$newSteps = $steps;
if($newSteps->add_step($newTower)){
$r = resolveHanoi($newTower,$newSteps);
if($r){
$result = true;
}
}
7 years ago
}
7 years ago
return $result;
7 years ago
}