# Dice 1
This is a simple game, designed and implemented just to confirm that our
skills for both BE and FE. Though, it has some potential and is currently a
nice bonus for Partner.
## Single player
This is the basic version, one user play against our system.
Code name `dice_1`. That means related tables, constants should start with `dice_1`.
## Rules
- Use can choose between 2 types:
- `BiggerWin`: enum value is 1
- `SmallerWin`: enum value is 2
- User place a bet by calling our API.
- Server generate 2 numbers in range 1 to 6, one for User, one for Dealer (us).
- Who get the bigger value (or smaller, depend on the config) will win.
## Technical solution
### DB
1 table:
- `dice_1_game_record`
- `id`, `ctime`: read-only, hence, no `mtime`
- `user_id`
- `result_type`: `UserWin` (1), `UserLost` (2), `Draw` (3)
- `game_type`: `BiggerWin` (1) or `SmallerWin` (2)
- `bet_amount`
We might introduce the second table `dice_1_config` later, if there's enough
requirements to add it.
## Staff API
- Read-only API for `dice_1_game_record`.
- CRUD API for `dice_1_config`.
## User API
RPC `/api/game/dice_1`
Request:
```json
{
"type": 1,
"bet_amount": 10000
}
```
Response format for `UserLost` case:
```json
{
"dealer": 3,
"user": 1,
"status": 2,
"reward": 0,
"refund": 0
}
```
Response format for `Draw` case:
```json
{
"dealer": 3,
"user": 3,
"status": 3,
"reward": 0,
"refund": 10000
}
```
Response format for `UserWin` case:
```json
{
"dealer": 3,
"user": 4,
"status": 1,
"reward": 20000,
"refund": 10000
}
```
## Implementation
Once client submit their bet, the server should generate 2 numbers and
update user balance immediately. Following records should be created:
- 1 transction type `Bet` that substract user balance.
- 1 bet record go into `dice_1_game_record`.
- If game status is `Draw` or `UserWin`, 1 transcation with corresponding type
should be created.
- `UserWin`: a new transaction with type `Reward` will be created. Its value
should be greater than absolute value of the `Bet` transaction.
- `Draw`: a new transaction with type `Refund` will be created. Its value
should be _equal_ to absolute value of the `Bet` transaction.
### Multi player with timer
See [its docs here](./dice_1_multi_player.md)