a Vietnamese gambling game using three dice

Overview

Near Cetificate Devoloper - Demo

Vietnamese gambling game: Gourd-Fish-Shrimp-Crab On NEAR

How to play

Instead of showing one to six pips, the sides of the dice have pictures of a fish, a prawn, a crab, a rooster, a calabash gourd,and a stag.We have 3 dice. Players place wagers on a board that has the six pictures The bettor will get their money back plus the corresponding amount of profit if the bet is correct If two (or three) dice correspond with a bet, the bettor receives tow (or three) times their money For instance, if one were to place $3 on fish, and the dealer rolls 1 fish, 1 crab and 1 stag, then the bettor would receive $3 while keeping the $3 they had bet

About Contract

It's need to be mentioned that it is a pure dapp project, which means there is no centralized backend nor data server, all persistent information is stored and mananged on NEAR chain by a contract.

Contract Structure

// information about bets allocation
#[derive(BorshDeserialize, BorshSerialize)]
pub struct BetInfo {
    pub fish: u128, 
    pub prawn: u128, 
    pub crab: u128, 
    pub rooster: u128, 
    pub gourd: u128, 
    pub stag: u128,
}

#[near_bindgen]
#[derive(BorshDeserialize, BorshSerialize)]
pub struct GourdCrab {
    pub owner_id: AccountId,
    pub accounts: UnorderedMap<AccountId, Balance>, // balance of user
    pub bets: UnorderedMap<AccountId,BetInfo>,      // bets in the room
    pub bet_level: Balance, 
}

Contract Interface

//****************/
//***** INIT *****/
//****************/

/// initialization of this contract
#[init]
    pub fn new(
        owner_id: AccountId,
        bet_level: U128, 
    ) -> Self;


//***************************/
//***** OWNER FUNCTIONS *****/
//***************************/

pub fn set_bet_level(&mut self, bet_level: U128);

pub fn deposit(&mut self); 

pub fn betting(
    &mut self, 
    num_fish: u128, 
    num_prawn: u128,
    num_crab: u128,
    num_rooster: u128, 
    num_gourd: u128,
    num_stag: u128);

pub fn cancel_betting(&mut self);

// roll the dice and calculate the payoff
pub fn rolling(&mut self);

// get account's balance
pub fn get_balance(&self, account_id: AccountId) -> u128;

Quick Start

To run this project locally:

  1. Prerequisites: Make sure you've installed Node.js ≥ 12

Now you'll have a local development environment backed by the NEAR TestNet!

Go ahead and play with the app and the code. As you make code changes, the app will automatically reload.

Exploring The Code

The "contract" code lives in the /src folder. See the README there for more info.

Preparation

Every smart contract in NEAR has its own associated account. When you run yarn dev, your smart contract gets deployed to the live NEAR TestNet with a throwaway account. When you're ready to make it permanent, here's how.

Install near-cli (optional)

near-cli is a command line interface (CLI) for interacting with the NEAR blockchain. It was installed to the local node_modules folder when you ran yarn install, but for best ergonomics you may want to install it globally:

yarn install --global near-cli

Or, if you'd rather use the locally-installed version, you can prefix all near commands with npx

Ensure that it's installed with near --version (or npx near --version)

How to run

After you clone the project, go to the project folder

Step 1: Login

Each account on NEAR can have at most one contract deployed to it. If you've already created an account such as your-name.testnet, you can deploy your contract to NCD-GroupA-Demo.your-name.testnet. Assuming you've already created an account on NEAR Wallet, here's how to create NCD-GroupA-Demo.your-name.testnet:

  1. Authorize NEAR CLI, following the commands it gives you:

    near login

  2. Create a subaccount (replace YOUR-NAME below with your actual account name):

    near create-account subacc.YOUR-NAME.testnet --masterAccount YOUR-NAME.testnet

  3. Export account to variable export ACCOUNT_ID=<YOUR_ACCOUNT_ID>

Step 2: build and testing

./build.sh
./test.sh

Step 3: deploy!

./deploy.sh

Step 4: Call contract from Near CLI

./call.sh <METHOD_NAME> <ARGs>

For example, both account_id1 = demo10.tlgk.testnet and account_id2 = demo10.kiendemo.testnet want to bet. You will get the following script

First, init contract:

./call.sh new '{"owner_id":"demo10.tlgk.testnet", "bet_level":"1000000000000000000000000"}'

deposit some money and place a bet. for instance, account_id1 want place 1 crab and 2 rooster, account_id2 want place 1 fish and 1 praw

./call.sh deposit '{}' --amount 40
./call.sh betting '{"num_fish": 0, "num_prawn": 0, "num_crab": 1,  "num_rooster": 2, "num_gourd": 0, "num_stag": 0}'

./call2.sh deposit '{}' --amount 40
./call2.sh betting '{"num_fish": 1, "num_prawn": 1, "num_crab": 0,  "num_rooster": 0,  "num_gourd": 0, "num_stag":0}'

You can check Bets by scripts:

./call.sh get_bet '{"account_id":"demo10.kiendemo.testnet"}'
./call.sh get_bet '{"account_id":"demo10.kiendemo.testnet"}'

Now, rolling dices

./call.sh rolling '{}'

You can check balance. ./call.sh get_balance '{"account_id":"demo10.tlgk.testnet"}' ./call.sh get_balance '{"account_id":"demo10.kiendemo.testnet"}'

Troubleshooting

On Windows, if you're seeing an error containing EPERM it may be related to spaces in your path. Please see this issue for more details.

You might also like...
Conway's Game of Life implemented for Game Boy Advance in Rust

game-of-life An implementation of a Conway's Game of Life environment on GBA. The ultimate game should have two modes: Edit and Run mode which can be

A game made in one week for the Bevy engine's first game jam

¿Quien es el MechaBurro? An entry for the first Bevy game jam following the theme of "Unfair Advantage." It was made in one week using the wonderful B

Managed game servers, matchmaking, and DDoS mitigation that lets you focus on building your game
Managed game servers, matchmaking, and DDoS mitigation that lets you focus on building your game

Managed game servers, matchmaking, and DDoS mitigation that lets you focus on building your game. Home - Docs - Twitter - Discord 👾 Features Everythi

Show puffin profiler flamegraph in-game using egui

Show puffin profiler flamegraph in-game using egui puffin is an instrumentation profiler where you opt-in to profile parts of your code: fn my_functio

Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions
Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions

Introduction Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions. (hand interaction with boxes missing

minesweeper-rs is a simple minesweeper game using Rust and windows-rs.
minesweeper-rs is a simple minesweeper game using Rust and windows-rs.

minesweeper-rs minesweeper-rs is a simple minesweeper game using Rust and windows-rs. Key Features TBA Quick Start TBA How To Contribute Contributions

A simple implementation of Conway's Game of Life using Fully homomorphic Encryption

Game of life using Fully homomorphic encryption A simple implementation of Conway's Game of Life built using Zama's concrete-boolean library. Build Ju

Self Study on developing a game engine using wgpu as the rendering API. Learning as I go.
Self Study on developing a game engine using wgpu as the rendering API. Learning as I go.

Fabled Engine Any issues, enhancement, features, or bugs report are always welcome in Issues. The obj branch is where frequent development and up to d

🕹 A quick'n'dirty game sample using kajiya, physx-rs, and dolly
🕹 A quick'n'dirty game sample using kajiya, physx-rs, and dolly

🕹️ Cornell McRay t'Racing A quick'n'dirty game sample using kajiya, physx-rs, and dolly. System requirements See the kajiya readme. Building Clone th

Owner
null
A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it techinically works

rustetris A tetris game I wrote in rust using ncurses. I'm sure that there's a better way to write a tetris game, and the code may be sus, but it tech

Eric G 3 Oct 15, 2022
A game of snake written in Rust using the Bevy game engine, targeting WebGL2

Snake using the Bevy Game Engine Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.toml (loca

Michael Dorst 0 Dec 26, 2021
A Client/Server game networking plugin using QUIC, for the Bevy game engine.

Bevy Quinnet A Client/Server game networking plugin using QUIC, for the Bevy game engine. Bevy Quinnet QUIC as a game networking protocol Features Roa

Gilles Henaux 65 Feb 20, 2023
A simple space shooter game. Runs in the terminal using characters-based UI. Fully written in Rust, using the "ruscii" library.

Thrust - a terminal shooter game Originally created as a project for the "Missing Semester" course at JKU Linz (338.006). The game is entirely written

Mathias Wöß 3 Jan 16, 2023
Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

Victor Winbringer 27 Jan 7, 2023
2-player game made with Rust and "ggez" engine, based on "Conway's Game of Life"

fight-for-your-life A 2-player game based on the "Conway's Game of Life", made with Rust and the game engine "ggez". Create shapes on the grid that wi

Petros 3 Oct 25, 2021
2d Endless Runner Game made with Bevy Game Engine

Cute-runner A 2d Endless Runner Game made with Bevy Game Engine. Table of contents Project Infos Usage Screenshots Disclaimer Project Infos Date: Sept

JoaoMarinho 2 Jul 15, 2022
A game for the game jam "1-Button Jam 2021"

One click ninja A game for the game jam "1-Button Jam 2021" written in Rust with the Bevy engine. A rhythm game, where you play a soldier that can def

Alex Helfet 7 Apr 12, 2022
Wasm game of life - A Rust and WebAssembly tutorial implementing the Game of Life

wasm_game_of_life Conway's Game of Life in Rust and WebAssembly Contributing | Chat Built with ?? ?? by The Rust and WebAssembly Working Group About T

Rust and WebAssembly 236 Dec 24, 2022
My first attempt at game programming. This is a simple target shooting game built in macroquad.

sergio My first attempt at game programming. This is a simple target shooting game built in macroquad. Rules Hit a target to increase score by 1 Score

Laz 1 Jan 11, 2022