I have a problem with creating an algorithm to predict a winner of thirty-one game.
Players from a deck of cards, take the Ace, 2, 3, 4, 5, and 6 of each suit. These 24 cards are laid out face up on a table. The players alternate turning over cards and the sum of the turned over cards is computed as play progresses. Each Ace counts as one. The only limit is the sum value of stacked cards: it cannot exceed 31. The player who cannot make a move loses.
My task is to determine the winner in the game based on stack of cards put aside. We assume that both players play perfectly.
356656 means gameplay: player A puts down 3, player B puts down 5, player A puts down 6, player B puts down 6, player A puts down 5, finally player B puts down 6 and wins because player A cannot make any move.
356656 -> winner B 35665 -> winner B 3566 -> winner A 111126666 -> winner A 552525 -> winner A 2 -> winner A