public List<Play> LegalPlays(int player, int[] dice)
{
List<Play> plays = new List<Play>(); // Contains the legal move sequences.
List<Play> partial_plays = new List<Play>(); // Contains move sequences, which leave one or more unused dice.
List<Move> moves_made = new List<Move>(); // Contains the moves made so far in the recursion.
List<int> free_dice = new List<int>(); // Contains unused dice so far in the recursion.
HashSet<string> board_hash = new HashSet<string>(); // Contains the hashes of already traversed boards.
free_dice.Add(Math.Max(dice[0], dice[1]));
free_dice.Add(Math.Min(dice[0], dice[1]));
if (dice[0] == dice[1])
{
free_dice.Add(dice[0]);
free_dice.Add(dice[1]);
}
Recursion(player, free_dice, this, moves_made, ref plays, ref partial_plays, ref board_hash);
//Recursion(player, free_dice, this, moves_made, ref move_hints);
if (plays.Count == 0 && partial_plays.Count > 0)
{
if (partial_plays.Count == 1)
{
plays.Add(partial_plays[0]);
}
else
{
if (dice[0] != dice[1])
{
foreach (Play partial_move_sequence in partial_plays)
if (partial_move_sequence[0].Distance == Math.Max(dice[0], dice[1]))
plays.Add(partial_move_sequence);
}
else
{
// I believe this should never happen
Console.WriteLine("LegalMoves Partialmovehints problem!");
}
}
}
return plays;
}