Skip to main content
5 of 7
deleted 42 characters in body
edc65
  • 32.2k
  • 3
  • 36
  • 90

#JavaScript (E6) 553 564 576

3 kinds of shapes:

  1. Back and Joker: more or less literal
  2. JQK: mark at topleft and rightbottom, inner frame and 3 kind of rows inside, always the same structure
  3. A...10: mark at topleft and rightbottom, inner frame with 3 kind of rows inside, variable with the numeric value. Taken care of with lookup using array and q variable

The z string (compressed) contains the basic building blocks for

  • numeric cards - 3 blocks, 7 chars each
  • joker - 11 blocks, 13 char each, used simply in sequence
F=c=>(
    p='|',b=' ',d=b+b,t=d+b,l='------',
    S='substr',
    z="9X2X4XJ55O1-02K |6|1E | J4|1R |1O3|3|2K2|3|3E1| J1|4R | O1|6| K2-01E55R".replace(/\d/g,n=>-n?b.repeat(-~n):l),
    i=8,
    console.log([c.split(b).map(c=>
      m==b
        ?' -'+l+l+b
        :p+(c=='B'
          ?' *'.repeat(7)[S](i&1,13)
          :c=='R'
            ?z[S](i,13)
            :(
               [,h,k]=c.match(/(.+)(.)/),
               k='♣♦♥♠'['CDHS'.search(k)], //uncomment to show the unicode symbols 
               n=h-1|0,
               s=t+t+t+(n>8?b:d),
               m-7
                ?m-8
                  ?m-9
                    ?d+p+(h>'A'
                      ?-m?m-6?m-3?t+b+t:t+h+t:t+t+k:k+t+t
                      :z[S](([64,1028,1092,8194,8258,8322,8326,9350,8802,9766][n]>>m*2&3)*7,7).replace(/X/g,k))+p+d
                    :t+'-'+l+t
                  :s+k+h
                :h+k+s
              )
         )+p
    ).join(b,i+=13)
  for(m of ' 79012345698 ')].join('\n'))
)

Test In FireFox/FireBug console

F('10C JD QH KS AC B R')

F('2C 3D 4H 5S 6C 7D 8H 9S')

Output

 -------------   -------------   -------------   -------------   -------------   -------------   ------------- 
|10♣          | |J♦           | |Q♥           | |K♠           | |A♣           | |* * * * * * *| |J            |
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | | * * * * * * | |O  -------   |
|  |♣     ♣|  | |  |♦      |  | |  |♥      |  | |  |♠      |  | |  |       |  | |* * * * * * *| |K |       |  |
|  |   ♣   |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | | * * * * * * | |E | J     |  |
|  |♣     ♣|  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |* * * * * * *| |R |  O    |  |
|  |       |  | |  |   J   |  | |  |   Q   |  | |  |   K   |  | |  |   ♣   |  | | * * * * * * | |  |   K   |  |
|  |♣     ♣|  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |* * * * * * *| |  |    E  | J|
|  |   ♣   |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | | * * * * * * | |  |     R | O|
|  |♣     ♣|  | |  |      ♦|  | |  |      ♥|  | |  |      ♠|  | |  |       |  | |* * * * * * *| |  |       | K|
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | | * * * * * * | |   -------  E|
|          ♣10| |           ♦J| |           ♥Q| |           ♠K| |           ♣A| |* * * * * * *| |            R|
 -------------   -------------   -------------   -------------   -------------   -------------   ------------- 

 -------------   -------------   -------------   -------------   -------------   -------------   -------------   ------------- 
|2♣           | |3♦           | |4♥           | |5♠           | |6♣           | |7♦           | |8♥           | |9♠           |
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   |
|  |       |  | |  |       |  | |  |♥     ♥|  | |  |♠     ♠|  | |  |♣     ♣|  | |  |♦     ♦|  | |  |♥     ♥|  | |  |♠     ♠|  |
|  |   ♣   |  | |  |   ♦   |  | |  |       |  | |  |       |  | |  |       |  | |  |   ♦   |  | |  |   ♥   |  | |  |       |  |
|  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |♠     ♠|  |
|  |       |  | |  |   ♦   |  | |  |       |  | |  |   ♠   |  | |  |♣     ♣|  | |  |♦     ♦|  | |  |♥     ♥|  | |  |   ♠   |  |
|  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |♠     ♠|  |
|  |   ♣   |  | |  |   ♦   |  | |  |       |  | |  |       |  | |  |       |  | |  |       |  | |  |   ♥   |  | |  |       |  |
|  |       |  | |  |       |  | |  |♥     ♥|  | |  |♠     ♠|  | |  |♣     ♣|  | |  |♦     ♦|  | |  |♥     ♥|  | |  |♠     ♠|  |
|   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   | |   -------   |
|           ♣2| |           ♦3| |           ♥4| |           ♠5| |           ♣6| |           ♦7| |           ♥8| |           ♠9|
 -------------   -------------   -------------   -------------   -------------   -------------   -------------   ------------- 

Not golfed code

F=c=>
{
  p='|',b=' ',d=b+b,t=d+b;
  l='------';
  z="9X2X4XJ55O10-2K |6|1E | J4|1R |1O3|3|2K2|3|3E1| J1|4R | O1|6| K20-1E55R".replace(/\d/g,n=>-n?b.repeat(-~n):l);
  c=c.split(b);
  for(o=i=''; c[0]&&i<13; i++)
  {
    o+=c.map(c => {
      if (i==0 || i==12) r=' -'+l+l+b;
      else
      {
        if (c=='B') r=' *'.repeat(7).substr(i&1,13);
        else if (c=='R') r=z.substr(i*13+8,13);
        else {
          [,h,k]=c.match(/(.+)(.)/),n=h-1|0,
          k='♣♦♥♠'[{C:0,D:1,H:2,S:3}[k]],
          r=t+t+t+(n>8?b:d);
          if(i==1)r=h+k+r;
          else if(i==11)r+=k+h;
          else if(i==2||i==10)r=t+'-'+l+t;
          else {
            if (h>'A')
            {
              if(i==3)r=k+t+t;
              else if(i==9)r=t+t+k;
              else if(i==6)r=t+h+t;
              else r=t+b+t
            }
            else 
            { 
              q=[64,1028,1092,8194,8258,8322,8326,9350,8802,9766][n]>>(i+i-6)&3,
              r=z.substr(q*7,7).replace(/X/g,k)
            }
            r=d+p+r+p+d
          }
        }
        r=p+r+p
      }
      return r
    }).join(' ')+'\n'
  }  
  console.log(o);
}
edc65
  • 32.2k
  • 3
  • 36
  • 90