## Fairness Hi-Lo

### Hi-Lo Game

Hi-Lo is a round-based card game where players play against the house. The main idea of the game is to guess the next card. The card deck consists of following 25 cards: Joker, 2 red, 2 black, 3 red, 3 black, 4 red, 4 black, 5 red, 5 black, 6 red, 6 black, 7 red, 7 black, 8 red, 8 black, 9 red, 9 black, J red, J black, Q red, Q black, K red, K black, A red, A black. Please note that cards hierarchy starts from 2 as the lowest card and goes up to Ace as the highest one. Some of bet options have a predefined chance and payout multiplier and some (hi and lo) are calculated dynamically based on the result (card) of the previous round.

### Randomization

In order to allow players to verify round results, we generate a chain of seeds for each game type. Each seed in a chain is SHA256 hash of a previous one which allows maintaining chain integrity over time. The game utilizes seeds from the chain in reverse order, that means knowing the seed of Nth round you can generate seeds for any number of previous rounds. The chain may consist of various amounts of seeds. We encode and publish the SHA256 hash of the last seed in the chain to Ethereum transaction’s data and use block hash as SALT. We can’t predict block hash, so by doing so results are uniformly distributed which means we can’t generate a chain of seeds with some specific distribution.

# | Seeds number | Salt | |
---|---|---|---|

1 | 100000 | 0xa60fd285f3b85cd24e01edf84048a5dec60af472054a62705ecb52274c1c0e75 | |

2 | 500000 | 0xf420dfbdae36e62605f674c96c1af0d46d0a17a3ef5fc476b791c2badcaf8bc8 |

Tower.bet Hi-Lo randomization #1 SHA-256 of last seen chain can be checked in ETH transaction under an Input Data section. Make sure to view Input Data in UTF-8.

### Result generation

To generate a number in the range [0, 24] we combine round seed with salt. Then calculate SHA256 hash of that combination. That gives us a string of 64 hexadecimal numbers.

Then we take the first 4 characters of that hash and convert it into a decimal number ranging from 0 to 65535 (16 ^ 4 - 1). If it is less than 65525, we use the remainder from division by 25 and use it as an outcome. Otherwise, we repeat using the next 4 characters. We are able to repeat the process up to 16 times. The outcome of this algorithm is a sequential number (position) of the result card in the deck.

### Sample code

```
const saltedSeed = CryptoJS.SHA256(seed + salt).toString();
let pos = 0;
do {
lucky = parseInt(saltedSeed.substr(pos, 4), 16);
pos += 4;
} while (lucky > 65525);
const number = lucky % 25;
```

### Verification

We're publishing the game's hash immediately after the game round ends. You can use round’s seed and SALT to verify that the bet result was not modified as well as verify that the seed was present in the original chain during randomization. There is a public verification script you can use to verify results, source code available and open. https://codepen.io/tower-bet/full/XWWPJvX