public ChessPiece(ChessPieces name, ChessColors color, Icon icon) { this.name = name; this.pieceColor = color; this.lastMove = 0; image = (new Icon(icon, 48, 48)).ToBitmap(); }
public Knight(Point position, ChessPieces pi, bool isblack) : base(position, pi, isblack) { if (isblack) { this.Image = Image.FromFile(Path.GetFullPath(@"Images\45px-Chess_ndt45.svg.png")); } else { this.Image = Image.FromFile(Path.GetFullPath(@"Images\White\45px-Chess_nlt45.svg.png")); } }
public Rook(Point position, ChessPieces pi, bool isblack) : base(position, pi, isblack) { if (isblack) { this.Image = Image.FromFile(Path.GetFullPath(@"Images\15351823890172195.png")); } else { this.Image = Image.FromFile(Path.GetFullPath(@"Images\White\45px-Chess_rlt45.svg.png")); } }
public Pawn(Point position, ChessPieces pi, bool isblack) : base(position, pi, isblack) { this.originalPoint = position; if (isblack) { this.Image = Image.FromFile(Path.GetFullPath(@"Images\45px-Chess_pdt45.svg.png")); } else { this.Image = Image.FromFile(Path.GetFullPath(@"Images\White\45px-Chess_plt45.svg.png")); } }
public int GetSumCertainPieces(ChessPieces chessPiece, bool isblack) { int sum = 0; for (int i = 0; i < grid.GetLength(0); i++) { for (int j = 0; j < grid.GetLength(1); j++) { if (grid[i, j].IsOccuppied()) { Piece temp = GetTile(i, j).GetPiece(); if (temp.GetChessPieceType() == chessPiece && temp.IsBlack() == isblack) { sum++; } } } } return(sum); }
public Piece(Point position, ChessPieces pi, bool isblack) { isBlack = isblack; this.position = position; pieceType = pi; if (this.isBlack && MainWindow.Player1.isBlack) { player = MainWindow.Player1; opposite = MainWindow.Player2; } else { player = MainWindow.Player2; opposite = MainWindow.Player1; } this.SizeMode = PictureBoxSizeMode.StretchImage; this.Size = new Size(40, 40); }
int GetDeduction(ChessBoard board, ChessPieces pie) { return(board.GetSumCertainPieces(pie, false) - board.GetSumCertainPieces(pie, true)); }
void mouseUp(ChessPieces cp, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (cp.pic.Parent == pic_chessboard) { cp.canmove = false; pic_chessboard.Cursor = Cursors.Default; if (cp.deadPanel.Name == "pnl_RedDied") { if (whichside == 0)//是否轮到黑棋 { if (cp.move()) { btn_TakeBack.Enabled = true; 悔棋ToolStripMenuItem.Enabled = true; turnToRed();//调用移动规则 移动成功则轮到红棋 } } else { cp.goBack();//若不是轮到黑棋 则返回初始位置 } } else { if (whichside == 1)//是否轮到红棋 { if (cp.move()) { btn_TakeBack.Enabled = true; 悔棋ToolStripMenuItem.Enabled = true; turnToBlack(); //调用移动规则 移动成功则轮到黑棋 } } else { cp.goBack();//若不是轮到红棋 则返回初始位置 } } } } }
void mouseMove(ChessPieces cp, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (cp.canmove) { int dx, dy; cp.pic.BringToFront();//改变其优先级使其显示在上方 pic_chessboard.Cursor = Cursors.Hand; dx = MousePosition.X - x1; dy = MousePosition.Y - y1; cp.moveto(cp.x_temp + dx, cp.y_temp + dy); } } }
void mouseDown(ChessPieces cp, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { stackPoint.Push(new Point(cp.getX(), cp.getY())); stackPictureBox.Push(cp.pic.Name); if (cp.canmove == false) { if (cp.pic.Parent == pic_chessboard) { cp.canmove = true; x1 = MousePosition.X; y1 = MousePosition.Y; cp.getTemp();//纪录起始位置 } } } else if (e.Button == MouseButtons.Right) { if (cp.canmove) { //MessageBox.Show("red"); cp.goBack(); pic_chessboard.Cursor = Cursors.Default; cp.canmove = false; } } }
public static void GetInputState(string folderpath, int input) { Bitmap bmp; Graphics gr; int[] Available_ChessPieces = new int[12]; string[,] cat = new string[8, 8]; byte[] buffer = new byte[64]; int dx = 0; int dy = 0; if (input == 0) { bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); gr = Graphics.FromImage(bmp); gr.CopyFromScreen(0, 0, 0, 0, bmp.Size); } else { bmp = new Bitmap(Program.directory + @"TempBitmap.PNG"); gr = Graphics.FromImage(bmp); } for (int i = 0; i < 8; i++) { if (i > 2) { dx = 1; if (i > 6) { dx = 2; } } else { dx = 0; } for (int j = 0; j < 8; j++) { if (j > 2) { dy = 1; if (j > 6) { dy = 2; } } else { dy = 0; } cat[i, j] = ChessPieces.CompareChessPiece(598 + 91 * i - dx, 179 + 91 * j - dy, bmp, folderpath); if (cat[i, j].Contains(",")) { int color = int.Parse(cat[i, j].Split(',')[0]); int category = int.Parse(cat[i, j].Split(',')[1]); int pieces = 0; for (int k = 0; k < category; k++) { pieces += ChessPieces_Count[k]; } pieces = (pieces + Available_ChessPieces[color * 6 + category]) * 2; buffer[color * 32 + pieces] = byte.Parse(j.ToString()); buffer[color * 32 + pieces + 1] = byte.Parse(i.ToString()); Available_ChessPieces[color * 6 + category]++; } } } File.WriteAllBytes(Program.directory + @"Chess Weights\InputState.txt", buffer); }