diff --git a/.vs/ChessGame/v16/.suo b/.vs/ChessGame/v16/.suo index c73e984..8c64e4a 100644 Binary files a/.vs/ChessGame/v16/.suo and b/.vs/ChessGame/v16/.suo differ diff --git a/ChessBots/SimpletronBot.cs b/ChessBots/SimpletronBot.cs index c29dcbe..e9d3614 100644 --- a/ChessBots/SimpletronBot.cs +++ b/ChessBots/SimpletronBot.cs @@ -81,41 +81,10 @@ private void CheckMovesDeep(Chessboard boardReadonly, int depth, ConcurrentBag<( Task.WaitAll(rootMoves.ToArray()); } - /* - private void CheckMovesDeep(Chessboard boardReadonly, int depth, ConcurrentBag<(int, Move)> moves, Move baseMove=null) - { - Chessboard board = new Chessboard(boardReadonly); - - if (depth == 0) - { - board.SimulateMove(FindBestMoves(board, boardReadonly.CurrentTurn)[0]); - moves.Add((board.MaterialSum, baseMove)); - return; - } - - foreach (var move in board.GetMoves(board.CurrentTurn)) - { - Chessboard newBoard = new Chessboard(board); - newBoard.SimulateMove(move); - - if (baseMove is null) - { - CheckMovesDeep(newBoard, depth - 1, moves, move); - } - else - { - CheckMovesDeep(newBoard, depth - 1, moves, baseMove); - } - } - }*/ - private Move GenerateMove(Chessboard board) { ConcurrentBag<(int, Move)> longerMoves = new ConcurrentBag<(int, Move)>(); - //List<(int, Move)> longerMoves = new List<(int, Move)>(); - - //CheckMovesDeep(board, 3, board.CurrentTurn, longerMoves); CheckMovesDeep(board, 2, longerMoves); List<(int, Move)> sortedMoves = longerMoves.OrderByDescending(material => material.Item1).ToList(); diff --git a/ChessBots/SkakinatorLogic.cs b/ChessBots/SkakinatorLogic.cs index 2dd77e7..a41c0c7 100644 --- a/ChessBots/SkakinatorLogic.cs +++ b/ChessBots/SkakinatorLogic.cs @@ -300,7 +300,6 @@ where Math.Round(moveEvaluation.Item1, 1) == bestEvaluation // Clean-up transpositionTable.Clear(); - //GC.Collect(); return sortedMoves[0]; } diff --git a/ChessForms/BoardDisplay.cs b/ChessForms/BoardDisplay.cs index 64f8b84..7e4f02e 100644 --- a/ChessForms/BoardDisplay.cs +++ b/ChessForms/BoardDisplay.cs @@ -22,16 +22,13 @@ public partial class BoardDisplay : Form private static readonly Color CheckedSquareColor = Color.DarkRed; private readonly Gamemode gamemode; + private readonly bool whiteLocal, blackLocal; private TilePictureControl[,] boardcells; private Coordinate? fromPosition = null; private Piece selectedPiece; private Chessboard chessboard; - private readonly bool whiteLocal, blackLocal; - private bool unFlipped = false; private Coordinate? recentMoveFrom = null; private Coordinate? recentMoveTo = null; - - //Sound private System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(Properties.Resources.SkakLydfil); public BoardDisplay(Gamemode gamemode, bool whiteLocal, bool blackLocal) @@ -41,9 +38,6 @@ public BoardDisplay(Gamemode gamemode, bool whiteLocal, bool blackLocal) this.gamemode = gamemode; this.whiteLocal = whiteLocal; this.blackLocal = blackLocal; - - // flip board if black is only local player - unFlipped = !(blackLocal && !whiteLocal); } private void BoardDisplay_Load(object sender, EventArgs e) @@ -139,7 +133,6 @@ private void onTurnStarted() if (MatchMaker.PlaySoundOnMove) { soundPlayer.Play(); - //Console.Beep(); } UpdateBoard(); @@ -158,14 +151,7 @@ private void onTurnStarted() private TilePictureControl GetCell(int x, int y) { - if (unFlipped) - { - return boardcells[chessboard.Width - 1 - x, chessboard.Height - 1 - y]; - } - else - { - return boardcells[x, y]; - } + return boardcells[x, y]; } /// @@ -228,15 +214,6 @@ public void UpdateBoard() { Coordinate pieceCoordinate; - /*if (unFlipped) - { - pieceCoordinate = new Coordinate(chessboard.Width - 1 - x, chessboard.Height - 1 - y); //Det her burde også fikse noget - } - else - { - pieceCoordinate = new Coordinate(x, y); - }*/ - pieceCoordinate = new Coordinate(x, y); Piece cellPiece = chessboard.GetPiece(pieceCoordinate); @@ -312,7 +289,7 @@ public void InstantiateUIBoard() { Label label = new Label { - Text = (chessboard.Height - y).ToString(), + Text = (y + 1).ToString(), TextAlign = ContentAlignment.MiddleCenter, Dock = DockStyle.Fill, Font = labelFont @@ -427,12 +404,6 @@ private void CellClicked(object sender, EventArgs e) int cellX = windowX / ((tableLayoutPanel1.Width - CoordinateSystemPixelSize) / chessboard.Width); int cellY = windowY / ((tableLayoutPanel1.Height - CoordinateSystemPixelSize) / chessboard.Height); - if (unFlipped) - { - cellY = (chessboard.Height - 1) - cellY; - cellX = (chessboard.Width - 1) - cellX; - } - Coordinate clickTarget = new Coordinate(cellX, cellY); // handle click diff --git a/ChessGame/Coordinate.cs b/ChessGame/Coordinate.cs index a1c8deb..3d8f8d0 100644 --- a/ChessGame/Coordinate.cs +++ b/ChessGame/Coordinate.cs @@ -46,41 +46,6 @@ public Coordinate(string notation) Rank = (byte)(notation[1] - 49); } - /* // proposed null functionality - [DebuggerStepThrough] - public static bool operator ==(Coordinate coordinate1, Coordinate coordinate2) - { - // this is way more complicated than I imagined, - // it's supposed to return true if all non-null equals withn their property group - // E.g. - // (null, 5) == (null, 5) == true - // (null, 5) == (3, 5) == true - // (null, null) == (3, 5) == false - // (null, 5) == (5, null) == false - // logic: - // (null, n) == (null, n) == true - // (n1, n2) == (n1, n2) == true - // (n1, null) == (n1, n2) == true - - // all are ambigous, no number is the same. - if (coordinate1.File is null && coordinate1.Rank is null || coordinate2.File is null && coordinate2.Rank is null) - { - return false; - } - - // file is null, compare rank. - if (coordinate1.File is null) - { - return coordinate1.Rank == coordinate2.Rank; - } - else if (coordinate1.Rank is null) // rank is null, compare file. - { - return coordinate1.File == coordinate1.Rank; - } - - return coordinate1.File == coordinate2.File && coordinate1.Rank == coordinate2.Rank; - }*/ - [DebuggerStepThrough] public static bool operator !=(Coordinate coordinate1, Coordinate coordinate2) => coordinate1.Rank != coordinate2.Rank || coordinate1.File != coordinate2.File; diff --git a/ChessGame/Gamemodes/PawnTestChess.cs b/ChessGame/Gamemodes/PawnTestChess.cs index 7bb1930..375abe0 100644 --- a/ChessGame/Gamemodes/PawnTestChess.cs +++ b/ChessGame/Gamemodes/PawnTestChess.cs @@ -20,7 +20,6 @@ public override Chessboard GenerateBoard() board[new Coordinate(5, 3)] = new Pawn { Color = TeamColor.White }; board[new Coordinate(6, 3)] = new Pawn { Color = TeamColor.White }; board[new Coordinate(7, 3)] = new Pawn { Color = TeamColor.White }; - //board[new Coordinate(2, 3)] = new Hypnotist { Color = TeamColor.White }; board[new Coordinate(0, 6)] = new Pawn { Color = TeamColor.Black }; board[new Coordinate(1, 6)] = new Pawn { Color = TeamColor.Black }; diff --git a/ChessGame/MovementPatterns/CardinalPattern.cs b/ChessGame/MovementPatterns/CardinalPattern.cs index baa4a7e..879a7f4 100644 --- a/ChessGame/MovementPatterns/CardinalPattern.cs +++ b/ChessGame/MovementPatterns/CardinalPattern.cs @@ -10,11 +10,11 @@ public class CardinalPattern : IMovementPattern { public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard board, bool guardedSquaresOnly = false) { - for (int n = 0; n < 4; n++) //The 4 directions from the piece + for (int n = 0; n < 4; n++) // The 4 directions from the piece { int Xdir = 1; int Ydir = 1; - switch (n) //Sets a direction for the checker + switch (n) // Sets a direction for the checker { case 0: Xdir = 1; @@ -36,18 +36,21 @@ public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard b break; } - for (int i = 1; i < board.Height * board.Width; i++) //Checker + for (int i = 1; i < board.Height * board.Width; i++) // Checker { - Coordinate checkPosition = new Coordinate((i * Xdir) + position.File, (i * Ydir) + position.Rank); //Position update + // Position update + Coordinate checkPosition = new Coordinate((i * Xdir) + position.File, (i * Ydir) + position.Rank); + // If the checking position is outside of the board if (checkPosition.Rank >= board.Height || checkPosition.Rank < 0 || - checkPosition.File >= board.Width || checkPosition.File < 0) //If the checking position is outside of the board + checkPosition.File >= board.Width || checkPosition.File < 0) break; // whether the position is occupied. Piece occupyingPiece = board.GetPiece(checkPosition); - if (occupyingPiece is null) // is position empty? + // is position empty? + if (occupyingPiece is null) { yield return new Move(checkPosition, position, piece, false, piece.Color); continue; @@ -58,9 +61,10 @@ public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard b break; } - if (occupyingPiece.Color != piece.Color || guardedSquaresOnly) // There is a enemy piece + // There is a enemy piece + if (occupyingPiece.Color != piece.Color || guardedSquaresOnly) { - yield return new Move(checkPosition, position, piece, true, piece.Color); //Sends the move + yield return new Move(checkPosition, position, piece, true, piece.Color); // Sends the move } break; diff --git a/ChessGame/MovementPatterns/DiagonalPattern.cs b/ChessGame/MovementPatterns/DiagonalPattern.cs index 6301b66..cc2a4ea 100644 --- a/ChessGame/MovementPatterns/DiagonalPattern.cs +++ b/ChessGame/MovementPatterns/DiagonalPattern.cs @@ -10,11 +10,11 @@ public class DiagonalPattern : IMovementPattern { public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard board, bool guardedSquaresOnly = false) { - for (int n = 0; n < 4; n++) //The 4 directions from the piece + for (int n = 0; n < 4; n++) // The 4 directions from the piece { int Xdir = 1; int Ydir = 1; - switch (n) //Sets a direction for the checker + switch (n) // Sets a direction for the checker { case 0: Xdir = 1; @@ -36,12 +36,12 @@ public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard b break; } - for (int i = 1; i < board.Width; i++) //Checker + for (int i = 1; i < board.Width; i++) // Checker { - Coordinate checkPosition = new Coordinate((i * Xdir) + position.File, (i * Ydir) + position.Rank); //Position update + Coordinate checkPosition = new Coordinate((i * Xdir) + position.File, (i * Ydir) + position.Rank); // Position update if (checkPosition.Rank >= board.Height || checkPosition.Rank < 0 || - checkPosition.File >= board.Width || checkPosition.File < 0) //If the checking position is outside of the board + checkPosition.File >= board.Width || checkPosition.File < 0) // If the checking position is outside of the board continue; // whether the position is occupied. @@ -60,7 +60,7 @@ public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard b if (occupyingPiece.Color != piece.Color) // There is a enemy piece { - yield return new Move(checkPosition, position, piece, true, piece.Color); //Sends the move + yield return new Move(checkPosition, position, piece, true, piece.Color); // Sends the move } break; diff --git a/ChessGame/MovementPatterns/KnightPattern.cs b/ChessGame/MovementPatterns/KnightPattern.cs index 7eaa347..e78412d 100644 --- a/ChessGame/MovementPatterns/KnightPattern.cs +++ b/ChessGame/MovementPatterns/KnightPattern.cs @@ -6,11 +6,11 @@ public class KnightPattern : IMovementPattern { public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard board, bool guardedSquaresOnly = false) { - for (int n = 0; n < 4; n++) //The 4 directions from the piece + for (int n = 0; n < 4; n++) // The 4 directions from the piece { int Xdir = 1; int Ydir = 1; - switch (n) //Sets a direction for the checker + switch (n) // Sets a direction for the checker { case 0: Xdir = 2; @@ -34,16 +34,16 @@ public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard b for (int i = 0; i < 2; i++) { - //First check - Coordinate checkPosition = new Coordinate(Xdir + position.File, Ydir + position.Rank); //Position update + // First check + Coordinate checkPosition = new Coordinate(Xdir + position.File, Ydir + position.Rank); // Position update - if (i != 0) //Second check + if (i != 0) // Second check { - checkPosition = new Coordinate(-Xdir + position.File, -Ydir + position.Rank); //Position update + checkPosition = new Coordinate(-Xdir + position.File, -Ydir + position.Rank); // Position update } if (checkPosition.Rank >= board.Height || checkPosition.Rank < 0 || - checkPosition.File >= board.Width || checkPosition.File < 0) //If the checking position is outside of the board + checkPosition.File >= board.Width || checkPosition.File < 0) // If the checking position is outside of the board continue; // whether the position is occupied. @@ -57,7 +57,7 @@ public IEnumerable GetMoves(Piece piece, Coordinate position, Chessboard b if (occupyingPiece.Color != piece.Color) // There is a enemy piece { - yield return new Move(checkPosition, position, piece, true, piece.Color); //Sends the move + yield return new Move(checkPosition, position, piece, true, piece.Color); // Sends the move } } }