0xPolygonMiden / compiler

Compiler from MidenIR to Miden Assembly
MIT License
56 stars 19 forks source link

MASM pseudo code for dealing procedure #148

Open nlok5923 opened 4 months ago

nlok5923 commented 4 months ago

Hi Guys!

Can you help me write MASM code for the below dealing procedure for a poker game.

Pseudo code for the dealing procedure

Description: Given a deck of cards where the cards are already encrypted and shuffled using dealing procedure we need to distribute the card among regular update accounts.

For now let’s assume that the card is a struct and we need to deal cards among 4 regular updatable account

struct Card {
  cardType: enum,
  cardNumber: number,
  cardColor: enum
}

struct Deck {
 isShuffled: boolean,
 Cards[52; Card],
 isEncrypted: boolean
}

Pseudo code for dealing

Game {
... // several other game procedures

accountId public players[4];
Deck public deck;
mapping(accountId => Card[2]) playerCards;

function dealCards() { 
    let _cardIndex = 0;
    for _, playerAccountId in players {
       for _ in 0..2 {
           playerCards[playerAccountId] = deck[_cardIndex];
           _cardIndex++;
       }
    }    
}

... // several other game procedures
}
Dominik1999 commented 4 months ago

After a short call, we can assume that

Then, the Account needs the following procedures:

proc.initiate_game
# => Account stores players represented by a WORD to memory slots

proc.encrypt_cards
# => Account encrypts the card array

proc.initiate_shuffling
# => Account creates a note containing the encrypted card array that gets passed to every player
proc.finalize_shuffling
# => The last player stores the final shuffled card array in the account

proc.deal_cards
# => Account loops over players and stores card info and sends notes with card info to each player