12
\$\begingroup\$

Cribbage is an interesting game, because you need a specific board to score your game. A cribbage board looks like this:

enter image description here

Notice how the first column is on the left as it goes up, then on the right as it goes down, then back on the left as it goes up again.

And here is what a poorly drawn rendered ASCII art of a cribbage board looks like:

                     * * *
   -----------      -------
  /     *     \     |*|*|*|
 /*     *     *\    |*|*|*|
/   *   *   *   \   |*|*|*|
|     *   *     |   |*|*|*|
|* * *     * * *|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
 * * *    |* * *     * * *|
          |     *   *     |
          \   *   *   *   /
           \*     *     */
            \     *     /
             -----------

Here is your challenge:

Step 1: Draw this ASCII art of a cribbage board. Trailing whitespace is OK, provided that there is no visible difference.

Step 2: Given three integers as input, display each peg in the correct hole. The pegs can be 0-indexed or 1-indexed. The inputs will be in [0-121] inclusive. You can take these inputs in any reasonable manner, for example, 3 separate inputs, an array, command line arguments, etc. Here's an example for the input (0, 37, 100) (1-indexed):

                     * * *
   -----------      -------
  /     *     \     |*|*|*|
 /*     *     *\    |*|*|*|
/   2   *   *   \   |*|*|*|
|     *   *     |   |*|*|*|
|* * *     * * *|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|3|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
 1 * *    |* * *     * * *|
          |     *   *     |
          \   *   *   *   /
           \*     *     */
            \     *     /
             -----------

Step 3: Output the whole thing.

Test IO:

Since each of these is pretty vertically tall, I will only include 2, but you can see more at this github gist.

#Input: (56, 56, 56)
#Output:
                     * * *
   -----------      -------
  /     *     \     |*|*|*|
 /*     *     *\    |*|*|*|
/   *   *   *   \   |*|*|*|
|     *   *     |   |*|*|*|
|* * *     * * *|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |3|2|1|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
 * * *    |* * *     * * *|
          |     *   *     |
          \   *   *   *   /
           \*     *     */
            \     *     /
             -----------

#Input: (120, 89, 23)
#Output:
                     * * *
   -----------      -------
  /     *     \     |1|*|*|
 /*     *     *\    |*|*|*|
/   *   *   *   \   |*|*|*|
|     *   *     |   |*|*|*|
|* * *     * * *|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|3|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|2|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
|*|*|*|   |*|*|*|   |*|*|*|
-------   -------   -------
 * * *    |* * *     * * *|
          |     *   *     |
          \   *   *   *   /
           \*     *     */
            \     *     /
             -----------

Standard loopholes apply, and the shortest answer in bytes wins!

\$\endgroup\$
4
\$\begingroup\$

Python 3, 496 bytes

z=r"""SSSWT 
WOSY
  /UR\UZ
 /RR*\W Z
/WQQQ\WZ
MWZ
NWZVVVVVVV
YWYWY
 TW NPW MPW \WQQQ/PU\RR*/ PS\UR/PS O"""
for y in'M|UQR|,N|TUT|,OY----,P\nS,Q*W,R*U,SWW,T* * *,UW  ,V\nYWYWYXXXXX,W   ,X\nZ   Z   Z,Y-------,Z|*|*|*|'.split(','):z=z.replace(y[0],y[1:])
L=list(range(50,-1,-1))
del L[1::6]
def f(*s):
 b=list(z)
 for p in(0,1,2):b[(L[:-5]+[3+p,2+p,3+p]+L[-6::-1]+[51+p,52+p,51+p]+L)[s[p]]*28+([2*p+1]*37+[2+2*p,8,14-2*p]+[15-2*p]*37+[16-2*p,18,20+2*p]+[21+2*p]*42)[s[p]]]=str(p+1)
 print(*b,sep='')

Running (or importing) the code creates a function that is called with the three players scores: f(5, 38, 53).

Somewhat ungolfed version

z=r"""SSSWT 
WOSY
  /UR\UZ
 /RR*\W Z
/WQQQ\WZ
MWZ
NWZVVVVVVV
YWYWY
 TW NPW MPW \WQQQ/PU\RR*/ PS\UR/PS O"""

subs='M|UQR|,N|TUT|,OY----,P\nS,Q*W,R*U,SWW,T* * *,UW  ,V\nYWYWYXXXXX,W   ,X\nZ   Z   Z,Y-------,Z|*|*|*|'

for y in subs.split(','):
   z=z.replace(y[0],y[1:])

L=list(range(50,-1,-1))
del L[1::6]

def f(*s):
 b=list(z)
 for p in(0,1,2):
  R = L[:-5] + [3+p,2+p,3+p] + L[-6::-1] + [51+p,52+p,51+p] + L
  C = [2*p+1]*37 + [2+2*p,8,14-2*p] + [15-2*p]*37 + [16-2*p,18,20+2*p] + [21+2*p]*42
  b[R[s[p]]*28+C[s[p]]] = str(p)

 print(*b,sep='')

z is a coded/compressed version of the empty cribbage board.

subs contains a comma separated list of substitutions to decode/uncompress z. In each substitution, the first letter is the substring to replace and the remainder of the string is the replacement. The for y in subs.split(','): loop does the substitutions. For example, Z|*|*|*| causes all 'Z's to be replaced by |*|*|*|. The compression method was used for its simplicity and effectiveness (its better than the stdlib). But it could probably be improved or replaced with something better.

Because, Python strings are immutable, b is a list of the characters in the game board.

R is a list mapping a player and score to a row in the ascii game board. It uses 'L', which is a list or row numbers from which row numbers corresponding to '-------'-rows have been deleted.

Similarly, C maps a player and score to a column in the ascii game board.

Using R and C, the proper peg hole in the game board can be set to the player's number.

Lastly, print(*b,sep='') prints each character in b without inserting a space between adjacent characters. (Saves a few bytes over using ''.join)

\$\endgroup\$
  • \$\begingroup\$ That's a nifty way to do multiple substitutions. \$\endgroup\$ – Chuck Morris Jun 19 '16 at 4:44
5
\$\begingroup\$

Matricks, 1441 980 bytes

Hooray for esolangs!

Edit: compressed checking each number into a loop to save a ton of bytes. Also made the bottom part "copy" the top (I need a reverse function). I also replaced most ascii characters with their raw values to save a few more. Also, I fixed a bug in the interpreter where number input wasn't working right.

a45;u[m"|;:5:1;];a[a45;u[m42:5:1;];];a{};a{};z:1;a[m32:6:1;a{a{};};];a{a{};};u{};u{};u{};z5:;v[mic%2:42:32;:1:17;s::"|;;s:16:"|;;s:7:32;s:9:32;v[m32:4:7;s1:2:42;s2:4:42;s3:6:42;a[mi(re3)&(c=1):42:32;:4:3;];a[m32:4:7;s3::42;s2:2:42;s1:4:42;];];s3::"|;;s3:16:"|;;s2::47;s1:1:47;s:2:47;s2:16:92;s1:15:92;s:14:92;v[mi(cT3)&(cE13)&(r=1):45:32;:2:17;];a[m32:7:3;];a[a45;u[m"|;:5:1;];a[a45;u[m42:5:1;];];a{};a{};z:1;v[mic%2:42:32;:1:7;];];];u{z43:10;q1:;u{q5:;};u{q4:;z2:;};u{q3:;z4:;};u{q2:;z6:;};u{q1:;z8:;};u{z10:;};q6:;s2::92;s3:1:92;s4:2:92;s2:16:47;s3:15:47;s4:14:47;b[mi(c%2)&(ce6):42:32;:1:10;];};s:1:48;s:2:-1;j1;
s:1:g:1;+1;s:2:g:2;+1;s::n;;ig:;E36:s(40-g:;)*1.2+2:1+g:2;*2:g:1;;:ig:;T80:s(120-g:;)*1.2+2:21+g:2;*2:g:1;;:i(g:;E76)&(g:;T40):s(g:;-31)*1.2-4:15-g:2;*2:g:1;;:ig:;=37:s3+g:2;:2+g:2;*2:g:1;;:ig:;=38:s2+g:2;:8:g:1;;:ig:;=39:s3+g:2;:14-g:2;*2:g:1;;:ig:;=77:s51+g:2;:16-g:2;*2:g:1;;:ig:;=78:s52+g:2;:18:g:1;;:s51+g:2;:20+g:2;*2:g:1;;;;;;;;;;ig:2;e2:j1;:s::;s:1:;;s:2:;

Takes input on command line: python matricks.py <filename> [[]] <num1>,<num2>,<num3> --asciiprint

Matricks is a language of my own creation. Documentation is on the Github page. The most recent update was a bugfix, no new features added or anything.

Breakdown of this solution:

  1. First block created
  2. Block copied to fill entire board
  3. Top curve
  4. Bottom curve
  5. Checking the placement of each number
\$\endgroup\$
4
\$\begingroup\$

Python 2, 615 bytes

def f(a):
 D="-";S=" ";A=S*55+D+S;B="|/4 /41/4 - 2  -4-3   -|/4 /43/4 - 2  -4-1   -".replace("4","    ");C=B.replace("/","\\");s=t=u="";d={"1":0,"2":0,"3":0}
 for i in range(23):j=15>i>7;k=i-i/8;x=k%7*5;y=(6-k%7)*5;M=A+S*52+("123","321")[i<8]+D+S+A;N=chr((x,y)[j]/10+49);Q=("|"+N)[i%2]*5+D;s+=(S+S*5*(i<7)+C[x+39:x+34:-1]*j+B[y+39:y+34:-1]*(i>15)+("| "[i<7]+N)[i%2]+D+Q*(7+(i>15))+("|"+N)[i%2]+B[x:x+5]*(i<7)+C[y:y+5]*j+S*(i<16),(M[::-1],M)[i<8])[i%8==7]
 for x in s:
    if "4">x>"0":d[x]+=1;x=("*"+x)[d[x]==a[x]+1]
    t+=x
 for i in range(1512):j=i/27;k=i%27;u+=t[k*57+(56-j,j)[16>k>10and 51>j>5]]+"\n"*(k>25)
 print u

The function is called by passing in a dictionary that contains the scores. For example:

f({"1":40, "2":70, "3":76})

The byte count reflects indenting the "for x" loop with tabs instead of spaces.

Explanation

The first loop builds the board horizontally into a 57x27 string, with track numbers instead of "holes".

       -|||||-|||||-|||||-|||||-|||||-|||||-|||||-||/
      1-11111-11111-11111-11111-11111-11111-11111-1  /
       -|||||-|||||-|||||-|||||-|||||-|||||-|||||-|  1/
      2-22222-22222-22222-22222-22222-22222-22222-2    -
       -|||||-|||||-|||||-|||||-|||||-|||||-|||||-| 2  -
      3-33333-33333-33333-33333-33333-33333-33333-3    -
       -|||||-|||||-|||||-|||||-|||||-|||||-|||||-|3   -
                                                       -
                                                    321-
                                                       -
    \||-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|3   -
   \  3-33333-33333-33333-33333-33333-33333-33333-3    -
  \3  |-|||||-|||||-|||||-|||||-|||||-|||||-|||||-| 2  -
 -    2-22222-22222-22222-22222-22222-22222-22222-2    -
 -  2 |-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|  1\
 -    1-11111-11111-11111-11111-11111-11111-11111-1  \
 -   1|-|||||-|||||-|||||-|||||-|||||-|||||-|||||-||\
 -
 -321
 -
 -   1|-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|
 -    1-11111-11111-11111-11111-11111-11111-11111-11111-1
 -  2 |-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|
 -    2-22222-22222-22222-22222-22222-22222-22222-22222-2
  /3  |-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|
   /  3-33333-33333-33333-33333-33333-33333-33333-33333-3
    /||-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|||||-|

The second loop copies the string, replacing the numbers with asterisks except at the scoring peg locations. The peg locations in the straight lines in the middle of the track come out backward.

The third loop changes the orientation to vertical, correcting the pegs in the middle track and adding newline characters.

Try it here

\$\endgroup\$
4
\$\begingroup\$

Batch, 1302 1099 1096 1079 bytes

@set s= set 
@%s%o=echo 
@%o%off
%s%x=41
%s%y=35
%s%z=121
%s%m=-------
%s%w=     
%s%p=if %1==
%s%q=if %2==
%s%r=if %3==
%s%l=call:l
%l%
%o%%w%%w%%w%%w% %g% %h% %i%
%o%   %m%---- %w%%m%
%l%
%p%38%s%j=1
%o%  /%w%%j%%w%\  %n%
%l%
%q%38%s%j=2
%o% /%f%%w%%j%%w%%a%\ %n%
%l%
%q%37%s%j=2
%q%39%s%k=2
%o%/   %j%   %c%   %k%   \%n%
%l%
%o%^|%w%%c%   %d%%w%^|%n%
%l%
%o%^|%a% %b% %c%%w%%d% %e% %f%^|%n%
%l%
for /l %%a in (1,1,7)do call:b
%o%%m%   %m%   %m%
%o% %a% %b% %c%    ^|%d% %e% %f%%w%%g% %h% %i%^|
%l%
%o%%w%%w%^|%w%%f%   %g%%w%^|
%l%
%q%77%s%j=2
%q%79%s%k=2
%o%%w%%w%\   %j%   %g%   %k%   /
%l%
%q%78%s%j=2
%o%%w%%w% \%i%%w%%j%%w%%d%/
%r%78%s%j=3
%o%%w%%w%  \%w%%j%%w%/
%o%%w%%w%   %m%----
exit/b
:b
%o%%m%   %m%   %m%
for /l %%a in (1,1,4)do call:o
:o
%o%^|%a%^|%b%^|%c%^|   ^|%d%^|%e%^|%f%^|%n%
:l
for %%a in (a b c d e f g h i j k) do%s%%%a=*
%p%%x%%s%a=1
%q%%x%%s%b=2
%r%%x%%s%c=3
%r%%y%%s%d=3
%q%%y%%s%e=2
%p%%y%%s%f=1
%p%%z%%s%g=1
%q%%z%%s%h=2
%r%%z%%s%i=3
%s%n=   ^^^|%g%^^^|%h%^^^|%i%^^^|
set/ax-=1,y+=1,z-=1

Ungolfed:

@echo off
@rem values that pegs at the very top of each column would be
set x=41
set y=35
set z=121
rem deal with the four custom pegs on the top curve
call :loop
echo                      %g% %h% %i%
echo    -----------      -------
call :loop
if %1==38 (set j=1) else set j=*
echo   /     %j%     \     ^|%g%^|%h%^|%i%^|
call :loop
if %2==38 (set j=2) else set j=*
echo  /%f%     %j%     %a%\    ^|%g%^|%h%^|%i%^|
call :loop
if %2==37 (set j=2) else set j=*
if %2==39 (set k=2) else set k=*
echo /   %j%   %c%   %k%   \   ^|%g%^|%h%^|%i%^|
call :loop
echo ^|     %c%   %d%     ^|   ^|%g%^|%h%^|%i%^|
call :loop
echo ^|%a% %b% %c%     %d% %e% %f%^|   ^|%g%^|%h%^|%i%^|
call :loop
rem deal with the 7 sets of 5 standard rows
call :block
call :block
call :block
call :block
call :block
call :block
call :block
rem deal with the four custom pegs on the bottom curve
echo -------   -------   -------
echo  %a% %b% %c%    ^|%d% %e% %f%     %g% %h% %i%^|
call :loop
echo           ^|     %f%   %g%     ^|
call :loop
if %2==77 (set j=2) else set j=*
if %2==79 (set k=2) else set k=*
echo           \   %j%   %g%   %k%   /
call :loop
if %2==78 (set j=2) else set j=*
echo            \%i%     %j%     %d%/
if %3==78 (set j=3) else set j=*
echo             \     %j%     /
echo              -----------
exit/b
:block
echo -------   -------   -------
call :output
call :output
call :output
call :output
:output
rem prints each of the 35 main rows
echo ^|%a%^|%b%^|%c%^|   ^|%d%^|%e%^|%f%^|   ^|%g%^|%h%^|%i%^|
:loop
rem check for pegs in the current row, also works for some of the curve
if %1==%x% (set a=1) else set a=*
if %2==%x% (set b=2) else set b=*
if %3==%x% (set c=3) else set c=*
if %3==%y% (set d=3) else set d=*
if %2==%y% (set e=2) else set e=*
if %1==%y% (set f=1) else set f=*
if %1==%z% (set g=1) else set g=*
if %2==%z% (set h=2) else set h=*
if %3==%z% (set i=3) else set i=*
rem decrement the first and third columns, increment the second column
set/a x-=1
set/a y+=1
set/a z-=1
\$\endgroup\$
  • 1
    \$\begingroup\$ Dang, I need to beat this \$\endgroup\$ – Blue Jun 12 '16 at 0:02
  • \$\begingroup\$ Very impressive for a batch file. \$\endgroup\$ – Chuck Morris Jun 12 '16 at 1:04
2
\$\begingroup\$

Java, 1059 1035 bytes

class C{static int[]i=new int[3];String d="-------",l=d+"----";<T>void p(String s,T...o){System.out.format(s+"\n",o);}C(){p("%26s\n%14s%13s\n  /%6s     \\%15s\n /%s%6s%6s\\%14s\n/%4s%4s%4s   \\%13s\n|%6s%4s     |%13s\n|%s%10s|%13s",o(121,0),l,d,s(38,0),t(120,0),s(37,0),s(38,1),s(39,0),t(119,0),s(37,1),s(38,2),s(39,1),t(118,0),s(37,2),s(39,2),t(117,0),o(36,0),o(40,2),t(116,0));for(int j=0;j<7;)g(j++*5);d();p(" %s    |%s%10s|\n%11s%6s%4s     |\n%11s%4s%4s%4s   /\n%12s%s%6s%6s/\n%13s%6s     /\n%24s",o(0,0),o(76,2),o(80,0),"|",s(77,0),s(79,0),"\\",s(77,1),s(78,0),s(79, 1),"\\",s(77,2),s(78,1),s(79,2),"\\",s(78,2),l);}String s(int r,int c){return r==i[c]?c+"":"*";}String t(int r,int d){return l.format("|%s|%s|%s|   ",s(r,d),s(r,1),s(r,2-d));}void r(int r){p(t(35-r,0)+t(41+r,2)+t(115-r,0));}void d(){p(d+"%10s%10s",d,d);}void g(int r){d();for(int j=0;j<5;)r(r+j++);}String o(int r,int d){return l.format("%s %s %s",s(r,d),s(r,1),s(r,2-d));}public static void main(String[]a){for(int j=0;j<3;)i[j]=Integer.decode(a[j++]);new C();}}

Ungolfed:

class Crib {

    static int[] input = new int[3];
    String divider = "-------", longDivider = divider + "----";

    <T> void p(String s, T...o) {
        System.out.format(s+"\n",o);
    }

    Crib() {

        p("%26s", troika(121,0));
        p("%14s%13s", longDivider, divider);
        p("  /%6s     \\%15s", star(38,0), trio(120,0));
        p(" /%s%6s%6s\\%14s", star(37,0), star(38,1), star(39,0), trio(119,0));
        p("/%4s%4s%4s   \\%13s", star(37,1), star(38,2), star(39,1), trio(118,0));
        p("|%6s%4s     |%13s", star(37,2), star(39,2), trio(117,0));
        p("|%s%10s|%13s", troika(36,0), troika(40,2), trio(116,0));
        for(int i = 0; i < 7;)
            group(i++*5);
        printDivider();
        p(" %s    |%s%10s|", troika(0,0), troika(76,2), troika(80,0));
        p("%11s%6s%4s     |", "|", star(77,0), star(79,0));
        p("%11s%4s%4s%4s   /", "\\", star(77,1), star(78,0), star(79, 1));
        p("%12s%s%6s%6s/", "\\", star(77,2), star(78,1), star(79,2));
        p("%13s%6s     /", "\\", star(78,2));
        p("%24s", longDivider);
    }

    String star(int row, int cell) {
        return row == input[cell] ? cell+"" : "*";
    }

    String trio(int row, int diff) {
        return longDivider.format("|%s|%s|%s|   ", star(row, diff), star(row, 1), star(row, 2-diff));
    }

    void printRow(int row) {
        p(trio(35-row, 0) + trio(41+row, 2) + trio(115-row, 0));
    }

    void printDivider() {
        p(divider + "%10s%10s", divider, divider);
    }

    void group(int row) {
        printDivider();
        for(int i = 0; i < 5;)
            printRow(row+i++);
    }

    String troika(int row, int diff) {
        return longDivider.format("%s %s %s", star(row, diff), star(row, 1), star(row, 2-diff));
    }

    public static void main(String[] args) {
        for(int i = 0; i < 3;)
            input[i] = Integer.decode(args[i++]);
        new Crib();
    }
}

Abuses formats (printfs) like mad, which is probably why it's not as small as it could be.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.