From a8ad6cf468bf74a997070612f8c2262edad26891 Mon Sep 17 00:00:00 2001 From: MarcUs7i Date: Sun, 19 Jan 2025 09:42:31 +0100 Subject: [PATCH] implemented ToH initialization in toh_solver.c --- toh_solver.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/toh_solver.c b/toh_solver.c index 61fff3d..8cf5102 100644 --- a/toh_solver.c +++ b/toh_solver.c @@ -12,6 +12,9 @@ /* Includes, definitions and instanciations */ #include "toh_board.h" +#include "config.h" +#include "toh_disk.h" +#include "toh_board.h" /* ========================================================= */ /* Private functions */ @@ -25,7 +28,7 @@ * @return True if the move was successful and according to the rules, false otherwise. */ 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. */ static bool ts_move_stack(unsigned short size, Rod source, Rod intermediate, Rod target) { - + return false; } /* ========================================================= */ /* 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; +} \ No newline at end of file