This program minimizes the number of points that a given player is left with at the end of a game of rummikub. It, in turn, helps the player to win the game. Since there is no "emotional" content to this game, this program could essentially play instead of the human.
Algorithm loosely based on this paper : The complexity of Rummikub Problems by Jan N. van Rijn, Frank W. Takes and Jonathan K. Vis -- http://liacs.leidenuniv.nl/~takesfw/pdf/rummikub.pdf
Here are the rules according to http://www.rummy-games.com/rules/rummikub.html:
SABRA WAY is played by 2, 3, or 4 people. It is played very much like cards except you play with tiles. There are 106 tiles in the game including 2 jokers.
There are 4 different color tiles, black, red, orange, and blue numbering 1 through 13.
The object of the game is to be the first to eliminate all the tiles from your rack by forming them into sets of runs and groups, and then melding them onto the table.
Your objective, therefore, is to keep as few points in your hand as possible.
Mix the tiles thoroughly face downward on the table. Each player picks a tile to see who goes first. The one who selects the highest tile is the first to play. The others follow going counterclockwise.
After you determine who plays first, all the players pick 14 tiles.
In order to place tiles on the table each player must make an initial meld of 50 points in one or more sets. These points must come from tiles in the hand only and not from tiles already on the table. Each tile is worth the number of points as valued on the tile. A joker may be substituted for any tile and its point value is the same as the tile it represents when melding, and worth 30 points when held on your rack while another player wins.
All runs must consist of at least 3 tiles of the same color -
EXAMPLES:4, 5, 6 red 1, 2, 3, 4 orange
Groups must consist of 3 or 4 tiles of different colors
EXAMPLE:#4 red, #4 blue, #4 black
Not acceptable: #4 orange, #4 orange, #4 red
Each loser adds up the value of the tiles left on his rack, counting 30 points for a joker and face value for all other tiles, and scores this as a minus (negative) amount.
The sum of all the loser's scores is credited to the winner as a plus amount. At the end of the session, each players final score is totalled for the final results. The total of the plus scores should equal the total of the minus scores if all the arithmetic has been done correctly.
In the rare case that all the tiles are used up before anyone goes Rummikub®, the player with the lowest count remaining on his rack is considered the winner. Each of the losers adds up his total remaining tile value, subtracts the winner's total and scores the result as a minus amount, and the winner gets a plus score by totalling the loser's scores.