C#如何编写中国象棋翻转棋盘与可以悔棋的象棋

C#中国象棋网络版源代码(三)-棋盘,玩家类-c/c++-电脑编程网C#中国象棋网络版源代码(三)-棋盘,玩家类作者:cnjack 和相关&&1.棋盘(ChessBoard)棋盘是个重要的类,学习重点是绘制棋盘DrawChessBoard()和移动棋子MoveChess()两个方法。
using Susing System.Collections.Gusing System.Tusing System.Dusing System.Windows.Fnamespace .ChineseChess.Library{&&&/// &summary& &&&/// 棋盘类 &&&/// &/summary& &&&public class ChessBoard&&&{&&&&&&private SetImage _SetI//事件 &&&&&&private PictureBox _pbChessBoard =//棋盘控件 &&&&&&private Chess[,] _chesses = new Chess[9, 10];//容器,存放棋子 &&&&&&private Chess _currentC&&&&&&private bool _EnableMove =&&&&&&&&&&&&#region 棋子索引器&&&&&&/// &summary&   &&&&&&/// 索引器,按坐标取返回棋子   &&&&&&/// &/summary& &&&&&&public Chess this[ChessPoint p]&&&&&&{&&&&&&&&&get&&&&&&&&&{&&&&&&&&&&&&return _chesses[p.X, p.Y];&&&&&&&&&}&&&&&&&&&set&&&&&&&&&{&&&&&&&&&&&&_chesses[p.X, p.Y] =&&&&&&&&&}&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 索引器,按坐标取返回棋子 &&&&&&/// &/summary& &&&&&&public Chess this[int x, int y]&&&&&&{&&&&&&&&&get&&&&&&&&&{&&&&&&&&&&&&return _chesses[x, y];&&&&&&&&&}&&&&&&&&&set&&&&&&&&&{&&&&&&&&&&&&_chesses[x, y] =&&&&&&&&&}&&&&&&}  &&&&&&  &&&&&&#endregion&&&&&&&&&&&&private Game _currentGame =&&&&&&public Game CurrentGame { get { return _currentG } }&&&&&&&&&&&&/// &summary& &&&&&&/// 当前棋子 &&&&&&/// &/summary& &&&&&&public Chess CurrentChess&&&&&&{&&&&&&&&&get { return _currentC }&&&&&&&&&set { _currentChess = }&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&///是否允许移动棋子 &&&&&&/// &/summary& &&&&&&public bool EnableMove { get { return _EnableM } set { _EnableMove = } }&&&&&&&&&&&&/// &summary& &&&&&&/// 棋盘构造函数 &&&&&&/// &/summary& &&&&&&public ChessBoard(PictureBox pb, Game game, SetImage handle)&&&&&&{&&&&&&&&&_SetImage =&&&&&&&&&_currentGame =&&&&&&&&&_pbChessBoard =&&&&&&&&&_pbChessBoard.MouseClick += new MouseEventHandler(OnChessBoard_MouseClick);&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 画棋盘 &&&&&&/// &/summary& &&&&&&public void Reset()&&&&&&{&&&&&&&&&_chesses = new Chess[9, 10];&&&&&&&&&&&&&&&&&&#region 黑棋&&&&&&&&&_chesses[0, 0] = new Rooks(ChessColor.Black, new ChessPoint(0, 0), this); //车 &&&&&&&&&_chesses[1, 0] = new Knights(ChessColor.Black, new ChessPoint(1, 0), this);//马 &&&&&&&&&_chesses[2, 0] = new Elephants(ChessColor.Black, new ChessPoint(2, 0), this);//象 &&&&&&&&&_chesses[3, 0] = new Mandarins(ChessColor.Black, new ChessPoint(3, 0), this);//士 &&&&&&&&&_chesses[4, 0] = new King(ChessColor.Black, new ChessPoint(4, 0), this);//将/帅 &&&&&&&&&_chesses[5, 0] = new Mandarins(ChessColor.Black, new ChessPoint(5, 0), this);//士 &&&&&&&&&_chesses[6, 0] = new Elephants(ChessColor.Black, new ChessPoint(6, 0), this);//象 &&&&&&&&&_chesses[7, 0] = new Knights(ChessColor.Black, new ChessPoint(7, 0), this);//马 &&&&&&&&&_chesses[8, 0] = new Rooks(ChessColor.Black, new ChessPoint(8, 0), this);//车 &&&&&&&&&_chesses[1, 2] = new Cannons(ChessColor.Black, new ChessPoint(1, 2), this);//炮 &&&&&&&&&_chesses[7, 2] = new Cannons(ChessColor.Black, new ChessPoint(7, 2), this);//炮 &&&&&&&&&_chesses[0, 3] = new Pawns(ChessColor.Black, new ChessPoint(0, 3), this);//兵 &&&&&&&&&_chesses[2, 3] = new Pawns(ChessColor.Black, new ChessPoint(2, 3), this);//兵 &&&&&&&&&_chesses[4, 3] = new Pawns(ChessColor.Black, new ChessPoint(4, 3), this);//兵 &&&&&&&&&_chesses[6, 3] = new Pawns(ChessColor.Black, new ChessPoint(6, 3), this);//兵 &&&&&&&&&_chesses[8, 3] = new Pawns(ChessColor.Black, new ChessPoint(8, 3), this);//兵 &&&&&&&&&#endregion&&&&&&&&&&&&&&&&&&#region 红棋&&&&&&&&&_chesses[0, 9] = new Rooks(ChessColor.Red, new ChessPoint(0, 9), this);&&&&&&&&&_chesses[1, 9] = new Knights(ChessColor.Red, new ChessPoint(1, 9), this);&&&&&&&&&_chesses[2, 9] = new Elephants(ChessColor.Red, new ChessPoint(2, 9), this);&&&&&&&&&_chesses[3, 9] = new Mandarins(ChessColor.Red, new ChessPoint(3, 9), this);&&&&&&&&&_chesses[4, 9] = new King(ChessColor.Red, new ChessPoint(4, 9), this);&&&&&&&&&_chesses[5, 9] = new Mandarins(ChessColor.Red, new ChessPoint(5, 9), this);&&&&&&&&&_chesses[6, 9] = new Elephants(ChessColor.Red, new ChessPoint(6, 9), this);&&&&&&&&&_chesses[7, 9] = new Knights(ChessColor.Red, new ChessPoint(7, 9), this);&&&&&&&&&_chesses[8, 9] = new Rooks(ChessColor.Red, new ChessPoint(8, 9), this);&&&&&&&&&_chesses[1, 7] = new Cannons(ChessColor.Red, new ChessPoint(1, 7), this);&&&&&&&&&_chesses[7, 7] = new Cannons(ChessColor.Red, new ChessPoint(7, 7), this);&&&&&&&&&_chesses[0, 6] = new Pawns(ChessColor.Red, new ChessPoint(0, 6), this);&&&&&&&&&_chesses[2, 6] = new Pawns(ChessColor.Red, new ChessPoint(2, 6), this);&&&&&&&&&_chesses[4, 6] = new Pawns(ChessColor.Red, new ChessPoint(4, 6), this);&&&&&&&&&_chesses[6, 6] = new Pawns(ChessColor.Red, new ChessPoint(6, 6), this);&&&&&&&&&_chesses[8, 6] = new Pawns(ChessColor.Red, new ChessPoint(8, 6), this);&&&&&&&&&#endregion&&&&&&&&&&&&&&&&&&this.DrawChessBoard();&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 绘制棋盘 &&&&&&/// &/summary& &&&&&&public void DrawChessBoard()&&&&&&{&&&&&&&&&//棋盘背景 &&&&&&&&&Bitmap map = ChineseChess.Res.Properties.Resources.xqboard.Clone() as B&&&&&&&&&&&&&&&&&&//画棋子 &&&&&&&&&Graphics g = Graphics.FromImage(map);&&&&&&&&&&&&&&&&&&for (int i = 0; i & 9; i++)&&&&&&&&&{&&&&&&&&&&&&for (int j = 0; j & 10; j++)&&&&&&&&&&&&{&&&&&&&&&&&&&&&if (_chesses[i, j] != null)&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&//计算物理坐标 &&&&&&&&&&&&&&&&&&Point p = CoordinateHelper.CalculatePyshicalPoint(new ChessPoint(i, j));&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&g.DrawImage(_chesses[i, j].ChessImage, p.X, p.Y, 43, 43); //画棋子 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//当前棋子上面画一个焦点框 &&&&&&&&&&&&&&&&&&if (_chesses[i, j] == _currentChess)&&&&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&&&&Bitmap focus = ChineseChess.Res.Properties.Resources.focus.Clone() as B&&&&&&&&&&&&&&&&&&&&&focus.MakeTransparent(Color.FromArgb(255, 255, 255));&&&&&&&&&&&&&&&&&&&&&g.DrawImage(focus, p.X, p.Y, 43, 43);&&&&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&}&&&&&&&&&&&&}&&&&&&&&&}&&&&&&&&&&&&&&&&&&g.Dispose();&&&&&&&&&&&&&&&&&&_pbChessBoard.Invoke(_SetImage, _pbChessBoard, map);&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 移动棋子到远程玩家发送来的棋子坐标 &&&&&&/// &/summary& &&&&&&public void MoveChessByRemote(ChessPoint fromPoint, ChessPoint toPoint)&&&&&&{&&&&&&&&&Chess from = this[fromPoint];&&&&&&&&&from.MoveTo(toPoint);//移动棋子 &&&&&&&&&&&&&&&&&&_EnableMove =&&&&&&&&&&&&&&&&&&this._currentGame.ShowHistory(from); //显示最后移动的棋子 &&&&&&&&&&&&&&&&&&//移动棋子完成,重画棋盘 &&&&&&&&&this.DrawChessBoard();&&&&&&&&&&&&&&&&&&//启动计时器 &&&&&&&&&this.CurrentGame.ControlPanel.StartTimer(ChessColor.Red);&&&&&&&&&this.CurrentGame.ControlPanel.StopTimer(ChessColor.Black);&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 移动棋子 &&&&&&/// &/summary& &&&&&&public void MoveChess(ChessPoint point)&&&&&&{&&&&&&&&&try&&&&&&&&&{&&&&&&&&&&&&Chess chess = this[point];//获取鼠标点的棋子 &&&&&&&&&&&&&&&&&&&&&&&&//之前没有选中棋子 &&&&&&&&&&&&if (this.CurrentChess == null)&&&&&&&&&&&&{&&&&&&&&&&&&&&&//当前棋子为空,又点了一个空白点 &&&&&&&&&&&&&&&if (chess == null)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//当前棋子为空,点击了一个不属于自己颜色的棋子 &&&&&&&&&&&&&&&if (chess.Color != ChessColor.Red)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&this.CurrentChess =//设置当前棋子 &&&&&&&&&&&&&&&this.DrawChessBoard();&&&&&&&&&&&&}&&&&&&&&&&&&else&&&&&&&&&&&&{&&&&&&&&&&&&&&&//之前选中了一个棋子,现在又点击了之前选中的棋子,退出 &&&&&&&&&&&&&&&if (chess == this.CurrentChess)&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//点中了自己的棋子,改变当前棋子到目标棋子 &&&&&&&&&&&&&&&if (chess != null && chess.Color == this.CurrentChess.Color)&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&this.CurrentChess =&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&else //点中对方的棋子或目标点为空,移动到目标点或吃掉对方的棋子&&&&&&&&&&&&&&&{&&&&&&&&&&&&&&&&&&ChessPoint currPoint = this.CurrentChess.CurrentP//保存变量 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&this.CurrentChess.MoveTo(point);//移动棋子 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//如果移动失败 &&&&&&&&&&&&&&&&&&if (!this.CurrentChess.CurrentPoint.Equals(point))&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//移动成功,通知(对方)远程更新棋盘 &&&&&&&&&&&&&&&&&&this.CurrentGame.SendPointToRemote(currPoint, point);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&_EnableMove = //禁用棋盘 &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&this._currentGame.ShowHistory(this.CurrentChess); //显示最后移动的棋子 &&&&&&&&&&&&&&&&&&this.CurrentChess =&&&&&&&&&&&&&&&}&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//移动棋子完成,重画棋盘 &&&&&&&&&&&&&&&this.DrawChessBoard();&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&//停止计时器 &&&&&&&&&&&&&&&this.CurrentGame.ControlPanel.StopTimer(ChessColor.Red);&&&&&&&&&&&&&&&this.CurrentGame.ControlPanel.StartTimer(ChessColor.Black);&&&&&&&&&&&&}&&&&&&&&&}&&&&&&&&&catch (GameLoseException ex)&&&&&&&&&{&&&&&&&&&&&&_currentGame.Victory();&&&&&&&&&&&&_currentGame.Gameover();&&&&&&&&&&&&Msg.ShowInformation(ex.Message);&&&&&&&&&}&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 鼠标点击事件 &&&&&&/// &/summary& &&&&&&private void OnChessBoard_MouseClick(object sender, MouseEventArgs e)&&&&&&{&&&&&&&&&if (!_EnableMove)//禁止移动,退出 &&&&&&&&&if (!_currentGame.PlayerRed.Ready)//未准备就绪,退出 &&&&&&&&&if (!_currentGame.IsPlaying)//未启动游戏,退出 &&&&&&&&&&&&&&&&&&//物理坐标转换为棋盘坐标 &&&&&&&&&ChessPoint point = CoordinateHelper.TranslatePointToChessPoint(e.Location);&&&&&&&&&&&&&&&&&&this.MoveChess(point); //移动棋子到目标点 &&&&&&}&&&&&&&&&}}
2.玩家(Player)一个简单的实体类
using Susing System.Collections.Gusing System.Tnamespace .ChineseChess.Library{&&&/// &summary& &&&/// 玩家 &&&/// &/summary& &&&public class Player&&&{&&&&&&private string _&&&&&&private ChessColor _&&&&&&private int _steps = 0;&&&&&&private int _timeout = 0;&&&&&&private string _IpAddress="";&&&&&&private bool _ready =&&&&&&&&&&&&/// &summary& &&&&&&/// 构造函数 &&&&&&/// &/summary& &&&&&&public Player(ChessColor color, string name)&&&&&&{&&&&&&&&&this._color =&&&&&&&&&this._name =&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 玩家颜色 &&&&&&/// &/summary& &&&&&&public ChessColor Color&&&&&&{&&&&&&&&&get { return _ }&&&&&&&&&set { _color = }&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 玩家名字 &&&&&&/// &/summary& &&&&&&public string Name&&&&&&{&&&&&&&&&get { return _ }&&&&&&&&&set { _name = }&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 走的步数 &&&&&&/// &/summary& &&&&&&public int Steps&&&&&&{&&&&&&&&&get { return _ }&&&&&&&&&set { _steps = }&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 玩家移动棋子前超时数 &&&&&&/// &/summary& &&&&&&public int TimeOut&&&&&&{&&&&&&&&&get { return _ }&&&&&&&&&set { _timeout = }&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 玩家IP地址 &&&&&&/// &/summary& &&&&&&public string IpAddress&&&&&&{&&&&&&&&&get { return _IpA }&&&&&&&&&set { _IpAddress = }&&&&&&}&&&&&&&&&&&&/// &summary& &&&&&&/// 准备就绪 &&&&&&/// &/summary& &&&&&&public bool Ready&&&&&&{&&&&&&&&&get { return _ }&&&&&&&&&set { _ready = }&&&&&&}&&&&&&&&&}}相关资料:|||||||C#中国象棋网络版源代码(三)-棋盘,玩家类来源网络,如有侵权请告知,即处理!编程Tags:                &                    C#的中国象棋游戏设计与实现+功能模块图
论文选择Visual C#作为系统开发工具,通过分析人工智能系统的需求,描述了系统设计、系统模块分析,重点对人工智能系统的实际开发实现做了介绍。系统主要实现了人机对战、悔棋、
摘& 要:本论文选择Visual C# 2005作为系统开发工具,通过分析人工智能系统的需求,描述了系统设计、系统模块分析,重点对人工智能系统的实际开发实现做了介绍。系统主要实现了人机对战、悔棋、残局布置、对战用时统计等模块。各个模块都建立了相应的类,通过类来实现相应的模块功能,基本实现了象棋的一般功能。
关键词:人工智能;Visual C#
Design and implementation of Chinese chess game based on c #
Abstract :This system chooses Visual c # 2005 as the system development tools, through the analysis of the system of artificial intelligence needs, describes the system design, system module analysis, focusing on the actual artificial intelligence system implemented are introduced. System mainly realizes the undo, endgame man-machine against, decorate, s statistics against module. Each module have established the corresponding class, through the class to realize the corresponding modules, basically achieved chess general function 请找qq六'维(论]文.网
&Key Words:Art Visual c # 2005;
摘& 要&& &1
关键词&& &1
引 言&& &1
1 系统开发背景和意义&& &2
1.1 背景&& &2
1.2 系统开发的目的和意义&& &2
1.3 主要工作&& &3
2 关键技术介绍&& &3
2.1 Visual C# 2005简介&& &3
2.2人工智能原理与方法简介&& &3
3 系统设计&& &4
3.1 需求分析&& &4
3.2 系统模块分析&& &4
3.3系统功能模块图4
4 人工智能象棋系统实现&& &5
4.1人工智能象棋系统设计与实现5
4.2功能和使用说明7
5总结&& &7
参考文献&& &8
致谢&& &9 ,4328
基于C#的中国象棋游戏设计与实现 请找腾讯来自六-维!论"文\网
博弈问题无所不在,小到孩童的游戏与争论、各种场合下的讨价还价,大到商家的竞争、各种突发事件(恐怖、灾害)的应急处理、国家的外交、流血的和不流血的战争,只要局中的双方主体存在某种利益冲突,博弈便成为矛盾表现和求解的一种方式.博弈与对策将成为一类智能系统研究的焦点问题。
象棋是从两军对阵中抽象出来的一种智力游戏,因此它是博弈的一个标准问题.下棋的双方无时不在调动自己的一切智能,充分发挥逻辑思维、形象思维和灵感思维的能力。所以,在人工智能领域始终将棋类的机器博弈作为最具挑战性的研究方向之一。
1 系统开发背景和意义
1997年,IBM公司的超级计算机&深蓝&与当时的国际象棋世界冠军卡斯帕罗夫进行了一场大肆渲染的比赛,这次被卡斯帕罗夫称作&终于来临的一天&的比赛以卡氏的失败而告终。IBM公司将&深蓝&的获胜称作是人工智能领域的一个里程碑。 请加qq六/维(论"文^网
人类对机器博弈的研究衍生了大量的研究成果, 这些成果不但对人工智能的其它领域产生了重要影响, 而且由此衍生而来的多种应用, 在诸如航空调度、 天气预报、 资源勘探、 军事博弈, 金融/经济调控等领域, 也取得了大量引人瞩目的成就。
在我国, 中国象棋有着深厚的群众基础, 能把这项古老的国粹和现代计算机技术相结合, 编制出超过人类智慧的中国象棋软件, 是许多研究中国象棋软件人梦寐以求的目标。但由于中国象棋在计算机实现方面比国际象棋更加复杂, 而且中国象棋博弈技术研究落后于国际象棋, 所以中国象棋软件还远未达到世界冠军水平。但近年来通过许多中国象棋软件编程爱好者和多个象棋开发团队的努力, 使中国象棋软件水平有长足的进步,慢棋已达到业余大师水平, 快棋可以和象棋大师对抗。 C#的中国象棋游戏设计与实现+功能模块图:
------分隔线----------------------------
在线教育系统就是一个在线教育网站,前台使用ASP.Net为开发工具...
基于电子商务的发展历史上对其现状进行分析并指出存在问题,...
对数据挖掘与隐私保护领域的隐私概念的论述,从数据分布、数...
运用Flash中提供的类包、脚本语言的编写来实现Flash 3D的效果、结...象棋程序设计_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
象棋程序设计
上传于||暂无简介
阅读已结束,如果下载本文需要使用1下载券
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,查找使用更方便
还剩19页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢}

我要回帖

更多关于 可以悔棋的象棋 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信