Print a Sorry Board

19

1

I was just playing the board game Sorry! with some people, and I realized that I could base a few interesting challenges off of it. This one is pretty simple.

You task is simply to output an version of a sorry board, placing pieces where I tell you to.

Specs

First, here is an image of an actual Sorry! board for reference:

Sorry! Board

The empty board looks like:

# > - - o # # # # > - - - o # #
#   #   S                     v
o   #             H # # # # # |
|   #                         |
|   #                       S o
|   #                         #
^   H                         #
#                             #
#                             #
#                         H   v
#                         #   |
o S                       #   |
|                         #   |
| # # # # # H             #   o
^                     S   #   #
# # o - - - < # # # # o - - < #

Notice a few features.

  • The #'s are empty squares.
  • The S's and H's are Start's and Home's respectively.
  • The >v<^'s are the start of the slides, depending on which direction they face.
  • The |'s and -'s are the middles of slides, depending on if they're horizontal or vertical.
  • The o's are the end's of slides.
  • Each column is separated by a column of spaces to make it look more square-like.

Now here is what you have to do:

  • Your input is a list of coordinates of various pieces that have been placed on the board.
  • The coordinates start at 0 at the square outside the Start of the bottom color (yellow in the picture), and increase by one per square clockwise.
  • After these 60 squares, the safe zones have the next and last 20 coordinates, starting from the one on the bottom (which gets 60-64), then going clockwise.
  • You will have to place star's(*'s) on the correct coordinate, replacing the character underneath for all players.
  • Additionally, if any of the players are on the start square of a slider, move them to the end of the slider before placing them.
  • You can assume that there will be no collisions, before or after resolving sliders.
  • You con't need to worry about the Home's or Start's.
  • You can be 1-indexed if you want, but the test cases are 0-indexed.

Test Cases

[0, 20] ->

# > - - o # # # # > - - - o # #
#   #   S                     v
*   #             H # # # # # |
|   #                         |
|   #                       S o
|   #                         #
^   H                         #
#                             #
#                             #
#                         H   v
#                         #   |
o S                       #   |
|                         #   |
| # # # # # H             #   o
^                     S   #   #
# # o - - - < # # # # * - - < #

[2, 7, 66] ->

# > - - o # # # # > - - - o # #
#   #   S                     v
o   #             H # # # # # |
|   #                         |
|   #                       S o
|   #                         #
^   H                         #
#                             #
#                             #
#                         H   v
#                         #   |
o S                       #   |
|                         #   |
| # * # # # H             #   o
^                     S   #   #
# # o - * - < # # * # o - - < #

Maltysen

Posted 2016-12-07T01:55:17.230

Reputation: 25 023

1I would have thought this would be more interesting if the values were given as distances from the respective start squares (so for instance the first test case might be 0, 5 and the second might be 2, 60, 37). – Neil – 2016-12-07T10:20:13.663

@Neil how would you know which start square to use? – Maltysen – 2016-12-07T12:24:34.043

Sorry, I assumed that you used the squares in clockwise order, but I guess that wouldn't be very fair for a 2-player game. – Neil – 2016-12-07T12:26:21.877

@Closevoters: What's unclear about this? If you identify some specific concerns, it will make it easier to fix them so that this can stay open. – James – 2016-12-07T17:30:15.007

My confusion is about the indexing, before and after 60 has been reached and when to mark locations in the home section. I think if you clarified your examples more it would make more sense. Otherwise it looks pretty cool. – jacksonecac – 2016-12-07T20:34:47.380

Can you clarify safe zones. I see, that there are 4 such zones for each color with 5 cells. And how do we treat them? If bottom safe zone is yellow (which is unclear too), why 66 is the 4th cell from the right in green? (going clockwise) Where is the #60 cell in this zones? – Dead Possum – 2017-04-06T15:26:41.180

Answers

1

Python 2, 476 bytes

Short 3-line solution (Try it online)

s=map(list,''.join(b if b in'#^v<>-|oSH~'else' '*int(b,16)for b in "#>--o####>---o##~#1#1SAv~o1#6H#####|~|1#C|~|1#BSo~|1#C#~^1HC#~#E#~#E#~#CH1v~#C#1|~oSB#1|~|C#1|~|#####H6#1o~^AS1#1#~##o---<####o--<#").split('~'))
for i in input():x,y=(lambda n:([11-n,15]*12+[0,26-n]*14+[n-26,0]*16+[15,n-41]*14+[71-n,15]*4+[13,n-50]*5+[70-n,13]*5+[2,75-n]*5+[n-65,2]*5)[2*n:2*n+2])((lambda n:4if n in[5,20,35,50]else 3if n in[12,27,42,57]else 0)(i)+i);s[y][x]='*'
for r in s:print' '.join(r)

One-liner in 534 (Try it online):

for r in(lambda B,I:[[[i,j]in map(lambda n:([11-n,15]*12+[0,26-n]*14+[n-26,0]*16+[15,n-41]*14+[71-n,15]*4+[13,n-50]*5+[n-64,13]*5+[2,75-n]*5+[n-65,2]*5)[2*n:2*n+2],map(lambda n:n+4if n in[5,20,35,50]else n+3if n in[12,27,42,57]else n,I))and'*'or b for i,b in enumerate(a)]for j,a in enumerate(B)])(map(list,''.join(b if b in'#^v<>-|oSH~'else' '*int(b,16)for b in"#>--o####>---o##~#1#1SAv~o1#6H#####|~|1#C|~|1#BSo~|1#C#~^1HC#~#E#~#E#~#CH1v~#C#1|~oSB#1|~|C#1|~|#####H6#1o~^AS1#1#~##o---<####o--<#").split('~')),input()):print' '.join(r)

I assume indices of safe zone this way:

#  >  -  -  o  #  #  #  #  >  -  -  -  o  #  #
#     74    S                                v
o     73                   H 75 76 77 78 79  |
|     72                                     |
|     71                                  S  o
|     70                                     #
^     H                                      #
#                                            #
#                                            #
#                                      H     v
#                                      60    |
o  S                                   61    |
|                                      62    |
|  69 68 67 66 65 H                    63    o
^                                S     64    #
#  #  o  -  -  -  <  #  #  #  #  o  -  -  <  #

Explanation (lines are separated a bit for better understanding):

# Hardcode board. Spaces are changed to their number in hex (as there are up to 14 spaces in row)
# Unfortunatly v^<> characters made board non-symmetrical and replacing chars costs too much in python, so I had to hardcode it all
B="#>--o####>---o##~#1#1SAv~o1#6H#####|~|1#C|~|1#BSo~|1#C#~^1HC#~#E#~#E#~#CH1v~#C#1|~oSB#1|~|C#1|~|#####H6#1o~^AS1#1#~##o---<####o--<#"

# Encode board to list of lists of characters
s=map(list,''.join(b if b in'#^v<>-|oSH~'else' '*int(b,16)for b in B).split('~'))

# Map coordinates, based on n (awfully long)
# Creates long list (lenght of 80) with values based on n and only one valid, which occures under index n
l=lambda n:([11-n,15]*12+[0,26-n]*14+[n-26,0]*16+[15,n-41]*14+[71-n,15]*4+[13,n-50]*5+[70-n,13]*5+[2,75-n]*5+[n-65,2]*5)[2*n:2*n+2]

# Returns additional move of n if it appers to be on slide start
j=lambda n:4if n in[5,20,35,50]else 3if n in[12,27,42,57]else 0

# Here takes input as list of numbers, get coordinates for them and update board with *
for i in input():x,y=l(j(i)+i);s[y][x]='*'

# Print board, spacing characters with one whitespace
for r in s:print' '.join(r)

Dead Possum

Posted 2016-12-07T01:55:17.230

Reputation: 3 256