-
Notifications
You must be signed in to change notification settings - Fork 1
/
sedsweeper
executable file
·99 lines (80 loc) · 1.65 KB
/
sedsweeper
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
#!/bin/sed -f
# Showing the start field.
:parse
# Process the current input.
#flagged
s/\(.*\)F/\1=F/
t flagged
s/0,0/&=1/
s/0,1/&=9/
s/0,2/&=9/
s/1,0/&=2/
s/1,1/&=5/
s/1,2/&=9/
s/2,0/&=9/
s/2,1/&=3/
s/2,2/&=9/
:flagged
# Append the latest input to the process row.
H
# Check whether the player stepped on a bomb.
/=9/ b game_over
# Otherwise, print out the new field.
# Expects a hold space of the form "\nr,c=b", where r(ow) and c(olumn) are
# digits, and b is 0 or 1, whether there's a mine or not. This pattern is
# repeated, seperated by dashes for each bomb known.
# Putting an empty field in the pattern space.
s/.*/---\n---\n---/
# Putting the process line in the pattern space.
G
s/\n\n/\n/
:process_input
# Loop the process line.
s/\(\).\(..\n...\n...\)\n0,0=\(.\)/\1\3\2/
t process_input
s/\(.\).\(.\n...\n...\)\n0,1=\(.\)/\1\3\2/
t process_input
s/\(..\).\(\n...\n...\)\n0,2=\(.\)/\1\3\2/
t process_input
s/\(...\n\).\(..\n...\)\n1,0=\(.\)/\1\3\2/
t process_input
s/\(...\n.\).\(.\n...\)\n1,1=\(.\)/\1\3\2/
t process_input
s/\(...\n..\).\(\n...\)\n1,2=\(.\)/\1\3\2/
t process_input
s/\(...\n...\n\).\(..\)\n2,0=\(.\)/\1\3\2/
t process_input
s/\(...\n...\n.\).\(.\)\n2,1=\(.\)/\1\3\2/
t process_input
s/\(...\n...\n..\).\(\)\n2,2=\(.\)/\1\3\2/
t process_input
# We check if the player just won the game.
/-/ !b finished
:new_input
# Otherwise, we print the pattern and ask for new input.
p
a\
Please input new coordinats
d
:game_over
a\
You lost.
q
:finished
# save the pattern space
H
s/[^F]//g
s/FFFFF//
s/F//
t cheater
:won
a\
Shit this guy is good.
q
:cheater
# Clean up the pattern/hold space.
g
s/\n[^\n]*$//
x
s/.*\n\(...\n...\n...\)/\1/
b new_input