CS306 Processing Systems and Structures Lockwood, Spring 2002

Machine Problem 4: The Maze (Part II)

Assigned Monday, March 18
Due Date Friday, March 29
Purpose: Algorithms, Recursion
Points 50

Introduction

Consider again the mouse of Machine Problem 3. For this assignment. For this assignment, you will write procedures that automatically guide the mouse through the maze to find the solution.

You will first implement an advance (Adv) routine to move the mouse in the maze by a single position. The advance routine checks that the move is valid before moving the mouse. A valid move is one that does not put the mouse into a wall. This routine is used by both by manual mode and turbo mode. Turbo mode allows the mouse to automatically advance forward through straight hallways.

Next, you will implement the 'Auto-Advance' function which automatically forwards the mouse through hallways and around turns. Recall that at each location in the maze is marked with a decision point where two or more hallways meet. Your 'Auto-Advance' routine will advance the mouse until reaching such a decision point.

Lastly, you will implment 'Auto-Solve' which implements a Depth First Search (DFS) algorithm. This procedure will automatically guide the mouse out of the maze.

Problem Description

There are four modes of operation to this program: Manual, Turbo, AutoAdvance, and AutoSolve. Modes can be selected by pressing the 'M' key, followed by a number (0 to 3). In manual mode (M0), pressing the arrows keys will advance you by one position. In turbo mode (M1), the mouse will run down a hallway until hitting a wall. In AutoAdvance mode (M2), the mouse will traverse down a hallway until hitting a decision point. In AutoSolve mode (M3), the mouse will find the solution to the maze automatically. The mode of the program is displayed at the top-center of the screen.

In modes 1-3, the speed of the mouse can be adjusted. The (+) and (-) keys determine the delay rate. A larger rate slows the mouse, while a smaller makes the mouse move faster. The delay rate is displayed at the top-right of the screen.

Recall that the _MAZE variable contains an array of HALL, WALL, DECPOS, and ENDPOS constants. A decision point is a location in the maze where the mouse must decide which way to travel (i.e., the hallway branches). For this machine problem, we will sub-divide the decision points into three types of nodes: the original (unvisted) decision point (DECPOS), a visited decision point (VISPOS), and finished decision point (FINPOS). You can toggle the type of decision point by pressing the 'v' key.

The ASM procedures that you will 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 that all subroutines will preserve the value of any register that they modify. The only exception is for registers that are used as outputs of procedures.

Adv

AutoAdv

AutoSolve

Points

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.

Starting Files


Relevant portions of MP3 Code for MP4

; You Name Here : ____________________________________ ; CS306: Machine Problem 4, Spring 2002 ; Prof. John W. Lockwood ; Washington University, Department of Computer Science ; Ver. 2.1 ; ================ Constants / Definitions / MACROs ===================== ; MAP Elements WALL EQU 0 ENDPOS EQU 1 HALL EQU 2 DECPOS EQU 3 ; Original Decision point VISPOS EQU 4 ; Visited Decision point FINPOS EQU 5 ; Finished Decision point ; .. More .. ; Modes MODEMAN EQU 0 MODEADV EQU 1 MODEAUTOADV EQU 2 MODEAUTOSOLVE EQU 3 ; .. More .. ; Public variables (used by libmp3) GLOBAL Movement, mazemode, mazedelay, updatescreen ; =================== External Library Procedures ======================= ; Your code can call these library routines (but not for free) EXTERN LibAdv EXTERN LibAutoAdv EXTERN LibAutoSolve ; The library routines may need call these ; procedures in your code GLOBAL AutoAdv GLOBAL AutoSolve GLOBAL Adv ; .. More .. mazemode db 0 ; By default, Start in Manual Mode mazedelay db 16 ; Default Delay Period ; ------------------------------------------------------------------------ Adv: Call LibAdv; [ Subject of Machine Problem 4 ] ret ; ------------------------------------------------------------------------ AutoAdv: Call LibAutoAdv ; [ Subject of Machine Problem 4 ] ret ; ------------------------------------------------------------------------ AutoSolve: Call LibAutoSolve; [ Subject of Machine Problem 4 ] ret ; ------------------------------------------------------------------------ _MazeManual: ; This code is given to you for free. ; It helps to understand this code in order ; to write the AutoAdv and AutoSolve routines. ; Purpose: Interactively allows user to traverse maze and run AutoSolve ; Variables: _MAZE, mazemode, mazedelay ; Input: From keyboard ; Output: None. PUSH BP PUSH DS PUSH ES PUSH SI PUSH DI MOV AX,VIDTEXTSEG ; Use ES=Video Segment MOV ES,AX MOV BL,NORTH ; By default, go north MMLoop: Call kbdin CMP AL,'Q' JNE MMNotDone1 JMP MMDone MMNotDone1: CMP AL,'q' JNE MMNotDone2 JMP MMDone MMNotDone2: CMP AL,FORWARDKEY JE MMForward CMP AL,BACKWARDKEY JE MMBackward CMP AL,LEFTKEY JE MMLeft CMP AL,RIGHTKEY JE MMRight CMP AL,'m' JE MMode CMP AL,'+' JE MMSlower CMP AL,'-' JE MMFaster CMP AL,'g' JE MMGrMode CMP AL,'t' JE MMTMode CMP AL,'v' JE MMMark JMP MMLoop ; Check for Keyboard Arrow Keys (up, down, left, right) ; Redefine keyboard - forward , back , left turn , right turn MMForward: MOV AL,BL ; Go Forward JMP MMArrow MMBackward: MOV AL,BL ADD AL,2 ; Reverse direction AND AL,3 CALL Adv ; Advance 1 MOV AL,BL ; Set Direction to forward CALL UpdateScreen ; Show screen JMP MMLoop MMLeft: ADD BL,3 ; Go Left AND BL,3 MOV AL,BL ; MOV SI,[_POS] ; should not be needed ; MOV DI,[_POS] Call UpdateScreen JMP MMLoop MMRight: ADD BL,1 ; Go Right AND BL,3 MOV AL,BL ; MOV SI,[_POS] ; MOV DI,[_POS] Call UpdateScreen JMP MMLoop ; Set Game Mode ('m0','m1','m2','m3') MMode: Call kbdin CMP AL,'0' JB MMLoop CMP AL,'3' JA MMLoop SUB AL,'0' MOV [mazemode],AL Call ShowMode JMP MMLoop ; Control Interactive Speed (Smaller Mazedelay==Faster) MMFaster: DEC byte [mazedelay] Call ShowMode JMP MMLoop MMSlower: INC byte [mazedelay] Call ShowMode JMP MMLoop MMGrMode: ; MP5 will support Graphics mode ; For now, do nothing. JMP MMLoop MMTMode: TMODE ; (Macro in MAZE.DEF) - Switch back to 80x25 Text Mode mov byte [VidMode],TEXTMODE Call ShowMaze Call ShowMode ; Need to redraw (entire) text screen JMP MMLoop ; after switching modes MMMark: mov DI,[_POS] ; New Feature - Hit 'v' to visit/unvisit node cmp byte [_MAZE+DI],DECPOS jne MMMark2 mov byte [_MAZE+DI],VISPOS jmp MMMarkD MMMark2: cmp byte [_MAZE+DI],VISPOS jne MMMark3 mov byte [_MAZE+DI],FINPOS jmp MMMarkD MMMark3: cmp byte [_MAZE+DI],FINPOS jne MMLoop mov byte [_MAZE+DI],DECPOS MMMarkD: MOV AL,BL MOV SI,DI Call UpdateScreen JMP MMLoop MMArrow: CMP byte [mazemode],3 ; AutoSolve Mode JE MMASolve CMP byte [mazemode],2 ; AutoAdvance Mode JE MMAutoAdv MMAdv: Call Adv ; Movement Loop Call UpdateScreen CMP byte [mazemode],0 JE MMLoop CMP byte [_MAZE+DI],HALL JNE MMLoop CMP AH,1 JE MMLoop Call delay JMP MMAdv MMAutoAdv: mov al,bl Call AutoAdv mov bl,al JMP MMLoop MMASolve: mov al,bl Call AutoSolve mov bl,al JMP MMLoop MMDone: MOV AX,0 ; Return value POP DI POP SI POP ES POP DS POP BP RET
Copyright 1996-2002 John Lockwood