Guest User

Untitled

a guest
Mar 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. uint8 public constant FLIPPINESS = 64;
  2. uint8 public constant FLIPPINESSROUNDBONUS = 16;
  3.  
  4. function throwSlammer(bytes32 _stack, bytes32 _counterStack, bytes32 _reveal)
  5. public
  6. returns (bool)
  7. {
  8. if(lastActor[_stack]==stacks[_stack].owner){
  9. require(stacks[_counterStack].owner==msg.sender);
  10. }else{
  11. require(stacks[_stack].owner==msg.sender);
  12. }
  13. require(stackCounter[_counterStack]==_stack);
  14. require(counterOfStack[_stack]==_counterStack);
  15. require(mode[_stack]==4);
  16.  
  17. require(uint32(block.number)>commitBlock[_stack]);
  18.  
  19. uint256[10] memory flipped;
  20. if(keccak256(_reveal)!=commit[_stack]){
  21. mode[_stack]=3;
  22. throwSlammerEvent(_stack,msg.sender,address(0),flipped);
  23. return false;
  24. }else{
  25. mode[_stack]=3;
  26. address previousLastActor = lastActor[_stack];
  27. bytes32 pseudoRandomHash = keccak256(_reveal,block.blockhash(commitBlock[_stack]));
  28. if(lastActor[_stack]==stacks[_stack].owner){
  29. lastBlock[_stack]=uint32(block.number);
  30. lastActor[_stack]=stacks[_counterStack].owner;
  31. }else{
  32. lastBlock[_stack]=uint32(block.number);
  33. lastActor[_stack]=stacks[_stack].owner;
  34. }
  35.  
  36. bool done=true;
  37. uint8 randIndex = 0;
  38. for(uint8 i=0;i<10;i++){
  39. if(mixedStack[_stack][i]>0){
  40. uint8 thisFlipper = uint8(pseudoRandomHash[randIndex++]);
  41. if(thisFlipper<(FLIPPINESS+round[_stack]*FLIPPINESSROUNDBONUS)){
  42. uint256 tempId = mixedStack[_stack][i];
  43. flipped[i]=tempId;
  44. mixedStack[_stack][i]=0;
  45. SlammerTime slammerTimeContract = SlammerTime(slammerTime);
  46. slammerTimeContract.transferBack(msg.sender,tempId);
  47. }else{
  48. done=false;
  49. }
  50. }
  51. }
  52.  
  53. throwSlammerEvent(_stack,msg.sender,previousLastActor,flipped);
  54.  
  55. if(done){
  56. FinishGame(_stack);
  57. mode[_stack]=9;
  58. delete mixedStack[_stack];
  59. delete stacks[_stack];
  60. delete stackCounter[_counterStack];
  61. delete stacks[_counterStack];
  62. delete lastBlock[_stack];
  63. delete lastActor[_stack];
  64. delete counterOfStack[_stack];
  65. delete round[_stack];
  66. delete commitBlock[_stack];
  67. delete commit[_stack];
  68. }else{
  69. round[_stack]++;
  70. }
  71.  
  72. return true;
  73. }
  74. }
  75.  
  76. 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);
  77. event FinishGame(bytes32 stack);
  78.  
  79. function throwSlammerEvent(bytes32 stack,address whoDoneIt,address otherAccount, uint256[10] flipArray)
  80. internal
  81. {
  82. ThrowSlammer(stack,whoDoneIt,otherAccount,flipArray[0],flipArray[1],flipArray[2],flipArray[3],flipArray[4],flipArray[5],flipArray[6],flipArray[7],flipArray[8],flipArray[9]);
  83. }
Add Comment
Please, Sign In to add comment