home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
games
/
pmmaze.zip
/
MAZE.C
< prev
next >
Wrap
Text File
|
1989-02-08
|
39KB
|
1,070 lines
#define INCL_PM
#include <os2.h>
#include <stdlib.h>
#include <malloc.h>
#include "maze.h"
// Added these #defines for the four colored items, replacing the literal
// values which I found in the code. (NjB 2/8/89)
#define WALLCOLOR CLR_PALEGRAY
#define FLOORCOLOR CLR_BLACK
#define GOODPATHCOLOR CLR_GREEN
#define BADPATHCOLOR CLR_RED
typedef struct row_rec
{
char *row_ptr;
struct row_rec *predecessor_ptr;
struct row_rec *successor_ptr;
} *row_rec_ptr;
typedef struct stack_1_rec
{
unsigned char index_1;
struct stack_1_rec *next_ptr;
} *stack_1_rec_ptr;
typedef struct stack_2_rec
{
unsigned char index_1;
unsigned char index_2;
struct stack_2_rec *next_ptr;
} *stack_2_rec_ptr;
static void clear_paths(row_rec_ptr *,int *);
MRESULT EXPENTRY ClientWndProc(HWND,USHORT,MPARAM,MPARAM);
static void create_maze(int *,int *,row_rec_ptr *,row_rec_ptr *,
int *);
static void destroy_maze(row_rec_ptr *,row_rec_ptr *);
MRESULT EXPENTRY HelpProc(HWND,USHORT,MPARAM,MPARAM);
int cdecl main(void);
static void optionally_have_computer_solve(row_rec_ptr *,
row_rec_ptr *,int *,int *,int *,int *);
static void paint_maze(row_rec_ptr *,int *,int *,int *,int *,int *,
int *,int *,HPS,int *);
static void size_maze(int *,int *,row_rec_ptr *,row_rec_ptr *,
int *,int *,int *,int *,int *,int *,int *,int *,int *,
int *,int *,int *);
int cdecl main(void)
{
ULONG ctldata;
HAB hAB;
HMQ hmq;
HWND hwndClient;
HWND hwndFrame;
QMSG qmsg;
static CHAR szClientClass [] = "Maze";
hAB=WinInitialize(NULL);
hmq=WinCreateMsgQueue(hAB,0);
WinRegisterClass(hAB,(PCH) szClientClass,(PFNWP) ClientWndProc,
CS_SYNCPAINT|CS_SIZEREDRAW,0);
ctldata=FCF_STANDARD & ~FCF_ACCELTABLE & ~FCF_ICON;
hwndFrame=WinCreateStdWindow(HWND_DESKTOP,
WS_VISIBLE,&ctldata,
(PCH) szClientClass,NULL,0L,(HMODULE) NULL,ID_MAINMENU,
(HWND FAR *) &hwndClient);
WinShowWindow(hwndFrame,TRUE);
while (WinGetMsg(hAB,(PQMSG) &qmsg,(HWND) NULL,0,0))
WinDispatchMsg(hAB,(PQMSG) &qmsg);
WinDestroyWindow(hwndFrame);
WinDestroyMsgQueue(hmq);
WinTerminate(hAB);
return(0);
}
MRESULT EXPENTRY ClientWndProc(HWND hwnd,USHORT msg,MPARAM mp1,
MPARAM mp2)
{
static row_rec_ptr current_ptr;
int delta_index_1;
static int delta_x [4] [24];
static int delta_y [4] [24];
static int fatal_error;
USHORT frequency;
HPS hPS;
HWND hwndMenu;
static int magnitude_delta_x;
static int magnitude_delta_y;
static int max_x;
static int max_y;
row_rec_ptr next_ptr;
static int num_columns;
static int num_rows;
int passage_found;
static POINTL position;
static row_rec_ptr row_head;
static row_rec_ptr row_tail;
static int r_n [8];
static int solved;
static int twice_magnitude_delta_x;
static int twice_magnitude_delta_y;
static int x;
static int x_max;
static int y_max;
int x_next;
switch (msg)
{
case WM_CREATE:
solved=TRUE;
max_x=0;
max_y=0;
create_maze(&delta_x[0][0],&delta_y[0][0],
&row_head,&row_tail,&fatal_error);
break;
case WM_CHAR:
if ((! solved) && (! fatal_error)
&& (max_x >= 20) && (max_y >= 20)
&& (! ((ULONG) KC_KEYUP & (ULONG) mp1)))
{
passage_found=TRUE;
if ((ULONG) KC_CHAR & (ULONG) mp1)
switch (SHORT1FROMMP(mp2))
{
case '8':
delta_index_1=1;
break;
case '4':
delta_index_1=2;
break;
case '6':
delta_index_1=0;
break;
case '2':
delta_index_1=3;
break;
default:
passage_found=FALSE;
break;
}
else
{
if ((ULONG) KC_VIRTUALKEY & (ULONG) mp1)
switch (SHORT2FROMMP(mp2))
{
case VK_UP:
delta_index_1=1;
break;
case VK_LEFT:
delta_index_1=2;
break;
case VK_RIGHT:
delta_index_1=0;
break;
case VK_DOWN:
delta_index_1=3;
break;
break;
default:
passage_found=FALSE;
break;
}
}
if (passage_found)
{
switch (delta_y[delta_index_1][0])
{
case -1:
x_next=x;
next_ptr=current_ptr->predecessor_ptr;
break;
case 1:
x_next=x;
next_ptr=current_ptr->successor_ptr;
break;
default:
x_next=x+delta_x[delta_index_1][0];
next_ptr=current_ptr;
break;
}
if (*((next_ptr->row_ptr)+x_next) == 'W')
passage_found=FALSE;
else
if (next_ptr->predecessor_ptr == NULL)
passage_found=FALSE;
else
{
hPS=WinGetPS(hwnd);
GpiMove(hPS,&position);
if (*((next_ptr->row_ptr)+x_next) == 'S')
{
GpiSetColor(hPS,BADPATHCOLOR);
*((current_ptr->row_ptr)+x)='A';
*((next_ptr->row_ptr)+x_next)='A';
}
else
{
GpiSetColor(hPS,GOODPATHCOLOR);
*((next_ptr->row_ptr)+x_next)='S';
}
switch (delta_y[delta_index_1][0])
{
case -1:
next_ptr=next_ptr->predecessor_ptr;
position.y-=twice_magnitude_delta_y;
break;
case 1:
next_ptr=next_ptr->successor_ptr;
if (next_ptr == NULL)
position.y+=magnitude_delta_y;
else
position.y+=twice_magnitude_delta_y;
break;
default:
x_next+=delta_x[delta_index_1][0];
position.x+=(twice_magnitude_delta_x
*delta_x[delta_index_1][0]);
break;
}
GpiLine(hPS,&position);
WinReleasePS(hPS);
current_ptr=next_ptr;
x=x_next;
if (current_ptr == NULL)
{
solved=TRUE;
frequency=10;
for (delta_index_1=1; delta_index_1 <= 100;
delta_index_1++)
{
DosBeep(frequency,56);
frequency+=10;
}
}
else
*((current_ptr->row_ptr)+x)='S';
}
}
if ((! passage_found)
&& (SHORT2FROMMP(mp2) != VK_NUMLOCK))
DosBeep(120,333);
}
return((MRESULT) 1);
break;
case WM_COMMAND:
hwndMenu=WinWindowFromID(WinQueryWindow(hwnd,QW_PARENT,FALSE),
FID_MENU);
switch (COMMANDMSG(&msg)->cmd)
{
case IDM_CLEAR:
if (! fatal_error)
{
clear_paths(&row_head,&num_columns);
position.x=magnitude_delta_x;
position.y=magnitude_delta_y;
current_ptr=row_head->successor_ptr;
x=1;
solved=FALSE;
}
WinInvalidateRect(hwnd,NULL,FALSE);
break;
case IDM_NEW:
if ((max_x >= 20) && (max_y >= 20))
{
size_maze(&delta_x[0][0],&delta_y[0][0],&row_head,
&row_tail,&magnitude_delta_x,&magnitude_delta_y,
&max_x,&max_y,&num_columns,&num_rows,&r_n[0],
&twice_magnitude_delta_x,&twice_magnitude_delta_y,
&x_max,&y_max,&fatal_error);
if (! fatal_error)
{
position.x=magnitude_delta_x;
position.y=magnitude_delta_y;
current_ptr=row_head->successor_ptr;
x=1;
}
}
solved=FALSE;
WinInvalidateRect(hwnd,NULL,FALSE);
break;
case IDM_SOLVE:
if ((! fatal_error) && (max_x >= 20) && (max_y >= 20))
{
clear_paths(&row_head,&num_columns);
optionally_have_computer_solve(&row_head,&row_tail,
&delta_x[0][0],&delta_y[0][0],&num_columns,
&fatal_error);
solved=TRUE;
}
WinInvalidateRect(hwnd,NULL,FALSE);
break;
case IDM_HELP:
WinDlgBox(HWND_DESKTOP,hwnd,HelpProc,NULL,IDD_HELPBOX,
NULL);
break;
default:
break;
}
break;
case WM_SIZE:
solved=FALSE;
max_x=SHORT1FROMMP(mp2)-1;
max_y=SHORT2FROMMP(mp2)-1;
if ((max_x >= 20) && (max_y >= 20))
{
size_maze(&delta_x[0][0],&delta_y[0][0],&row_head,
&row_tail,&magnitude_delta_x,&magnitude_delta_y,
&max_x,&max_y,&num_columns,&num_rows,&r_n[0],
&twice_magnitude_delta_x,&twice_magnitude_delta_y,
&x_max,&y_max,&fatal_error);
if (! fatal_error)
{
position.x=magnitude_delta_x;
position.y=magnitude_delta_y;
current_ptr=row_head->successor_ptr;
x=1;
}
solved=FALSE;
}
break;
case WM_ERASEBACKGROUND:
return(TRUE);
break;
case WM_PAINT:
hPS=WinBeginPaint(hwnd,(HPS) NULL,(PWRECT) NULL);
if ((max_x >= 20) && (max_y >= 20))
paint_maze(&row_head,&num_columns,&magnitude_delta_x,
&magnitude_delta_y,&twice_magnitude_delta_x,
&twice_magnitude_delta_y,&x_max,&y_max,hPS,&fatal_error);
WinEndPaint(hPS);
break;
case WM_DESTROY:
destroy_maze(&row_head,&row_tail);
break;
default:
return(WinDefWindowProc(hwnd,msg,mp1,mp2));
break;
}
return(0L);
}
MRESULT EXPENTRY HelpProc(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
{
switch (msg)
{
case WM_COMMAND:
switch (COMMANDMSG(&msg)->cmd)
{
case DID_OK:
case DID_CANCEL:
WinDismissDlg(hwnd,TRUE);
break;
default:
break;
}
break;
default:
return(WinDefDlgProc(hwnd,msg,mp1,mp2));
}
return(0);
}
static void create_maze(delta_x,delta_y,row_head,row_tail,fatal_error)
int *delta_x;
int *delta_y;
row_rec_ptr *row_head;
row_rec_ptr *row_tail;
int *fatal_error;
{
int delta_index_1a;
int delta_index_1b;
int delta_index_1c;
int delta_index_1d;
int delta_index_2;
*fatal_error=FALSE;
*delta_x=1;
*(delta_y+24)=1;
*(delta_x+48)=-1;
*(delta_y+72)=-1;
*delta_y=0;
*(delta_x+24)=0;
*(delta_y+48)=0;
*(delta_x+72)=0;
delta_index_2=-1;
for (delta_index_1a=0; delta_index_1a < 4; delta_index_1a++)
for (delta_index_1b=0; delta_index_1b < 4; delta_index_1b++)
if (delta_index_1a != delta_index_1b)
for (delta_index_1c=0; delta_index_1c < 4;
delta_index_1c++)
if ((delta_index_1a != delta_index_1c)
&& (delta_index_1b != delta_index_1c))
for (delta_index_1d=0; delta_index_1d < 4;
delta_index_1d++)
if ((delta_index_1a != delta_index_1d)
&& (delta_index_1b != delta_index_1d)
&& (delta_index_1c != delta_index_1d))
{
delta_index_2=delta_index_2+1;
*(delta_x+(24*delta_index_1a+delta_index_2))
=*delta_x;
*(delta_y+(24*delta_index_1a+delta_index_2))
=*delta_y;
*(delta_x+(24*delta_index_1b+delta_index_2))
=*(delta_x+24);
*(delta_y+(24*delta_index_1b+delta_index_2))
=*(delta_y+24);
*(delta_x+(24*delta_index_1c+delta_index_2))
=*(delta_x+48);
*(delta_y+(24*delta_index_1c+delta_index_2))
=*(delta_y+48);
*(delta_x+(24*delta_index_1d+delta_index_2))
=*(delta_x+72);
*(delta_y+(24*delta_index_1d+delta_index_2))
=*(delta_y+72);
}
*row_head=NULL;
*row_tail=NULL;
return;
}
static void size_maze(delta_x,delta_y,row_head,row_tail,
magnitude_delta_x,magnitude_delta_y,max_x,max_y,num_columns,num_rows,
r_n,twice_magnitude_delta_x,twice_magnitude_delta_y,x_max,y_max,
fatal_error)
int *delta_x;
int *delta_y;
row_rec_ptr *row_head;
row_rec_ptr *row_tail;
int *magnitude_delta_x;
int *magnitude_delta_y;
int *max_x;
int *max_y;
int *num_columns;
int *num_rows;
int *r_n;
int *twice_magnitude_delta_x;
int *twice_magnitude_delta_y;
int *x_max;
int *y_max;
int *fatal_error;
{
int column_num;
char *column_ptr;
row_rec_ptr current_ptr;
int finished;
int delta_index_1;
int delta_index_2;
int digit;
int digit_num;
row_rec_ptr next_ptr;
row_rec_ptr previous_ptr;
int recurse;
int r_n_index_1;
int r_n_index_2;
int row_num;
DATETIME seed;
stack_2_rec_ptr stack_head;
stack_2_rec_ptr stack_ptr;
int sum;
int tem_int;
int x;
int x_next;
int x_out;
int y;
int y_out;
DosGetDateTime(&seed);
*r_n=seed.year%29;
*(r_n+1)=seed.month;
*(r_n+2)=seed.day%29;
*(r_n+3)=seed.hours;
*(r_n+4)=seed.minutes%29;
*(r_n+5)=seed.seconds%29;
*(r_n+6)=seed.hundredths%29;
*(r_n+7)=0;
*num_columns=(*max_x)/10;
*num_rows=(*max_y)/10;
*magnitude_delta_x=(*max_x)/(*num_columns)/2;
*twice_magnitude_delta_x
=(*magnitude_delta_x)+(*magnitude_delta_x);
*magnitude_delta_y=(*max_y)/(*num_rows)/2;
*twice_magnitude_delta_y
=(*magnitude_delta_y)+(*magnitude_delta_y);
*x_max=*twice_magnitude_delta_x*(*num_columns);
*y_max=*twice_magnitude_delta_y*(*num_rows);
while (*row_head != NULL)
{
free((*row_head)->row_ptr);
previous_ptr=*row_head;
*row_head=(*row_head)->successor_ptr;
free((char *) previous_ptr);
}
if ((*row_head=(struct row_rec *)
malloc((unsigned) sizeof(struct row_rec))) == NULL)
*fatal_error=TRUE;
else
{
(*row_head)->predecessor_ptr=NULL;
(*row_head)->successor_ptr=NULL;
*row_tail=*row_head;
if (((*row_head)->row_ptr=
malloc((unsigned) 2*(*num_columns)+1)) == NULL)
*fatal_error=TRUE;
else
{
column_ptr=(*row_head)->row_ptr;
for (column_num=0; column_num < 2*(*num_columns)+1;
column_num++)
{
*column_ptr='W';
column_ptr++;
}
}
}
row_num=1;
while ((row_num <= *num_rows) && (! *fatal_error))
{
if ((current_ptr=(struct row_rec *)
malloc((unsigned) sizeof(struct row_rec))) == NULL)
*fatal_error=TRUE;
else
{
(*row_tail)->successor_ptr=current_ptr;
current_ptr->predecessor_ptr=*row_tail;
current_ptr->successor_ptr=NULL;
*row_tail=current_ptr;
if ((current_ptr->row_ptr=
malloc((unsigned) 2*(*num_columns)+1)) == NULL)
*fatal_error=TRUE;
else
{
column_ptr=current_ptr->row_ptr;
for (column_num=0; column_num < 2*(*num_columns)+1;
column_num++)
{
*column_ptr='W';
column_ptr++;
}
}
}
if ((current_ptr=(struct row_rec *)
malloc((unsigned) sizeof(struct row_rec))) == NULL)
*fatal_error=TRUE;
else
{
(*row_tail)->successor_ptr=current_ptr;
current_ptr->predecessor_ptr=*row_tail;
current_ptr->successor_ptr=NULL;
*row_tail=current_ptr;
if ((current_ptr->row_ptr=
malloc((unsigned) 2*(*num_columns)+1)) == NULL)
*fatal_error=TRUE;
else
{
column_ptr=current_ptr->row_ptr;
for (column_num=0; column_num < 2*(*num_columns)+1;
column_num++)
{
*column_ptr='W';
column_ptr++;
}
}
}
row_num++;
}
sum=0;
for (digit_num=1; digit_num <= 3; digit_num++)
{
digit=*r_n;
r_n_index_1=0;
for (r_n_index_2=1; r_n_index_2 < 8; r_n_index_2++)
{
tem_int=*(r_n+r_n_index_2);
*(r_n+r_n_index_1)=tem_int;
r_n_index_1++;
digit+=tem_int;
if (digit >= 29)
digit-=29;
}
*(r_n+7)=digit;
sum=29*sum+digit;
}
x=2*(sum%(*num_columns))+1;
sum=0;
for (digit_num=1; digit_num <= 3; digit_num++)
{
digit=*r_n;
r_n_index_1=0;
for (r_n_index_2=1; r_n_index_2 < 8; r_n_index_2++)
{
tem_int=*(r_n+r_n_index_2);
*(r_n+r_n_index_1)=tem_int;
r_n_index_1++;
digit+=tem_int;
if (digit >= 29)
digit-=29;
}
*(r_n+7)=digit;
sum=29*sum+digit;
}
y=2*(sum%(*num_rows))+1;
current_ptr=*row_head;
for (y_out=0; y_out < y; y_out++)
current_ptr=current_ptr->successor_ptr;
finished=FALSE;
recurse=TRUE;
stack_head=NULL;
while ((! finished) && (! *fatal_error))
{
if (recurse)
{
*((current_ptr->row_ptr)+x)=' ';
delta_index_1=0;
do
{
delta_index_2=*r_n;
r_n_index_1=0;
for (r_n_index_2=1; r_n_index_2 < 8; r_n_index_2++)
{
tem_int=*(r_n+r_n_index_2);
*(r_n+r_n_index_1)=tem_int;
r_n_index_1++;
delta_index_2+=tem_int;
if (delta_index_2 >= 29)
delta_index_2-=29;
}
*(r_n+7)=delta_index_2;
}
while (delta_index_2 >= 24);
recurse=FALSE;
}
while ((delta_index_1 < 4)
&& (! recurse)
&& (! *fatal_error))
{
x_next=x+2*(*(delta_x+(24*delta_index_1+delta_index_2)));
if ((x_next <= 0) || (x_next >= 2*(*num_columns)))
delta_index_1++;
else
{
switch (*(delta_y+(24*delta_index_1+delta_index_2)))
{
case -1:
next_ptr=(current_ptr->predecessor_ptr)->
predecessor_ptr;
break;
case 1:
next_ptr=(current_ptr->successor_ptr)->
successor_ptr;
break;
default:
next_ptr=current_ptr;
break;
}
if (next_ptr == NULL)
delta_index_1++;
else
{
if (*((next_ptr->row_ptr)+x_next) == 'W')
{
if (x == x_next)
if ((*(delta_y
+(24*delta_index_1+delta_index_2)))
== 1)
*(((current_ptr->successor_ptr)
->row_ptr)+x)=' ';
else
*(((current_ptr->predecessor_ptr)
->row_ptr)+x)=' ';
else
{
x_out=(x+x_next)/2;
*((current_ptr->row_ptr)+x_out)=' ';
}
x=x_next;
current_ptr=next_ptr;
if ((stack_ptr=
(struct stack_2_rec *) malloc(
(unsigned) sizeof(struct stack_2_rec)))
== NULL)
*fatal_error=TRUE;
else
{
stack_ptr->next_ptr=stack_head;
stack_head=stack_ptr;
stack_head->index_1
=(unsigned char) delta_index_1;
stack_head->index_2
=(unsigned char) delta_index_2;
recurse=TRUE;
}
}
else
delta_index_1++;
}
}
}
if ((! recurse) && (! *fatal_error))
{
delta_index_1=(int) stack_head->index_1;
delta_index_2=(int) stack_head->index_2;
stack_ptr=stack_head;
stack_head=stack_head->next_ptr;
free((char *) stack_ptr);
if (stack_head == NULL)
finished=TRUE;
else
switch (*(delta_y+(24*delta_index_1+delta_index_2)))
{
case -1:
current_ptr=(current_ptr->successor_ptr)->
successor_ptr;
break;
case 1:
current_ptr=(current_ptr->predecessor_ptr)->
predecessor_ptr;
break;
default:
x-=
(2*(*(delta_x+(24*delta_index_1+delta_index_2))));
break;
}
}
}
if (! *fatal_error)
{
*(((*row_head)->row_ptr)+1)='S';
*((((*row_head)->successor_ptr)->row_ptr)+1)='S';
*(((*row_tail)->row_ptr)+(2*(*num_columns)-1))=' ';
}
return;
}
static void paint_maze(row_head,num_columns,magnitude_delta_x,
magnitude_delta_y,twice_magnitude_delta_x,twice_magnitude_delta_y,
x_max,y_max,hPS,fatal_error)
row_rec_ptr *row_head;
int *num_columns;
int *magnitude_delta_x;
int *magnitude_delta_y;
int *twice_magnitude_delta_x;
int *twice_magnitude_delta_y;
int *x_max;
int *y_max;
HPS hPS;
int *fatal_error;
{
int column_num;
row_rec_ptr current_ptr;
POINTL ending_position;
int even;
POINTL path_position;
char *pixel_ptr;
POINTL starting_position;
if (* fatal_error)
{
GpiSetColor(hPS,BADPATHCOLOR);
starting_position.x=0;
starting_position.y=0;
ending_position.x=*x_max;
ending_position.y=*y_max;
GpiMove(hPS,&starting_position);
GpiBox(hPS,DRO_FILL,&ending_position,(long) 0,(long) 0);
DosBeep(60,333);
}
else
{
GpiSetColor(hPS,FLOORCOLOR);
starting_position.x=0;
starting_position.y=0;
ending_position.x=*x_max;
ending_position.y=*y_max;
GpiMove(hPS,&starting_position);
GpiBox(hPS,DRO_FILL,&ending_position,(long) 0,(long) 0);
current_ptr=*row_head;
even=TRUE;
starting_position.y=0;
while (current_ptr != NULL)
{
if (even)
{
pixel_ptr=(current_ptr->row_ptr)+1;
starting_position.x=0;
ending_position.y=starting_position.y;
for (column_num=1; column_num <= *num_columns;
column_num++)
{
ending_position.x=starting_position.x
+(*twice_magnitude_delta_x);
switch (*pixel_ptr)
{
case 'A':
GpiSetColor(hPS,BADPATHCOLOR);
path_position.x=starting_position.x
+(*magnitude_delta_x);
if (starting_position.y == 0)
path_position.y=0;
else
path_position.y=starting_position.y
-(*magnitude_delta_y);
GpiMove(hPS,&path_position);
if (current_ptr->successor_ptr == NULL)
path_position.y=starting_position.y;
else
path_position.y=starting_position.y
+(*magnitude_delta_y);
GpiLine(hPS,&path_position);
break;
case 'S':
GpiSetColor(hPS,GOODPATHCOLOR);
path_position.x=starting_position.x
+(*magnitude_delta_x);
if (starting_position.y == 0)
path_position.y=0;
else
path_position.y=starting_position.y
-(*magnitude_delta_y);
GpiMove(hPS,&path_position);
if (current_ptr->successor_ptr == NULL)
path_position.y=starting_position.y;
else
path_position.y=starting_position.y
+(*magnitude_delta_y);
GpiLine(hPS,&path_position);
break;
case 'W':
GpiSetColor(hPS,WALLCOLOR);
GpiMove(hPS,&starting_position);
GpiLine(hPS,&ending_position);
break;
default:
break;
}
starting_position.x=ending_position.x;
pixel_ptr+=2;
}
}
else
{
pixel_ptr=(current_ptr->row_ptr);
starting_position.x=0;
ending_position.y=starting_position.y
+(*twice_magnitude_delta_y);
for (column_num=1; column_num <= *num_columns;
column_num++)
{
ending_position.x=starting_position.x;
switch (*pixel_ptr)
{
case 'A':
GpiSetColor(hPS,BADPATHCOLOR);
path_position.x=starting_position.x
-(*magnitude_delta_x);
path_position.y=starting_position.y
+(*magnitude_delta_y);
GpiMove(hPS,&path_position);
path_position.x=starting_position.x
+(*magnitude_delta_x);
GpiLine(hPS,&path_position);
break;
case 'S':
GpiSetColor(hPS,GOODPATHCOLOR);
path_position.x=starting_position.x
-(*magnitude_delta_x);
path_position.y=starting_position.y
+(*magnitude_delta_y);
GpiMove(hPS,&path_position);
path_position.x=starting_position.x
+(*magnitude_delta_x);
GpiLine(hPS,&path_position);
break;
case 'W':
GpiSetColor(hPS,WALLCOLOR);
GpiMove(hPS,&starting_position);
GpiLine(hPS,&ending_position);
break;
default:
break;
}
starting_position.x+=(*twice_magnitude_delta_x);
pixel_ptr+=2;
}
ending_position.x=starting_position.x;
GpiSetColor(hPS,WALLCOLOR);
GpiMove(hPS,&starting_position);
GpiLine(hPS,&ending_position);
starting_position.y=ending_position.y;
}
even=! even;
current_ptr=current_ptr->successor_ptr;
}
DosBeep(1000,333);
}
return;
}
static void destroy_maze(row_head,row_tail)
row_rec_ptr *row_head;
row_rec_ptr *row_tail;
{
row_rec_ptr previous_ptr;
while (*row_head != NULL)
{
free((*row_head)->row_ptr);
previous_ptr=*row_head;
*row_head=(*row_head)->successor_ptr;
free((char *) previous_ptr);
}
*row_tail=NULL;
return;
}
static void clear_paths(row_head,num_columns)
row_rec_ptr *row_head;
int *num_columns;
{
row_rec_ptr current_ptr;
int x;
current_ptr=*row_head;
while (current_ptr != NULL)
{
for (x=1; x < 2*(*num_columns); x++)
if (*((current_ptr->row_ptr)+x) != 'W')
*((current_ptr->row_ptr)+x)=' ';
current_ptr=current_ptr->successor_ptr;
}
*(((*row_head)->row_ptr)+1)='S';
*((((*row_head)->successor_ptr)->row_ptr)+1)='S';
return;
}
static void optionally_have_computer_solve(row_head,row_tail,delta_x,
delta_y,num_columns,fatal_error)
row_rec_ptr *row_head;
row_rec_ptr *row_tail;
int *delta_x;
int *delta_y;
int *num_columns;
int *fatal_error;
{
row_rec_ptr current_ptr;
int finished;
unsigned char delta_index_1;
row_rec_ptr next_ptr;
int recurse;
stack_1_rec_ptr stack_head;
stack_1_rec_ptr stack_ptr;
int x;
int x_next;
x=1;
current_ptr=(*row_head)->successor_ptr;
next_ptr=current_ptr->successor_ptr;
finished=FALSE;
recurse=TRUE;
stack_head=NULL;
while ((! finished) && (! *fatal_error))
{
if (recurse)
{
delta_index_1=0;
recurse=FALSE;
};
while ((delta_index_1 < 4)
&& (! finished)
&& (! recurse)
&& (! *fatal_error))
{
switch (*(delta_y+(24*delta_index_1)))
{
case -1:
x_next=x;
next_ptr=current_ptr->predecessor_ptr;
break;
case 1:
x_next=x;
next_ptr=current_ptr->successor_ptr;
break;
default:
next_ptr=current_ptr;
x_next=x+(*(delta_x+(24*delta_index_1)));
break;
}
if (*((next_ptr->row_ptr)+x_next) == ' ')
{
*((next_ptr->row_ptr)+x_next)='S';
switch (*(delta_y+(24*delta_index_1)))
{
case -1:
next_ptr=next_ptr->predecessor_ptr;
break;
case 1:
next_ptr=next_ptr->successor_ptr;
break;
default:
x_next+=(*(delta_x+(24*delta_index_1)));
break;
}
if (next_ptr != NULL)
{
*((next_ptr->row_ptr)+x_next)='S';
x=x_next;
current_ptr=next_ptr;
if ((stack_ptr=(struct stack_1_rec *) malloc(
(unsigned) sizeof(struct stack_1_rec)))
== NULL)
*fatal_error=TRUE;
else
{
stack_ptr->next_ptr=stack_head;
stack_head=stack_ptr;
stack_head->index_1
=(unsigned char) delta_index_1;
recurse=TRUE;
}
}
else
finished=TRUE;
}
else
delta_index_1++;
};
if ((delta_index_1 >= 4) && (! *fatal_error))
{
*((current_ptr->row_ptr)+x)=' ';
x_next=x;
next_ptr=current_ptr;
delta_index_1=stack_head->index_1;
stack_ptr=stack_head;
stack_head=stack_head->next_ptr;
free((char *) stack_ptr);
switch (*(delta_y+(24*delta_index_1)))
{
case -1:
current_ptr=current_ptr->successor_ptr;
*((current_ptr->row_ptr)+x)=' ';
current_ptr=current_ptr->successor_ptr;
break;
case 1:
current_ptr=current_ptr->predecessor_ptr;
*((current_ptr->row_ptr)+x)=' ';
current_ptr=current_ptr->predecessor_ptr;
break;
default:
x-=(*(delta_x+(24*delta_index_1)));
*((current_ptr->row_ptr)+x)=' ';
x-=(*(delta_x+(24*delta_index_1)));
break;
}
delta_index_1++;
}
};
if (! *fatal_error)
*(((*row_tail)->row_ptr)+(2*(*num_columns)-1))='S';
while (stack_head != NULL)
{
stack_ptr=stack_head;
stack_head=stack_head->next_ptr;
free((char *) stack_ptr);
}
return;
}