Around this time, it seemed like everyone in the world was obsessed with this game 2048. I was never very good at these things and didn't really have the patience to try to get good, so I usually tried to find a way to "hack my way to the top". In this case, I hypothesized that just alternating between two keystrokes would lead you to success depending on the initial conditions and some luck in terms of what tiles you got during the course of the game. I think it proved pretty successful, doing better than I had been able to do myself, but I don't think it ever won the game.

read more
delay 2

-- 123: left, 124: right, 126 up, 125 down

tell application "System Events"
	--set now to the seconds of the (current date)
	--set later to now + 3
	--if later > 60 then set later to later - 60
	
	
	set counter to 1
	repeat while 1 < 2
		
		
		if counter mod 2 is equal to 1 then
			key down (key code 123)
		else
			key down (key code 126)
		end if
		
		
		if counter mod 20 is equal to 0 then
			
			key down (key code 124)
			
			
			repeat 5 times
				key down (key code 126)
			end repeat
			
		end if
		
		
		--if counter mod 100 is equal to 0 then
		--	tell process "Google Chrome"
		--		display dialog "done?"
		--	end tell
		--	tell application "System Events" to set frontmost of process "Google Chrome" to true
		--	end if
		
		if counter mod 100 is equal to 0 then
			delay 0.3
		end if
		
		if counter mod 800 is equal to 0 then
			delay 1
			tell application "Safari"
				activate
				tell document 1
					do JavaScript "document.getElementsByClassName('retry-button')[0].click()"
				end tell
			end tell
		end if
		
		
		set counter to counter + 1
		
	end repeat
end tell