-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbig.c
102 lines (96 loc) · 1.61 KB
/
big.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// The maze demo is taken from Felipe Andres Manzano's blog:
// http://feliam.wordpress.com/2010/10/07/the-symbolic-maze/
//
//
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <stdbool.h>
#define H 13
#define W 17
char maze[H][W]={
"+-+-------------+",
"| | |",
"| | +-----* *---+",
"| | |",
"+---+-* *-------+",
"| |",
"+ +-------------+",
"| | | |#|",
"| | *---+ * * * |",
"| | | | |",
"| +---* +-------+",
"| |",
"+---------------+",};
void draw ()
{
int i, j;
for (i = 0; i < H; i++)
{
for (j = 0; j < W; j++)
printf ("%c", maze[i][j]);
printf ("\n");
}
printf ("\n");
}
int
main (int argc, char *argv[])
{
int x, y; //Player position
int ox, oy; //Old player position
int i = 0; //Iteration number
#define ITERS 512
char program[ITERS];
x = 1;
y = 1;
maze[y][x]='X';
draw();
read(0,program,ITERS);
while(i < ITERS)
{
#ifndef MAZE_NO_BT
maze[y][x]=' ';
#endif
ox = x; //Save old player position
oy = y;
//transition(hashint(x,y));
switch (program[i])
{
case 'w':
y--;
break;
case 's':
y++;
break;
case 'a':
x--;
break;
case 'd':
x++;
break;
default:
printf("Wrong command!(only w,s,a,d accepted!)\n");
printf("You lose!\n");
exit(-1);
}
if (maze[y][x] == '#')
{
assert(0);
}
if (maze[y][x] != ' ') {
x = ox;
y = oy;
}
#ifdef MAZE_NO_BT
if (ox==x && oy==y){
printf("You lose\n");
exit(-2);
}
#endif
maze[y][x]='X';
draw (); //draw it
i++;
}
printf("You lose\n");
}