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

Feat: Added update current turn after proc raise is called #14

Merged
merged 25 commits into from
May 21, 2024
Merged
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7f1a841
feat: add update current turn in proc raise
Created-for-a-purpose May 19, 2024
c0d043f
fix: update proc raise unit test
Created-for-a-purpose May 19, 2024
18d35ef
fix: merge main into rg/add-raise-contract
Created-for-a-purpose May 19, 2024
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
2f69d71
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
088a797
Merge pull request #15 from RizeLabs/rg/add-call-contract
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
160 changes: 105 additions & 55 deletions lib/contracts/core/game.masm
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# use.miden::contracts::poker::poker
use.miden::account
use.miden::tx
use.std::crypto::dsa::rpo_falcon512
use.miden::contracts::wallets::basic->basic_wallet
use.miden::contracts::auth::basic

const.PLAYER_1_PUB_KEY_INDEX=65 # use this index to find other player pub key slot index which would always be second to the player account id
const.PLAYER_STATS_SLOTS=13
const.SMALL_BLIND_INDEX=54
const.BIG_BLIND_INDEX=55
const.BUY_IN_INDEX=56
const.NO_OF_PLAYERS_INDEX=57
const.RAISER_INDEX=58
const.CURRENT_PLAYER_PUB_KEY_INDEX=60 # at 63 we stored pub key for current player (it will contain)
const.HIGHEST_BET_SLOT_INDEX=61 # highest bet amount which player will try to match with call
const.CURRENT_TURN_INDEX=60 # index of the player whose turn it is currently
const.CURRENT_TURN_PLAYER_PUB_KEY_INDEX=60 # need to check it's storage initially small blind public key on slot 62
const.CURRENT_PHASE=62 # whole game is divided into 4 phases
const.PLAYER_CHECK_COUNTER=63
const.PLAYER_STATS_SLOTS=13
const.FIRST_PLAYER_INDEX=64
const.CARDS_SLOTS=52

# game events
@@ -68,6 +66,86 @@ export.poker_auth_tx_rpo_falcon512
# => []
end

export.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

export.play_call

# although we will enforce this checks from frontend but it's go to have certain require here
@@ -149,98 +227,70 @@ export.play_raise
# => [player_bet]

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

drop drop drop
# => [current turn player pub key index, player_bet]
# => [current turn index, player_bet]

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

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

## update raiser
mem_load.1 push.2 sub
# => [current turn pub key index]
mem_load.1 push.3 sub
# => [current turn index]

padw drop push.RAISER_INDEX
#[RAISER_INDEX, 0, 0, 0, current turn pub key index]
#[RAISER_INDEX, 0, 0, 0, current turn index]

exec.account::set_item
dropw dropw
#[]

## update the remaining balance of player

push.CURRENT_PLAYER_PUB_KEY_INDEX exec.account::get_item drop drop drop
# [current turn player pub key index]
push.CURRENT_TURN_INDEX exec.account::get_item drop drop drop
# [current turn index]

push.3 add
# [current turn player pub key index + 3]
push.4 add
# [current turn index + 4]

dup
# [current turn player pub key index + 3, current turn player pub key index + 3]
# [current turn index + 4, current turn index + 4]

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

push.HIGHEST_BET_SLOT_INDEX
# [HIGHEST_BET_SLOT_INDEX, player_remaining_balance, current turn player pub key index + 3]
# [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 player pub key index + 3] -> ig here we need player_remaining_balance and then player_bet or we need to take it's absolute value
# [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 player pub key index + 3]
# [player_bet, player_remaining_balance, current turn player pub key index + 3]
# [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 player pub key index + 3]
# [player_balance_after_bet, current turn index + 4]

swap
# [current turn player pub key index + 3, player_balance_after_bet]
# [current turn index + 4, player_balance_after_bet]

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

# need to confirm the phase logic
# - update phase/round n sum

# push.CURRENT_TURN_INDEX drop drop drop
#[CURRENT_TURN_INDEX]

# push.4 add
#[CURRENT_TURN_INDEX+4]

# push.CURRENT_PHASE drop drop drop
#[CURRENT_PHASE, CURRENT_TURN_INDEX+4]

# add push.1 swap sub dup
#[CURRENT_PHASE + CURRENT_TURN_INDEX + 4 -1, CURRENT_PHASE + CURRENT_TURN_INDEX + 4 -1 ]

# exec.account::get_item drop drop drop
#[phase_n_sum, CURRENT_PHASE + CURRENT_TURN_INDEX + 4 -1]

# push.HIGHEST_BET_SLOT_INDEX drop drop drop
#[HIGHEST_BET_SLOT_INDEX, phase_n_sum, CURRENT_PHASE + CURRENT_TURN_INDEX + 4 -1]

# exec.account::get_item drop drop drop
#[highest_bet, phase_n_sum, CURRENT_PHASE + CURRENT_TURN_INDEX + 4 -1]

# add
#[highest_bet + phase_n_sum, CURRENT_PHASE + CURRENT_TURN_INDEX + 4 -1]

# swap exec.account::set_item
# []
exec.update_current_turn
end


Loading