⌚SB Watch 2
⌚SB Watch 2
🚚 Free fedex shipping from 97 $
🌎 WORLDWIDE SHIPPING for 25 $
Search
Close this search box.

Atom Stack

About

This mini-app is called Atom Stack! The goal is to show you how you can use MagiScript’s database functions to work with cards and card stacks. You can also use this app to learn stacks. The Si Stebbins, Mnemonica, Aronson, and Memorandum stacks are currently supported, but we can add more on demand.

The idea is simple. Enter the position of a card in an AC->AK, AD->KD, AH->KH, and AS->KS card stack (we call this “simple”), and Atom will display this and the next two cards in your chosen card stack. AC is 1. 2C is 2. 9C is 9. AH is 27. 3H is 29. AK is 52.

You can also “move around” with the bottom left and bottom right buttons. You can use this to learn, try guessing the next cards.

If you need help, just enter 00, and you will get some. 🙂

				
					const STACK = 'sistebbins';
/*
  '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('AtomStack');
  setTimeout(help, 2000);
}

let card = '';
let cardPosInStack = 0;
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) {
        help();
        return;
    }
    cardCode = (cardCode - 1) % 52; // 1st card has index 0

    let simpleCard = db.query('card', 'simple', cardCode);
    let cardInStack = db.query('card', STACK, simpleCard.name);
    cardPosInStack = cardInStack.pos;
    display();
}
function move(direction) {
    if (direction === '<') {
        cardPosInStack = cardPosInStack - 1;
        if (cardPosInStack < 0) {
            cardPosInStack = 51;
        }
    }
    if (direction === '>') {
        cardPosInStack = cardPosInStack + 1;
        if (cardPosInStack > 51) {
            cardPosInStack = 0;
        }
    }
    display();
}

let timeout = 0;
function onButtonClick(buttonId) {
    let key = mapping[buttonId];
    if (key === '<' || key === '>') {
        move(key);
        return;
    }
    card = card + key;
    ps.print(`<${card}>`);

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

function display() {
    const card1 = db.query('card', STACK, cardPosInStack);
    const card2 = db.query('card', STACK, cardPosInStack + 1);
    const card3 = db.query('card', STACK, cardPosInStack + 2);
    ps.print(`${card1.name} ${card2.name} ${card3.name}`);
}

function help() {
    ps.print('♣ 0 ♦13\n♥26 ♠39');
}

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

Let me explain how the code calculates the cards. Line 36, gets the representation of the card referred by the position number you have entered. Then using the name of this card (like 7D), it gets the representation of the card in the chosen stack. The important property is the “pos”, we are storing it, and at line 75 in the display function, the three cards will be queried, and their string name will be used to display them. If PeekSmith 3’s “Smart Text” is on, these will be displayed as color cards.

 

Tips and Tricks

change the constant in the first row to use an other stack

see the mapping array, that is the button layout, perhaps if you create one, this is a great way to format it like this

I’m not using the “cryptic” button ID 9 and 11 to match the bottom left and bottom right buttons but used the mapping, and the code is more clear.

 

Challanges

Modify the code to print this at the beginning. Use the \n notation to add a new line character.
AtomStack
Si Stebbins

Modify the code to not display the card you entered, but the next 3, or the previous 3 cards!

What about displaying 6 cards in 2 lines?
3S 6D 9C
QH 2S 5D

Can you add PeekSmith button support? The front buttons should move backward and forward as the Atom buttons do.