예제 #1
0
 public void Add_SmallerSecondDisk_AddsOneMoreDiskToTower()
 {
     var tower = new Tower();
     tower.AddDisk("B");
     tower.AddDisk("A");
     tower.Count.ShouldEqual(2);
     tower.TopDisk().ShouldEqual("A");
 }
예제 #2
0
        public void Add_LargerSecondDisk_ThrowsException()
        {
            var tower = new Tower();
            tower.AddDisk("A");
            try
            {
                tower.AddDisk("B");
            }
            catch (InvalidOperationException ex)
            {
            }

            tower.Count.ShouldEqual(1);
            tower.TopDisk().ShouldEqual("A");
        }
예제 #3
0
 public void Add_FirstDisk_AddsOneDiskToTower()
 {
     var tower = new Tower();
     tower.AddDisk("A");
     tower.Count.ShouldEqual(1);
     tower.TopDisk().ShouldEqual("A");
 }
예제 #4
0
    public IEnumerator MoveDisk(Tower targetTower)
    {
        yield return(stack.Peek().MoveDisk(targetTower));

        if (stack.Count > 0)
        {
            targetTower.AddDisk(RemoveDisk());
        }
    }
예제 #5
0
        private async Task SolveTower(int totalDisks, Tower start, Tower end, Tower mid)
        {
            if (totalDisks > 0)
            {
                await SolveTower(totalDisks - 1, start, mid, end);

                ++_moveStep;
                var disk = start.RemoveDisk();
                end.AddDisk(disk);
                var mov = new Move(new List <Tower> {
                    start, end, mid
                }, disk, _moveStep, _hanoi);
                _moveRepository.NoTransactionAdd(mov);
                await SolveTower(totalDisks - 1, mid, end, start);
            }
        }
예제 #6
0
    private void CreateStartedDisk()
    {
        for (int i = 0; i < listDisks.Count; i++)
        {
            Destroy(listDisks[i].gameObject);
        }

        listDisks.Clear();;

        for (int i = 0; i < diskCount; i++)
        {
            Disk disk = Instantiate(DiskPrefab);
            disk.Initialization(i, StartTower);
            StartTower.AddDisk(disk);
            listDisks.Add(disk);
        }
    }