🎂 Houdini 150   🚚 FREE FEDEX SHIPPING from 397 USD   🌎 WORLDWIDE SHIPPING for 25 USD

Poker Hands by Jordy Thys

Introduction

MagiScript has a built-in database for several cards stack. Jordy Thys has contributed this code which can calculate poker hands and display the hands on a PeekSmith screen.

The Routine

Have a spectator cut the deck until they are satisfied, let them choose how many poker hands they want to be dealt, and let them choose which pile they want.

The magician can name all five cards from the pile.

The magician can also name the cards from the other piles upon request.

The effect uses a memorized deck.

Four digits are entered into Atom:

  • First two digits: the stack value of the bottom card after cutting (peek at 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".

/*
    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));
  }
}
cross