//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.16; //Erc20 contract User { /*modifier enoughmoney { require(balanceOf[msg.sender>=1]); _; }*/ address PlayerA; address PlayerB; function DefineUserA() public { PlayerA = msg.sender; } function DefineUserB() public { PlayerB = msg.sender; } //needs a lock, so functions can't be called while game is still going on } contract Fields { enum fieldValue { noValue, aValue, bValue } fieldValue Value; fieldValue constant defaultValue= fieldValue.noValue; //Field on a 3x3 Plan, value describes which player has chosen this field fieldValue [3][3] public fields; //I'm not sure if this is the way you use enums //together with twodimensional arrays modifier occupation(uint _i, uint _k) { // fields is already public require(fields[_i][_k] == fieldValue.noValue); _; } //if someone wants to choose a field, we need to make sure that it isn't occupied yet // i describes the row, k the column // function names should follow camelCase https://en.wikipedia.org/wiki/Camel_case function fieldChange (uint _i, uint _k, fieldValue _Value){ //not sure if I used enum correctly here fields[_i][_k] = fieldValue.Value; } //this function is called when sb. wants to choose a field /*function createFields () public { for (uint i=1; i<=3; i++) { for (uint k=1; k<=3; k++) { fields[_i][_k] = "N"; } } } //the 3x3 fields are created I'm not sure is this function is still needed as the default Value for all Fields in the 2dimensional array is already set to "noValue"...*/ function PlayA(uint _i, uint _k) public occupation(_i, _k) { require(msg.sender == PlayerA); Value = fieldValue.aValue; fieldChange (_i, _k, Value); } //function which is called by PlayerA to choose field i,k function PlayB(uint _i, uint _k) public occupation(_i, _k) { require(msg.sender == PlayerB); Value = fieldValue.bValue; fieldChange (_i, _k, Value); } //function which is called by PlayerA to choose field i,k } /* k=1 k=2 k=3 ___________ Plan i=1 |___|___|___| i=2 |___|___|___| i=3 |___|___|___| */ contract Winner { uint count = 0; function wonGame (fieldValue _Value) public returns (bool) { //columns for (uint i=0; i<=2; i++) { for (uint k=0; k<=2; k++) { if (fields[_i][_k] == fieldValue.Value) { count++; } } } if (count == 3) { return true; } else { count = 0; } //rows for (k=0; k<=2; k++) { for (i=0; i<=2; i++) { if (fields[_i][_k] == fieldValue.Value) { count++; } } } if (count == 3) { return true; } else {count = 0; } //bottom left to top right i = 3; for (k=0; k<=2; k++) { i = i - 1; if (fields[_i][_k] == fieldValue.Value) { count++; } } if (count == 3) { return true; } else {count = 0; } //top left to bottom right i = 0; for ( k=0; k<=2; k++) { if (fields[_i][_k] == fieldValue.Value) { count++; } i++; } if (count == 3) { return true; } else {count = 0; } } }
0.4.16