Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity ^0.4.25;
- /**
- * @title Base contract for all slots
- */
- contract BaseSlot {
- //This order of declaration saves us 40 gas
- uint256[][] public reels;
- uint256[][] public wins;
- uint256[][] public lines;
- function getReelLength(uint256 reel)
- view
- public
- returns (uint256) {
- require(reel < reels.length);
- return reels[reel].length;
- }
- /**
- * @notice Gets win for given spin
- *
- * @param rand Spin's random values'
- * @param bet Bet per line
- * @param lineCount Line Count of the bet
- * @return Win
- * This order of arguments saves from stack too deep problem.
- */
- function getWinAmmount(uint256 bet,uint256 lineCount,uint256[] rand)
- view
- public
- returns (uint256) {
- uint256 winsLength= wins.length;
- uint256 reelsLength= reels.length;
- uint256 linesLength= lines.length;
- require(0 != linesLength);
- require(0 != winsLength);
- require(0 != reelsLength);
- require(rand.length == reelsLength);
- require(lineCount <= linesLength);
- uint256 w = 0; // Rate to be calculated
- for (uint256 i = 0; i < lineCount; ++i) {
- uint256 n = lines[i].length - 1;
- uint256 j = 0;
- while (j < n) {
- uint256 jj = j + 1;
- if (reels[j][(rand[j] + lines[i][j]) % reels[j].length] != reels[jj][(rand[jj] + lines[i][jj]) % reels[jj].length]) {
- break;
- }
- j = jj;
- }
- uint256 s = reels[0][lines[i][0]];
- require(s < winsLength);
- require(j < wins[s].length);
- w += wins[s][j];
- }
- return bet * w;
- }
- ///@notice Constructor
- constructor() public {
- }
- }
Add Comment
Please, Sign In to add comment