public List<Move> Calculate(Game game, int diskCount) { var calc = new MoveCalculator(); return calc .GeneratePlaySequence(diskCount) .Select(disk => calc.GenerateNextMove(game, diskCount, disk)) .ToList(); }
public Move GenerateNextMove(Game game, int diskCount, string disk) { var index = new AlphaNumericConverter().AlphaToNumeric(disk); var move = new Move { Disk = disk }; var oddStackPositionStepDirection = StackHasOddNumberOfDisks(diskCount) // If stack has an odd disk count ? StepDirection.Left // start with move to left : StepDirection.Right; // else start with move to the right // Disks moves alternate between left and right move.StepDirection = DiskIsInEvenStackPosition(index) ? ReverseStepDirection(oddStackPositionStepDirection) : oddStackPositionStepDirection; return move; }
public Tower FindDisk(Game game, string disk) { return game.Towers.Cast<Tower>() .FirstOrDefault(tower => tower.TopDisk() == disk); }