ECE291 Computer Engineering II Lockwood, Spring 1997

Machine Problem 3: The Bakery of Hanoi

Assigned Tuesday 2/25/97
Due Date Tuesday 3/11/97
Purpose: Understand recursion, text-mode video, and mouse control.
Points50

Introduction

A wedding is planned in the town of Hanoi, Illinois. For the event, a baker has prepared an elaborate wedding cake with multiple tiers. Each tier of the cake is a different size. Initially, the cake is stacked at the bakery with the largest tier at the bottom and progressively smaller cakes stacked above one another. Using manual labor and the bakery's single delivery truck, a plan is needed to transport the entire cake to the recepton. A diagram is shown below:

The baker must transport the entire cake to the reception. Because the cake is heavy, it must be moved one tier at a time. To insure that the cakes are not damaged before the reception, the cake tiers must always be kept at the bakery, in the delivery van, or on the table at the reception. Tiers of cake can be moved directly between all three locations. Tiers of the cake may be stacked, but a larger tier must never be placed atop a smaller one for fear of collapsing the smaller tier.

The baker's delivery man, Igor, has already moved some of the tiers of cake. Wrought with confusion and frustration from moving the cake, Igor has called the baker and quit his job. With the wedding reception only hours away, the baker is desparate to find someone to get all of the cakes to the reception and stacked in the proper order.

As a student of ECE291, the baker has hired you to help him devise a plan to start where Igor left the tiers and assemble the cake at the reception as efficiently as possible.

Implementation

For this machine problem, you will write a program which:

A screen dump of the running program is shown above. Along the top of the screen are a series of buttons. Each of these buttons responds to a mouse-click. Just below the buttons, the program displays the current number of moves as well as the number of tiers of cake. The lower portion of the screen contains the bakery, the delivery truck, and reception. To win the game, the entire cake should be moved to the reception (the right-most location).

Usage Instructions

The library-based MP3.EXE demo can be run from the DOS prompt. Use the mouse to press the on-screen buttons and move tiers of cake between locations. Tiers are moved by moving the mouse to the source, pressing the mouse button, moving the mouse to the destination, then releasing the mouse button. The program will not allow larger tiers of cake to be placed atop smaller tiers. If the mouse does not appear on your screen, enter mouse to load your mouse driver. This program should operate both in full-screen text-mode and within a window.

Data Structures

The following variables are used throughout the program and by the library functions.

Procedures

The ASM procedures that you need to implement are described below. There are working library versions of each of these procedures in libmp3.lib. Unless otherwise noted, it is expected that all routines will preserve the value of any register modified other than the output.

You are encouraged to write your own procedures to handle repetive tasks. You will find, for example, that a function which writes messages on the screen at given location can be used throughout your program.

Be sure that you have experimented with the library-based program before you begin. It is important that you fully understand the problem before you try to write the code. Because library functions call other library functions, you are encouraged to begin coding with the MAIN routine.

Program Assignment

You earn points by replacing each subroutine with your own code. Your score will be proportional to the percentage of the code that your write yourself. The breakdown in points is given below. Your routine MUST perform all functions of the subroutine to receive credit.

Preliminary Procedure

Clearifications and Erratica


MP3.ASM

PAGE 75, 132 TITLE ECE291:MP3:Hanoi - Your Name - Date COMMENT % The Bakery of Hanoi ------------------- ECE291: Machine Problem 3 Prof. John W. Lockwood Unversity of Illinois, Dept. of Electrical & Computer Engineering Spring 1997 Documentation: http://www.ece.uiuc.edu/~ece291/mp/mp3/mp3.html Revision 1.0 % ;====== Constants ========================================================= CR EQU 13 LF EQU 10 ESCKEY EQU 27 SPACE EQU 32 VIDTXTSEG EQU 0B800h ; VGA Video Segment Adddress (Text Mode) ;====== Externals ========================================================= ; -- LIB291 Routines (Free) --- extrn kbdine:near, kbdin:near, dspout:near ; LIB291 Routines extrn dspmsg:near, binasc:near, ascbin:near ; (Always Free) ; -- LIBMP3 Routines (You need to write these) extrn MoveTier:near ; Remove this line to use your own code extrn DrawScreen:near ; Remove this line to use your own code extrn RedrawScreen:near ; Remove this line to use your own code extrn ResetGame:near ; Remove this line to use your own code extrn Distribute:near ; Remove this line to use your own code extrn MouseCtrl:near ; Remove this line to use your own code extrn AutoSolve:near ; Remove this line to use your own code extrn MainLIB:near ; Remove this line to use your own code extrn mp3xit:near ;====== Stack segment ==================================================== stkseg segment stack ; *** STACK SEGMENT *** db 64 dup ('STACK ') ; 64*8 = 512 Bytes of Stack stkseg ends ;====== Code/Data segment ================================================ cseg segment public ; *** CODE SEGMENT *** assume cs:cseg, ds:cseg, ss:stkseg, es:nothing ;====== Variables ========================================================= Moves DW 0 ; Number of moves required (Reset to zero for each game) Tiers DW 4 ; Number of Tiers (Default with 4 tiers) Bakery DW 0000000000000001b ; -- Sample Bit-mapped array -- Truck DW 0000000000000010b ; ### Recept DW 0000000000001100b ; ######### ####### ##### ; Bakery Truck Recept ; Dest=0 Dest=1 Dest=2 HanoiMsg db ' ECE291 MP3 ver 1.0 ' db ' THE BAKERY OF HANOI ' db ' Lockwood Spr97','$' RandSeed DW 13 ; Random Number Seed PUBLIC HanoiMsg, Moves, Tiers, RandSeed, Bakery, Truck, Recept ;====== Main procedure ==================================================== main proc far mov ax, cseg ; Initialize DS register mov ds, ax mov ax, VIDTXTSEG ; Segment address of video memory mov es, ax mov AX, 0002h ; Set 80x25 text mode and clear screen int 10h mov tiers, 4 ; Start with Default of 4 Cake Tiers call Distribute ; Randomly distribute to bakery,truck,recept call DrawScreen ; Draw the text-mode video screen mov ax,0 ; init mouse int 33h mov ax,1 ; Show Mouse int 33h ; ------------------------------------------- ; Your MAIN code goes here ; ------------------------------------------- Call MainLIB ; Replace this with your own code call mp3xit ; Exit to DOS main endp cseg ends end main