Skip to content

Latest commit

 

History

History
597 lines (324 loc) · 8.97 KB

MasterMind.md

File metadata and controls

597 lines (324 loc) · 8.97 KB

MasterMind

Marco Antonio Corallo

MasterMind

An implementation of MasterMind on Ethereum Blockchain

Methods

AFK

function AFK(uint256 id) external nonpayable

sender put under accusation the opponent

Parameters

Name Type Description
id uint256 : game id

claimStakeByAFK

function claimStakeByAFK(uint256 id) external nonpayable

transfer the stake to the player that accuse and win the AFK

Parameters

Name Type Description
id uint256 : game id

declareStake

function declareStake(uint256 id, uint256 stake) external nonpayable

set stake value. If the two players declare different values => close the game

Parameters

Name Type Description
id uint256 : game id
stake uint256 : stake declared by the sender

joinGame

function joinGame() external nonpayable

Overload with no params: join a random game

joinGame

function joinGame(uint256 id) external nonpayable

Parameters

Name Type Description
id uint256 : identifier of the game the challenger wants to join

leaveGame

function leaveGame(uint256 id) external nonpayable

Allow a player to leave the game. If the stake has already been put, the give-up player lose the game.

Parameters

Name Type Description
id uint256 : game id

newGame

function newGame() external nonpayable returns (uint256)

Overload with no params: create a new game without a specific challenger

Returns

Name Type Description
_0 uint256 undefined

newGame

function newGame(address challenger_addr) external nonpayable returns (uint256)

Parameters

Name Type Description
challenger_addr address : address of the player the game creator wants to play with or address(0)

Returns

Name Type Description
_0 uint256 game's id

prepareGame

function prepareGame(uint256 id) external payable

Allow players to put stake. When both the players put it, shuffle roles If a player put a different stake from what was declared, the tx is reverted.

Parameters

Name Type Description
id uint256 : game id

sendCode

function sendCode(bytes32 _hash, uint256 id) external nonpayable

allow a player to send the secret code

Parameters

Name Type Description
_hash bytes32 : secret code, hashed and salted off-chain
id uint256 : game id

sendFeedback

function sendFeedback(uint8 CC, uint8 NC, uint256 id) external nonpayable

allow the codemaker to send a feedback about the last guess

Parameters

Name Type Description
CC uint8 : number of colors belonging to the last guess in the correct position
NC uint8 : number of colors belonging to the last guess, but not in the correc: game id positions
id uint256 : game id

sendGuess

function sendGuess(enum Color[4] code, uint256 id) external nonpayable

allow the codebreaker to send the secret code

Parameters

Name Type Description
code enum Color[4] : proposed secret code
id uint256 : game id

startDispute

function startDispute(uint256 id, uint8 feedback_id) external nonpayable

allow the codebreaker to start a dispute on a given feedback

Parameters

Name Type Description
id uint256 : game id
feedback_id uint8 : reference to the disputed feedback

submitSolution

function submitSolution(uint256 id, enum Color[4] code, uint8[5] salt) external nonpayable

allow the codemaker to reveal the solution <code, salt>. Starts dispute timer.

Parameters

Name Type Description
id uint256 : game id
code enum Color[4] : secret code he choose at the beginning
salt uint8[5] : numeric code to improve robustness

updateScore

function updateScore(uint256 id) external nonpayable

after the dispute time update points and, if all turns have been played, draw winner

Parameters

Name Type Description
id uint256 : game id

Events

AFKStart

event AFKStart(uint256 indexed id, address who)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined

AFKStop

event AFKStop(uint256 indexed id)

Parameters

Name Type Description
id indexed uint256 undefined

Dispute

event Dispute(uint256 indexed id, uint8 feedback_id)

Parameters

Name Type Description
id indexed uint256 undefined
feedback_id uint8 undefined

FeedbackSent

event FeedbackSent(uint256 indexed id, address who, uint8 CC, uint8 NC)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined
CC uint8 undefined
NC uint8 undefined

GameClosed

event GameClosed(uint256 indexed id)

Parameters

Name Type Description
id indexed uint256 undefined

GameCreated

event GameCreated(address indexed who, uint256 indexed id, address indexed challenger)

Parameters

Name Type Description
who indexed address undefined
id indexed uint256 undefined
challenger indexed address undefined

GameJoined

event GameJoined(address indexed who, uint256 indexed id)

Parameters

Name Type Description
who indexed address undefined
id indexed uint256 undefined

GameLeft

event GameLeft(uint256 indexed id, address who)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined

GuessSent

event GuessSent(uint256 indexed id, address who, enum Color[4] code)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined
code enum Color[4] undefined

PointsUpdated

event PointsUpdated(uint256 indexed id, uint8 points)

Parameters

Name Type Description
id indexed uint256 undefined
points uint8 undefined

Punished

event Punished(uint256 indexed id, address who)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined

SecretCodeSent

event SecretCodeSent(uint256 indexed id, address who)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined

Shuffled

event Shuffled(uint256 indexed id, address _codemaker, address _codebreaker)

Parameters

Name Type Description
id indexed uint256 undefined
_codemaker address undefined
_codebreaker address undefined

SolutionSubmitted

event SolutionSubmitted(uint256 indexed id, enum Color[4] code, uint8[5] salt)

Parameters

Name Type Description
id indexed uint256 undefined
code enum Color[4] undefined
salt uint8[5] undefined

StakeDeclared

event StakeDeclared(uint256 indexed id, address who, uint256 _stake)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined
_stake uint256 undefined

StakePut

event StakePut(uint256 indexed id, address who, uint256 _stake)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined
_stake uint256 undefined

Tie

event Tie(uint256 indexed id)

Parameters

Name Type Description
id indexed uint256 undefined

Transfered

event Transfered(uint256 indexed id, address who, uint256 howmuch)

Parameters

Name Type Description
id indexed uint256 undefined
who address undefined
howmuch uint256 undefined

Winning

event Winning(uint256 indexed id, address player)

Parameters

Name Type Description
id indexed uint256 undefined
player address undefined