17
4
Given a string representing the current state of a game of Monopoly at the beginning of a player's turn, compress all the necessary data into the smallest output. Answers will be judged by output size and source size.
Note: There are many regional variations, but all references in this post to property names, etc, are based on this board.
Input:
Input will be given as a single ;
separated string. This string is given to the program in whatever way is customary in your chosen language, whether that's stdin, arguments, etc.
The unformatted input looks like this:
numPlayers (1 to 8)
whose turn (0 to numPlayers-1)
for each player:
bankrupt? (true/false)
money (0 to 2^16-1)
get-out-of-jail-free cards (0 to 2)
position (0 to 39)
jail turns (-1 to 2)
for 28 properties:
owner (-1 to numPlayers-1)
mortgaged? (true/false)
improvement level (0 to 5)
for 16 chance cards in deck:
card index (-1 to 15)
for 16 community chest cards in deck:
card index (-1 to 15)
An example formatted input is this:
3;1;false;1546;0;14;-1;false;7692;1;10;1;true;1;false;1;1;false;0;0;true;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;-1;false;0;0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;3;12;7;4;5;2;13;11;15;6;8;9;10;1;14;-1;
Taken bit by bit:
3;1;
There are 3 players, and it is player 1's turn (zero-indexed, so the second player)
Players
false;1546;0;14;-1;
false;7692;1;10;1;
true;
The first player:
- is not bankrupt
- has $1546 cash on hand
- owns 0 get-out-of-jail-free cards
- is on position 14 (Virginia Ave)
- is not in jail
The second player is in jail, and has been for one turn. I'm not sure why, since he has a GOoJF card, but he's there.
The third player is bankrupt, and more information is neither required nor given.
Properties
1;false;1;
1;false;0;
0;true;0;
-1;false;0;
-1;false;0;
-1;false;0;
...
Properties are listed in order around the board, starting from Mediterranean and ending at Boardwalk. Properties that cannot be owned are not included in this list, so there will be a total of 28. Improvement level 0
means unimproved. Level 1
is one house, up to level 5
for a hotel. A -1
for owner means it is not owned by any player.
According to standard rules, a property that is mortgaged must be owned and must not be improved. A property that is improved must be owned and must not be mortgaged.
In addition, for a property to be improved, a player must own the entire color block. For the purposes of this game, we do not care if properties are being improved "evenly".
Note that these positions are not the same as the player positions given above. For instance, a player on the 5
position would be on Reading Railroad, which is the third property in the list (since Go, Community Chest, and Income Tax cannot be owned). Player positions run from 0
(Go) clockwise to 39
(Boardwalk).
Cards
0;1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;
3;12;7;4;5;2;13;11;15;6;8;9;10;1;14;-1;
Each of the Chance and Community Chest decks have 16
total cards. The numbers are presented as they appear in the currently shuffled deck. For this example, the first card pulled off the Chance deck will be card 0
, followed by card 1
(whoever shuffled that deck sucks). The first card pulled from Community chest is card 3
, then 12
.
Don't worry about what each card means (the card text), except for card 0
. That is the Get Out of Jail Free card for that deck. If a player owns it, it will be at the end of the list, represented as -1
.
Output:
You must output (to console, stdout, or file) a representation of the game state. This must include all information required to represent the game. For example, you could omit (or abbreviate) unowned properties, since they can neither be improved or mortgaged. The input cannot omit them because it is an unindexed list.
Compression should be done in a way that you can compute worst-case output size. This may disqualify certain compression algorithms (unless you can prove the worst case, and give an example of worst-case input).
Unless your source code is unreasonably verbose, give an explanation of how the game is represented. Answers consisting of nothing but a golfed program and compressed output are discouraged. For example, if you are omitting certain values, explain how it is possible to derive them from the output.
Scoring/Rules:
Scoring is based both on worst-case compression size in bits, and source code size in bytes:
score = (outputBits * 2) + encoderSourceBytes
A complete answer must include:
- Output example
- Encoder source
- Decoder source (not counted against score)
All encoders must be complete programs, and standard loopholes are forbidden. Using built-in or external compression libraries is also forbidden.
The winner is the answer with the lowest score, as defined above.
Hm, why not require a decoder as well as a proof that the encoding actually works (and is revertible)? Also what about including stuff like built-in gzip compression? That would make it really hard to figure out the worst-case compression size. – Martin Ender – 2014-05-01T16:56:03.450
@m.buettner Edited. I added a bit about compression libraries, and a bit about proof of worst-case. I don't really want to enforce a decoder. Posters can include them if they wish to prove their solution, but it won't be counted against the score. – Geobits – 2014-05-01T17:15:50.853
Oh yeah, I wasn't suggesting to add them to the score. You could still require an (ungolfed) decoder as proof. That makes it easier to test whether submissions can handle special cases. – Martin Ender – 2014-05-01T17:19:12.683
@m.buettner You make an excellent point. Decoders it is. – Geobits – 2014-05-01T17:24:01.053
2
The second player is in jail, and has been for one turn. I'm not sure why, since he has a GOoJF card, but he's there.
Being in jail is good lategame because you're not paying rent. :) – undergroundmonorail – 2014-05-01T17:50:56.163@undergroundmonorail Oh, I know, but only two properties are owned in this input. If this is late game, these are horrible players. In addition, one is bankrupt, so he must have been hit hard by the dice ;) – Geobits – 2014-05-01T17:53:12.887
@Geobits Heh, I didn't bother going through the rest of the input. Fair enough. :P – undergroundmonorail – 2014-05-01T17:59:32.013
Err, three are owned. I had one owned by a bankrupt player and one improved without matching properties. Fixed to make input legal. – Geobits – 2014-05-01T18:00:42.133
Does the output have match the input exactly or could changes be made that do not actually affect the state of the game? (e.g. moving bankrupt players to the end of the list wouldn't really matter since their not part of turns any longer) – Martin Ender – 2014-05-01T18:12:46.270
@m.buettner No, it doesn't have to exactly match. However, I'd hesitate to swap players unless you can show which player was originally in what position. You should be able to match it up to a player list (0->Alice,1->Bob,2->Charlie). – Geobits – 2014-05-01T18:20:34.447
@Geobits that does make sense. – Martin Ender – 2014-05-01T18:22:35.373