diff --git a/Chessboard Control/Board/Board.cs b/Chessboard Control/Board/Board.cs
index abfcd9a..663e606 100644
--- a/Chessboard Control/Board/Board.cs
+++ b/Chessboard Control/Board/Board.cs
@@ -43,7 +43,7 @@ public class Board
{
private const int EMPTY_SQUARE = -1;
- public static readonly string DEFAULT_FEN_POSITION = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
+ public static readonly string INITIAL_FEN_POSITION = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
private enum PawnMove
{
@@ -159,11 +159,11 @@ private enum PawnMove
#region Constructors
///
- /// Creates an instance of the class initialized with the default position.
+ /// Creates an instance of the class initialized with the initial position.
///
public Board()
{
- LoadFEN(DEFAULT_FEN_POSITION);
+ LoadFEN(INITIAL_FEN_POSITION);
}
///
@@ -321,21 +321,12 @@ public void Clear()
MoveHistory = new Stack();
}
- ///
- /// Returns a ChessPiece corresponding to its FEN abbreviation
- ///
- /// Case insensitive FEN abbreviation. Possible values are: p, n, b, r, q, k.
- ///
- public static ChessPieceKind FenToChessPiece(string fenPiece)
- {
- return FenToChessPiece(fenPiece[0]);
- }
-
///
/// Returns the kind of a chess piece corresponding to its FEN abbreviation.
///
/// Case insensitive FEN abbreviation. Possible values are: p, n, b, r, q, k.
///
+ /// Thrown when the char doesn’t match any FEN formatted chess piece kind.
public static ChessPieceKind FenToChessPiece(char fenPiece)
{
switch (char.ToLower(fenPiece))
@@ -958,7 +949,7 @@ public void PutPiece(ChessPiece piece, string square)
///
public void Reset()
{
- LoadFEN(DEFAULT_FEN_POSITION);
+ LoadFEN(INITIAL_FEN_POSITION);
}
///
diff --git a/Chessboard Control/Chessboard Control.csproj b/Chessboard Control/Chessboard Control.csproj
index 67592f3..27e2652 100644
--- a/Chessboard Control/Chessboard Control.csproj
+++ b/Chessboard Control/Chessboard Control.csproj
@@ -38,6 +38,7 @@
+
@@ -67,12 +68,20 @@
Chessboard.cs
+
+
+
+ Form
+
+
+ FrmPromotion.cs
+
True
@@ -84,6 +93,9 @@
Chessboard.cs
+
+ FrmPromotion.cs
+
ResXFileCodeGenerator
Resources.Designer.cs
@@ -125,6 +137,11 @@
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Chessboard Control/Chessboard.bmp b/Chessboard Control/Chessboard.bmp
new file mode 100644
index 0000000..519a207
Binary files /dev/null and b/Chessboard Control/Chessboard.bmp differ
diff --git a/Chessboard Control/Chessboard.cs b/Chessboard Control/Chessboard.cs
index 089a9b3..efd7399 100644
--- a/Chessboard Control/Chessboard.cs
+++ b/Chessboard Control/Chessboard.cs
@@ -2,10 +2,13 @@
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
+using System.Collections.Generic;
namespace ChessboardControl
{
+ [Designer(typeof(ChessboardDesigner))]
[DefaultEvent("OnPieceMoved")]
+ [ToolboxBitmap(@"C:\Users\AdminSRV\source\repos\Chessboard Control\Chessboard Control\Chessboard.bmp")]
public partial class Chessboard : Control
{
// Sizes
@@ -36,27 +39,30 @@ internal DragOperation(ChessPieceKind selectedPiece, ChessSquare source)
public Chessboard()
{
InitializeComponent();
+ SetStyle(ControlStyles.OptimizedDoubleBuffer |
+ ControlStyles.UserPaint |
+ ControlStyles.AllPaintingInWmPaint, true);
Size = new Size(340, 340);
- WhiteSquareColor = DEFAULT_WHITE_SQUARE_COLOR;
- BlackSquareColor = DEFAULT_BLACK_SQUARE_COLOR;
+ LightSquaresColor = DEFAULT_WHITE_SQUARE_COLOR;
+ DarkSquaresColor = DEFAULT_BLACK_SQUARE_COLOR;
CoordinateAreaBackColor = DEFAULT_COORDINATE_BACKGROUND_COLOR;
}
#region Properties
- private Color _blackSquareColor;
+ private Color _darkSquaresColor;
///
- /// Gets or sets the color used to draw black squares.
+ /// Gets or sets the color used to draw dark squares.
///
[DefaultValue(typeof(Color), "#FF4682B4")]
- public Color BlackSquareColor
+ public Color DarkSquaresColor
{
- get { return _blackSquareColor; }
+ get { return _darkSquaresColor; }
set
{
- if (value != _blackSquareColor)
+ if (value != _darkSquaresColor)
{
- _blackSquareColor = value;
+ _darkSquaresColor = value;
Invalidate();
}
}
@@ -124,6 +130,29 @@ private int LetterAreaHeight
///
private Board ChessEngine { get; } = new Board();
+ private Color _lightSquaresColor;
+ ///
+ /// Gets or sets the color used to draw light squares.
+ ///
+ [DefaultValue(typeof(Color), "#FFF5F5F5")]
+ public Color LightSquaresColor
+ {
+ get { return _lightSquaresColor; }
+ set
+ {
+ if (value != _lightSquaresColor)
+ {
+ _lightSquaresColor = value;
+ Invalidate();
+ }
+ }
+ }
+
+ ///
+ /// Gets or sets whether to show visual hints.
+ ///
+ public bool ShowVisualHints { get; set; } = false;
+
///
/// Gets or sets the size of the control. Minimum value is 255x255.
///
@@ -162,24 +191,6 @@ private int SquareWidth
get { return Math.Max(MINIMUM_SQUARE_WIDTH, (int)(this.Size.Width / 8.5)); }
}
- private Color _whiteSquareColor;
- ///
- /// Gets or sets the color used to draw white squares.
- ///
- [DefaultValue(typeof(Color), "#FFF5F5F5")]
- public Color WhiteSquareColor
- {
- get { return _whiteSquareColor; }
- set
- {
- if (value != _whiteSquareColor)
- {
- _whiteSquareColor = value;
- Invalidate();
- }
- }
- }
-
#endregion Properties
#region Methods
@@ -257,8 +268,8 @@ public void MovePiece(ChessSquare from, ChessSquare to)
private void RedrawSquare(ChessSquare targetedSquare)
{
var g = this.CreateGraphics();
- var blackSquareBrush = new Pen(BlackSquareColor).Brush;
- var whiteSquareBrush = new Pen(WhiteSquareColor).Brush;
+ var blackSquareBrush = new Pen(DarkSquaresColor).Brush;
+ var whiteSquareBrush = new Pen(LightSquaresColor).Brush;
var x = (int)targetedSquare.File;
var y = (int)targetedSquare.Rank;
var isWhiteSquare = (((int)targetedSquare.File + (int)targetedSquare.Rank) % 2) != 0;
@@ -310,17 +321,16 @@ public void SetPieceAt(ChessSquare squareCoordinate, ChessPieceKind piece)
///
public void SetupInitialPosition()
{
- ChessEngine.LoadFEN(Board.DEFAULT_FEN_POSITION);
+ ChessEngine.LoadFEN(Board.INITIAL_FEN_POSITION);
Invalidate();
}
protected override void OnPaint(PaintEventArgs pe)
{
- this.SuspendLayout();
var g = pe.Graphics;
var coordinateAreaBrush = new Pen(CoordinateAreaBackColor).Brush;
- var blackSquareBrush = new Pen(BlackSquareColor).Brush;
- var whiteSquareBrush = new Pen(WhiteSquareColor).Brush;
+ var darkSquaresBrush = new Pen(DarkSquaresColor).Brush;
+ var lightSquaresBrush = new Pen(LightSquaresColor).Brush;
// Draw a filled rectangle for digits
g.FillRectangle(coordinateAreaBrush, 0, 0, DigitAreaWidth, this.Height);
@@ -357,27 +367,29 @@ protected override void OnPaint(PaintEventArgs pe)
// Draw Turn indicator
var turnIndicatorBorder = new Rectangle(0, Height - LetterAreaHeight, DigitAreaWidth, LetterAreaHeight);
var turnIndicatorSquare = new RectangleF(0, Height - LetterAreaHeight, DigitAreaWidth, LetterAreaHeight);
- g.FillRectangle(ChessEngine.Turn == ChessColor.White ? whiteSquareBrush : blackSquareBrush, turnIndicatorSquare);
+ g.FillRectangle(ChessEngine.Turn == ChessColor.White ? lightSquaresBrush : darkSquaresBrush, turnIndicatorSquare);
g.DrawRectangle(new Pen(Color.Black), turnIndicatorBorder);
// Draw cells
- bool isWhiteSquare = true;
+ bool isLightSquare = true;
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
var square = new RectangleF(DigitAreaWidth + x * SquareWidth, y * SquareHeight, SquareWidth, SquareHeight);
- g.FillRectangle(isWhiteSquare ? whiteSquareBrush : blackSquareBrush, square);
- ChessSquare currentSquare = BoardDirection == BoardDirection.BlackOnTop ? new ChessSquare((ChessFile)x, (ChessRank)7 - y) : new ChessSquare((ChessFile)7 - x, (ChessRank)y);
+ g.FillRectangle(isLightSquare ? lightSquaresBrush : darkSquaresBrush, square);
+ ChessSquare currentSquare = BoardDirection == BoardDirection.BlackOnTop ?
+ new ChessSquare((ChessFile)x, (ChessRank)7 - y) :
+ new ChessSquare((ChessFile)7 - x, (ChessRank)y);
ChessPiece currentPiece = ChessEngine.GetPieceAt(currentSquare);
if (currentPiece != null)
{
g.DrawImage(GetPieceImage(currentPiece), square);
}
- isWhiteSquare = !isWhiteSquare;
+ isLightSquare = !isLightSquare;
}
- isWhiteSquare = !isWhiteSquare;
+ isLightSquare = !isLightSquare;
}
// Draw borders
@@ -385,7 +397,28 @@ protected override void OnPaint(PaintEventArgs pe)
g.DrawRectangle(new Pen(Color.Black), borders);
g.Flush();
- this.ResumeLayout();
+ }
+
+ private void DrawVisualHints()
+ {
+ if (ShowVisualHints && DragDropOperation.Origin != null)
+ {
+ var g = this.CreateGraphics();
+ List legalMoves = ChessEngine.GetLegalMoves(DragDropOperation.Origin);
+ foreach (ChessMove chessMove in legalMoves)
+ {
+ g.FillEllipse(new SolidBrush(Color.FromArgb(150, 92, 214, 92)),
+ BoardDirection == BoardDirection.BlackOnTop ?
+ GetHintRectangle((int)chessMove.To.File, 7 - (int)chessMove.To.Rank) :
+ GetHintRectangle(7 - (int)chessMove.To.File, (int)chessMove.To.Rank));
+ }
+ g.Flush();
+ }
+ }
+
+ private RectangleF GetHintRectangle(int x, int y)
+ {
+ return new RectangleF(DigitAreaWidth + x * SquareWidth + SquareWidth / 4, y * SquareHeight + SquareHeight / 4, SquareWidth / 2f, SquareHeight / 2f);
}
#endregion Methods
@@ -426,6 +459,7 @@ private void Chessboard_MouseDown(object sender, MouseEventArgs e)
Cursor = new Cursor(resizedBitmap.GetHicon());
DragDropOperation = new DragOperation(selectedPiece.Kind, origin);
RedrawSquare(origin);
+ DrawVisualHints();
OnSquareSelected?.Invoke(this, origin, selectedPiece.Kind);
}
}
@@ -445,9 +479,23 @@ private void Chessboard_MouseUp(object sender, MouseEventArgs e)
var moveValidation = ChessEngine.GetMoveValidity(DragDropOperation.Origin, destinationSquare);
if (moveValidation.IsValid)
{
- ChessEngine.Move(moveValidation);
- Invalidate();
- OnPieceMoved?.Invoke(this, DragDropOperation.Origin, destinationSquare, DragDropOperation.DraggedPiece, moveValidation.CapturedPiece);
+ var promotionCancelled = false;
+ if ((moveValidation.MoveKind & ChessMoveType.Promotion) == ChessMoveType.Promotion)
+ {
+ var pieceChooser = new FrmPromotion(ChessEngine.Turn);
+ promotionCancelled = (pieceChooser.ShowDialog() != DialogResult.OK);
+ moveValidation.PromotedTo = pieceChooser.ChoosePiece;
+ }
+ if (!promotionCancelled)
+ {
+ ChessEngine.Move(moveValidation);
+ Invalidate();
+ OnPieceMoved?.Invoke(this, DragDropOperation.Origin, destinationSquare, DragDropOperation.DraggedPiece, moveValidation.CapturedPiece);
+ }
+ else
+ {
+ Invalidate();
+ }
}
else
{
diff --git a/Chessboard Control/ChessboardDesigner.cs b/Chessboard Control/ChessboardDesigner.cs
new file mode 100644
index 0000000..a9e788f
--- /dev/null
+++ b/Chessboard Control/ChessboardDesigner.cs
@@ -0,0 +1,23 @@
+using System.Windows.Forms.Design;
+using System.ComponentModel.Design;
+
+namespace ChessboardControl
+{
+ public class ChessboardDesigner: ControlDesigner
+ {
+ private DesignerActionListCollection actionLists;
+
+ public override DesignerActionListCollection ActionLists
+ {
+ get
+ {
+ if (actionLists == null)
+ {
+ actionLists = new DesignerActionListCollection();
+ actionLists.Add(new ChessboardDesignerActionList(this.Component));
+ }
+ return actionLists;
+ }
+ }
+ }
+}
diff --git a/Chessboard Control/ChessboardDesignerActionList.cs b/Chessboard Control/ChessboardDesignerActionList.cs
new file mode 100644
index 0000000..c4aa453
--- /dev/null
+++ b/Chessboard Control/ChessboardDesignerActionList.cs
@@ -0,0 +1,60 @@
+using System.ComponentModel.Design;
+using System.ComponentModel;
+using System.Drawing;
+
+namespace ChessboardControl
+{
+ public class ChessboardDesignerActionList : DesignerActionList
+ {
+ private Chessboard _control;
+
+ public ChessboardDesignerActionList(IComponent component) : base(component)
+ {
+ _control = component as Chessboard;
+ }
+
+ private void SetPropValue(string propName, object value)
+ {
+ PropertyDescriptor prop = TypeDescriptor.GetProperties(_control)[propName];
+ if (prop != null) { prop.SetValue(_control, value); }
+ }
+
+ public Color DarkSquaresColor
+ {
+ get { return _control.DarkSquaresColor; }
+ set { SetPropValue("DarkSquaresColor", value); }
+ }
+
+ public Color LightSquaresColor
+ {
+ get { return _control.LightSquaresColor; }
+ set { SetPropValue("LightSquaresColor", value); }
+ }
+
+ public BoardDirection BoardDirection
+ {
+ get { return _control.BoardDirection; }
+ set { SetPropValue("BoardDirection", value); }
+ }
+
+ public void Reset()
+ {
+ DarkSquaresColor = Color.SteelBlue;
+ LightSquaresColor = Color.WhiteSmoke;
+ BoardDirection = BoardDirection.BlackOnTop;
+ }
+
+ public override DesignerActionItemCollection GetSortedActionItems()
+ {
+ DesignerActionItemCollection items = new DesignerActionItemCollection();
+
+ items.Add(new DesignerActionHeaderItem("Appearance"));
+ items.Add(new DesignerActionPropertyItem("DarkSquaresColor", "Dark squares color", "Appearance"));
+ items.Add(new DesignerActionPropertyItem("LightSquaresColor", "Light squares color", "Appearance"));
+ items.Add(new DesignerActionPropertyItem("BoardDirection", "Board direction", "Appearance"));
+ items.Add(new DesignerActionMethodItem(this, "Reset", "Reset settings", true));
+
+ return items;
+ }
+ }
+}
diff --git a/Chessboard Control/FrmPromotion.Designer.cs b/Chessboard Control/FrmPromotion.Designer.cs
new file mode 100644
index 0000000..5071277
--- /dev/null
+++ b/Chessboard Control/FrmPromotion.Designer.cs
@@ -0,0 +1,111 @@
+
+namespace ChessboardControl
+{
+ partial class FrmPromotion
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.PctBxQueen = new System.Windows.Forms.PictureBox();
+ this.PctBxRook = new System.Windows.Forms.PictureBox();
+ this.PctBxBishop = new System.Windows.Forms.PictureBox();
+ this.PctBxKnight = new System.Windows.Forms.PictureBox();
+ ((System.ComponentModel.ISupportInitialize)(this.PctBxQueen)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.PctBxRook)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.PctBxBishop)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.PctBxKnight)).BeginInit();
+ this.SuspendLayout();
+ //
+ // PctBxQueen
+ //
+ this.PctBxQueen.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.PctBxQueen.Location = new System.Drawing.Point(12, 12);
+ this.PctBxQueen.Name = "PctBxQueen";
+ this.PctBxQueen.Size = new System.Drawing.Size(60, 60);
+ this.PctBxQueen.TabIndex = 0;
+ this.PctBxQueen.TabStop = false;
+ this.PctBxQueen.Click += new System.EventHandler(this.PctBxQueen_Click);
+ //
+ // PctBxRook
+ //
+ this.PctBxRook.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.PctBxRook.Location = new System.Drawing.Point(78, 12);
+ this.PctBxRook.Name = "PctBxRook";
+ this.PctBxRook.Size = new System.Drawing.Size(60, 60);
+ this.PctBxRook.TabIndex = 0;
+ this.PctBxRook.TabStop = false;
+ this.PctBxRook.Click += new System.EventHandler(this.PctBxRook_Click);
+ //
+ // PctBxBishop
+ //
+ this.PctBxBishop.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.PctBxBishop.Location = new System.Drawing.Point(144, 12);
+ this.PctBxBishop.Name = "PctBxBishop";
+ this.PctBxBishop.Size = new System.Drawing.Size(60, 60);
+ this.PctBxBishop.TabIndex = 0;
+ this.PctBxBishop.TabStop = false;
+ this.PctBxBishop.Click += new System.EventHandler(this.PctBxBishop_Click);
+ //
+ // PctBxKnight
+ //
+ this.PctBxKnight.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+ this.PctBxKnight.Location = new System.Drawing.Point(210, 12);
+ this.PctBxKnight.Name = "PctBxKnight";
+ this.PctBxKnight.Size = new System.Drawing.Size(60, 60);
+ this.PctBxKnight.TabIndex = 0;
+ this.PctBxKnight.TabStop = false;
+ this.PctBxKnight.Click += new System.EventHandler(this.PctBxKnight_Click);
+ //
+ // FrmPromotion
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.BackColor = System.Drawing.Color.DarkGray;
+ this.ClientSize = new System.Drawing.Size(282, 84);
+ this.Controls.Add(this.PctBxKnight);
+ this.Controls.Add(this.PctBxBishop);
+ this.Controls.Add(this.PctBxRook);
+ this.Controls.Add(this.PctBxQueen);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
+ this.Name = "FrmPromotion";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+ this.Text = "Promotion";
+ ((System.ComponentModel.ISupportInitialize)(this.PctBxQueen)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.PctBxRook)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.PctBxBishop)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.PctBxKnight)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PictureBox PctBxQueen;
+ private System.Windows.Forms.PictureBox PctBxRook;
+ private System.Windows.Forms.PictureBox PctBxBishop;
+ private System.Windows.Forms.PictureBox PctBxKnight;
+ }
+}
\ No newline at end of file
diff --git a/Chessboard Control/FrmPromotion.cs b/Chessboard Control/FrmPromotion.cs
new file mode 100644
index 0000000..c83ed96
--- /dev/null
+++ b/Chessboard Control/FrmPromotion.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace ChessboardControl
+{
+ public partial class FrmPromotion : Form
+ {
+ public FrmPromotion(ChessColor turn)
+ {
+ InitializeComponent();
+
+ switch (turn)
+ {
+ case ChessColor.Black:
+ PctBxQueen.Image = Properties.Resources.BlackQueen;
+ PctBxRook.Image = Properties.Resources.BlackRook;
+ PctBxBishop.Image = Properties.Resources.BlackBishop;
+ PctBxKnight.Image = Properties.Resources.BlackKnight;
+ break;
+ case ChessColor.White:
+ PctBxQueen.Image = Properties.Resources.WhiteQueen;
+ PctBxRook.Image = Properties.Resources.WhiteRook;
+ PctBxBishop.Image = Properties.Resources.WhiteBishop;
+ PctBxKnight.Image = Properties.Resources.WhiteKnight;
+ break;
+ }
+ }
+
+ ///
+ /// Gets or sets what piece has been chosen.
+ ///
+ public ChessPieceKind ChoosePiece { get; private set; } = ChessPieceKind.None;
+
+ private void PctBxQueen_Click(object sender, EventArgs e)
+ {
+ ChoosePiece = ChessPieceKind.Queen;
+ DialogResult = DialogResult.OK;
+ }
+
+ private void PctBxRook_Click(object sender, EventArgs e)
+ {
+ ChoosePiece = ChessPieceKind.Rook;
+ DialogResult = DialogResult.OK;
+ }
+
+ private void PctBxBishop_Click(object sender, EventArgs e)
+ {
+ ChoosePiece = ChessPieceKind.Bishop;
+ DialogResult = DialogResult.OK;
+ }
+
+ private void PctBxKnight_Click(object sender, EventArgs e)
+ {
+ ChoosePiece = ChessPieceKind.Knight;
+ DialogResult = DialogResult.OK;
+ }
+ }
+}
diff --git a/Chessboard Control/FrmPromotion.resx b/Chessboard Control/FrmPromotion.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/Chessboard Control/FrmPromotion.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Chessboard Control/Properties/AssemblyInfo.cs b/Chessboard Control/Properties/AssemblyInfo.cs
index 9bd8489..6d84a55 100644
--- a/Chessboard Control/Properties/AssemblyInfo.cs
+++ b/Chessboard Control/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.2101.12")]
-[assembly: AssemblyFileVersion("1.0.2101.12")]
+[assembly: AssemblyVersion("1.0.2101.14")]
+[assembly: AssemblyFileVersion("1.0.2101.14")]
diff --git a/Chessboard Control/Properties/Resources.Designer.cs b/Chessboard Control/Properties/Resources.Designer.cs
index fefff9c..963bccf 100644
--- a/Chessboard Control/Properties/Resources.Designer.cs
+++ b/Chessboard Control/Properties/Resources.Designer.cs
@@ -120,6 +120,16 @@ internal static System.Drawing.Bitmap BlackRook {
}
}
+ ///
+ /// Recherche une ressource localisée de type System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap Chessboard {
+ get {
+ object obj = ResourceManager.GetObject("Chessboard", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
///
/// Recherche une ressource localisée de type System.Drawing.Bitmap.
///
diff --git a/Chessboard Control/Properties/Resources.resx b/Chessboard Control/Properties/Resources.resx
index dbf99df..0b3a547 100644
--- a/Chessboard Control/Properties/Resources.resx
+++ b/Chessboard Control/Properties/Resources.resx
@@ -136,6 +136,9 @@
..\Resources\BlackRook.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+ ..\Chessboard.bmp;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
..\Resources\WhiteBishop.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
diff --git a/Chessboard Control/Resources/Chessboard.bmp b/Chessboard Control/Resources/Chessboard.bmp
new file mode 100644
index 0000000..103cd25
Binary files /dev/null and b/Chessboard Control/Resources/Chessboard.bmp differ
diff --git a/Chessboard Tester/Form1.Designer.cs b/Chessboard Tester/Form1.Designer.cs
index 0f00126..9682bda 100644
--- a/Chessboard Tester/Form1.Designer.cs
+++ b/Chessboard Tester/Form1.Designer.cs
@@ -44,6 +44,7 @@ private void InitializeComponent()
this.BtnMovePiece = new System.Windows.Forms.Button();
this.ChkBxFlipBoard = new System.Windows.Forms.CheckBox();
this.BtnSaveToFile = new System.Windows.Forms.Button();
+ this.ChkBxShowVisualHints = new System.Windows.Forms.CheckBox();
this.chessboard1 = new ChessboardControl.Chessboard();
this.SuspendLayout();
//
@@ -239,6 +240,18 @@ private void InitializeComponent()
this.BtnSaveToFile.UseVisualStyleBackColor = true;
this.BtnSaveToFile.Click += new System.EventHandler(this.BtnSaveToFile_Click);
//
+ // ChkBxShowVisualHints
+ //
+ this.ChkBxShowVisualHints.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.ChkBxShowVisualHints.AutoSize = true;
+ this.ChkBxShowVisualHints.Location = new System.Drawing.Point(358, 312);
+ this.ChkBxShowVisualHints.Name = "ChkBxShowVisualHints";
+ this.ChkBxShowVisualHints.Size = new System.Drawing.Size(78, 17);
+ this.ChkBxShowVisualHints.TabIndex = 17;
+ this.ChkBxShowVisualHints.Text = "Show hints";
+ this.ChkBxShowVisualHints.UseVisualStyleBackColor = true;
+ this.ChkBxShowVisualHints.CheckedChanged += new System.EventHandler(this.ChkBxShowVisualHints_CheckedChanged);
+ //
// chessboard1
//
this.chessboard1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@@ -246,9 +259,10 @@ private void InitializeComponent()
| System.Windows.Forms.AnchorStyles.Right)));
this.chessboard1.Location = new System.Drawing.Point(12, 12);
this.chessboard1.Name = "chessboard1";
+ this.chessboard1.ShowVisualHints = false;
this.chessboard1.Size = new System.Drawing.Size(340, 340);
- this.chessboard1.TabIndex = 16;
- this.chessboard1.Text = "chessboard2";
+ this.chessboard1.TabIndex = 18;
+ this.chessboard1.Text = "chessboard1";
this.chessboard1.OnSquareSelected += new ChessboardControl.Chessboard.SelectedSquareEventHandler(this.chessboard1_OnSquareSelected);
this.chessboard1.OnPieceMoved += new ChessboardControl.Chessboard.PieceMovedEventHandler(this.chessboard1_OnPieceMoved);
this.chessboard1.OnPieceRemoved += new ChessboardControl.Chessboard.PieceRemovedEventHandler(this.chessboard1_OnPieceRemoved);
@@ -260,6 +274,7 @@ private void InitializeComponent()
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(442, 462);
this.Controls.Add(this.chessboard1);
+ this.Controls.Add(this.ChkBxShowVisualHints);
this.Controls.Add(this.BtnSaveToFile);
this.Controls.Add(this.ChkBxFlipBoard);
this.Controls.Add(this.BtnMovePiece);
@@ -301,6 +316,7 @@ private void InitializeComponent()
private System.Windows.Forms.Button BtnMovePiece;
private System.Windows.Forms.CheckBox ChkBxFlipBoard;
private System.Windows.Forms.Button BtnSaveToFile;
+ private System.Windows.Forms.CheckBox ChkBxShowVisualHints;
private ChessboardControl.Chessboard chessboard1;
}
}
diff --git a/Chessboard Tester/Form1.cs b/Chessboard Tester/Form1.cs
index db15ff1..d53a5b2 100644
--- a/Chessboard Tester/Form1.cs
+++ b/Chessboard Tester/Form1.cs
@@ -88,5 +88,10 @@ private void BtnSaveToFile_Click(object sender, EventArgs e)
}
}
}
+
+ private void ChkBxShowVisualHints_CheckedChanged(object sender, EventArgs e)
+ {
+ chessboard1.ShowVisualHints = ChkBxShowVisualHints.Checked;
+ }
}
}
diff --git a/Chessboard Tester/Properties/AssemblyInfo.cs b/Chessboard Tester/Properties/AssemblyInfo.cs
index e1011d6..7c171d8 100644
--- a/Chessboard Tester/Properties/AssemblyInfo.cs
+++ b/Chessboard Tester/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.2101.12")]
-[assembly: AssemblyFileVersion("1.0.2101.12")]
+[assembly: AssemblyVersion("1.0.2101.14")]
+[assembly: AssemblyFileVersion("1.0.2101.14")]
diff --git a/Ressources/Chessboard.bmp b/Ressources/Chessboard.bmp
new file mode 100644
index 0000000..103cd25
Binary files /dev/null and b/Ressources/Chessboard.bmp differ
diff --git a/UnitTest Chessboard Control/Properties/AssemblyInfo.cs b/UnitTest Chessboard Control/Properties/AssemblyInfo.cs
index 2ebf783..afe8205 100644
--- a/UnitTest Chessboard Control/Properties/AssemblyInfo.cs
+++ b/UnitTest Chessboard Control/Properties/AssemblyInfo.cs
@@ -16,5 +16,5 @@
[assembly: Guid("7f46f0c8-b7ae-4e64-aea7-5238103ac97a")]
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.2101.12")]
-[assembly: AssemblyFileVersion("1.0.2101.12")]
+[assembly: AssemblyVersion("1.0.2101.14")]
+[assembly: AssemblyFileVersion("1.0.2101.14")]
diff --git a/UnitTest Chessboard Control/UnitTest_Board.cs b/UnitTest Chessboard Control/UnitTest_Board.cs
index 3f8cd35..4d045bc 100644
--- a/UnitTest Chessboard Control/UnitTest_Board.cs
+++ b/UnitTest Chessboard Control/UnitTest_Board.cs
@@ -18,7 +18,7 @@ public void Constructor_Should_InitializeWithInitialPosition()
string fen = board.GetFEN();
// Assert
- Assert.AreEqual(SUT.DEFAULT_FEN_POSITION, fen);
+ Assert.AreEqual(SUT.INITIAL_FEN_POSITION, fen);
}
[TestMethod]
@@ -94,14 +94,14 @@ public void Reset_Should_ResetAndSetupInitialPosition()
board.Reset();
// Assert
- Assert.AreEqual(SUT.DEFAULT_FEN_POSITION, board.GetFEN());
+ Assert.AreEqual(SUT.INITIAL_FEN_POSITION, board.GetFEN());
Assert.AreEqual(ChessColor.White, board.Turn);
Assert.AreEqual(ChessCastling.KingSide | ChessCastling.QueenSide, board.GetCastlingRights(ChessColor.White));
Assert.AreEqual(ChessCastling.KingSide | ChessCastling.QueenSide, board.GetCastlingRights(ChessColor.Black));
}
[TestMethod]
- public void GetPieceAt_Should_ReturnsThePiece()
+ public void GetPieceAt_Should_ReturnThePiece()
{
// Arrange
SUT board = new SUT();
@@ -224,7 +224,7 @@ public void RemovePieceAt_Should_ThrowArgumentNullException()
}
[TestMethod]
- public void Ascii_Should_ReturnsCorrectFormat()
+ public void Ascii_Should_ReturnCorrectFormat()
{
// Arrange
SUT board = new SUT();
@@ -260,7 +260,7 @@ public void Ascii_Should_ReturnsCorrectFormat()
[DataRow(ChessPieceKind.Bishop, ChessColor.Black, "b")]
[DataRow(ChessPieceKind.Queen, ChessColor.Black, "q")]
[DataRow(ChessPieceKind.King, ChessColor.Black, "k")]
- public void ChessPieceToFEN_Should_ReturnsCorrectFENPiece(ChessPieceKind pieceKind, ChessColor pieceColor, string expectedFEN)
+ public void ChessPieceToFEN_Should_ReturnCorrectFENPiece(ChessPieceKind pieceKind, ChessColor pieceColor, string expectedFEN)
{
// Assert
Assert.AreEqual(expectedFEN, SUT.ChessPieceToFEN(new ChessPiece(pieceKind, pieceColor)));
@@ -273,8 +273,36 @@ public void ChessPieceToFEN_Should_ThrowArgumentNullException_WhenPieceIsNull()
SUT.ChessPieceToFEN(null);
}
+
+ [TestMethod]
+ [DataRow('p', ChessPieceKind.Pawn)]
+ [DataRow('r', ChessPieceKind.Rook)]
+ [DataRow('n', ChessPieceKind.Knight)]
+ [DataRow('b', ChessPieceKind.Bishop)]
+ [DataRow('q', ChessPieceKind.Queen)]
+ [DataRow('k', ChessPieceKind.King)]
+ [DataRow('P', ChessPieceKind.Pawn)]
+ [DataRow('R', ChessPieceKind.Rook)]
+ [DataRow('N', ChessPieceKind.Knight)]
+ [DataRow('B', ChessPieceKind.Bishop)]
+ [DataRow('Q', ChessPieceKind.Queen)]
+ [DataRow('K', ChessPieceKind.King)]
+ public void FenToChessPiece_Should_Return_ChessPieceKind(char piece, ChessPieceKind expectedResult)
+ {
+ // Assert
+ Assert.AreEqual(expectedResult, SUT.FenToChessPiece(piece));
+ }
+
+ [TestMethod]
+ [ExpectedException(typeof(System.ArgumentOutOfRangeException))]
+ public void FenToChessPiece_Should_ThrowArgumentOutOfRangeException()
+ {
+ // Act
+ SUT.FenToChessPiece('v');
+ }
+
[TestMethod]
- public void GetLegalMoves_Should_ReturnsAllLegalMovesForInitialPosition()
+ public void GetLegalMoves_Should_ReturnAllLegalMovesForInitialPosition()
{
// Arrange
SUT board = new SUT();
@@ -302,7 +330,7 @@ public void GetLegalMoves_Should_ReturnsAllLegalMovesForInitialPosition()
[DataRow("8/7P/2P5/8/4b3/8/6P1/1P6 b - - 0 1", "e4", "c6,d5,f3,g2,b1,c2,d3,f5,g6,h7")]
[DataRow("8/8/8/8/4n3/8/8/8 b - - 0 1", "e4", "d6,f6,g5,g3,d2,f2,c3,c5")]
[DataRow("8/8/8/8/4N3/8/8/8 w - - 0 1", "e4", "d6,f6,g5,g3,d2,f2,c3,c5")]
- public void GetLegalMoves_Should_ReturnsAllLegalMoves(string fen, string from , string moves)
+ public void GetLegalMoves_Should_ReturnAllLegalMoves(string fen, string from , string moves)
{
// Arrange
SUT board = new SUT(fen);
@@ -333,7 +361,7 @@ public void GetLegalMoves_Should_ReturnsAllLegalMoves(string fen, string from ,
}
[TestMethod]
- public void GetLegalMoves_Should_ReturnsEmptyList()
+ public void GetLegalMoves_Should_ReturnEmptyList()
{
// Arrange
SUT board = new SUT("8/4p3/p3k3/P2R1R2/4K1p1/6P1/8/8 b - - 0 1");
@@ -347,7 +375,7 @@ public void GetLegalMoves_Should_ReturnsEmptyList()
}
[TestMethod]
- public void LegalMoves_Should_ReturnsKingSideCastle()
+ public void LegalMoves_Should_ReturnKingSideCastle()
{
// Arrange
SUT board = new SUT("rnbqk2r/pppp1ppp/5n2/4p3/8/b7/8/4K2R w Kkq - 0 1");
@@ -367,7 +395,7 @@ public void LegalMoves_Should_ReturnsKingSideCastle()
}
[TestMethod]
- public void LegalMoves_Should_ReturnsQueenSideCastle()
+ public void LegalMoves_Should_ReturnQueenSideCastle()
{
// Arrange
SUT board = new SUT("rnbqk2r/pppp1ppp/3b1n2/4p3/8/8/8/R3K3 w Qkq - 0 1");
@@ -506,7 +534,7 @@ public void IsMoveLegal_Should_Return_False_When_NotRightTurn()
[DataRow("rnbqkbnr/8/8/8/pppppppp/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1", "f4", "f3", ChessMoveType.Normal)]
[DataRow("rnbqkbnr/8/8/8/pppppppp/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1", "g4", "g3", ChessMoveType.Normal)]
[DataRow("rnbqkbnr/8/8/8/pppppppp/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1", "h4", "h3", ChessMoveType.Normal)]
- public void IsMoveLegal_Should_Returns_True_When_PawnMoveIsLegal(
+ public void IsMoveLegal_Should_Return_True_When_PawnMoveIsLegal(
string fen,
string from,
string to,
@@ -638,7 +666,7 @@ public void IsMoveLegal_Should_Returns_True_When_PawnMoveIsLegal(
[DataRow("rnbqkbnr/pppppp1p/8/8/5Pp1/8/PPPPP1PP/RNBQKBNR b KQkq f3 0 1", "g4", "f3", ChessMoveType.EP_Capture, ChessPieceKind.Pawn)]
[DataRow("rnbqkbnr/pppppp1p/8/8/6pP/8/PPPPPPP1/RNBQKBNR b KQkq h3 0 1", "g4", "h3", ChessMoveType.EP_Capture, ChessPieceKind.Pawn)]
[DataRow("rnbqkbnr/ppppppp1/8/8/6Pp/8/PPPPPP1P/RNBQKBNR b KQkq g3 0 1", "h4", "g3", ChessMoveType.EP_Capture, ChessPieceKind.Pawn)]
- public void IsMoveLegal_Should_Returns_True_When_PawnCaptureIsLegal(
+ public void IsMoveLegal_Should_Return_True_When_PawnCaptureIsLegal(
string fen,
string from,
string to,
@@ -783,7 +811,7 @@ public void IsMoveLegal_Should_Returns_True_When_PawnCaptureIsLegal(
[DataRow("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "h2", "f4", ChessMoveRejectedReason.NotMovingLikeThis)]
[DataRow("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "h2", "e5", ChessMoveRejectedReason.NotMovingLikeThis)]
[DataRow("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", "h2", "d6", ChessMoveRejectedReason.NotMovingLikeThis)]
- public void IsMoveLegal_Should_Returns_False_When_PawnMoveIsIllegal(
+ public void IsMoveLegal_Should_Return_False_When_PawnMoveIsIllegal(
string fen,
string from,
string to,
diff --git a/UnitTest Chessboard Control/UnitTest_FenValidator.cs b/UnitTest Chessboard Control/UnitTest_FenValidator.cs
index 3e1d3ce..aaa832e 100644
--- a/UnitTest Chessboard Control/UnitTest_FenValidator.cs
+++ b/UnitTest Chessboard Control/UnitTest_FenValidator.cs
@@ -26,7 +26,7 @@ public class UnitTest_FenValidator
[DataRow("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Q - 0 1")]
[DataRow("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq g6 0 1")]
[DataRow("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq b3 0 1")]
- public void IsValid_Should_Retuns_True(string fen)
+ public void IsValid_Should_Retun_True(string fen)
{
// Assert
Assert.IsTrue(SUT.Validate(fen).IsValid);