7 ms·
Show HN: Chessboardify – Make the grid a chessboard
- mapehe 10y agoI wanted to sketch this idea of a puzzle game that I came up with while on a walk. It turned out to roll pretty well though it couldn't be any more minimal. Simple things are pretty powerful sometimes, don't you think?
- pg_is_a_butt 10y agosimple things are simple always. i do think, lady
- jtokoph 10y agoNeat variation on LightsOut (http://chenglou.github.io/react-lights-out/ http://chenglou.github.io/react-lights-out/). I had some trouble since the rules for which lights toggle are slightly different with this one: Classic lights out only toggles the light you press and the 4 lights in the 4 cardinal directions. I was surprised how baked into my brain that was and how much trouble I had getting my brain to adapt.
- egypturnash 10y agoI used to play something similar all the time on my Merlin back in 1978. https://en.wikipedia.org/wiki/Merlin_(game) https://en.wikipedia.org/wiki/Merlin_(game)
- rustyfe 10y agoMy only complaint is that the alert box prevents seeing the final board. It'd be nice to get to actually see my beautiful chessboard creations.
- lgas 10y agoDismiss the alert. Tada.
- Animux 10y agoThen a new round is started and the final board is removed.
- deleted 10y ago[deleted]
- mapehe 10y agoThat's how it behaves on my device, actually, and that indeed is how it's supposed to work. Thanks for pointing this out!
- mapehe 10y agoI did a little update which should address this! Thanks again!
- deleted 10y ago[deleted]
- dorianm 10y agoI did it in one move ;). Pretty neat game. http://imgur.com/f5sryfs http://imgur.com/f5sryfs
- mapehe 10y agoGood job! I think it's pretty amazing how good you get in this game once you play it a little more. At first it's simply impossible, but you start to recognize the patterns pretty quickly and you can usually beat the 3x3 ones in less than 10 moves.
- monfrere 10y agoYou should never have to use more than 9 moves for 3x3. Hitting the same square twice has no net effect, even if the two moves on the same square are separated by other moves.
- InkyBlinky 10y agoYou can actually knock that down to 8 moves (maybe less?) as the max required for a solution. You never have to press the middle square, since it flips every square, inverting the board. Inversion doesn't bring you closer to the checkered pattern of the chessboard. (An inverted chessboard... is a chessboard!)
- mapehe 10y agoI just posted this on Facebook: https://www.facebook.com/chessboardify/?fref=nf https://www.facebook.com/chessboardify/?fref=nf There is a lot of math involved in this game and you can quite quickly note some less obvious rules like this one. Maybe there are some very nontrivial, but interesting things out there. I'm not good enough in combinatorics to tell... :D
- 0508 10y ago8 moves are sometimes required. If you have a chessboard 3x3 grid with the middle square the wrong color, you have to flip all squares except the middle.
- Artlav 10y agoAm i the only one who finds it more fun to try to get all the squares the same color, rather than into a chessboard? Neat game.
- RodgerTheGreat 10y agoCool! I was inspired to write an implementation of the game in K: http://johnearnest.github.io/ok/ike/ike.html?gist=0007b9afbe6e625b25e95eb286e32b98 http://johnearnest.github.io/ok/ike/ike.html?gist=0007b9afbe...
- alxv 10y agoLike Lights Out, this game can be solved using Gaussian elimination over Z/2 (integers modulo 2). This means the order of the tiles you press do not matter, and that you can solve the board by forming the desired pattern row by row.
- memonkey 10y agoThis is interesting but I don't really understand because I've tried doing what you're saying. Maybe a side note: I'm very interested in learning algorithms but they are so inaccessible to me.
- tgb 10y agoHave you taken linear algebra? It gives a structure for solving systems of linear equations and the parent post is noting that the game state is a linear function of which squares you've pressed, when considering the states of a square as either one or zero and doing arithmetic mod 2. So the standard techniques of linear algebra can solve this system, such as Gaussian elimination. However, you still have to write down the large matrix that encodes what each square does (an n x n board will need an n^2 x n^2 matrix which shows how each square affects all the others once pressed). Then you solve that system. For this particular game there is probably a more intuitive way to directly solve it.
- tgb 10y agoSorry how does it follow that you can form the pattern row by row? When you write this down as a linear algebra problem you kinda forget about the structure of the board, and the rows of the resulting matrix you apply Gauss elimination to don't correspond to the rows of the game board. So you must have meant something else that I'm missing, but I'm confused how you would solve just the bottom row without touching any others.
- alxv 10y agoFor every boards are two chessboard patterns we can solve for. For example, for a 3x3 board we can have: 101 010 010 or 101 101 010 where 1 is a white square and 0 is a black square. We can represent any N×N board as a N² vector. So, we can represent one of the chessboard pattern as: 010 101 = 010101010 = y 010 At the beginning of the game, the board is at some random initial pattern. 110 111 = 110111010 = y0 010 The goal of the game is to find the necessary moves to form the chessboard pattern. Hence, we want to solve the equation (y - y0) = Mx where M is a N²×N² matrix representing the effect of every possible moves. Pressing on a tile is equation to addition by 1 modulo 2. 1 + 1 = 0 (mod 2) 0 + 1 = 1 (mod 2) For example, pressing the top left tile is the same as adding this effect vector to the board vector: 110110000 If we do this for all 9 tiles of the 3x3 board, we find the matrix M to be: 110110000 111111000 011011000 110110110 111111111 = M 011011011 000110110 000111111 000011011 where the i-th row is the effect of pressing the i-th tile. Now, we can just solve for x (assuming M is not singular). Re-using our above example, we find (y - y0) = Mx (010101010 - 110111010) = Mx 100010000 = Mx 111100100 = x (by Gaussian elimination) This means we can press the following tiles (in any order) on the board to solve it: 111 100 100 If you are interested, I wrote some quick demo code that shows how this could be implemented in Python: https://gist.github.com/avassalotti/7452318c9e9b8dec637bc7c0fac32951 https://gist.github.com/avassalotti/7452318c9e9b8dec637bc7c0...
- flippant 10y agoWhat are you using Socket.IO for on the page?
- mapehe 10y agoThe puzzles are generated and the solutions are verified on the server. I'm passing data back and forth with that.
- BariumBlue 10y agoGot an excel solver for the 3x3 I'd share i'd via google spreadsheet if I could do it anonymously without creating a throwaway account (All this in 3x3 grids, with the numbers mod 2) - 1. Add the current light up state to the desired light state (chessboard) - 2. Create a grid that's lit up as if from button presses from previous grid (using the game rules) - 3. Flip the positions of the previous grid across the center. This grid is the grid of buttons to push No idea how it works though, and it doesn't seem to work in the 4x4 case either
- Diggsey 10y agoI just created a solver for the 4x4 case, also in google sheets... Who would have though it could handle ~15,000 rows with decent performance! Works by calculating via formulae the result of any sequence, 6 moves or less. The bit patterns of each individual move are XORed together for each possible combination of moves. The difference between the current state and the target is calculated, again via XOR, and then looked up in this data sheet via the query functionality, to give the sequence of moves which resulted in that delta bit pattern.
- Grue3 10y agoIs it me, or bigger boards are much easier than 3x3? You can pretty much build those row by row.
- mapehe 10y agoI think it really depends on the size. Often the 5x5 feels like a breeze, but then 6x6 is a lot tougher. Probably there is some mathematical reason for this related to the divisibility of the grid side length.