当前位置:编程学习 > C#/ASP.NET >>

棋盘一马,从定点走到指定位置,所有路径

[csharp] 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
 
/************************************************************************/ 
/* 问题描叙:棋盘一马,从定点走到指定位置,所有路径                                                                     */ 
/************************************************************************/ 
namespace Chess_Horse 

    class Program 
    { 
        static void Main(string[] args) 
        { 
            Horse myHorse = new Horse(0, 0, 6, 7); 
            myHorse.Find(0, 0); 
            Console.ReadKey(); 
        } 
    } 
    /// <summary>  
    /// 定义一个棋盘类  
    /// </summary>  
    class ChessBoard 
    { 
        private Int32 Row; 
        private Int32 Column; 
        private Int32[,] MyChessBoard; 
        private Int32 _Step; 
        public ChessBoard(Int32 row, Int32 column) 
        { 
            Row = row; 
            Column = column; 
            MyChessBoard = new Int32[Row,Column]; 
            for(int i = 0; i < Row; i++) 
                for(int j = 0; j < Column; j++) 
                    MyChessBoard[i,j] = 0; 
            _Step = 0; 
        } 
 
        public override string ToString() 
        { 
            Console.WriteLine("棋盘的行数:{0},列数:{1}", Row, Column); 
            return base.ToString(); 
        } 
 
        public void SetChess(Int32 x, Int32 y, Int32 step) 
        { 
            MyChessBoard[y, x] = step; 
            _Step = step; 
        } 
 
        public Int32 GetChess(Int32 x, Int32 y) 
        { 
            return MyChessBoard[y, x]; 
        } 
 
        public Int32 ChessBoardRow 
        { 
            get 
            { 
                return Row; 
            } 
        } 
 
        public Int32 ChessBoardColumn 
        { 
            get 
            { 
                return Column; 
            } 
        } 
 
        public Int32 Step 
        { 
            get 
            { 
                return _Step; 
            } 
        } 
 
        public void DisplayChessBoardInformation() 
        { 
            Console.WriteLine("此路径走了{0}步", _Step); 
            for (int i = 0; i < Row; i++) 
            { 
                for (int j = 0; j < Column; j++) 
                { 
                    Console.Write("{0, -3} ", MyChessBoard[i, j]); 
                } 
                Console.WriteLine(); 
            } 
            Console.ReadKey(); 
        } 
 
        public void Clear() 
        { 
            for (int i = 0; i < Row; i++) 
                for (int j = 0; j < Column; j++) 
                    MyChessBoard[i, j] = 0; 
        } 
 &n
补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,