之所以选择围棋作为大作业一方面是想挑战一下,另一方面是由于从6岁学围棋到11岁放下,再到今天已将近8年了,也算是回味一下童年吧,毕竟,曾梦想执子走天涯。

这是效果图:

这个程序除了一开始参考了中国象棋,其他的都是自己完成的。

不说了,上代码!!!

这个是主窗口代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Media;//该产品归属****大学18级信息工程学院计算机系王**所有,如需转载,请注明原作者及出处:https://blog.csdn.net/Luoriliming
namespace AlphaGo
{public partial class FormMain : Form{//加载围棋类private PlayChess playchess = new PlayChess();public FormMain(){InitializeComponent();//根据屏幕分辨率调整大小playchess._rowHeight = Screen.PrimaryScreen.Bounds.Size.Height / 25;playchess._colWidth = playchess._rowHeight;playchess._lefttop.Y = 2* playchess._rowHeight;playchess._lefttop.X = playchess._lefttop.Y;}//绘制private void FormMain_Paint(object sender, PaintEventArgs e){playchess.Drawboard(e.Graphics);playchess.DrawPiece(e.Graphics);}//开局private void toolStripMenuItemBegin_Click(object sender, EventArgs e){timer1.Enabled = true;timer2.Enabled = false;playchess. PlaySound("begin.wav");playchess.Begin(Player.白);Invalidate();}//计时器private void timer1_Tick(object sender, EventArgs e){if (playchess._time1 <= 0){if (playchess._curPlayer == Player.黑)playchess._curPlayer = Player.白;elseplaychess._curPlayer = Player.黑;if (playchess._pickChess == Piece.黑子)playchess._pickChess = Piece.白子;elseplaychess._pickChess = Piece.黑子;if (playchess._timeColor == Color.Yellow)playchess._timeColor = Color.Red;elseplaychess._timeColor = Color.Yellow;playchess._time2 = 60;playchess._time1 = 60;timer1.Enabled = !timer1.Enabled;timer2.Enabled = !timer2.Enabled;}else{playchess._time1 = playchess._time1 - 1;Invalidate();}}//鼠标移动private void FormMain_MouseMove(object sender, MouseEventArgs e){playchess._curMousePoint = e.Location;Invalidate();}private void FormMain_MouseDown(object sender, MouseEventArgs e){//若单击右键if (e.Button == MouseButtons.Left){int row, col;//输出此时鼠标位置,并判断是否在范围内bool valid = playchess.ConvertPointToRowCol(new Point(e.X, e.Y), out row, out col);playchess._dropRow = row;playchess._dropCol = col;if (valid == true){if (playchess._chess[playchess._dropRow, playchess._dropCol] == Piece.无子){playchess.PlaySound("drop.wav");if (timer2.Enabled == false)timer2.Enabled = true;elsetimer2.Enabled = false;if (timer1.Enabled == false)timer1.Enabled = true;elsetimer1.Enabled = false;playchess.DropPiece(playchess._dropRow, playchess._dropCol);}Invalidate();}}}//计时器public void timer2_Tick(object sender, EventArgs e){if (playchess._time2 <= 0){if (playchess._curPlayer == Player.黑)playchess._curPlayer = Player.白;elseplaychess._curPlayer = Player.黑;if (playchess._pickChess == Piece.黑子)playchess._pickChess = Piece.白子;elseplaychess._pickChess = Piece.黑子;playchess._time2 = 60;playchess._time1 = 60;timer1.Enabled = !timer1.Enabled;timer2.Enabled = !timer2.Enabled;}else{playchess._time2 = playchess._time2 - 1;Invalidate();}}//判断胜负private void ToolStripMenuItemEnd_Click(object sender, EventArgs e){if (playchess.IsOver() == Player.黑){MessageBox.Show("黑棋获胜!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);playchess . _black++;}else if (playchess.IsOver() == Player.白){MessageBox.Show("白棋获胜!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);playchess._white++;}else if (playchess.IsOver() == Player.无){MessageBox.Show("和棋!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification);}timer1.Enabled = false;timer2.Enabled = false;playchess._pickChess = Piece.无子;}private void ToolStripMenuItemSave_Click(object sender, EventArgs e){//显示保存残局对话框if (saveFileDialog1.ShowDialog() == DialogResult.OK){FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create);BinaryWriter bw = new BinaryWriter(fs);playchess.WriteTo(bw);bw.Close();fs.Close();}}private void ToolStripMenuItemOpen_Click(object sender, EventArgs e){//显示打开残局对话框if (openFileDialog1.ShowDialog() == DialogResult.OK){FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);BinaryReader br = new BinaryReader(fs);playchess.ReadFrom(br);br.Close();fs.Close();Invalidate();}}}
}

这个是围棋类代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Media;//该产品归属****大学18级信息工程学院计算机系王**所有,如需转载,请注明原作者及出处:https://blog.csdn.net/Luorilimingnamespace AlphaGo
{//枚举类型:棋子public enum Piece{无子 = 0, 黑子 = 1, 白子 = 2}//枚举类型:双方棋手public enum Player{无 = 0, 黑 = 1, 白 = 2}//类:走棋步骤public class Step{public Player _player;//走棋方public int _dropRow;//落下棋子行号public int _dropCol;//落下棋子列号public Piece _dropPiece;//落下位置棋子}//类:围棋class PlayChess{//类字段:棋子public Piece[,] _chess = new Piece[25, 25];//初始化执子为无子public Piece _pickChess = Piece.无子;//落下棋子的位置public int _dropRow = 0;public int _dropCol = 0;//闪烁public Color _timeColor = Color.Yellow;//类字段:走棋方public Player _curPlayer = Player.无;//鼠标移动位置public Point _curMousePoint = new Point(0, 0);//类字段:设置走棋步骤表public List<Step> _listStep = new List<Step>();//保存棋盘左上角坐标public Point _lefttop = new Point(100, 100);//棋子半径public int _pieceR = 10;//保存行高和列宽public int _rowHeight = 30;public int _colWidth = 30;//加载图像//导入各种图片Bitmap deskbmp = new Bitmap("desktop.jpg");public Bitmap _redbmp = new Bitmap("黑方头像.jpg");public Bitmap _bluebmp = new Bitmap("白方头像.jpg");//设置是否遍历数组public bool[,] _bianli = new bool[25, 25];//设置气的数组public int[,] _qi = new int[20, 20];//设置白棋黑棋个数public int _Whitechess;public int _Blackchess;//计时public int _time1 = 60;public int _time2 = 60;//黑白子各胜局数public int _black = 0;public int _white = 0;//劫private bool[,] _jie = new bool[25, 25];public int _lastrow = 0;public int _lastcol = 0;public int _chessnumber = 0;//类 最后一次走棋步骤public Step _LastStep{get{int stepCount = _listStep.Count;if (stepCount > 0)return _listStep[stepCount - 1];elsereturn null;}}//类构造方法public PlayChess(){//初始化围棋Initialize();}//类:初始化围棋public void Initialize(){for (int i = 1; i <= 19; i++){for (int j = 1; j <= 19; j++){_chess[j, i] = Piece.无子;}}_listStep.Clear();}//类:围棋开局public void Begin(Player FirstPlayer){//初始化围棋Initialize();//初始化开局棋子布局for (int i = 1; i <= 19; i++){for (int j = 1; j <= 19; j++){_chess[j, i] = Piece.无子;}}//初始化时间_time1 = 60;_time2 = 60;//初始化当前走棋方_curPlayer = Player.白;_pickChess = Piece.白子;//初始化遍历条件for (int i = 1; i <= 20; i++){for (int j = 1; j <= 20; j++){_bianli[i, j] = false;}}//初始化劫for (int i = 1; i <= 20; i++){for (int j = 1; j <= 20; j++){_jie[i, j] = false;}}for (int i = 1; i <= 20; i++){for (int j = 1; j <= 20; j++){_jie[i, j] = false;}}//初始化落子属性_dropCol = 0;_dropRow = 0;_chessnumber = 0;}//类:落下棋子public bool DropPiece(int dropRow, int dropCol){if (_curPlayer != Player.无 && MatchRules(_curPlayer, _dropRow, _dropCol) == true&&_jie[dropRow,dropCol]==false){//保存走棋步骤到_listStep中Step step = new Step();step._player = _curPlayer;step._dropRow = dropRow;step._dropCol = dropCol;step._dropPiece = _chess[dropRow, dropCol];_listStep.Add(step);_chess[dropRow, dropCol] = _pickChess;//播放落子声音PlaySound("drop.wav");//从左上角开始判断所有棋子,为了避免像虚竹一样自杀的存在EatChess(1, 1);//重置遍历for (int i = 1; i <= 19; i++){for (int j = 1; j <= 19; j++){_bianli[i, j] = false;}}//判断劫for (int i = 1; i <= 20; i++){for (int j = 1; j <= 20; j++){_jie[i, j] = false;}}_jie[_lastrow, _lastcol] = true;//交换走棋方if (_pickChess == Piece.黑子)_pickChess = Piece.白子;else if (_pickChess == Piece.白子)_pickChess = Piece.黑子;elsereturn false;if (_curPlayer == Player.黑)_curPlayer = Player.白;else_curPlayer = Player.黑;//重置时间_time2 = 60;_time1 = 60;//步数加一_chessnumber = _chessnumber + 1;//添加上一步的存入_dropCol = dropCol;_dropRow = dropRow;_lastcol = _dropCol;_lastrow = _dropRow;return true;}elsereturn false;}//类:判断胜负public Player IsOver(){//初始化黑白棋子所围的子_Blackchess = 0;_Whitechess = 0;for (int i = 1; i <= 20; i++){for (int j = 1; j <= 20; j++){for (int l = 1; l <= 20; l++){for (int k = 1; k <= 20; k++){_bianli[l, k] = false;}}//查找该子属于黑子还是白子int x = SearchChess(i, j);if (x == 2)_Whitechess++;else if (x == 1)_Blackchess++;}}//如果黑子多于白子,则黑方获胜;如果白子多于黑子,则白方获胜;如果双方棋子数相同,则平局if (_Blackchess > _Whitechess){return Player.黑;}else if (_Whitechess > _Blackchess){return Player.白;}elsereturn Player.无;}//类:围棋规则public bool MatchRules(Player player, int dropRow, int dropCol){bool matchflag = false;{//只能下在无子的位置if (_chess[dropRow, dropCol] == Piece.无子 ){matchflag = true;}return matchflag;}}//保存残局public void WriteTo(BinaryWriter binaryWriter){binaryWriter.Write(_curPlayer.ToString());for (int j = 1; j <= 10; j++){for (int i = 1; i <= 10; i++){binaryWriter.Write(_chess[i, j].ToString());}}binaryWriter.Write(_listStep.Count);for (int i = 0; i <= _listStep.Count - 1; i++){binaryWriter.Write(_listStep[i]._player.ToString());binaryWriter.Write(_listStep[i]._dropRow);binaryWriter.Write(_listStep[i]._dropPiece.ToString());binaryWriter.Write(_listStep[i]._dropCol);}}//读取残局public void ReadFrom(BinaryReader binaryReader){Initialize();_curPlayer = (Player)Enum.Parse(typeof(Player), binaryReader.ReadString());for (int j = 1; j <= 10; j++){for (int i = 1; i <= 10; i++){_chess[i, j] = (Piece)Enum.Parse(typeof(Piece), binaryReader.ReadString());}}int stepCount = binaryReader.ReadInt32();for (int i = 0; i <= _listStep.Count - 1; i++){Step step = new Step();step._player = (Player)binaryReader.ReadInt32();step._dropRow = binaryReader.ReadInt32();step._dropPiece = (Piece)binaryReader.ReadInt32();step._dropCol = binaryReader.ReadInt32();_listStep.Add(step);}_pickChess = Piece.无子;}public void Drawboard(Graphics g){//绘制桌面g.DrawImage(deskbmp, new Point(0, 0));//创建粗笔和细笔Pen thickPen = new Pen(Color.Black, 6);Pen thinPen = new Pen(Color.Black, 2);//绘制粗外边框int gap = (int)(_rowHeight * 0.25);g.DrawRectangle(thickPen, new Rectangle(_lefttop.X - gap, _lefttop.Y - gap, _colWidth * 18 + 2 * gap, _rowHeight * 18 + 2 * gap));//绘制横轴竖轴for (int i = 1; i <= 19; i++){g.DrawLine(thinPen, new Point(_lefttop.X, _lefttop.Y + (i - 1) * _rowHeight),new Point(_lefttop.X + 18 * _colWidth, _lefttop.Y + (i - 1) * _rowHeight));}for (int i = 1; i <= 19; i++){g.DrawLine(thinPen, new Point(_lefttop.X + _colWidth * (i - 1), _lefttop.Y),new Point(_lefttop.X + (i - 1) * _colWidth, _lefttop.Y + 18 * _rowHeight));}SolidBrush Brush = new SolidBrush(Color.Black);SolidBrush white = new SolidBrush(Color.White);SolidBrush num = new SolidBrush(Color.Blue);//书写坐标Font font2 = new Font("黑体", (float)(_rowHeight * 0.6), FontStyle.Regular, GraphicsUnit.Pixel);for (int i = 1; i <= 19; i++){g.DrawString(i.ToString(), font2, Brush, new Point((int)(_lefttop.X - _colWidth * 1.1),(int)(_lefttop.Y - _rowHeight * 0.4 + _rowHeight * (i - 1))));}string[] colNumber = new string[19] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S" };Font font3 = new Font("华文行楷", (float)(_rowHeight * 1.5), FontStyle.Regular, GraphicsUnit.Pixel);for (int i = 1; i <= 19; i++){g.DrawString(colNumber[i - 1], font2, Brush, new Point((int)(_lefttop.X - _colWidth * 0.3 + _colWidth * (i - 1)),(int)(_lefttop.Y - _rowHeight * 1.1)));}//绘制黑白双方g.DrawString("黑方", font3, Brush, new Point((int)(_lefttop.X + _colWidth * 19),(int)(_lefttop.Y + _rowHeight * 2.2)));g.DrawString("白方", font3, white, new Point((int)(_lefttop.X + _colWidth * 19),(int)(_lefttop.Y + _rowHeight * 9.4)));SolidBrush fontBrush = new SolidBrush(Color.Black);g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 3 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 3 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 15 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 3 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 9 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 3 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 3 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 9 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 15 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 9 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 9 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 9 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 3 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 15 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 15 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 15 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));g.FillEllipse(fontBrush, _lefttop.X + _colWidth * 9 - (int)(_pieceR * 0.7), _lefttop.Y + _rowHeight * 15 - (int)(_pieceR * 0.7), (int)(_pieceR * 1), (int)(_pieceR * 1));Font font4 = new Font("仿宋", (float)(_rowHeight * 1.5), FontStyle.Regular, GraphicsUnit.Pixel);//步数g.DrawString("步数:", font3, Brush, new Point((int)((int)(_lefttop.X + _colWidth * 21)),(int)(_lefttop.Y - _rowHeight)));g.DrawString(_chessnumber.ToString(), font4, num, new Point((int)(_lefttop.X + _colWidth * 25),(int)(_lefttop.Y - _rowHeight * 1.1)));//黑白各胜局数g.DrawString("黑:白   :", font2, Brush, new Point((int)((int)(_lefttop.X + _colWidth * 5)),(int)(_lefttop.Y + _rowHeight * 20)));g.DrawString(_black.ToString(), font2, num, new Point((int)(_lefttop.X + _colWidth * 7),(int)(_lefttop.Y + _rowHeight * 20)));g.DrawString(_white.ToString(), font2, num, new Point((int)(_lefttop.X + _colWidth * 8),(int)(_lefttop.Y + _rowHeight * 20)));//g.DrawRectangle(thickPen, (int)(_lefttop.X + _colWidth * 25), (int)(_lefttop.Y - _rowHeight), 130, 60);g.DrawString("白方计时器:", font3, white, new Point((int)((int)(_lefttop.X + _colWidth * 19)),(int)(_lefttop.Y + _rowHeight * 16)));g.DrawString("黑方计时器:", font3, Brush, new Point((int)((int)(_lefttop.X + _colWidth * 19)),(int)(_lefttop.Y + _rowHeight * 6)));g.DrawString(_time2.ToString() + "s", font4, num, new Point((int)(_lefttop.X + _colWidth * 27),(int)(_lefttop.Y + _rowHeight * 6)));g.DrawString(_time1.ToString() + "s", font4, num, new Point((int)(_lefttop.X + _colWidth * 27),(int)(_lefttop.Y + _rowHeight * 16)));//加载黑白方图片if (_curPlayer == Player.白){g.DrawImage(_bluebmp, new Point(_lefttop.X + 8 * _colWidth + 625, _lefttop.Y + 9 * _rowHeight + 10));}else if (_curPlayer == Player.黑){g.DrawImage(_redbmp, new Point(_lefttop.X + 8 * _colWidth + 625, _lefttop.Y + 2 * _rowHeight - 10));}DrawPickDropMark(g, _dropRow, _dropCol);}public void DrawPiece(Graphics g){for (int j = 1; j <= 19; j++){for (int i = 1; i <= 19; i++){if (_chess[i, j] != Piece.无子){//绘制棋子DrawPieceByCode(g, i, j, _chess[i, j]);}}}//绘制跟随鼠标移动的棋子DrawMousePiece(g, _curMousePoint.X, _curMousePoint.Y, _pickChess);}//鼠标位置public bool ConvertPointToRowCol(Point p, out int row, out int col){row = (p.Y - _lefttop.Y) / _rowHeight + 1;if ((p.Y - _lefttop.Y) % _rowHeight >= _rowHeight / 2){row++;}col = (p.X - _lefttop.X) / _colWidth + 1;if ((p.X - _lefttop.X) % _colWidth >= _colWidth / 2){col++;}Point chessP = new Point();chessP.X = _lefttop.X + _colWidth * (col - 1);chessP.Y = _lefttop.Y + _rowHeight * (row - 1);double dist = Math.Sqrt(Math.Pow(p.X - chessP.X, 2) + Math.Pow(p.Y - chessP.Y, 2));if (dist <= _pieceR && (row <= 19) && (row >= 1) && (col <= 19) && (col >= 1)){return true;}else{row = 0;col = 0;return false;}}//绘制棋子public void DrawMousePiece(Graphics g, int x, int y, Piece chess){SolidBrush fontBrush;_pieceR = (int)(_rowHeight * 0.3);if (chess != Piece.无子){if (chess == Piece.黑子){fontBrush = new SolidBrush(Color.Black);}else{fontBrush = new SolidBrush(Color.White);}g.FillEllipse(fontBrush, x - (int)(_pieceR * 1.0), y - (int)(_pieceR * 1), _pieceR * 2, _pieceR * 2);}}//绘制手中棋子public void DrawPieceByCode(Graphics g, int row, int col, Piece chess){SolidBrush fontBrush;_pieceR = (int)(_rowHeight * 0.3);if (chess != Piece.无子){if (chess == Piece.黑子){fontBrush = new SolidBrush(Color.Black);}else{fontBrush = new SolidBrush(Color.White);}g.FillEllipse(fontBrush, _lefttop.X + _colWidth * (col - 1) - (int)(_pieceR), _lefttop.Y + _rowHeight * (row - 1) - (int)(_pieceR), _pieceR * 2, _pieceR * 2);}}public void DrawPickDropMark(Graphics g, int row, int col){//在棋盘范围内绘制闪烁标记if (row > 0){Pen pen = new Pen(_timeColor, 4);Point p = new Point(_lefttop.X + _colWidth * (col - 1), _lefttop.Y + _rowHeight * (row - 1));//绘制闪烁标记g.DrawLine(pen, p.X - _pieceR, p.Y - _pieceR, p.X - _pieceR / 2, p.Y - _pieceR);g.DrawLine(pen, p.X - _pieceR, p.Y - _pieceR, p.X - _pieceR, p.Y - _pieceR / 2);g.DrawLine(pen, p.X + _pieceR, p.Y - _pieceR, p.X + _pieceR / 2, p.Y - _pieceR);g.DrawLine(pen, p.X + _pieceR, p.Y - _pieceR, p.X + _pieceR, p.Y - _pieceR / 2);g.DrawLine(pen, p.X - _pieceR, p.Y + _pieceR, p.X - _pieceR / 2, p.Y + _pieceR);g.DrawLine(pen, p.X - _pieceR, p.Y + _pieceR, p.X - _pieceR, p.Y + _pieceR / 2);g.DrawLine(pen, p.X + _pieceR, p.Y + _pieceR, p.X + _pieceR / 2, p.Y + _pieceR);g.DrawLine(pen, p.X + _pieceR, p.Y + _pieceR, p.X + _pieceR, p.Y + _pieceR / 2);}}//吃子判定(因为不用考虑时间和空间复杂度,用暴力跑的,主要这段时间被卡超时卡太烦了)public void EatChess(int row, int col){for (int i = 1; i <= 19; i++){for (int j = 1; j <= 19; j++){if (_chess[i, j] != Piece.无子){_qi[i, j] = Judge(_chess[i, j], i, j);}}}for (int i = 1; i <= 19; i++){for (int j = 1; j <= 19; j++){if (_chess[i, j] == _chess[i + 1, j] && i <= 18){_qi[i + 1, j] = _qi[i, j] + _qi[i + 1, j];}if (_chess[i, j] == _chess[i, j + 1] && j <= 18){_qi[i, j + 1] = _qi[i, j] + _qi[i, j + 1];}}}for (int i = 1; i <= 19; i++){for (int j = 1; j <= 19; j++){if (_chess[i, j] == _chess[i + 1, j] && i <= 18){if (_qi[i, j] < _qi[i + 1, j])_qi[i, j] = _qi[i + 1, j];else_qi[i + 1, j] = _qi[i, j];}if (_chess[i, j] == _chess[i, j + 1] && j <= 18){if (_qi[i, j] < _qi[i, j + 1])_qi[i, j] = _qi[i, j + 1];else_qi[i, j + 1] = _qi[i, j];}if (_chess[i, j] == _chess[i - 1, j] && i >= 2){if (_qi[i, j] < _qi[i - 1, j])_qi[i, j] = _qi[i - 1, j];else_qi[i - 1, j] = _qi[i, j];}if (_chess[i, j] == _chess[i, j - 1] && j >= 2){if (_qi[i, j] < _qi[i, j - 1])_qi[i, j] = _qi[i, j - 1];else_qi[i, j - 1] = _qi[i, j];}}}for (int i = 19; i >= 1; i--){for (int j = 19; j >= 1; j--){if (_chess[i, j] == _chess[i + 1, j] && i <= 18){if (_qi[i, j] < _qi[i + 1, j])_qi[i, j] = _qi[i + 1, j];else_qi[i + 1, j] = _qi[i, j];}if (_chess[i, j] == _chess[i, j + 1] && j <= 18){if (_qi[i, j] < _qi[i, j + 1])_qi[i, j] = _qi[i, j + 1];else_qi[i, j + 1] = _qi[i, j];}if (_chess[i, j] == _chess[i - 1, j] && i >= 2){if (_qi[i, j] < _qi[i - 1, j])_qi[i, j] = _qi[i - 1, j];else_qi[i - 1, j] = _qi[i, j];}if (_chess[i, j] == _chess[i, j - 1] && j >= 2){if (_qi[i, j] < _qi[i, j - 1])_qi[i, j] = _qi[i, j - 1];else_qi[i, j - 1] = _qi[i, j];}}}for (int i = 1; i <= 19; i++){for (int j = 19; j >= 1; j--){if (_chess[i, j] == _chess[i + 1, j] && i <= 18){if (_qi[i, j] < _qi[i + 1, j])_qi[i, j] = _qi[i + 1, j];else_qi[i + 1, j] = _qi[i, j];}if (_chess[i, j] == _chess[i, j + 1] && j <= 18){if (_qi[i, j] < _qi[i, j + 1])_qi[i, j] = _qi[i, j + 1];else_qi[i, j + 1] = _qi[i, j];}if (_chess[i, j] == _chess[i - 1, j] && i >= 2){if (_qi[i, j] < _qi[i - 1, j])_qi[i, j] = _qi[i - 1, j];else_qi[i - 1, j] = _qi[i, j];}if (_chess[i, j] == _chess[i, j - 1] && j >= 2){if (_qi[i, j] < _qi[i, j - 1])_qi[i, j] = _qi[i, j - 1];else_qi[i, j - 1] = _qi[i, j];}}}for (int i = 19; i >= 1; i--){for (int j = 1; j <= 19; j++){if (_chess[i, j] == _chess[i + 1, j] && i <= 18){if (_qi[i, j] < _qi[i + 1, j])_qi[i, j] = _qi[i + 1, j];else_qi[i + 1, j] = _qi[i, j];}if (_chess[i, j] == _chess[i, j + 1] && j <= 18){if (_qi[i, j] < _qi[i, j + 1])_qi[i, j] = _qi[i, j + 1];else_qi[i, j + 1] = _qi[i, j];}if (_chess[i, j] == _chess[i - 1, j] && i >= 2){if (_qi[i, j] < _qi[i - 1, j])_qi[i, j] = _qi[i - 1, j];else_qi[i - 1, j] = _qi[i, j];}if (_chess[i, j] == _chess[i, j - 1] && j >= 2){if (_qi[i, j] < _qi[i, j - 1])_qi[i, j] = _qi[i, j - 1];else_qi[i, j - 1] = _qi[i, j];}}}for (int i = 1; i <= 19; i++){for (int j = 1; j <= 19; j++){if (_qi[i, j] == 0 && _chess[i, j] != _pickChess)_chess[i, j] = Piece.无子;}}}//判断气public int Judge(Piece nowchess, int row, int col){int qi = 0;_bianli[row, col] = true;if (_chess[row, col + 1] == Piece.无子 && col <= 18){qi++;}if (_chess[row, col - 1] == Piece.无子 && col >= 2){qi++;}if (_chess[row + 1, col] == Piece.无子 && row <= 18){qi++;}if (_chess[row - 1, col] == Piece.无子 && row >= 2){qi++;}return qi;}//搜索public int SearchChess(int i, int j){_bianli[i, j] = true;if (_chess[i, j] == Piece.黑子)return 1;else if (_chess[i, j] == Piece.白子)return 2;else{if (i + 1 <= 19 && _bianli[i + 1, j] == false)return SearchChess(i + 1, j);if (j + 1 <= 19 && _bianli[i, j + 1] == false)return SearchChess(i, j + 1);if (i - 1 >= 1 && _bianli[i - 1, j] == false)return SearchChess(i - 1, j);if (j - 1 >= 1 && _bianli[i, j - 1] == false)return SearchChess(i, j - 1);if (j - 1 >= 1 && _bianli[i, j - 1] == false)return SearchChess(i, j - 1);if (i - 1 >= 1 && _bianli[i - 1, j] == false)return SearchChess(i - 1, j);if (j + 1 <= 19 && _bianli[i, j + 1] == false)return SearchChess(i, j + 1);if (i + 1 <= 19 && _bianli[i + 1, j] == false)return SearchChess(i + 1, j);return 0;}}public void PlaySound(string wavFile){//装载声音SoundPlayer soundplay = new SoundPlayer(wavFile);//播放声音soundplay.Play();}}
}

c#大作业——围棋(单机版)相关推荐

  1. 【网页设计】期末大作业html+css(体育网站)-围棋 4页

    ⛵ 源码获取 文末联系 ✈ Web前端开发技术 描述 网页设计题材,DIV+CSS 布局制作,HTML+CSS网页设计期末课程大作业 | 校园篮球网页设计 | 足球体育运动 | 体育游泳运动 | 兵乓 ...

  2. 基于C++的不围棋NOGO代码-PKU计算概论A大作业-MCTS算法Minimax算法

    关于评论区提出的问题,我补充一下,这篇代码是pku同学<计算概论A2020>的大作业,代码是需要提交在botzone上的,文章中有些代码是与botzone的交互,具体交互过程与规则见维基百 ...

  3. 基于JavaSwing开发连连看游戏(单机版) 课程设计 大作业源码 毕业设计

    基于JavaSwing开发连连看游戏(单机版):   (大作业) 开发环境: Windows操作系统 开发工具: MyEclipse/Eclipse+Jdk 运行效果图:  基于JavaSwing开发 ...

  4. 小程序 const moment = require('moment')_C++大作业-XXX管理程序

    理工科大一往往会学习C/C++,期末会有大作业.这篇文章就是一个简单的C++大作业程序.我也是大一,所以觉着哪里写得不好欢迎在评论区提出.程序总体上讲是个"总分总"结构. 一 实现 ...

  5. 游戏分析鉴赏选修大作业

    选修期末大作业需要写一个游戏分析,想找一个 参考一下,找了半天也没找到想要的,于是就弄了一个给以后的小伙伴们一个借鉴的. 题目如下: 文档中需要包含以下几个题目: 一.游戏目标 二.基本功能介绍 三. ...

  6. java 大作业 题目_java大作业题目

    课程大作业 1.计算器(仿windows中的计算器功能,另外加数据库连接,必须用户注册登录后才能使用该程序,保存每次的操作,记录用户名,登录时间,登录IP,使用时长等....) 2.扫雷(仿windo ...

  7. java大作业私人管家系统_操作系统概念(Operating System Concepts)第十版期中大作业...

    更正: 第一题中,哲学家就餐问题中的哲学家的状态state[i]应属于临界区变量,是可能会产生读写冲突的,所以对其进行读写的时候均需要加一把互斥锁. 非常感谢不听不听不听的指正. ---------- ...

  8. 大一c语言大作业课题大全,昆明理工大学大一C语言大作业题目.doc

    昆明理工大学大一C语言大作业题目 综合性实践排序求平均值(包括将数拆散求最大最小值).函数ReadDat()随机产生100个存放到数组aa中00个jsSort()函数的功能是:进行降序排列.最后调用函 ...

  9. 清华贵系的期末大作业:奋战三周,造台计算机!

    大数据文摘授权转载自AI科技评论 作者 | 蒋宝尚 编辑丨陈彩娴 本科大三,正在学习计算机组成原理,能做个什么项目? 清华大学贵系说:造台计算机吧! 清华有门本科三年级必修课,名为<计算机组成原 ...

最新文章

  1. CSS自适应的占位符效果
  2. Autodesk Infrastructure Map Server 2014的开发文档在哪里?
  3. android源码出现的@字符意义总结
  4. 6kyu Steps in k-prime
  5. 面试必备:缓存穿透,缓存雪崩的四种解决方案
  6. 取火的N种方式:学好物理是野外求生第一步
  7. Httpclient处理摘要认证
  8. js中避免函数名和变量名跟别人冲突
  9. MySQL的常用SQL脚本
  10. 新股上市涨跌幅规则?
  11. Linux 要如何查看系统架构
  12. 京东联盟导购平台开发指南(附带API接口)
  13. C/C++描述 - 矩阵乘积的计算
  14. XSSF 导入导出excel.xlsx 解决获取空白单元格自动跳过问题,校验excel表头是否符合需求
  15. 解决pads新建总是提示替换字体
  16. win10控制面板快捷键_你没玩过的全新版本 Win10这些操作你知多少
  17. VMware虚拟机装系统提示Units specified dont exist!
  18. 数据结构 图 思维导图上
  19. bs84c12引脚_BS84B08A-3_(HOLTEK(台湾合泰/盛群))BS84B08A-3中文资料_价格_PDF手册-立创电子商城...
  20. NETCONF配置CISCO XE(csr1000v)初体验

热门文章

  1. VSCode 连接 SSH 服务器
  2. 虚拟机使用主机显卡(hyper-v和WSL2)
  3. C# DirectInput游戏手柄开发心得
  4. HCIP华为认证网络工程师多久能够考过呢
  5. 一名程序猿的习惯养成记录手帐(九)
  6. 百度之星资格赛 1003 度度熊与邪恶大魔王(二维dp)
  7. 2018年安防行业发展现状与趋势分析
  8. python实现有障碍物的贪吃蛇_python实现贪吃蛇游戏源码
  9. 【SUMO】一文学会构建简单的交通路网仿真模拟器
  10. 仿抖音评论底部弹出框(列表框+发表框)