Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uint8 public constant FLIPPINESS = 64;
- uint8 public constant FLIPPINESSROUNDBONUS = 16;
- function throwSlammer(bytes32 _stack, bytes32 _counterStack, bytes32 _reveal)
- public
- returns (bool)
- {
- if(lastActor[_stack]==stacks[_stack].owner){
- require(stacks[_counterStack].owner==msg.sender);
- }else{
- require(stacks[_stack].owner==msg.sender);
- }
- require(stackCounter[_counterStack]==_stack);
- require(counterOfStack[_stack]==_counterStack);
- require(mode[_stack]==4);
- require(uint32(block.number)>commitBlock[_stack]);
- uint256[10] memory flipped;
- if(keccak256(_reveal)!=commit[_stack]){
- mode[_stack]=3;
- throwSlammerEvent(_stack,msg.sender,address(0),flipped);
- return false;
- }else{
- mode[_stack]=3;
- address previousLastActor = lastActor[_stack];
- bytes32 pseudoRandomHash = keccak256(_reveal,block.blockhash(commitBlock[_stack]));
- if(lastActor[_stack]==stacks[_stack].owner){
- lastBlock[_stack]=uint32(block.number);
- lastActor[_stack]=stacks[_counterStack].owner;
- }else{
- lastBlock[_stack]=uint32(block.number);
- lastActor[_stack]=stacks[_stack].owner;
- }
- bool done=true;
- uint8 randIndex = 0;
- for(uint8 i=0;i<10;i++){
- if(mixedStack[_stack][i]>0){
- uint8 thisFlipper = uint8(pseudoRandomHash[randIndex++]);
- if(thisFlipper<(FLIPPINESS+round[_stack]*FLIPPINESSROUNDBONUS)){
- uint256 tempId = mixedStack[_stack][i];
- flipped[i]=tempId;
- mixedStack[_stack][i]=0;
- SlammerTime slammerTimeContract = SlammerTime(slammerTime);
- slammerTimeContract.transferBack(msg.sender,tempId);
- }else{
- done=false;
- }
- }
- }
- throwSlammerEvent(_stack,msg.sender,previousLastActor,flipped);
- if(done){
- FinishGame(_stack);
- mode[_stack]=9;
- delete mixedStack[_stack];
- delete stacks[_stack];
- delete stackCounter[_counterStack];
- delete stacks[_counterStack];
- delete lastBlock[_stack];
- delete lastActor[_stack];
- delete counterOfStack[_stack];
- delete round[_stack];
- delete commitBlock[_stack];
- delete commit[_stack];
- }else{
- round[_stack]++;
- }
- return true;
- }
- }
- event ThrowSlammer(bytes32 indexed stack, address indexed whoDoneIt, address indexed otherPlayer, uint256 token1Flipped, uint256 token2Flipped, uint256 token3Flipped, uint256 token4Flipped, uint256 token5Flipped, uint256 token6Flipped, uint256 token7Flipped, uint256 token8Flipped, uint256 token9Flipped, uint256 token10Flipped);
- event FinishGame(bytes32 stack);
- function throwSlammerEvent(bytes32 stack,address whoDoneIt,address otherAccount, uint256[10] flipArray)
- internal
- {
- ThrowSlammer(stack,whoDoneIt,otherAccount,flipArray[0],flipArray[1],flipArray[2],flipArray[3],flipArray[4],flipArray[5],flipArray[6],flipArray[7],flipArray[8],flipArray[9]);
- }
Add Comment
Please, Sign In to add comment