# Zodiac Racer - The game play of zodiac racer is very simple, imagine there is race between 12 animals such as dog, cat, mouse, etc. And user have to guess which animal is gonna in the top 3 of the race. - The animal win the race is the one reach the finish line first, similarly to the 2nd place and 3rd place in which belong to animals reach the finish line second and third. - There is no such a case that 2 or more animals can reach the finish line at the same time - User can place their bets on multiple animals to have a higher chance to win - If user's animal position is in top 3, user will be rewarded. The reward is based on the position of user's animal. the higher position, the higher reward. # Odds - 1st place: 1-3 - 2nd place: 1-2 - 3rd place: 1-1 # DB Design - `zodiac_racer_game_record` - `id(bigint)`: primary key - `user_id(bigint)` - `partner_id(int)` - `total_bet_amount(bigint)`: sum of bet_amount of all bets - `total_reward_amount(bigint)`: total reward amount of winning bets - `race_results(text[])`: array of animal, the indexes of array tell the positions of animal. For example ["09',"01","02", ...] mean "09" win the 1st place, "01" win the 2nd place and "02" win the 3rd place - `ctime, status` - `zodiac_racer_bet_record` - `id(bigint)`: primary key - `zodiac_racer_game_record_id(bigint)`: reference to zodiac_racer_game_record - `animal(text)`: reference to Animal enum list - `bet_amount(bigint)`: amount of money user bet in - `game_result(int)`: either WIN(1) or LOSE(2) - `reward_amount(bigint)`: amount of money user win - `ctime, status` - `zodiac_racer_config` - `id(bigint)`: primary key - `bet_max(bigint)`: maximum amount of money user can bet in a game - `bet_min(bigint)`: minimum amount of money user have to bet in a game - `odds([]float)`: odds for 1st, 2nd and 3rd place - `ctime, mtime, status` # Animal enum list - ZodiacRacerAnimal01 = "01" - ZodiacRacerAnimal02 = "02" - ZodiacRacerAnimal03 = "03" - ZodiacRacerAnimal04 = "04" - ZodiacRacerAnimal05 = "05" - ZodiacRacerAnimal06 = "06" - ZodiacRacerAnimal07 = "07" - ZodiacRacerAnimal08 = "08" - ZodiacRacerAnimal09 = "09" - ZodiacRacerAnimal10 = "10" - ZodiacRacerAnimal11 = "11" - ZodiacRacerAnimal12 = "12" - The reason I don't name ZodiacRacerAnimal by animal name such as "CAT", "DOG". Because each partner may have a specific requirement about animal graphic, for example a China partner may want there is dragon in the list, but a Australia may want a kangaroo in the list # API specs ## Request - `bets(array)`: a list of bet objects ## Bet object - `animal(text)`: reference to Animal enum list - `bet_amount(bigint)`: amount of money user bet in a animal ## Response - `total_reward_amount(bigint)`: total amount of money user win - `bet_records(array)`: an array of bet record objects - `race_results(array)`: an array of animal positions ## Bet record object - `animal(text)`: reference to animal enum list - `bet_amount(bigint)`: - `game_result(int)`: either WIN(1) or LOSE(2) - `reward_amount(bigint)`: ## Example ```shell script echo '{"bets":[ {"animal":"01", "bet_amount":100000}, {"animal":"02", "bet_amount":100000} ]}' | http POST $cards_url/api/game/zodiac_racer/bet HTTP/1.1 200 { "total_reward_amount": 500000, "bet_records": [ {"animal": "01", "game_result":1, "bet_amount": 100000, "reward_amount":500000}, {"animal": "02", "game_result":2, "bet_amount": 100000, "reward_amount":0} ], "results": ["12", "09", "08", "01", "02", "03", "05", "06", "04", "07", "10", "11"] } ``` # BE implementation - Validate session, config, bets, balance - Create bet transaction, and deduct money from user's wallet - Init race_results array ["01", "02", ... , "12"], and shuffle race_result array - Loop through user bets and check if the bet win - Insert game record and bet records into db - If total reward greater than zero, create a reward transaction and add up money to the user's wallet