欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實現(xiàn)圍棋游戲

 更新時間:2022年05月10日 14:36:32   作者:龍木  
這篇文章主要為大家詳細(xì)介紹了C#實現(xiàn)圍棋游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C#實現(xiàn)圍棋游戲的具體代碼,供大家參考,具體內(nèi)容如下

之所以選擇圍棋作為大作業(yè)一方面是想挑戰(zhàn)一下,另一方面是由于從6歲學(xué)圍棋到11歲放下,再到今天已將近8年了,也算是回味一下童年吧,畢竟,曾夢想執(zhí)子走天涯。

這是效果圖:

這個程序除了一開始參考了中國象棋,其他的都是自己完成的。

不說了,上代碼?。?!

這個是主窗口代碼:

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;
?
//該產(chǎn)品歸屬****大學(xué)18級信息工程學(xué)院計算機系王**所有,如需轉(zhuǎn)載,請注明原作者及出處:https://blog.csdn.net/Luoriliming
namespace AlphaGo
{
? ? public partial class FormMain : Form
? ? {
? ? ? ? //加載圍棋類
? ? ? ? private PlayChess playchess = new PlayChess();
?
? ? ? ? public FormMain()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? //根據(jù)屏幕分辨率調(diào)整大小
? ? ? ? ? ? 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.白;
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? playchess._curPlayer = Player.黑;
? ? ? ? ? ? ? ? if (playchess._pickChess == Piece.黑子)
? ? ? ? ? ? ? ? ? ? playchess._pickChess = Piece.白子;
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? playchess._pickChess = Piece.黑子;
? ? ? ? ? ? ? ? if (playchess._timeColor == Color.Yellow)
? ? ? ? ? ? ? ? ? ? playchess._timeColor = Color.Red;
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? playchess._timeColor = Color.Yellow;
? ? ? ? ? ? ? ? playchess._time2 = 60;
? ? ? ? ? ? ? ? playchess._time1 = 60;
? ? ? ? ? ? ? ? timer1.Enabled = !timer1.Enabled;
? ? ? ? ? ? ? ? timer2.Enabled = !timer2.Enabled;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
?
? ? ? ? ? ? ? ? playchess._time1 = playchess._time1 - 1;
? ? ? ? ? ? ? ? Invalidate();
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //鼠標(biāo)移動
? ? ? ? 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;
? ? ? ? ? ? ? ? //輸出此時鼠標(biāo)位置,并判斷是否在范圍內(nèi)
? ? ? ? ? ? ? ? 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;
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? timer2.Enabled = false;
? ? ? ? ? ? ? ? ? ? ? ? if (timer1.Enabled == false)
? ? ? ? ? ? ? ? ? ? ? ? ? ? timer1.Enabled = true;
? ? ? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? ? ? ? ? timer1.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.白;
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? playchess._curPlayer = Player.黑;
? ? ? ? ? ? ? ? if (playchess._pickChess == Piece.黑子)
? ? ? ? ? ? ? ? ? ? playchess._pickChess = Piece.白子;
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? playchess._pickChess = Piece.黑子;
? ? ? ? ? ? ? ? playchess._time2 = 60;
? ? ? ? ? ? ? ? playchess._time1 = 60;
? ? ? ? ? ? ? ? timer1.Enabled = !timer1.Enabled;
? ? ? ? ? ? ? ? timer2.Enabled = !timer2.Enabled;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
?
? ? ? ? ? ? ? ? playchess._time2 = playchess._time2 - 1;
? ? ? ? ? ? ? ? Invalidate();
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //判斷勝負(fù)
? ? ? ? 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;
?
//該產(chǎn)品歸屬****大學(xué)18級信息工程學(xué)院計算機系王**所有,如需轉(zhuǎn)載,請注明原作者及出處:https://blog.csdn.net/Luoriliming
?
namespace 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];
? ? ? ? //初始化執(zhí)子為無子
? ? ? ? public Piece _pickChess = Piece.無子;
? ? ? ? //落下棋子的位置
? ? ? ? public int _dropRow = 0;
? ? ? ? public int _dropCol = 0;
? ? ? ? //閃爍
? ? ? ? public Color _timeColor = Color.Yellow;
? ? ? ? //類字段:走棋方
? ? ? ? public Player _curPlayer = Player.無;
? ? ? ? //鼠標(biāo)移動位置
? ? ? ? public Point _curMousePoint = new Point(0, 0);
? ? ? ? //類字段:設(shè)置走棋步驟表
? ? ? ? public List<Step> _listStep = new List<Step>();
? ? ? ? //保存棋盤左上角坐標(biāo)
? ? ? ? public Point _lefttop = new Point(100, 100);
? ? ? ? //棋子半徑
? ? ? ? public int _pieceR = 10;
? ? ? ? //保存行高和列寬
? ? ? ? public int _rowHeight = 30;
? ? ? ? public int _colWidth = 30;
? ? ? ? //加載圖像
? ? ? ? //導(dǎo)入各種圖片
? ? ? ? Bitmap deskbmp = new Bitmap("desktop.jpg");
? ? ? ? public Bitmap _redbmp = new Bitmap("黑方頭像.jpg");
? ? ? ? public Bitmap _bluebmp = new Bitmap("白方頭像.jpg");
? ? ? ? //設(shè)置是否遍歷數(shù)組
? ? ? ? public bool[,] _bianli = new bool[25, 25];
? ? ? ? //設(shè)置氣的數(shù)組
? ? ? ? public int[,] _qi = new int[20, 20];
? ? ? ? //設(shè)置白棋黑棋個數(shù)
? ? ? ? public int _Whitechess;
? ? ? ? public int _Blackchess;
? ? ? ? //計時
? ? ? ? public int _time1 = 60;
? ? ? ? public int _time2 = 60;
? ? ? ? //黑白子各勝局?jǐn)?shù)
? ? ? ? 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];
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? return null;
?
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? //類構(gòu)造方法
? ? ? ? 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;
? ? ? ? ? ? //初始化當(dāng)前走棋方
? ? ? ? ? ? _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.黑子;
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? if (_curPlayer == Player.黑)
? ? ? ? ? ? ? ? ? ? _curPlayer = Player.白;
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? _curPlayer = Player.黑;
? ? ? ? ? ? ? ? //重置時間
? ? ? ? ? ? ? ? _time2 = 60;
? ? ? ? ? ? ? ? _time1 = 60;
? ? ? ? ? ? ? ? //步數(shù)加一
? ? ? ? ? ? ? ? _chessnumber = _chessnumber + 1;
? ? ? ? ? ? ? ? //添加上一步的存入
? ? ? ? ? ? ? ? _dropCol = dropCol;
? ? ? ? ? ? ? ? _dropRow = dropRow;
? ? ? ? ? ? ? ? _lastcol = _dropCol;
? ? ? ? ? ? ? ? _lastrow = _dropRow;
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? ? ? return false;
?
? ? ? ? }
? ? ? ? //類:判斷勝負(fù)
? ? ? ? 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++;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? //如果黑子多于白子,則黑方獲勝;如果白子多于黑子,則白方獲勝;如果雙方棋子數(shù)相同,則平局
? ? ? ? ? ? if (_Blackchess > _Whitechess)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return Player.黑;
? ? ? ? ? ? }
? ? ? ? ? ? else if (_Whitechess > _Blackchess)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return Player.白;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? ? ? return Player.無;
?
? ? ? ? }
? ? ? ? //類:圍棋規(guī)則
? ? ? ? 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));
? ? ? ? ? ? //創(chuàng)建粗筆和細(xì)筆
? ? ? ? ? ? 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);
? ? ? ? ? ? //書寫坐標(biāo)
? ? ? ? ? ? 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);
? ? ? ? ? ? //步數(shù)
? ? ? ? ? ? g.DrawString("步數(shù):", 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)));
? ? ? ? ? ? //黑白各勝局?jǐn)?shù)
? ? ? ? ? ? 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]);
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? //繪制跟隨鼠標(biāo)移動的棋子
? ? ? ? ? ? DrawMousePiece(g, _curMousePoint.X, _curMousePoint.Y, _pickChess);
? ? ? ? }
? ? ? ? //鼠標(biāo)位置
? ? ? ? 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)
? ? ? ? {
? ? ? ? ? ? //在棋盤范圍內(nèi)繪制閃爍標(biāo)記
? ? ? ? ? ? if (row > 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Pen pen = new Pen(_timeColor, 4);
? ? ? ? ? ? ? ? Point p = new Point(_lefttop.X + _colWidth * (col - 1), _lefttop.Y + _rowHeight * (row - 1));
? ? ? ? ? ? ? ? //繪制閃爍標(biāo)記
? ? ? ? ? ? ? ? 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);
?
? ? ? ? ? ? }
?
? ? ? ? }
? ? ? ? //吃子判定(因為不用考慮時間和空間復(fù)雜度,用暴力跑的,主要這段時間被卡超時卡太煩了)
? ? ? ? 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();
? ? ? ? }
? ? }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論