Skip to content

Commit

Permalink
fix: adding some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Created-for-a-purpose committed May 10, 2024
1 parent 93f7e3d commit 824c535
Show file tree
Hide file tree
Showing 9 changed files with 3,339 additions and 3,499 deletions.
6,573 changes: 3,287 additions & 3,286 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ miden-tx = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch =
# miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base.git", branch = "main", version = "0.2", features = ["serde"] }
miden-client = { git = "https://github.com/0xPolygonMiden/miden-client.git", branch = "main", features= ["concurrent","testing"] }
miden-objects = { version = "0.2", default-features = false }
aze-types = { path = "../types" }

[dev-dependencies]

[build-dependencies]
Expand Down
22 changes: 19 additions & 3 deletions lib/contracts/core/game.masm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const.HIGHEST_BET_SLOT_INDEX=61 # highest bet amount which player will try to ma
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_STATS_SLOTS=13

# game events
# TODO: fix some storage for the value corresponding to these events
Expand Down Expand Up @@ -277,6 +278,21 @@ export.play_fold

# 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.13 mul
push.52 add
# => [last_player_index, next_turn_index]

mem_store.0
# => [next_turn_index]

push.1
# => [1, next_turn_index]

Expand All @@ -290,11 +306,11 @@ export.play_fold

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

if.true
push.13 add
push.PLAYER_STATS_SLOTS add
push.1
# => [1, next_turn_index + 13]
else
Expand All @@ -316,7 +332,7 @@ export.play_fold
push.0
end
end
drop
dropw
# => [...]
end

Expand Down
23 changes: 20 additions & 3 deletions lib/contracts/notes/game/fold.masm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ 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

proc.play_fold
push.CURRENT_TURN_INDEX exec.account::get_item
Expand Down Expand Up @@ -38,6 +40,21 @@ proc.play_fold

# 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.13 mul
push.52 add
# => [last_player_index, next_turn_index]

mem_store.0
# => [next_turn_index]

push.1
# => [1, next_turn_index]

Expand All @@ -51,11 +68,11 @@ proc.play_fold

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

if.true
push.13 add
push.PLAYER_STATS_SLOTS add
push.1
# => [1, next_turn_index + 13]
else
Expand All @@ -77,7 +94,7 @@ proc.play_fold
push.0
end
end
drop
dropw
# => [...]
end

Expand Down
196 changes: 0 additions & 196 deletions lib/contracts/poker/poker.masm

This file was deleted.

3 changes: 2 additions & 1 deletion lib/src/accounts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use miden_objects::{

use miden_lib::{ transaction::TransactionKernel, AuthScheme };
use crate::storage::GameStorageSlotData;
use crate::constants::PLAYER_STATS_SLOTS;

fn construct_game_constructor_storage(
auth_scheme: AuthScheme,
Expand Down Expand Up @@ -173,7 +174,7 @@ fn construct_game_constructor_storage(
];
player_pub_keys.extend(player_slots);

slot_index += 13; // since the mid 9 elements would cover the player stats and initially all those values are zero
slot_index += PLAYER_STATS_SLOTS; // since the mid 13 elements would cover the player stats and initially all those values are zero
}

// merge player_id with card_suit
Expand Down
3 changes: 2 additions & 1 deletion lib/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ pub const CURRENT_TURN_INDEX: u8 = 65;
pub const PLAYER_INITIAL_BALANCE: u8 = 10;
pub const HIGHEST_BET: u8 = SMALL_BLIND_AMOUNT;
pub const PLAYER_BALANCE_SLOT: u8 = 68;
pub const CURRENT_TURN_INDEX_SLOT: u8 = 60;
pub const CURRENT_TURN_INDEX_SLOT: u8 = 60;
pub const PLAYER_STATS_SLOTS: u8 = 13;
9 changes: 3 additions & 6 deletions node/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ async fn test_create_aze_game_account() {
async fn test_cards_distribution() {
let mut client: AzeClient = create_test_client();

let slot_data = GameStorageSlotData::new(0, 0, 0, 0, 0, 0);

let (game_account, player1_account_id, faucet_account_id, _) = setup_accounts(&mut client);

let game_account_id = game_account.id();
Expand All @@ -223,6 +221,7 @@ async fn test_cards_distribution() {
.unwrap();

fund_account(&mut client, game_account_id, faucet_account_id).await;
fund_account(&mut client, game_account_id, faucet_account_id).await;

let fungible_asset = FungibleAsset::new(faucet_account_id, BUY_IN_AMOUNT).unwrap();

Expand Down Expand Up @@ -563,8 +562,6 @@ async fn assert_slot_status_fold(
}

async fn fund_account(client: &mut AzeClient, account_id: AccountId, faucet_account_id: AccountId) {
let note_1 = mint_note(client, account_id, faucet_account_id, NoteType::Public).await;
consume_notes(client, account_id, &[note_1]).await;
let note_2 = mint_note(client, account_id, faucet_account_id, NoteType::Public).await;
consume_notes(client, account_id, &[note_2]).await;
let note = mint_note(client, account_id, faucet_account_id, NoteType::Public).await;
consume_notes(client, account_id, &[note]).await;
}
7 changes: 4 additions & 3 deletions types/src/actions.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use actix_web::{
error::ResponseError,
get,
http::{header::ContentType, StatusCode},
post, put,
http::{ header::ContentType, StatusCode },
post,
put,
web::Data,
web::Json,
web::Path,
HttpResponse,
};
use derive_more::Display;
use serde::{Deserialize, Serialize};
use serde::{ Deserialize, Serialize };

#[derive(Debug, Display)]
pub enum GameActionError {
Expand Down

0 comments on commit 824c535

Please sign in to comment.