forked from Aze-Cards/aze-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from RizeLabs/rg/add-play-check
Feat: Adding proc fold, its endpoint and its unit test
- Loading branch information
Showing
13 changed files
with
3,827 additions
and
3,416 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
use.miden::account | ||
use.miden::note | ||
use.miden::contracts::wallets::basic->wallet | ||
|
||
const.NO_OF_PLAYERS_INDEX=57 | ||
const.CURRENT_TURN_INDEX=60 | ||
const.PLAYER_STATS_SLOTS=13 | ||
const.CARDS_SLOTS=52 | ||
|
||
proc.play_fold | ||
push.CURRENT_TURN_INDEX exec.account::get_item | ||
# => [0, 0, 0, current_turn_index] | ||
|
||
drop drop drop | ||
# => [current_turn_index] | ||
|
||
push.9 | ||
# 9, current_turn_index | ||
add | ||
# => [current_turn_index + 9] | ||
dup #for getting the get item | ||
dup #for updating the turn | ||
# => [current_turn_index + 9, current_turn_index + 9, current_turn_index + 9] | ||
|
||
# getting the is_fold of player | ||
exec.account::get_item | ||
drop drop drop | ||
# => [is_fold, current_turn_index + 9, current_turn_index + 9] | ||
|
||
# making sure that is_fold is zero currently | ||
assertz | ||
# => [current_turn_index + 9, current_turn_index + 9] | ||
push.1 | ||
# => [1, current_turn_index + 9, current_turn_index + 9] | ||
|
||
swap padw drop movup.3 | ||
# => [current_turn_index + 9, 0, 0, 0, 1, current_turn_index + 9] | ||
exec.account::set_item | ||
dropw drop drop drop | ||
# => [current_turn_index + 9] | ||
|
||
# adding 4 will give the slot of next player | ||
push.4 add | ||
# => [next_turn_index] | ||
|
||
# find last player's index | ||
push.NO_OF_PLAYERS_INDEX exec.account::get_item | ||
drop drop drop | ||
# => [no_of_players, next_turn_index] | ||
|
||
# Calculate last_player_index = 52 + 13 * no_of_players + 0 | ||
push.PLAYER_STATS_SLOTS mul | ||
push.CARDS_SLOTS add | ||
# => [last_player_index, next_turn_index] | ||
|
||
mem_store.0 | ||
# => [next_turn_index] | ||
|
||
push.1 | ||
# => [1, next_turn_index] | ||
|
||
while.true | ||
|
||
dup push.9 add | ||
# => [next_turn_index + 9, 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 | ||
push.0 | ||
end | ||
else | ||
# checking is fold | ||
# => [next_turn_index] | ||
|
||
padw drop | ||
# => [0, 0, 0, next_turn_index] | ||
|
||
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 | ||
|
||
begin | ||
dropw | ||
|
||
call.play_fold | ||
# => [...] | ||
|
||
dropw | ||
exec.note::get_assets drop mem_loadw | ||
# => [ASSET, ...] | ||
|
||
# load the asset and add it to the account | ||
call.wallet::receive_asset | ||
# => [...] | ||
|
||
dropw | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.