Printing the Cracker Barrel Game

9

Revised formatting and instructions

Given a list of moves for a Cracker Barrel peg board game, or as @Steveverrill stated, Peg Triangle Solitaire:

Game 1        Game 2         Game 3
1:  0 ,-1, -1   C, -1, -1     4, -1, -1  #starting point
2:  3, 1, 0     3, 7, C       B, 7, 4    #jump_from, jump_over, jump_to
3:  A, 6, 3     0, 1, 3       D, C, B
4:  8, 4, 1     6, 3, 1       5, 8, C
5:  B, 7, 4     5, 2, 0       1, 4, 8
6:  2, 4, 7     C, 8, 5       E, 9, 5
7:  D, C, B     A, B, C       6, 3, 1
8:  9, 5, 2     D, C, B       2, 5, 9
9:  1, 3, 6     9, 5, 2       B, C, D
10: 0, 2, 5     1, 4, 8       9, 8, 7
11: 6, 7, 8     0, 2, 5       0, 1, 3
12: 5, 8, C     5, 8, C       3, 7, C
13: B, C, D     B, C, D       D, C, B
14: E, D, C     E, D, C       A, B, C

Here is your task

  • Write a program that takes a list of moves, each move has three arguments which are slots on the board (jump_from, jump_over, jump_to). Move the peg from jump_from to jump_to and remove jump_over. (If that is unclear then read the instructions linked at the top)
  • Print the board for each move
    • The direction of the move a.k.a. the arrow
    • The slot jumped from a.k.a. the *
    • The slot jumped to (if peg 3 was in slot 3, and jumped to slot 0, then print a 3 in slot 0)
    • print a . for any empty slots

How to play

-If you don't understand these rules then there is a link at the top.

I've provided three different games that result in one peg remaining. The idea of the game is to start with one peg missing in the board and remove pegs until there is one left. A move is jumping over a peg into an empty slot and removing the peg you jumped over. Valid moves are diagonals and horizontal moves only. Example (assume slots 1, 2, 3, and 6 are open):

8 over 4 to 1 is valid

8 over 7 to 6 is valid

8 over 7 or 4 to 3 is invalid

B over 7 and 4 is invalid

Your output should look like the following. Each board printed is one move

(Use hex instead of decimal since printing the board in decimal causes the last row to be too wide)

This is Game 1 from the move set at the top

       / 0 \        #This is the board with all slots filled
      / 1 2 \       
     / 3 4 5 \      
    / 6 7 8 9 \     
   / A B C D E \ 

       / * \        #Move 1: remove the first peg which is 0
      / 1 2 \       
     / 3 4 5 \      
    / 6 7 8 9 \     
   / A B C D E \    

       / 3 \        #Move 2: Move peg 3 from slot 3 over slot 1 to slot 0
      / ↗ 2 \       Remove peg 1 from slot 1
     / * 4 5 \      
    / 6 7 8 9 \     
   / A B C D E \    

       / 3 \        #Move 3
      / . 2 \       
     / A 4 5 \      
    / ↗ 7 8 9 \     
   / * B C D E \    

       / 3 \        #Move 4
      / 8 2 \       
     / A ↖ 5 \      
    / . 7 * 9 \     
   / . B C D E \    

       / 3 \        #Move 5
      / 8 2 \       
     / A B 5 \      
    / . ↗ . 9 \     
   / . * C D E \    

       / 3 \        #Move 6
      / 8 * \       
     / A ↙ 5 \      
    / . 2 . 9 \     
   / . . C D E \    

       / 3 \       #Move 7
      / 8 . \       
     / A . 5 \      
    / . 2 . 9 \     
   / . D ← * E \    

       / 3 \        #Move 8
      / 8 9 \       
     / A . ↖ \      
    / . 2 . * \     
   / . D . . E \    

       / 3 \        #Move 9:
      / * 9 \       Move peg 8 from slot 1 over slot 3 to slot 6
     / ↙ . . \      Remove peg A
    / 8 2 . . \     
   / . D . . E \    

       / * \        #Move 10
      / . ↘ \       
     / . . 3 \      
    / 8 2 . . \     
   / . D . . E \    

       / . \        #Move 11
      / . . \       
     / . . 3 \      
    / * → 8 . \     
   / . D . . E \    

       / . \        #Move 12
      / . . \       
     / . . * \      
    / . . ↙ . \     
   / . D 3 . E \    

       / . \        #Move 13
      / . . \       
     / . . . \      
    / . . . . \     
   / . * → D E \    

       / . \        #Move 14
      / . . \       
     / . . . \      
    / . . . . \     
   / . . E ← * \   

The * represents the most recent peg removed. That is why the board starts with a * at slot 0 instead of a 0. . represents an empty slot. The slots stay in the same position but the pegs are numbered and move around so for the very last move peg E moves from slot E over peg/slot D to slot C

The direction of the move is the unicode characters u2190 through u2199

This is code golf so lowest number of bytes wins. Good Luck!

If something is unclear don't hesitate to ask. I will do my best to clarify.

SirParselot

Posted 2015-07-20T12:52:13.097

Reputation: 389

3I don't understand your representation of the board. There is no "0" peg at the beginning, but after the first jump, a "0" peg appears. So I thought maybe you are just numbering the positions, but then somehow a 3 ended up on the bottom row, which means the pegs are moving around. Can you explain your output? – Rainbolt – 2015-07-20T13:16:34.673

@Rainbolt You were confused for good reason. I had my output screwed up but I think I fixed it and if not hopefully enough to be understood. I also added some clarification near the end – SirParselot – 2015-07-20T13:29:53.647

2You've explained the meaning of the * and ., but the non-ASCII symbols are not mentioned. Are they required in the output? – trichoplax – 2015-07-20T13:54:38.480

That's the direction of the move which is required. I have that at the top but I'll make it more clear – SirParselot – 2015-07-20T13:57:14.823

@Rainbolt The input should always be valid. There's no need to check for invalid moves. Regarding the identifying holes vs pegs if you only identify holes then you can represent the pegs being moved, only the holes being filled or not which makes the board harder to read. It's however you want to look at it honestly. I chose pegs and holes to describe which peg was moving and to where. Lastly, I will change it to be hex only since the board doesn't display neatly with the last row being decimal. – SirParselot – 2015-07-20T16:54:26.513

@SirParselot Whoops, I deleted my comment right before you replied because it was only really a suggestion and this is your first challenge. By the way, you can post challenge in the Sandbox once you gain a tiny amount of reputation (I think 50?), and then you can get feedback on challenges before you post them. Totally optional, but highly recommended if you want your challenge to be polished before you post it.

– Rainbolt – 2015-07-20T16:58:42.123

@Rainbolt I appreciate the suggestions. I like hearing feedback about my challenge. – SirParselot – 2015-07-20T17:01:12.223

What are the rules of the game? Are you missing words to the effect of "For each move in the list" somewhere in the description of what should be output, or is the example covering lots of different inputs? How can we "post your output as well" if the output depends on the input? (And if it's going to be the same as the example output, why on Earth should we force everyone who wants to read the answers to scroll past a massive chunk of text which doesn't add any value to the page?) – Peter Taylor – 2015-07-20T17:49:43.817

@PeterTaylor Sorry, I just assumed people would know the rules of the game. Everyone knows them from where I'm from. I'll post them. I will also add more description about the moves in the list. – SirParselot – 2015-07-20T18:05:26.417

3We don't have Cracker Barrel restaurants outside the US. I've added a link to a website with the rules (it seems the name of the game is in fact peg triangle solitaire) but I think you should describe them also. – Level River St – 2015-07-20T18:07:58.537

@steveverrill thanks, I completely passed over that detail – SirParselot – 2015-07-20T18:44:26.760

No answers