View difference between Paste ID: UvprK4Pm and nxPcv8ih
SHOW: | | - or go back to the newest paste.
1-
clock = [
1+
_ms_clock = [
2
	strreplace (concat (
3-
		zeropad (div $arg1 3600000)
3+
		div $arg1 1000
4
	) (
5-
		zeropad (mod (div $arg1 60000) 60)
5+
		padnum (padnum (mod $arg1 1000) 10) 100
6
	)) " " ":"
7-
		zeropad (mod (div $arg1 1000) 60)
7+
8
9
padnum = [concatword (? (< $arg1 $arg2) 0) $arg1]
10
append = [$arg1 = (concat (getalias $arg1) $arg2)]
11-
zeropad = [concatword (? (< $arg1 10) 0) $arg1]
11+
precf = [substr $arg1 0 (+ (strstr $arg1 ".") (+ $arg2 1))]
12
13-
precf = [substr $arg1 0 (+ (strstr $arg1 .) (+ $arg2 1))]
13+
14
_ms_w  = 9  // board width
15
_ms_m  = 10 // board mines
16
_ms_th = 9  // temp H
17
_ms_tw = 9  // temp W
18
_ms_tm = 10 // temp M
19-
_ms_mt = 0  // board tiles (total)
19+
_ms_bt = 0  // board tiles (total)
20
_ms_t1 = 0  // timer start (ms)
21-
_ms_t  = 0  // timer start (ms)
21+
_ms_t2 = 0  // timer end (ms)
22-
_ms_tt = 0  // timer toggle
22+
_ms_ua = 1  // undo toggle
23
_ms_u  = 0  // undo counter
24
_ms_um = 0  // undo max
25-
_ms_up = -1 // undo tile position
25+
26
_ms_gm = 0  // game mode: 0 waiting; 1 active; 2 failure ; 3 victory
27
28
_ms_mf = "" // board containing mine placement
29
_ms_mp = "" // supplement list with mine positions
30
_ms_fp = "" // supplement list with flag positions
31
_ms_nf = "" // board containing tile numbers
32-
_ms_tf = "" // board used upon victory/fail
32+
33
_ms_tq = "" // supplement list with tile reveal queue
34
35
_ms_tile_find = [
36
	local n c1 c2 c3 c4 c5 c6 c7 c8
37
	n = 0
38
	c1 = (- $arg9 $_ms_w)       // UP
39
	c2 = (+ $arg9 $_ms_w)       // DN
40
	c3 = (- $arg9 1)            // LT
41
	c4 = (+ $arg9 1)            // RT
42
	c5 = (- $arg9 (+ $_ms_w 1)) // UP-LT
43
	c6 = (- $arg9 (- $_ms_w 1)) // UP-RT
44
	c7 = (+ $arg9 (- $_ms_w 1)) // DN-LT
45
	c8 = (+ $arg9 (+ $_ms_w 1)) // DN-RT
46-
	if (< $c2 $_ms_mt)                                          $arg2 // DN
46+
47
	if (< $c2 $_ms_bt)                                          $arg2 // DN
48
	if (> (mod $arg9 $_ms_w) 0)                                 $arg3 // LT
49
	if (< (mod $arg9 $_ms_w) (- $_ms_w 1))                      $arg4 // RT
50
	if (&& (> $c5 -1) (> (mod $arg9 $_ms_w) 0))                 $arg5 // UP-LT
51-
	if (&& (< $c7 $_ms_mt) (> (mod $arg9 $_ms_w) 0))            $arg7 // DN-LT
51+
52-
	if (&& (< $c8 $_ms_mt) (< (mod $arg9 $_ms_w) (- $_ms_w 1))) $arg8 // DN-RT
52+
	if (&& (< $c7 $_ms_bt) (> (mod $arg9 $_ms_w) 0))            $arg7 // DN-LT
53
	if (&& (< $c8 $_ms_bt) (< (mod $arg9 $_ms_w) (- $_ms_w 1))) $arg8 // DN-RT
54
	arg10
55
]
56
57-
	if (&& [= $_ms_gm 1] [=s (at $_ms_cf $arg1) "C"]) [
57+
58-
		local n
58+
	if (&& [= $_ms_gm 1] [=s (at $_ms_cf $arg1) "H"]) [
59
		local n t
60
		n = (at $_ms_nf $arg1)
61-
			// Reserved for mines!
61+
62
			// mark the mine as hit
63-
			_ms_up = $arg1 ; _ms_gm = 2
63+
			_ms_cf = (listsplice $_ms_cf "R" $arg1 1)
64-
			
64+
			// if lives are enabled, reduce by one, otherwise
65
			if (&& $_ms_ua $_ms_u) [ _ms_u = (- $_ms_u 1) ] [
66-
			// Reserved for flags!
66+
				// game over, board is populated by hit and undiscovered mines and flag marks
67-
			
67+
				looplist i $_ms_mp [
68
					if (!=s (at $_ms_cf $i) "R") [
69
						_ms_cf = (listsplice $_ms_cf "X" $i 1)
70
					]
71
				]
72-
					if (= @@@n 0) [
72+
				_ms_gm = 2
73-
						_ms_tile_open $c@@@(+ $i 1)
73+
				_ms_t2 = (getmillis)
74
			]
75
		] "R" [
76-
			) $arg1 ]
76+
			// do nothing here, simply skip
77
		] "F" [
78-
			if (= $_ms_pc (- $_ms_mt $_ms_m)) [
78+
			// do nothing here, simply skip
79-
				// In case of board completion, victory
79+
		] "0" [
80-
				_ms_gm = 3
80+
			// explore all surrounding tiles until number border
81
			append _ms_tq $arg1
82
			while [listlen $_ms_tq] [
83
				do [ _ms_tile_find @(
84
					loopconcat i 8 [result [[
85
						// make sure the tile is not revealed, otherwise skip tile
86
						if (=s (at $_ms_cf $c@@(+ $i 1)) "H") [
87
							// make sure tile is blank and not in work queue, then add it
88
							if (&& [=s (at $_ms_nf $c@@@@(+ $i 1)) "0"] [< (indexof $_ms_tq $c@@@@(+ $i 1)) 0]) [
89
								append _ms_tq $c@@@@(+ $i 1)
90-
	_ms_h = $_ms_th ; _ms_w = $_ms_tw ; _ms_nf = ""
90+
							]
91-
	_ms_mt = (* $_ms_h $_ms_w) ; _ms_pc = 0; i = 0
91+
							// reveal the tile around the blank tile and add to completion percentage
92
							_ms_cf = (listsplice $_ms_cf (at $_ms_nf $c@@@(+ $i 1)) $c@@@(+ $i 1) 1)
93-
	_ms_up = -1 ; _ms_t = (getmillis) ; _ms_tt = 1
93+
							_ms_pc = (+ $_ms_pc 1)
94-
	_ms_gm = 1 ; 
94+
95
					]]]
96-
	_ms_mf = (loopconcat i $_ms_mt [result "0"])
96+
				) (at $_ms_tq 0) ]
97-
	_ms_cf = (loopconcat i $_ms_mt [result "C"])
97+
				// remove used tile from work queue
98
				_ms_tq = (sublist $_ms_tq 1)
99
			]
100-
		r = (rnd $_ms_mt)
100+
101-
		if (! (at $_ms_mf $r)) [ // Make sure it's not writing to a previously picked spot
101+
			// reveal the tile and add to completion percentage
102
			_ms_cf = (listsplice $_ms_cf $n $arg1 1)
103
			_ms_pc = (+ $_ms_pc 1)
104
		]
105
			// in case of board completion, victory
106
		if (= $_ms_pc (- $_ms_bt $_ms_m)) [
107-
	loop y $_ms_mt [
107+
			_ms_gm = 3 ; _ms_t2 = (getmillis)
108
		]
109
	]
110
]
111
112
_ms_make_board = [
113
	// Initialise variables
114
	local i n r
115
	_ms_th = $arg1 ; _ms_tw = $arg2 ; _ms_m = $arg3
116
	_ms_h = $_ms_th ; _ms_w = $_ms_tw ; _ms_tm = $_ms_m
117
	_ms_bt = (* $_ms_h $_ms_w) ; _ms_pc = 0; i = 0
118
	_ms_um = (+ (div $_ms_m 20) 1); _ms_u = $_ms_um
119
	_ms_t1 = (getmillis) ; _ms_t2 = 0 ; _ms_tq = ""
120
	_ms_gm = 1 ; _ms_mp = "" ; _ms_fp = "" ; _ms_nf = ""
121
	// Initialise boards
122
	_ms_mf = (loopconcat i $_ms_bt [result "0"])
123-
			absf (precf (*f (divf $_ms_pc (- $_ms_mt $_ms_m)) 100) 1)
123+
	_ms_cf = (loopconcat i $_ms_bt [result "H"])
124
	// Begin randomly placing mines
125-
			clock (? $_ms_tt (- (getmillis) $_ms_t) 0)
125+
126
		r = (rnd $_ms_bt)
127
		// Make sure it's not writing to a previously picked spot
128
		if (! (at $_ms_mf $r)) [
129
			_ms_mf = (listsplice $_ms_mf "1" $r 1)
130
			append _ms_mp $r
131
			i = (+ $i 1)
132
		]
133
	]
134
	// Generate complete board with numbers
135
	loop y $_ms_bt [
136
		if (at $_ms_mf $y) [ append _ms_nf "X" ] [
137
			do [ _ms_tile_find @(
138
				loopconcat i 8 [result [[
139
					n = (+ (at $_ms_mf $c@@(+ $i 1)) $n)
140
				]]]
141
			) $y [ append _ms_nf $n ] ]
142
		]
143
	]
144-
					_ms_make_board $_ms_th $_ms_tw $_ms_m
144+
145
146-
				guilist [
146+
147-
					guibutton "Undo Move" [
147+
148-
						if (&& [> $_ms_up -1] $_ms_u) [
148+
149-
							_ms_cf = (listsplice $_ms_cf "C" $_ms_up 1)
149+
150-
							_ms_u = (- $_ms_u 1) ; _ms_up = -1 ; _ms_gm = 1
150+
151
			absf (precf (*f (divf $_ms_pc (- $_ms_bt $_ms_m)) 100) 1)
152-
					] 0
152+
153
			_ms_clock (case $_ms_gm 0 0 1 (- (getmillis) $_ms_t1) () (- $_ms_t2 $_ms_t1))
154-
					guitext (format "^f2(%1/%2)" $_ms_u $_ms_um) 0
154+
155
		guistrut 0.5
156-
				guistrut 0.5
156+
157-
				guilist [
157+
158
				loop y $_ms_h [
159-
						guialign 0 [ guitext "" "minesweeper/resize_h.png" ]
159+
160-
						guifield _ms_th 2 [ _ms_th = (max (min $_ms_th 24) 9) ]
160+
161
							n = (+ (* $y $_ms_w) $x)
162
							guiimage (format "packages/icons/minesweeper/%1.png" (at $_ms_cf $n)) [
163-
						guialign 0 [ guitext "" "minesweeper/resize_w.png" ]
163+
164-
						guifield _ms_tw 2 [ _ms_tw = (max (min $_ms_tw 30) 9) ]
164+
165
						]
166
					]
167
				]
168-
						guialign 0 [ guitext "" "minesweeper/mine_raw.png" ]
168+
169-
						guifield _ms_m 3 [ _ms_m = (max (min $_ms_m (div (* $_ms_th $_ms_tw) 3)) 10) ]
169+
170
			guilist [
171
				guibutton "New Minefield" [
172-
				guistrut 1
172+
					_ms_make_board $_ms_th $_ms_tw $_ms_tm
173-
				guibutton "Beginner"     [ _ms_make_board  9  9 10 ] 0
173+
174-
				guibutton "Intermediate" [ _ms_make_board 16 16 40 ] 0
174+
				guitext (format "^f7Lives: ^f2%1/%2" $_ms_u $_ms_um) 0
175-
				guibutton "Expert"       [ _ms_make_board 16 30 80 ] 0
175+
				//if (! $_ms_gm) [
176-
				guistrut 1
176+
177-
				guibutton "^f6Show Board" [ _ms_cf = $_ms_nf ] 0
177+
178
						guilist [
179
							guialign 0 [ guitext "" "minesweeper/resize_h.png" ]
180
							guifield _ms_th 2 [ _ms_th = (max (min $_ms_th 24) 9) ]
181
						]
182
						guilist [
183
							guialign 0 [ guitext "" "minesweeper/resize_w.png" ]
184
							guifield _ms_tw 2 [ _ms_tw = (max (min $_ms_tw 30) 9) ]
185
						]
186
						guistrut 0.5
187
						guilist [
188
							guialign 0 [ guitext "" "minesweeper/mine_raw.png" ]
189
							guifield _ms_tm 3 [ _ms_tm = (max (min $_ms_tm (div (* $_ms_th $_ms_tw) 3)) 10) ]
190
						]
191
					]
192
					guistrut 1
193
					guititle "^f2Difficulty"
194
					guistrut 0.5
195
					guibutton "Beginner"     [ _ms_make_board  9  9 10 ] 0
196
					guibutton "Intermediate" [ _ms_make_board 16 16 40 ] 0
197
					guibutton "Expert"       [ _ms_make_board 16 30 80 ] 0
198
				//]
199
				//guibutton "^f6Show Board" [ _ms_cf = $_ms_nf ] 0
200
			]
201
		]
202
	]
203
] 0