0xPolygonMiden / compiler

Compiler from MidenIR to Miden Assembly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MASM pseudo code for dealing procedure

nlok5923 opened this issue · comments

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
}

After a short call, we can assume that

  • Cards can be represented by an array of 52 WORDs
  • The card array can be encrypted and decrypted
  • Shuffling uses a note that passes sequentially from the gaming account to each player. Every player applies a permutation to the card vector
  • A player could be stored as [account_id, card_1, card_2, position]

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