Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added update current turn and update phase logic in proc call #15

Merged
merged 20 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e19bc91
add update current turn in proc call
Created-for-a-purpose May 19, 2024
975a234
add update phase logic in proc call
Created-for-a-purpose May 19, 2024
e8f8416
fix: update current turn in actions
Created-for-a-purpose May 19, 2024
42e933c
feat: add update current turn and phase logic in proc fold
Created-for-a-purpose May 19, 2024
658d7ae
fix: update current turn in actions
Created-for-a-purpose May 19, 2024
63358e1
fix: update fold offset in proc fold test
Created-for-a-purpose May 19, 2024
44ea50f
feat: add update current turn and phase logic in proc check
Created-for-a-purpose May 19, 2024
910b0d1
fix: update proc check unit test
Created-for-a-purpose May 19, 2024
54cf153
feat: add proc bet contract
Created-for-a-purpose May 19, 2024
ee97a0b
feat: add proc bet
Created-for-a-purpose May 19, 2024
81ebb9b
feat: add e2e test
Created-for-a-purpose May 19, 2024
c6a10c2
fix: remove redundant code
Created-for-a-purpose May 19, 2024
302d845
feat: add test for proc bet
Created-for-a-purpose May 20, 2024
f3b8a7b
e2e test reorganization
Created-for-a-purpose May 20, 2024
640ae11
add e2e test path in cargo.toml
Created-for-a-purpose May 20, 2024
71b39d4
Merge branch 'feat/add-bet-contract' into feat/add-e2e-test
Created-for-a-purpose May 21, 2024
d93a962
Merge pull request #19 from RizeLabs/feat/add-e2e-test
nlok5923 May 21, 2024
5b41cae
Merge pull request #18 from RizeLabs/feat/add-bet-contract
nlok5923 May 21, 2024
7c77a9f
Merge pull request #17 from RizeLabs/rg/active-player
nlok5923 May 21, 2024
e70dd26
Merge pull request #16 from RizeLabs/rg/add-play-check
nlok5923 May 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions lib/contracts/core/game.masm
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,75 @@ export.play_check
drop
end

export.play_bet
# => [player_bet]
dup mem_store.0
# => [player_bet]

padw drop push.HIGHEST_BET_SLOT_INDEX
exec.account::set_item
dropw dropw
# => []

mem_load.0
# => [player_bet]

## raise amount = current player bet - it should be (bet amount - last call amount) ??
push.CURRENT_TURN_INDEX exec.account::get_item
# => [0, 0, 0, current turn index, player_bet]

drop drop drop
# => [current turn index, player_bet]

push.3 add
# => [current turn index + 3, player_bet]
dup mem_store.1
# => [current turn index + 3, player_bet]

padw drop movup.3
exec.account::set_item
dropw
# => []

## update the remaining balance of player

push.CURRENT_TURN_INDEX exec.account::get_item drop drop drop
# [current turn index]

push.4 add
# [current turn index + 4]

dup
# [current turn index + 4, current turn index + 4]

exec.account::get_item drop drop drop
# [player_remaining_balance, current turn index + 4]

push.HIGHEST_BET_SLOT_INDEX
# [HIGHEST_BET_SLOT_INDEX, player_remaining_balance, current turn index + 4]

exec.account::get_item drop drop drop
# [player_bet, player_remaining_balance, current turn index + 4] -> ig here we need player_remaining_balance and then player_bet or we need to take it's absolute value

dup.1 dup.1 gte assert
# [0/1, player_bet, player_remaining_balance, current turn index + 4]
# [player_bet, player_remaining_balance, current turn index + 4]

sub
# [player_balance_after_bet, current turn index + 4]

swap
# [current turn index + 4, player_balance_after_bet]

padw drop movup.3
# [current turn index + 4, 0, 0, 0, player_balance_after_bet]
exec.account::set_item
dropw dropw
# []

exec.update_current_turn
end


# some basic account methods

Expand Down
179 changes: 179 additions & 0 deletions lib/contracts/notes/game/bet.masm
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
use.miden::account
use.miden::note
use.miden::contracts::wallets::basic->wallet

const.PLAYER_STATS_SLOTS=13
const.NO_OF_PLAYERS_INDEX=57
const.RAISER_INDEX=58
const.CURRENT_TURN_INDEX=60
const.HIGHEST_BET_SLOT_INDEX=61 # highest bet amount which player will try to match with call
const.FIRST_PLAYER_INDEX=64

proc.update_current_turn

push.CURRENT_TURN_INDEX exec.account::get_item
# => [0, 0, 0, current_turn_index]
drop drop drop
# => [current_turn_index]

push.PLAYER_STATS_SLOTS add
# => [current_turn_index + 13]
# => [next_turn_index]

push.NO_OF_PLAYERS_INDEX exec.account::get_item
drop drop drop
# => [no_of_players, next_turn_index]

# Calculate last_player_index = 64 + 13 * (no_of_players - 1) + 0
push.1 sub
push.PLAYER_STATS_SLOTS mul
push.FIRST_PLAYER_INDEX add
# => [last_player_index, next_turn_index]

mem_store.0
# => [next_turn_index]

push.1
# => [1, next_turn_index]

while.true

dup push.10 add
# => [next_turn_index + 10, next_turn_index]
exec.account::get_item
drop drop drop
# => [is_fold, next_turn_index]

if.true
# if player has folded
dup mem_load.0 lt
# => [0/1, next_turn_index]

if.true
push.PLAYER_STATS_SLOTS add
push.1
# => [1, next_turn_index + 13]
else
# Rotate turn
push.FIRST_PLAYER_INDEX
push.1
# => [1, first_player_index]
end
else
# if player has not folded
dup mem_load.0 lte
# => [0/1, next_turn_index]

if.true
# => [next_turn_index]
padw drop
# => [0, 0, 0, next_turn_index]
else
# Rotate turn
push.FIRST_PLAYER_INDEX
padw drop
# => [0, 0, 0, first_player_index]
end

dup.3 mem_store.1
push.CURRENT_TURN_INDEX # slot of current turn
# => [CURRENT_TURN_INDEX, 0, 0, 0, next_turn_index]

exec.account::set_item
dropw dropw
# => [...]
push.0
end
end
dropw
# => [...]
end

proc.play_bet
# => [player_bet]
dup mem_store.0
# => [player_bet]

padw drop push.HIGHEST_BET_SLOT_INDEX
exec.account::set_item
dropw dropw
# => []

mem_load.0
# => [player_bet]

## raise amount = current player bet - it should be (bet amount - last call amount) ??
push.CURRENT_TURN_INDEX exec.account::get_item
# => [0, 0, 0, current turn index, player_bet]

drop drop drop
# => [current turn index, player_bet]

push.3 add
# => [current turn index + 3, player_bet]
dup mem_store.1
# => [current turn index + 3, player_bet]

padw drop movup.3
exec.account::set_item
dropw
# => []

## update the remaining balance of player

push.CURRENT_TURN_INDEX exec.account::get_item drop drop drop
# [current turn index]

push.4 add
# [current turn index + 4]

dup
# [current turn index + 4, current turn index + 4]

exec.account::get_item drop drop drop
# [player_remaining_balance, current turn index + 4]

push.HIGHEST_BET_SLOT_INDEX
# [HIGHEST_BET_SLOT_INDEX, player_remaining_balance, current turn index + 4]

exec.account::get_item drop drop drop
# [player_bet, player_remaining_balance, current turn index + 4] -> ig here we need player_remaining_balance and then player_bet or we need to take it's absolute value

dup.1 dup.1 gte assert
# [0/1, player_bet, player_remaining_balance, current turn index + 4]
# [player_bet, player_remaining_balance, current turn index + 4]

sub
# [player_balance_after_bet, current turn index + 4]

swap
# [current turn index + 4, player_balance_after_bet]

padw drop movup.3
# [current turn index + 4, 0, 0, 0, player_balance_after_bet]
exec.account::set_item
dropw dropw
# []

exec.update_current_turn
end

begin
dropw

push.0 exec.note::get_inputs drop
mem_loadw drop drop drop

call.play_bet
# => [...]

dropw
exec.note::get_assets drop mem_loadw
# => [ASSET, ...]

# load the asset and add it to the account
call.wallet::receive_asset
# => [...]

dropw
end
Loading