wip
This commit is contained in:
parent
ea305819ab
commit
6f0b9eb321
|
@ -30,7 +30,8 @@ class Tower{
|
||||||
return json_encode($this->get_tower_array());
|
return json_encode($this->get_tower_array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
to rewrite with move object
|
||||||
public function list_moves_availables(){
|
public function list_moves_availables(){
|
||||||
$moves = array(
|
$moves = array(
|
||||||
array('from' => 0, 'to' => 1),
|
array('from' => 0, 'to' => 1),
|
||||||
|
@ -49,7 +50,7 @@ class Tower{
|
||||||
}
|
}
|
||||||
return $movesAvailables;
|
return $movesAvailables;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
private function get_tower_array(){
|
private function get_tower_array(){
|
||||||
return array(
|
return array(
|
||||||
$this->tower0,
|
$this->tower0,
|
||||||
|
@ -59,15 +60,19 @@ class Tower{
|
||||||
}
|
}
|
||||||
private function check_if_move_is_available(Move $move){
|
private function check_if_move_is_available(Move $move){
|
||||||
$fromTower = "tower".$move->from;
|
$fromTower = "tower".$move->from;
|
||||||
$toTower = "tower".$move->to;
|
$toTower = "tower".(string)$move->to;
|
||||||
if(($from == $to) || (empty($this->$fromTower)) || (end($this->$toTower) < end($this->$fromTower))){
|
echo "kk$toTower\n".$move."|";
|
||||||
|
print_r($this->{$toTower});
|
||||||
|
//echo end($this->$toTower)."|". end($this->$fromTower);
|
||||||
|
|
||||||
|
if(($move!==false) || (empty($this->$fromTower)) || (end($this->$toTower) < end($this->$fromTower))){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add_move(Move $move){
|
public function add_move(Move $move){
|
||||||
if($this->check_if_move_is_available($move->from,$move->to)){
|
if($this->check_if_move_is_available($move)){
|
||||||
$towerArr = $this->get_tower_array();
|
$towerArr = $this->get_tower_array();
|
||||||
$towerArr[$move->to][] = end($towerArr[$move->from]);
|
$towerArr[$move->to][] = end($towerArr[$move->from]);
|
||||||
array_pop($towerArr[$move->from]);
|
array_pop($towerArr[$move->from]);
|
||||||
|
@ -164,20 +169,17 @@ class Move{
|
||||||
case "1 to 0":
|
case "1 to 0":
|
||||||
$move->set_value(Move::$from1to0);
|
$move->set_value(Move::$from1to0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "1 to 2":
|
case "1 to 2":
|
||||||
$move->set_value(Move::$from1to2);
|
$move->set_value(Move::$from1to2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "2 to 0":
|
case "2 to 0":
|
||||||
$move->set_value(Move::$from2to0);
|
$move->set_value(Move::$from2to0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "2 to 1":
|
case "2 to 1":
|
||||||
$move->set_value(Move::$from2to1);
|
$move->set_value(Move::$from2to1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return $move;
|
return $move;
|
||||||
|
|
|
@ -6,7 +6,11 @@ include("class.towers.php");
|
||||||
|
|
||||||
|
|
||||||
$tower = new Tower($discCount);
|
$tower = new Tower($discCount);
|
||||||
echo $tower;
|
echo "1".$tower."\n";
|
||||||
|
$move = new Move();
|
||||||
|
$move->make("0 to 1");
|
||||||
|
$tower = $tower->add_move($move);
|
||||||
|
echo "2".$tower."\n";
|
||||||
/*
|
/*
|
||||||
resolveHanoi($tower);
|
resolveHanoi($tower);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user