0 Members and 3 Guests are viewing this topic.
RULE is "right"FINDLOOP is falseBOTTLENECK is falseCUR is the current pixelMARK is the first mark, and is not setMARK2 is the second mark, and is not setmain loop: if CUR is bound by 4 edge pixels paint CUR all possible pixels have been filled, so exit the routine if CUR is bound by 3 edge pixels paint CUR move based on RULE continue main loop if CUR is bound by 2 edge pixels if the two bounding edge pixels are not across from each other, and the corner opposite both edge pixels is not filled paint CUR move according to RULE continue main loop else if RULE is "right" and MARK is not set set MARK to CUR's location and direction set FINDLOOP to false else, if MARK is set if MARK2 is not set if CUR is at MARK's location if CUR's direction is the same as MARK's remove MARK set RULE to "right" else set RULE to "left" set CUR to MARK's direction set FINDLOOP to false else, if FINDLOOP is true set MARK2 to CUR's location and direction else if CUR is at MARK's location set CUR to MARK2's direction and location remove MARK remove MARK2 set RULE to "right" else if CUR is at MARK2's location set MARK to MARK2's direction and location set CUR's direction to MARK2's direction remove MARK2 if RULE is "right" and MARK is not set if BOTTLENECK is false paint CUR set BOTTLENECK to false move according to RULE continue main loop if CUR is bound by 1 edge pixel if RULE is "left" and FINDLOOP is false set FINDLOOP to true else, if neither of the corners opposite the bounding pixel are filled paint CUR move according to RULE continue main loop if CUR is bound by 0 edge pixels if RULE is "left" and FINDLOOP is false set FINDLOOP to true set BOTTLENECK to false move any direction (use a default direction, not a random one) continue main loop##############################how to move according to RULE: if CUR is filled or the rule-side-corner is filled move CUR one step forward else if MARK is at the pixel one step forward set BOTTLENECK to true else, if MARK2 is at the pixel one step forward set MARK to MARK2's direction and location set CUR's direction to MARK2's direction remove MARK2 if RULE is "left" and FINDLOOP is false if either the pixel two steps forward is filled or the non-rule-side pixel is filled set FINDLOOP to true move CUR one step forward move CUR one step to the RULE side##############################every time you paint: remove MARK, if set remove MARK2, if set set FINDLOOP to false set BOTTLENECK to false set RULE to "right"
To be consistent, each case in the main loop should probably end with continue main loop. Also, I don't see any code that sets MARK2.
Interesting, thanks for the link. I am curious if in some occasions it can loop forever, though? Because once it seemed to go through the same path 5 times until it finally started filling more stuff, and as an ASM program, if it can end up into an endless loop, then that means a battery pull/RAM Clear
Hmm, maybe I should rewrite my JavaScript minesweeper to use a better algorithm.I just made mine form scratch, so its probably not efficient.
Ah maybe I didn't notice, since it was going on pretty fast. Also I'm curious how fast this would be in z80 ASM, considering you don't have to update the LCD every frame but only at the end.
For javascript, you shouldn't have to worry about stack or memory issues, so a simple recursive flood-fill would be best. This one is much too slow to be worthwhile for any system that can handle recursive/stack-based flood-fills.
How fast is this when it only draws to the screen when it finishes rather than plot every pixel individually?