A bunch of people created a chess system that runs on the EVM: here.

I'd like to make a similar game of battleships but there seems to be an apparent difference. In battleships, you can't know what the other person's board looks like whereas in chess, nothing is hidden.

This answer explains quite well why the data is irrevocably public. What I'd like to know is, how easy would it be for a player to cheat by, for example, looking through the blockchain?

1 Answer 1


An implementation of battleships could be done using some sort of commit-and-reveal mechanism where a hash of the two players' boards are stored along with, optionally, some sort of encoding for individual tiles. If the game is being played for a reward, the reward should be forfeit if players fail to reveal information when appropriate. The reward might only be collectable if the ostensible winner reveals that player's starting positions (thus proving the player did not lose). Alternately, to further align incentives of players in a game played for reward, a deposit can be required that can only be recovered by revealing the initial board state at the end of the game. This prevents certain tactics that cheaters can use to put pressure on players obeying the rules by incentivizing them to both reveal their starting boards.

  • Thanks! I think commit-and-reveal is exactly what I need. Is there a practical way of doing it with solidity? I'd imagine that using encryption could be costly.
    – NeRoboto
    Sep 22, 2017 at 22:51
  • That wikipedia page lists a lot of complicated versions of it. You can ignore most of them; commit and reveal only needs hashing.
    – Macil
    Sep 22, 2017 at 23:40
  • @AgentME Excellent. I see there are hashing functions in Solidity. Salting should be easy. The hard part now is serializing the board states on both sides so that they hash the same way.
    – NeRoboto
    Sep 23, 2017 at 8:55
  • Not sure what you mean by "hash the same way"; you'd want each player to salt their board using a secret salt that is only revealed at the end of the game (or a series of salts, one for each game space, revealed upon each move, if you want to validate as the game is ongoing). So, if anything, you'd want the same configuration to have many possible hashes.
    – lungj
    Sep 23, 2017 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.