pragma solidity ^0.4.26; contract TicTacToe { enum CellState { Clear, Owner, Player } enum NextMove { Owner, Player } struct Game { address owner; address player; NextMove nextMove; CellState[3][3] state; } uint256 private nextGameId = 0; mapping(uint256 => Game) private games; function createGame() public returns (uint256 gameId) { Game memory game; game.owner = msg.sender; gameId = nextGameId; nextGameId++; games[gameId] = game; } function acceptInvite(uint256 gameId) public returns (NextMove nextMove) { Game storage game = games[gameId]; require(game.owner != address(0), "Game not found"); require(game.player == address(0), "Game invite was already accepted"); game.player = msg.sender; bytes32 draw = keccak256(abi.encodePacked(block.coinbase, game.owner, game.player)); if (draw[0] >> 7 == 0x0) nextMove = NextMove.Owner; else nextMove = NextMove.Player; game.nextMove = nextMove; } }
0.4.18