Guest User

Untitled

a guest
Oct 16th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. pragma solidity ^0.4.25;
  2.  
  3. /**
  4. * @title Base contract for all slots
  5. */
  6. contract BaseSlot {
  7.  
  8.  
  9. //This order of declaration saves us 40 gas
  10. uint256[][] public reels;
  11. uint256[][] public wins;
  12. uint256[][] public lines;
  13.  
  14. function getReelLength(uint256 reel)
  15. view
  16. public
  17. returns (uint256) {
  18.  
  19. require(reel < reels.length);
  20. return reels[reel].length;
  21. }
  22.  
  23. /**
  24. * @notice Gets win for given spin
  25. *
  26. * @param rand Spin's random values'
  27. * @param bet Bet per line
  28. * @param lineCount Line Count of the bet
  29. * @return Win
  30. * This order of arguments saves from stack too deep problem.
  31. */
  32. function getWinAmmount(uint256 bet,uint256 lineCount,uint256[] rand)
  33. view
  34. public
  35. returns (uint256) {
  36.  
  37. uint256 winsLength= wins.length;
  38. uint256 reelsLength= reels.length;
  39. uint256 linesLength= lines.length;
  40. require(0 != linesLength);
  41. require(0 != winsLength);
  42. require(0 != reelsLength);
  43. require(rand.length == reelsLength);
  44. require(lineCount <= linesLength);
  45. uint256 w = 0; // Rate to be calculated
  46.  
  47. for (uint256 i = 0; i < lineCount; ++i) {
  48. uint256 n = lines[i].length - 1;
  49. uint256 j = 0;
  50. while (j < n) {
  51. uint256 jj = j + 1;
  52. if (reels[j][(rand[j] + lines[i][j]) % reels[j].length] != reels[jj][(rand[jj] + lines[i][jj]) % reels[jj].length]) {
  53. break;
  54. }
  55. j = jj;
  56. }
  57. uint256 s = reels[0][lines[i][0]];
  58. require(s < winsLength);
  59. require(j < wins[s].length);
  60. w += wins[s][j];
  61. }
  62. return bet * w;
  63. }
  64.  
  65.  
  66. ///@notice Constructor
  67. constructor() public {
  68. }
  69. }
Add Comment
Please, Sign In to add comment