910 points · by golergka · 12y ago · 194 comments
The offending code (from http://gameaboutsquares.com/game.c.js, beautified):
(function($) {
try {
document.createEvent("TouchEvent");
return;
} catch (f) {}
var eventMap = {
mousedown : "touchstart",
mouseup : "touchend",
mousemove : "touchmove"
};
// mouse handling code follows
Never do this! Remove the entire try-catch block. There is absolutely no reason for you to be limiting touch-capable users to touch-only.We're now treating the touch-only versions as optimized for specific platforms. For example, we have a mobile version that is optimized for, and only displays on, Android and iOS. Going forward, we may explore a pointer event polyfill to improve support for less common touch devices.
Just curious, how do you design these levels? Work backwards from the solution?
edit: I'm a little further in, and I'm starting to think the annoying comment thing is on purpose...
They were alright at first but I started developing a sense of urgency, like I just had to complete a few training examples before some kind of main introduction to the "real game" (which I expected to develop into some form of a puzzle game world, with labeled levels and sections, maybe themes, etc). After more and more one liners (that don't add any substance and aren't particularly funny) I became increasingly annoyed and was trying to pass levels just to get past that phase of the game. After a while I realized that that was the whole game, and my expectations had set me off on the wrong foot, so to speak, and I lost the will to continue.
I do like the concept and the puzzles were enjoyable, but I guess my recommendation would be to leave out the comments that make it seem like they are leading up to some prize or event but never actually go anywhere. The complete lack of indication of the level I'm on and where that is in the puzzle world (Am I still in training, or...?) also contributed to me losing interest.
https://gist.github.com/CyberShadow/39f43cf25dac0534f8a9
The solver uses BFS with delayed duplicate detection for pruning visited states (instead of, say, hash tables).
The DDD part can be summed up in two lines of code:
prevStates = (prevStates ~ states).sort.uniq.array();
states = nextStates.sort.uniq.setDifference(prevStates).array();
// ... expand states into nextStates ...
These were part of the solver's code at one point, although now I've expanded them a bit to improve memory efficiency.I love D.
1. Duplicate detection is done delayed and in bulk, not after expanding each node
2. The linear memory access of the bulk check is more cache friendly than random-like hash table access
Allow me to quote from the first Google result:
Surprisingly, delayed duplicate detection is useful even when all nodes fit in memory, resulting in reduced running time due to improved cache performance. In the standard implementation of breadth-first search in memory, the Open list is stored in a hash table. As each new node is generated, it is looked up in the hash table, which often results in a cache miss, since the hash function is designed to randomly scatter the nodes.
http://www.ijcai.org/Past%20Proceedings/IJCAI-2003/PDF/267.p...
Javascript is not the best language to write AI.
(Also, you want the one on the left)
While it's technically possible (several app stores do just that), the results are far from good quality. When colors are used to convey meaning, the transformations needed to allow blind-color users to see them will be application-dependent.
This may be enough to allow these users to play simple games, but ideally developers should learn enough about the human API so as to cater to the real needs of their users. Depending on invisible colors for gameplay should be seen as bad as letting an uncaught exception crash your application.
That's really too bad, because the game is very fun.
Level 21 however is being a pain.
Otherwise, Google Play will have a clone by the weekend if not sooner, and iTunes, maybe a week or two.
I'm not familiar with the Play Store or Android in general but it seems like a lot of clones and cheap ripoffs are available.
Nicely done, I have no negative comments to make. I'd totally pay for this.
Edit: got it. http://www.flotcharts.org/
I am the 1%.
You can also look into some of the research that has been done on Sokoban AI's.
Of the levels I saw (up to 31), the relevant board area was never more than 20x20 and there were never more than 4 arrows. So the state space had size 16(2020 choose 4) ~= 17 billion. Of course most of those states won't be reachable from the starting state... so the actual number of states you need to explore is probably more like a million or even a thousand.
I think a program could solve all of the game's puzzles in under a second.
But yeah, definitely pretty doable with a brute-force memoized search. I imagine a lot of state space could be pruned by doing some analysis of when squares can only move further away from their home dots (and not be turned around or pushed back or anything).
I was wondering, for you guys out there that went past 25, were you able to visualise how the puzzle worked and plan out the moves or did you try different stuff until you got in a situation that seemed solvable and then baffled at the realization that you actually did it?
Still, even with all of that, there was usually one particularly hard state to achieve that required some unusual step, and everything else mostly fell into place afterward.
1) Don't worry about the colors at all, because you can usually shuffle them around to get the right order.
2) If there's a particularly cute combo, it's probably part of the solution.
3) Work out the most likely last few moves, going backwards from a winning position.
Where are the mobile versions? I'd like to play it in my iPad.
Kudos.
Sign of a good game.
Such silliness really drives me away from hn.
1) Ignore the colors and just figure out how to get the pieces on the goal squares (working backwards helps a lot).
2) Find a cyclical part of the puzzle that lets you swap the order of tiles.
Then you just look for any color-agnostic states in Part 2 that overlap with Part 1.
(FF 31 on OSX, why do you ask?)
For me, it was because I had dom.storage.enabled=false. LocalStorage obeys cookie settings, so I guess disabling cookies would do that too.
<meta name="viewport" content="minimal-ui">
[1] : https://itunes.apple.com/us/app/swap-boxes/id753811885?mt=8
One problem with puzzles of this type though, the structure of the problem leads to the solution. If you simply play with the mechanism for re-ordering boxes, you can 'brute force' the solution fairly easily.
https://play.google.com/store/search?q=%22Game%20about%20Squ...
Edit: Got it with stinos' comment
Edit: I know this is a terrible comment that contributes nothing, please don't downvote it just for that... :3
It's PSPACE to solve, right?
We just released our first iOS game and sadly that latter group can be enough to hurt your ratings!
I've left 1* ratings for games I play all the time because I absolutely hated the in-app purchase intrusiveness.