任何人都知道如何在C#中制作河内塔游戏 [英] Any body know how to make a Tower of Hanoi game in c#

查看:83
本文介绍了任何人都知道如何在C#中制作河内塔游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个河内塔游戏,这意味着应该有N个磁盘和K个钉子.主要问题是试图将钉子从第一个更改为最后一个,磁盘的半径为从1到N,完整的磁盘应从第一个钉移到最后一个(在每个阶段,磁盘应按Radius大小的递增顺序堆积.
任何有任何想法的人?

I would like to make a Tower of Hanoi game that means there should be N number of disk and K pegs.The Main problem is trying to change the pegs from 1st to the last one.The radius of the disk will be from 1 to N and the complete disks should be moved from the first peg to the last one(the disks should be piled in the increasing order of Radius size at every stage.
Any one having any Idea??

推荐答案

河内拼图模拟塔 [ http://azerdark.wordpress.com/2008/07/30/c-tower -of-hanoi/ [ ^ ]
Google[^] knows.

Towers of Hanoi Puzzle Simulation[^]
http://azerdark.wordpress.com/2008/07/30/c-tower-of-hanoi/[^]


看看我的文章:
河内的塔 [ ^ ]
Have a look at my article:
Towers of Hanoi[^]




Hi,

// The Towers Of Hanoi
// C#
// Tested under Visual Studio .NET
//

using System;

namespace Hanoi
{
  class Solution
  {
    public static void doHanoi(int n, string f, string t, string u)
    {
      if (n <= 1) 
      {
        System.Console.WriteLine(f + " --> " + t);
      } 
      else 
      {
        doHanoi(n - 1, f, u, t);
        System.Console.WriteLine(f + " --> " + t);
        doHanoi(n - 1, u, t, f);
      }
    }

    [STAThread]

    static void Main(string[] args)
    {
      if (args.Length != 1) 
      {
        System.Console.WriteLine("usage: hanoi <number>");
        System.Environment.Exit(1);
      }

      int n = System.Convert.ToInt32(args[0]);

      if ((n < 1) || (n > 10)) 
      {
        System.Console.WriteLine("usage: hanoi <number> /* 1 <= number <= 10 */");
        System.Environment.Exit(1);
      }

      doHanoi(n, "1", "3", "2");

      System.Environment.Exit(0);
    }
  }
</number></number>


这篇关于任何人都知道如何在C#中制作河内塔游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆