implemented ToH initialization in toh_solver.c
This commit is contained in:
parent
811dee37e5
commit
a8ad6cf468
1 changed files with 39 additions and 2 deletions
41
toh_solver.c
41
toh_solver.c
|
|
@ -12,6 +12,9 @@
|
||||||
|
|
||||||
/* Includes, definitions and instanciations */
|
/* Includes, definitions and instanciations */
|
||||||
#include "toh_board.h"
|
#include "toh_board.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "toh_disk.h"
|
||||||
|
#include "toh_board.h"
|
||||||
|
|
||||||
/* ========================================================= */
|
/* ========================================================= */
|
||||||
/* Private functions */
|
/* Private functions */
|
||||||
|
|
@ -25,7 +28,7 @@
|
||||||
* @return True if the move was successful and according to the rules, false otherwise.
|
* @return True if the move was successful and according to the rules, false otherwise.
|
||||||
*/
|
*/
|
||||||
static bool ts_move_disk(Rod source, Rod target) {
|
static bool ts_move_disk(Rod source, Rod target) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -41,8 +44,42 @@ static bool ts_move_disk(Rod source, Rod target) {
|
||||||
* @return True if the move was successful and according to the rules, false otherwise.
|
* @return True if the move was successful and according to the rules, false otherwise.
|
||||||
*/
|
*/
|
||||||
static bool ts_move_stack(unsigned short size, Rod source, Rod intermediate, Rod target) {
|
static bool ts_move_stack(unsigned short size, Rod source, Rod intermediate, Rod target) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================================================= */
|
/* ========================================================= */
|
||||||
/* Public functions */
|
/* Public functions */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initials a 'Tower of Hanoi' board with the given number of disks.
|
||||||
|
* To initialize the board, all reqired disks are placed on the left rod
|
||||||
|
* in ascending order of their size, the smallest disk at the top.
|
||||||
|
* The middle and right rod are empty.
|
||||||
|
*
|
||||||
|
* All disks are initialized accordingly.
|
||||||
|
*
|
||||||
|
* @param disk_count The number of disks to use. Must be less than 'MAX_DISKS'.
|
||||||
|
*/
|
||||||
|
void ts_init(unsigned short disk_count) {
|
||||||
|
if(disk_count < 1 || disk_count > MAX_DISKS) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
TohBoard board = tb_get_board();
|
||||||
|
tb_clear_board(board);
|
||||||
|
|
||||||
|
for (unsigned short i = disk_count; i > 0; i--) {
|
||||||
|
Disk disk = td_get_disk(i);
|
||||||
|
tb_push_disk(board, LEFT, disk);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Solves the puzzle by moving all disks from the left rod to the right rod.
|
||||||
|
* In fact, this is the only function needed to 'play' the game after the
|
||||||
|
* board was initialized.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void ts_solve() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue