Scripts/Cards Generator

From J Wiki
Jump to: navigation, search

Template:Tick

This script generates a deck of cards as a graphical bitmap suitable for visualizing card layouts. The deck contains 52 cards, a joker, two coats and a blank.

Cards28x40.png

Features

  • suits are arranged by ascending value as used in some games
  • card dimension 28×40 (width, height) fits on a PocketPC screen
  • picture layout allows partially covered stacking
  • the bitmap above is suitable for loading "as is" with readbmp
  • cards can be extracted as matrices and composed in a layout

The bitmap file

You need to have the bmp file before using the cards in other utilities.

The easiest way is to download the bitmap from here

  • right-click on the image above
  • select "Save Picture As ..." or similar menu item
  • choose location j\user\cards\cards28x40.png
  • open it in your favorite image viewer/editor, such as Paint in Windows, and save as cards28x40.bmp in BMP format.

You can create a bitmap from the generator as shown below, however the image on this page was generated with system font configuration to ensure best quality.

f_run ''    NB. show the generated cards in a form
f_save ''   NB. save to user/cards/cards28x40.bmp

Bridge

Template:Tick

Here is an example of using the generated cards to lay out a table of bridge.

Bridge1.png

Generated with view deal'' from the script below.

require 'viewmat'

F=: readbmp jpath'~user/cards/cards28x40.bmp'
C=: ,/}:"_1 ] 0 3 2 1{(,:~40 28) ];.3 F
T=: 16ba000

    maxd =: |:@:({.@$&>) {@;&(>./) {:@$&>
  table  =: [: > [: ,&.>/ [: ,.&.>/"1 maxd {.!.T&.> ]
    hand =: (,!.T)&.>/
    stack=: (,.~ 12&{."1)~/
    group=: [: (<.@%&13 </. ]) /:~
  shand  =: empty`([: >@hand (<C) stack@:{&.>~ group)@.(*@#)
  tabmat =: 3 3 $&, a:&,.
view     =: [:viewrgb [:table [:shand&.> tabmat
deal     =: _13(<\?~)52"_


Contributed by Oleg Kobchenko