⚛️ Atom 2 Smart Remote   🚚 FREE FEDEX SHIPPING from 397 USD   🌎 WORLDWIDE SHIPPING for 25 USD

Poker Hands par Jordy Thys

Introduction

MagiScript dispose d'une base de données intégrée pour plusieurs piles de cartes. Jordy Thys a contribué ce code qui peut calculer les mains de poker et les afficher sur un écran PeekSmith.

La routine

Demandez à un spectateur de couper le jeu jusqu'à ce qu'il soit satisfait, laissez-le choisir le nombre de mains de poker qu'il veut recevoir et laissez-le choisir la pile qu'il veut.

Le magicien peut nommer les cinq cartes de la pile.

Le magicien peut également nommer les cartes des autres piles sur demande.

L'effet utilise un jeu de cartes mémorisé.

Quatre chiffres sont entrés dans Atom :

  • Deux premiers chiffres : la valeur de la pile de la carte inférieure après la coupe (coup d'œil à la carte inférieure).
  • Troisième chiffre : nombre de mains à distribuer
  • Quatrième chiffre : la main choisie

Cet effet est basé sur une idée de Craig Raley du "TAP Users Group".

/*
    Effect:
    Have a spectator cut the deck until they are
    satisfied, let them choose how many poker hands
    they want to deal and let them choose which pile
    they want. 
    The magician can name all five cards from the pile.
    On request, the magician can also name the cards
    from the other piles.

    The effect uses a memorised deck.

    Four digits are entered into Atom:
    First two digits: the stack value of the bottom
    card after cutting (peek the bottom card)
    Third digit: number of hands to deal
    Fourth digit: the chosen hand

    This effect is based on an idea by Craig Raley
    of the "TAP Users Group".

    Hope you like it!
    Jordi Thys
*/

const STACK = 'memorandum';
/*
  'simple': simple deck: clubs, diamonds, hearts, and spades from Ace to King
  'new': a new deck order: AH->KH, AC->KC, KD->AD, KS->AS
  'sistebbins': Si Stebbins stack
  'mnemonica': Mnemonica by Juan Tamariz
  'aronson': Aronson stack by Simon Aronson
  'memorandum': Memorandum by Woody Aragón
*/

function main() {
  ps.connect('*');
  ps.print('Poker');
}

let timeout = 0;
let card = '';
let cardPosInStack = 0;
let bottomCard = -1;
let hands = -1;
let whichHand = -1;
let mapping = [
    '1', '2', '3',
    '4', '5', '6',
    '7', '8', '9',
    '<', '0', '>'
];

function search() {
    if (card === '') return;
    let cardCode = parseInt(card);
    card = ''; // reset the input

    if (cardCode === 0) {
        cardCode = -1;
        return;
    }

    bottomCard = cardCode;
}

function move(direction) {
    if (direction === '<') {
        whichHand--;
        if (whichHand < 0) {
            whichHand = hands - 1;
        }
    }
    if (direction === '>') {
        whichHand++;
        if (whichHand > hands - 1) {
            whichHand = 0;
        }
    }
    display();
}

function onButtonClick(buttonId) {
    let key = mapping[buttonId];

    if (key === '<' || key === '>') {
        move(key);
        return;
    }

    if (bottomCard !== -1) {
        if (hands === -1) {
            hands = parseInt(key);
            ps.print(`<${bottomCard} ${hands}>`);
            return;
        }
        if (whichHand === -1) {
            whichHand = parseInt(key) - 1;
            if (whichHand > hands - 1) {
                whichHand = -1;
                return;
            }
            ps.print(`<${bottomCard} ${hands} ${whichHand + 1}>`);
            display();
            return;
        }
    }

    bottomCard = -1;
    hands = -1;
    whichHand = -1;

    card = card + key;
    ps.print(`<${card}>`);

    clearTimeout(timeout);
    if (strLen(card) === 2) {
        search();
    } else {
        timeout = setTimeout(search, 3000);
    }
}

function display() {
    let cards = [];

    for (let i = 0; i < 5; i++) {
        let index = bottomCard + whichHand + hands * i;
        cards[i] = db.query('card', STACK, index);
    }

    let cardString = `${cards[4].name} ${cards[3].name} ${cards[2].name} ${cards[1].name} ${cards[0].name}`;

    ps.print(cardString);

    card = '';
}

function onEvent(e) {
  if (e.type === 'click' && e.source === 'atom:button') {
    onButtonClick(parseInt(e.value));
  }
}
croix