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 1 commit
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
Next Next commit
add update current turn in proc call
  • Loading branch information
Created-for-a-purpose committed May 19, 2024
commit e19bc91a997a8f7f67a9aebc9947f166f8d4ce76
56 changes: 38 additions & 18 deletions lib/contracts/core/game.masm
Original file line number Diff line number Diff line change
Expand Up @@ -153,47 +153,67 @@ export.play_call
# TODO: checks the player has enough amount for matching bet
# TODO: checks the first player can't go for check

push.CURRENT_TURN_PLAYER_PUB_KEY_INDEX exec.account::get_item
# => [0, 0, 0, pub key index of current player]
push.CURRENT_TURN_INDEX exec.account::get_item
# => [0, 0, 0, current_turn_index]

# dropping three zeroes
drop drop drop dup
# => [pub key index of current player, pub key index of current player]
# => [current_turn_index, current_turn_index]

push.2 add exec.account::get_item
# => [0, 0, 0, player last bet, pub key index of current player]
push.3 add exec.account::get_item
# => [0, 0, 0, player last bet, current_turn_index]
drop drop drop
# => [player last bet, pub key index of current player]
# => [player last bet, current_turn_index]

# when user wants to just call and match the bet
push.HIGHEST_BET_SLOT_INDEX exec.account::get_item
# => [0, 0, 0, highest bet, player last bet, pub key index of current player]
# => [0, 0, 0, highest bet, player last bet, current_turn_index]

drop drop drop
# => [highest bet, current bet, pub key index of current player]
# => [highest bet, current bet, current_turn_index]

swap sub
# => [highest bet - current bet, pub key index of current player] subtract this amount from player balance
# => [difference, pub key index of current player]
# => [highest bet - current bet, current_turn_index] subtract this amount from player balance
# => [difference, current_turn_index]

swap dup movup.2 swap
# => [current player pub key index, difference, current player pub key index]
push.3 add exec.account::get_item
# => [current_turn_index, difference, current_turn_index]
push.4 add exec.account::get_item
drop drop drop
# => [balance, difference, current player pub key index]
# => [balance, difference, current_turn_index]

swap sub
# => [balance - difference, current player pub key index]
# => [balance - difference, current_turn_index]
swap padw drop movup.3
# => [current player pub key index, 0, 0, 0, remaining balance]
push.3 add
# => [current player pub key index + 3, 0, 0, 0, remaining balance]
# => [current_turn_index, 0, 0, 0, remaining balance]
push.4 add
# => [current_turn_index + 4, 0, 0, 0, remaining balance]

# => updated player balance
exec.account::set_item
dropw dropw

# TODO: need to add procedure for updating player turns
# update player last bet
push.HIGHEST_BET_SLOT_INDEX exec.account::get_item
# => [0, 0, 0, highest bet]
drop drop drop
# => [highest bet]

push.CURRENT_TURN_INDEX exec.account::get_item
# => [0, 0, 0, current_turn_index, highest bet]
drop drop drop
# => [current_turn_index, highest_bet]
push.3 add
# => [current_turn_index + 3, highest_bet]
padw drop movup.3
# => [current_turn_index + 3, 0, 0, 0, highest_bet]

exec.account::set_item
dropw dropw
# => [...]

# update current turn
exec.update_current_turn
end

# need to setup asm build first for this
Expand Down
150 changes: 125 additions & 25 deletions lib/contracts/notes/game/call.masm
Original file line number Diff line number Diff line change
@@ -1,59 +1,159 @@
use.miden::account
use.miden::note
use.miden::contracts::wallets::basic->wallet
use.miden::contracts::poker::poker

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.SMALL_BLIND_INDEX=54
const.BIG_BLIND_INDEX=55
const.BUY_IN_INDEX=56
const.PLAYER_STATS_SLOTS=13
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_PLAYER_PUB_KEY_INDEX=60
const.CURRENT_TURN_INDEX=60
const.HIGHEST_BET_SLOT_INDEX=61
const.CURRENT_PHASE=62
const.PLAYER_CHECK_COUNTER=63
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_call

push.CURRENT_TURN_PLAYER_PUB_KEY_INDEX exec.account::get_item
# => [0, 0, 0, pub key index of current player]
push.CURRENT_TURN_INDEX exec.account::get_item
# => [0, 0, 0, current_turn_index]

# dropping three zeroes
drop drop drop dup
# => [pub key index of current player, pub key index of current player]
# => [current_turn_index, current_turn_index]

push.2 add exec.account::get_item
# => [0, 0, 0, player last bet, pub key index of current player]
push.3 add exec.account::get_item
# => [0, 0, 0, player last bet, current_turn_index]
drop drop drop
# => [player last bet, pub key index of current player]
# => [player last bet, current_turn_index]

# when user wants to just call and match the bet
push.HIGHEST_BET_SLOT_INDEX exec.account::get_item
# => [0, 0, 0, highest bet, player last bet, pub key index of current player]
# => [0, 0, 0, highest bet, player last bet, current_turn_index]

drop drop drop
# => [highest bet, current bet, pub key index of current player]
# => [highest bet, current bet, current_turn_index]

swap sub
# => [highest bet - current bet, pub key index of current player] subtract this amount from player balance
# => [difference, pub key index of current player]
# => [highest bet - current bet, current_turn_index] subtract this amount from player balance
# => [difference, current_turn_index]

swap dup movup.2 swap
# => [current player pub key index, difference, current player pub key index]
push.3 add exec.account::get_item
# => [current_turn_index, difference, current_turn_index]
push.4 add exec.account::get_item
drop drop drop
# => [balance, difference, current player pub key index]
# => [balance, difference, current_turn_index]

swap sub
# => [balance - difference, current player pub key index]
# => [balance - difference, current_turn_index]
swap padw drop movup.3
# => [current player pub key index, 0, 0, 0, remaining balance]
push.3 add
# => [current player pub key index + 3, 0, 0, 0, remaining balance]
# => [current_turn_index, 0, 0, 0, remaining balance]
push.4 add
# => [current_turn_index + 4, 0, 0, 0, remaining balance]

# => updated player balance
exec.account::set_item
dropw dropw

# update player last bet
push.HIGHEST_BET_SLOT_INDEX exec.account::get_item
# => [0, 0, 0, highest bet]
drop drop drop
# => [highest bet]

push.CURRENT_TURN_INDEX exec.account::get_item
# => [0, 0, 0, current_turn_index, highest bet]
drop drop drop
# => [current_turn_index, highest_bet]
push.3 add
# => [current_turn_index + 3, highest_bet]
padw drop movup.3
# => [current_turn_index + 3, 0, 0, 0, highest_bet]

exec.account::set_item
dropw dropw
# => [...]

# update current turn
exec.update_current_turn
end


Expand Down