├── .gitignore ├── Docs └── SharpChess.Model.XML ├── GNU_GPL_Licence.txt ├── README.txt ├── Settings.StyleCop ├── SharpChess Game ├── AssemblyInfo.cs ├── Backup │ ├── XMLtoOB.txt │ ├── xBackup.txt │ ├── xFutilityPruning.txt │ ├── xHashTable.txt │ ├── xImport.txt │ ├── xQuiesce.txt │ └── xVerifiedNullMove.txt ├── Cursors │ ├── BlackBishop.cur │ ├── BlackKing.cur │ ├── BlackKnight.cur │ ├── BlackPawn.cur │ ├── BlackQueen.cur │ ├── BlackRook.cur │ ├── WhiteBishop.cur │ ├── WhiteKing.cur │ ├── WhiteKnight.cur │ ├── WhitePawn.cur │ ├── WhiteQueen.cur │ └── WhiteRook.cur ├── Forms │ ├── frmAbout.cs │ ├── frmAbout.resx │ ├── frmDifficulty.cs │ ├── frmDifficulty.resx │ ├── frmMain.cs │ ├── frmMain.resx │ ├── frmMoveAnalysis.cs │ ├── frmMoveAnalysis.resx │ ├── frmPieceSelector.cs │ ├── frmPieceSelector.resx │ ├── frmWinBoard.cs │ └── frmWinBoard.resx ├── Images │ ├── Logo │ │ └── logo.bmp │ ├── PieceGraphics │ │ ├── Bishop_Black.gif │ │ ├── Bishop_White.gif │ │ ├── King_Black.gif │ │ ├── King_White.gif │ │ ├── Knight_Black.gif │ │ ├── Knight_White.gif │ │ ├── Pawn_Black.gif │ │ ├── Pawn_White.gif │ │ ├── Queen_Black.gif │ │ ├── Queen_White.gif │ │ ├── Rook_Black.gif │ │ └── Rook_White.gif │ └── ToolbarGraphics │ │ ├── Computer.gif │ │ ├── FlipBoard.gif │ │ ├── Knight.gif │ │ ├── MoveNow.gif │ │ ├── New.gif │ │ ├── Open.gif │ │ ├── Pause.gif │ │ ├── Play.gif │ │ ├── Redo.gif │ │ ├── RedoAll.gif │ │ ├── Save.gif │ │ ├── Undo.gif │ │ └── UndoAll.gif ├── Properties │ └── app.manifest ├── Settings.StyleCop ├── SharpChess.csproj ├── SharpChessIcon.ico └── app.config ├── SharpChess Performance Tester ├── Main.Designer.cs ├── Main.cs ├── Main.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Settings.StyleCop ├── SharpChess Performance Tester.csproj ├── SharpChess Performance Tester.sln ├── SharpChessIcon.ico ├── SharpChessIcon.png ├── TestPosition.sharpchess ├── TestRig.cs └── app.config ├── SharpChess Setup └── SharpChess Setup.vdproj ├── SharpChess Solution.sln ├── SharpChess Tests └── SharpChess Tests │ ├── BestMoveTest.cs │ ├── GameXTest.cs │ ├── HashTableCheckTest.cs │ ├── MovesTest.cs │ ├── PlayerTest.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Settings.StyleCop │ ├── SharpChess Tests.csproj │ └── Test References │ └── SharpChess2.accessor ├── SharpChess.Model.Tests ├── BestMoveTest.cs ├── GameTest.cs ├── HashTableCheckTest.cs ├── MovesTest.cs ├── PieceTest.cs ├── PlayerTest.cs ├── Properties │ └── AssemblyInfo.cs ├── SharpChess.Model.Tests.csproj └── Test References │ └── SharpChess.Model.accessor ├── SharpChess.Model ├── AI │ ├── Brain.cs │ ├── ForceImmediateMoveException.cs │ ├── HashTable.cs │ ├── HashTableCheck.cs │ ├── HashTablePawnKing.cs │ ├── History.cs │ ├── HistoryHeuristic.cs │ ├── KillerMoves.cs │ ├── OpeningBook.cs │ ├── OpeningBookSimple.cs │ └── Search.cs ├── Board.cs ├── BoardDebug.cs ├── FEN.cs ├── Game.cs ├── IPieceTop.cs ├── Move.cs ├── Moves.cs ├── PGNtoXML.cs ├── Piece.cs ├── PieceBishop.cs ├── PieceHashCodes.cs ├── PieceKing.cs ├── PieceKnight.cs ├── PiecePawn.cs ├── PieceQueen.cs ├── PieceRook.cs ├── Pieces.cs ├── Player.cs ├── PlayerBlack.cs ├── PlayerClock.cs ├── PlayerDebug.cs ├── PlayerWhite.cs ├── Properties │ └── AssemblyInfo.cs ├── SharpChess.Model.csproj ├── Square.cs ├── Squares.cs └── WinBoard.cs ├── UpgradeLog.htm ├── UpgradeLog2.htm └── UpgradeLog3.htm /.gitignore: -------------------------------------------------------------------------------- 1 | # git ignore file 2 | 3 | # Compiled source # 4 | ################### 5 | *.com 6 | *.class 7 | *.dll 8 | *.exe 9 | *.o 10 | *.so 11 | *.msi 12 | bin/ 13 | obj/ 14 | Obj/ 15 | Generated_Code/ 16 | PrecompiledWeb 17 | ClientBin/ 18 | 19 | 20 | # Local and user files # 21 | ###################### 22 | *.testsettings 23 | *.user 24 | *.suo 25 | *.ncb 26 | *.ccscc 27 | *.cache 28 | *.ignore 29 | *.vsmdi 30 | 31 | # Packages # 32 | ############ 33 | # it's better to unpack these files and commit the raw source 34 | # git has its own built in compression methods 35 | *.7z 36 | *.dmg 37 | *.gz 38 | *.iso 39 | *.jar 40 | *.rar 41 | *.tar 42 | *.zip 43 | 44 | 45 | # Logs and databases # 46 | ###################### 47 | *.log 48 | *.sql 49 | *.sqlite 50 | 51 | 52 | # OS generated files # 53 | ###################### 54 | .DS_Store* 55 | ehthumbs.db 56 | Icon? 57 | Thumbs.db 58 | 59 | 60 | # Resharper files # 61 | ###################### 62 | _ReSharper.SharpChess Solution/ 63 | 64 | 65 | # Test results # 66 | ###################### 67 | TestResults/ 68 | 69 | # Profiler documents # 70 | ###################### 71 | *.vsp 72 | *.psess 73 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | SharpChess is a free, open-source, computer application that enables you to play chess against the computer. 2 | 3 | SharpChess also uses the Chess Engine Communication Protocol, and can therefore play against other chess engines using WinBoard or Arena. SharpChess has competed in computer vs. computer chess tournaments (WBEC and ChessWar). Developers are invited to participate in the open-source SharpChess project at GitHub in order to improve SharpChess's chess-playing powers! 4 | 5 | SharpChess has been wholly developed using, C# (C Sharp), and runs on Microsoft Windows and Mono. 6 | 7 | Find out more about SharpChess at http://SharpChess.com 8 | 9 | An excellent resource for chess programming can be found at http://chessprogramming.wikispaces.com 10 | 11 | --------------------------------------------------------------- 12 | 13 | SharpChess Copyright (c) Peter Hughes 2011. All rights reserved. 14 | 15 | All aspects of SharpChess are covered by the GNU GPL v3 License. See GNU_GPL_Licence.txt for full details. 16 | 17 | 18 | This program is free software: you can redistribute it and/or modify 19 | it under the terms of the GNU General Public License as published by 20 | the Free Software Foundation, either version 3 of the License, or 21 | (at your option) any later version. 22 | 23 | This program is distributed in the hope that it will be useful, 24 | but WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 | GNU General Public License for more details. 27 | 28 | You should have received a copy of the GNU General Public License 29 | along with this program. If not, see . -------------------------------------------------------------------------------- /Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SharpChess 6 | Peter Hughes 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /SharpChess Game/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // AssemblyInfo.cs 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | #region Using 27 | 28 | using System.Reflection; 29 | using System.Runtime.InteropServices; 30 | 31 | #endregion 32 | 33 | // General Information about an assembly is controlled through the following 34 | // set of attributes. Change these attribute values to modify the information 35 | // associated with an assembly. 36 | [assembly: AssemblyTitle("SharpChess")] 37 | [assembly: AssemblyDescription("C# Chess Game")] 38 | [assembly: AssemblyConfiguration("")] 39 | [assembly: AssemblyCompany("SharpChess.com")] 40 | [assembly: AssemblyProduct("SharpChess")] 41 | [assembly: AssemblyCopyright("Peter Hughes")] 42 | [assembly: AssemblyTrademark("")] 43 | [assembly: AssemblyCulture("")] 44 | 45 | // Version information for an assembly consists of the following four values: 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // You can specify all the values or you can default the Revision and Build Numbers 51 | // by using the '*' as shown below: 52 | [assembly: AssemblyVersion("2.6.9")] 53 | 54 | // In order to sign your assembly you must specify a key to use. Refer to the 55 | // Microsoft .NET Framework documentation for more information on assembly signing. 56 | // Use the attributes below to control which key is used for signing. 57 | // Notes: 58 | // (*) If no key is specified, the assembly is not signed. 59 | // (*) KeyName refers to a key that has been installed in the Crypto Service 60 | // Provider (CSP) on your machine. KeyFile refers to a file which contains 61 | // a key. 62 | // (*) If the KeyFile and the KeyName values are both specified, the 63 | // following processing occurs: 64 | // (1) If the KeyName can be found in the CSP, that key is used. 65 | // (2) If the KeyName does not exist and the KeyFile does exist, the key 66 | // in the KeyFile is installed into the CSP and used. 67 | // (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. 68 | // When specifying the KeyFile, the location of the KeyFile should be 69 | // relative to the project output directory which is 70 | // %Project Directory%\obj\. For example, if your KeyFile is 71 | // located in the project directory, you would specify the AssemblyKeyFile 72 | // attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] 73 | // (*) Delay Signing is an advanced option - see the Microsoft .NET Framework 74 | // documentation for more information on this. 75 | [assembly: AssemblyDelaySign(false)] 76 | [assembly: AssemblyKeyFile("")] 77 | [assembly: AssemblyKeyName("")] 78 | [assembly: ComVisible(false)] 79 | [assembly: AssemblyFileVersionAttribute("2.6.9")] 80 | -------------------------------------------------------------------------------- /SharpChess Game/Backup/XMLtoOB.txt: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Xml; 3 | 4 | namespace SharpChess 5 | { 6 | public class OpeningBook 7 | { 8 | private struct HashEntry 9 | { 10 | public ulong HashCodeA; 11 | public ulong HashCodeB; 12 | public byte From; 13 | public byte To; 14 | public Move.enmName MoveName; 15 | } 16 | 17 | public int HASH_TABLE_SIZE = 0; 18 | public const Move UNKNOWN = null; 19 | static HashEntry[] m_arrHashEntry = new HashEntry[HASH_TABLE_SIZE]; 20 | 21 | static OpeningBook() 22 | { 23 | Clear(); 24 | } 25 | 26 | public static void ResetStats() 27 | { 28 | Entries = 0; 29 | Collisions = 0; 30 | Probes = 0; 31 | Hits = 0; 32 | } 33 | 34 | public static void Clear() 35 | { 36 | ResetStats(); 37 | for (uint intIndex=0; intIndex>8 & 0xff), (byte)(intScanMove & 0xff), Move.enmName.Standard, player.Colour ); 63 | } 64 | } 65 | 66 | static unsafe int ScanPly(Player player, XmlElement xmlnodeParent) 67 | { 68 | Move moveUndo; 69 | int intReturnScore = 0; 70 | int intReturnMove = 0; 71 | int intScanMove; 72 | int intScore; 73 | 74 | foreach (XmlElement xmlnodeMove in xmlnodeParent.ChildNodes) 75 | { 76 | Move.enmName movename = xmlnodeMove.GetAttribute("N")==null ? Move.enmName.Standard : Move.MoveNameFromString(xmlnodeMove.GetAttribute("N")); 77 | Square from = Board.GetSquare(xmlnodeMove.GetAttribute("F")); 78 | Square to = Board.GetSquare(xmlnodeMove.GetAttribute("T")); 79 | Piece piece = from.Piece; 80 | 81 | intScore = Convert.ToInt32(xmlnodeMove.GetAttribute(player.Colour==Player.enmColour.White ? "W":"B")); 82 | if (intScore>intReturnScore) 83 | { 84 | intReturnScore = intScore; 85 | intReturnMove = from.Ordinal<<8 | to.Ordinal; 86 | } 87 | 88 | moveUndo = piece.Move(movename, to); 89 | 90 | intScanMove = ScanPly(player.OtherPlayer, xmlnodeMove); 91 | if (intScanMove!=0) 92 | { 93 | RecordHash(Board.HashCodeA, Board.HashCodeB, (byte)(intScanMove>>8 & 0xff), (byte)(intScanMove & 0xff), movename, player.OtherPlayer.Colour ); 94 | } 95 | 96 | Move.Undo(moveUndo); 97 | } 98 | return intReturnMove; 99 | } 100 | 101 | private unsafe static void RecordHash(ulong HashCodeA, ulong HashCodeB, byte From, byte To, Move.enmName MoveName, Player.enmColour colour) 102 | { 103 | if (colour==Player.enmColour.Black) 104 | { 105 | HashCodeA |= 0x1; 106 | HashCodeB |= 0x1; 107 | } 108 | else 109 | { 110 | HashCodeA &= 0xFFFFFFFFFFFFFFFE; 111 | HashCodeB &= 0xFFFFFFFFFFFFFFFE; 112 | } 113 | 114 | Entries++; 115 | 116 | fixed (HashEntry* phashBase = &m_arrHashEntry[0]) 117 | { 118 | HashEntry* phashEntry = phashBase; 119 | phashEntry += ((uint)(HashCodeA % HASH_TABLE_SIZE)); 120 | if (phashEntry->HashCodeA!=0 && phashEntry->HashCodeA!=HashCodeA && phashEntry->HashCodeB!=HashCodeB) 121 | { 122 | Collisions++; 123 | } 124 | phashEntry->HashCodeA = HashCodeA; 125 | phashEntry->HashCodeB = HashCodeB; 126 | phashEntry->From = From; 127 | phashEntry->To = To; 128 | phashEntry->MoveName = MoveName; 129 | } 130 | } 131 | 132 | private unsafe static Move ProbeForBestMove(ulong HashCodeA, ulong HashCodeB, Player.enmColour colour) 133 | { 134 | if (colour==Player.enmColour.Black) 135 | { 136 | HashCodeA |= 0x1; 137 | HashCodeB |= 0x1; 138 | } 139 | else 140 | { 141 | HashCodeA &= 0xFFFFFFFFFFFFFFFE; 142 | HashCodeB &= 0xFFFFFFFFFFFFFFFE; 143 | } 144 | 145 | Probes++; 146 | 147 | fixed (HashEntry* phashBase = &m_arrHashEntry[0]) 148 | { 149 | HashEntry* phashEntry = phashBase; 150 | phashEntry += ((uint)(HashCodeA % HASH_TABLE_SIZE)); 151 | 152 | if (phashEntry->HashCodeA == HashCodeA && phashEntry->HashCodeB == HashCodeB) 153 | { 154 | Hits++; 155 | return new Move(0, 0, phashEntry->MoveName, Board.GetPiece(phashEntry->From), Board.GetSquare(phashEntry->From), Board.GetSquare(phashEntry->To), null, 0, 0); 156 | } 157 | } 158 | return UNKNOWN; 159 | } 160 | 161 | } 162 | } 163 | -------------------------------------------------------------------------------- /SharpChess Game/Backup/xFutilityPruning.txt: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SharpChess.Backup 4 | { 5 | /// 6 | /// Summary description for FutilityPruning. 7 | /// 8 | public class FutilityPruning 9 | { 10 | // Futility Pruning 11 | bool blnEvalDone = false; 12 | int intLazyEval = 0; 13 | if (intTotalExtensions==0) 14 | { 15 | switch (depth) 16 | { 17 | case 2: 18 | case 3: 19 | case 4: 20 | if (moveThis.pieceCaptured==null && !player.IsInCheck && !move.IsEnemyInCheck) 21 | { 22 | 23 | if (!blnEvalDone) 24 | { 25 | intLazyEval = this.TotalPieceValue - this.OtherPlayer.TotalPieceValue; 26 | blnEvalDone = true; 27 | 28 | // if (Math.Abs( intLazyEval - this.Score) > 2000) 29 | // { 30 | // Console.WriteLine("too big"); 31 | // } 32 | } 33 | 34 | switch (depth) 35 | { 36 | case 2: 37 | // Standard Futility Pruning 38 | if (intLazyEval+3000<=alpha) 39 | { 40 | intExtension--; 41 | } 42 | break; 43 | 44 | case 3: 45 | // Extended Futility Pruning 46 | if (intLazyEval+6000<=alpha) 47 | { 48 | intExtension--; 49 | } 50 | break; 51 | 52 | case 4: 53 | // Razoring 54 | if (intLazyEval+9750<=alpha) 55 | { 56 | intExtension--; 57 | } 58 | break; 59 | } 60 | } 61 | break; } 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /SharpChess Game/Backup/xHashTable.txt: -------------------------------------------------------------------------------- 1 | 2 | // else 3 | // { 4 | // if ( phashEntry->Type==enmHashType.Exact ) 5 | // { 6 | // m_intHits++; 7 | // return -phashEntry->Result; 8 | // } 9 | // if ( (phashEntry->Type==enmHashType.Alpha) && (phashEntry->Result<=alpha)) 10 | // { 11 | // m_intHits++; 12 | // return alpha; 13 | // } 14 | // if ( (phashEntry->Type==enmHashType.Beta) && (phashEntry->Result>=beta)) 15 | // { 16 | // m_intHits++; 17 | // return beta; 18 | // } 19 | // } 20 | 21 | 22 | 23 | 24 | using System; 25 | 26 | namespace SharpChess 27 | { 28 | public class xHashTable 29 | { 30 | public enum HashType 31 | { 32 | Exact 33 | , Alpha 34 | , Beta 35 | } 36 | 37 | private struct HashEntry 38 | { 39 | public ulong Key; 40 | public sbyte Depth; 41 | public HashType Type; 42 | public int Result; 43 | public sbyte BestFrom; 44 | public sbyte BestTo; 45 | public Move.enmName MoveName; 46 | } 47 | 48 | public const int HASH_TABLE_SIZE = 1000007; 49 | public const int UNKNOWN = int.MinValue; 50 | static HashEntry[] m_arrHashEntry = new HashEntry[HASH_TABLE_SIZE]; 51 | private static int m_intProbes = 0; 52 | private static int m_intHits = 0; 53 | private static int m_intEntries = 0; 54 | 55 | public static int Probes 56 | { 57 | get {return m_intProbes;} 58 | } 59 | 60 | public static int Hits 61 | { 62 | get {return m_intHits;} 63 | } 64 | 65 | public static int Entries 66 | { 67 | get {return m_intEntries;} 68 | } 69 | 70 | public xHashTable() 71 | { 72 | Clear(); 73 | } 74 | 75 | public unsafe static Move BestMoveAtDepth(int depth, Player.enmColour colour) 76 | { 77 | Move moveBest = null; 78 | int intBest = int.MinValue; 79 | int intIndex=0 ; 80 | 81 | fixed (HashEntry* phashBase = &m_arrHashEntry[0]) 82 | { 83 | HashEntry* phashEntry = phashBase; 84 | 85 | if (colour==Player.enmColour.Black) 86 | { 87 | intIndex++; 88 | phashEntry++; 89 | } 90 | 91 | for (; intIndexDepth == depth && phashEntry->Key > 0 && phashEntry->Type == HashType.Exact) 94 | { 95 | if (phashEntry->Result > intBest) 96 | { 97 | intBest = phashEntry->Result; 98 | moveBest = new Move(0, 0, phashEntry->MoveName, null, Board.GetSquare(phashEntry->BestFrom), Board.GetSquare(phashEntry->BestTo), null, 0, 0); 99 | } 100 | } 101 | } 102 | } 103 | return moveBest; 104 | } 105 | 106 | public static void Clear() 107 | { 108 | ResetStats(); 109 | for (uint intIndex=0; intIndexKey == HashKey && phashEntry->Depth >= depth) 148 | { 149 | if ( phashEntry->Type == HashType.Exact ) 150 | { 151 | m_intHits++; 152 | return phashEntry->Result; 153 | } 154 | if ( phashEntry->Type == HashType.Alpha && phashEntry->Result <= alpha) 155 | { 156 | m_intHits++; 157 | return alpha; 158 | } 159 | if ( phashEntry->Type == HashType.Beta && phashEntry->Result >= beta) 160 | { 161 | m_intHits++; 162 | return beta; 163 | } 164 | } 165 | } 166 | return UNKNOWN; 167 | } 168 | 169 | public unsafe static void RecordHash(ulong HashKey, int depth, int val, HashType type, int BestFrom, int BestTo, Move.enmName MoveName, Player.enmColour colour) 170 | { 171 | if (colour==Player.enmColour.Black) 172 | { 173 | HashKey |= 0x1; 174 | } 175 | else 176 | { 177 | HashKey &= 0xFFFFFFFFFFFFFFFE; 178 | } 179 | 180 | if (depth<0) 181 | { 182 | depth=0; 183 | } 184 | 185 | fixed (HashEntry* phashBase = &m_arrHashEntry[0]) 186 | { 187 | HashEntry* phashEntry = phashBase; 188 | phashEntry += ((uint)(HashKey % HASH_TABLE_SIZE)); 189 | phashEntry->Key = HashKey; 190 | phashEntry->Result = val; 191 | phashEntry->Type = type; 192 | phashEntry->Depth = (sbyte)depth; 193 | phashEntry->BestFrom = (sbyte)BestFrom; 194 | phashEntry->BestTo = (sbyte)BestTo; 195 | phashEntry->MoveName = MoveName; 196 | } 197 | m_intEntries++; 198 | } 199 | 200 | public unsafe static Move ProbeForBestMove(ulong HashKey, Player.enmColour colour) 201 | { 202 | if (colour==Player.enmColour.Black) 203 | { 204 | HashKey |= 0x1; 205 | } 206 | else 207 | { 208 | HashKey &= 0xFFFFFFFFFFFFFFFE; 209 | } 210 | 211 | fixed (HashEntry* phashBase = &m_arrHashEntry[0]) 212 | { 213 | HashEntry* phashEntry = phashBase; 214 | phashEntry += ((uint)(HashKey % HASH_TABLE_SIZE)); 215 | 216 | if (phashEntry->Key == HashKey && phashEntry->BestFrom >= 0) 217 | { 218 | return new Move(0, 0, phashEntry->MoveName, Board.GetPiece(phashEntry->BestFrom), Board.GetSquare(phashEntry->BestFrom), Board.GetSquare(phashEntry->BestTo), null, 0, phashEntry->Result); 219 | } 220 | } 221 | return null; 222 | } 223 | 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /SharpChess Game/Backup/xQuiesce.txt: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SharpChess.Backup 4 | { 5 | /// 6 | /// Summary description for xQuiesce. 7 | /// 8 | public class xQuiesce 9 | { 10 | 11 | private int Quiesce(Player player, int alpha, int beta, Move moveFromPreviousPly, Moves movesPV_Parent) 12 | { 13 | int val = player.Score; 14 | if (val >= beta) 15 | { 16 | return beta; 17 | } 18 | if (val > alpha) 19 | { 20 | alpha = val; 21 | } 22 | 23 | Moves movesPV = new Moves(); 24 | Moves movesPossible = new Moves(); 25 | player.GenerateLazyMoves(-999, movesPossible, Moves.enmMovesType.CapturesChecksPromotions, moveFromPreviousPly); 26 | 27 | // Sort moves 28 | foreach (Move movex in movesPossible) 29 | { 30 | movex.Score = 0; 31 | 32 | switch (movex.Name) 33 | { 34 | case Move.enmName.PawnPromotionQueen: 35 | movex.Score += 975000; 36 | break; 37 | case Move.enmName.PawnPromotionRook: 38 | movex.Score += 500000; 39 | break; 40 | case Move.enmName.PawnPromotionBishop: 41 | movex.Score += 325000; 42 | break; 43 | case Move.enmName.PawnPromotionKnight: 44 | movex.Score += 325000; 45 | break; 46 | } 47 | 48 | if (movex.pieceCaptured!=null) 49 | { 50 | // movex.Score += SEE(movex)*100; 51 | movex.Score += (movex.pieceCaptured.Value*10 - movex.Piece.Value); 52 | } 53 | 54 | } 55 | movesPossible.SortByScore(); 56 | 57 | 58 | Move moveThis = null; 59 | foreach (Move move in movesPossible) 60 | { 61 | moveThis = move.Piece.Move(move.Name, move.To); 62 | if (player.IsInCheck) { Move.Undo(moveThis); continue; } 63 | 64 | if (m_blnDisplayMoveAnalysisTree) 65 | { 66 | // Add moves to post-move analysis tree, if option set by user 67 | moveFromPreviousPly.Moves.Add(moveThis); 68 | } 69 | 70 | val = -Quiesce(player.OtherPlayer, -beta, -alpha, moveThis, movesPV); 71 | 72 | Move.Undo(moveThis); 73 | 74 | if (val >= beta) 75 | { 76 | return beta; 77 | } 78 | 79 | if (val > alpha) 80 | { 81 | alpha = val; 82 | // Collect the Prinicial Variation 83 | movesPV_Parent.Clear(); 84 | movesPV_Parent.Add(moveThis); 85 | foreach (Move moveCopy in movesPV) 86 | { 87 | movesPV_Parent.Add(moveCopy); 88 | } 89 | } 90 | } 91 | 92 | return alpha; 93 | } 94 | 95 | 96 | 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /SharpChess Game/Backup/xVerifiedNullMove.txt: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SharpChess.Backup 4 | { 5 | /// 6 | /// Summary description for VerifiedNullMove. 7 | /// 8 | public class VerifiedNullMove 9 | { 10 | bool failhigh = false; 11 | 12 | // Verified Null-move forward pruning. The is also MEGA, and improved search depth from 6 plies up to 10 ! 13 | const int R = 3; 14 | if (depth>0 && !this.IsInCheck && moveAnalysed!=null && moveAnalysed.Name!=Move.enmName.NullMove && (!verify || depth > 1) ) 15 | { 16 | Move moveNull = new Move(Game.TurnNo, 0, Move.enmName.NullMove, null, null, null, null, 0, 0); 17 | val = -AlphaBeta(player.OtherPlayer, ply-1, Math.Max(depth - R - 1, 0), -beta, -beta + 1, verify, moveNull, movesPV, intTotalExtensions); 18 | if (m_blnForceImmediateMove) goto TimeExpired; 19 | if (val >= beta) 20 | { 21 | if (verify) 22 | { 23 | depth--; // reduce the depth by one ply 24 | // turn verification off for the sub-tree 25 | verify = false; 26 | // mark a fail-high flag, to detect zugzwangs later 27 | failhigh = true; 28 | } 29 | else // cutoff in a sub-tree with fail-high report 30 | { 31 | //return val; 32 | return beta; 33 | } 34 | } 35 | } 36 | 37 | ReSearch: 38 | 39 | if(failhigh && alpha < beta) 40 | { 41 | depth++; 42 | failhigh = false; 43 | verify = true; 44 | goto ReSearch; 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /SharpChess Game/Cursors/BlackBishop.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/BlackBishop.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/BlackKing.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/BlackKing.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/BlackKnight.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/BlackKnight.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/BlackPawn.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/BlackPawn.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/BlackQueen.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/BlackQueen.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/BlackRook.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/BlackRook.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/WhiteBishop.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/WhiteBishop.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/WhiteKing.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/WhiteKing.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/WhiteKnight.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/WhiteKnight.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/WhitePawn.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/WhitePawn.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/WhiteQueen.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/WhiteQueen.cur -------------------------------------------------------------------------------- /SharpChess Game/Cursors/WhiteRook.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Cursors/WhiteRook.cur -------------------------------------------------------------------------------- /SharpChess Game/Forms/frmMoveAnalysis.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | 123 | AAABAAIAICAQAAAAAADoAgAAJgAAABAQEAAAAAAAKAEAAA4DAAAoAAAAIAAAAEAAAAABAAQAAAAAAAAC 124 | AAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAgAAAgAAAAICAAIAAAACAAIAAgIAAAICAgADAwMAAAAD/AAD/ 125 | AAAA//8A/wAAAP8A/wD//wAA////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACwCwAAAA/wAAAAAAAA 126 | AAAAuwuwAAAP8AAAAAAAAAAAu7u7u7AAD/AAAAAAAAAAAAu7u7u7AA/wAAAAAAAAAAAAC7C7AAAP8AAA 127 | AAAAAAAAAAuwuwAAD/AAAAAAAAAAAAu7u7u7AA/wAAAPAAAAAAAAu7u7u7AP8AAADwAAAAAAAAC7C7AA 128 | /wAA8AAAAAAAAAAAsAsAAP8AAP8AAAAAAAAAAAAAAAD/AAAPAAAAAAAAAAAAAAAA/wAAAAAAAAAAAAAA 129 | AAAAAP8AAAAAAAAAAAAAAAAAAA/wAAAAAAAAAAAAAAAAAAAP8AAAAAAAAAAAAAAAAAAAD/AAAAAAAAAA 130 | AAAAAAAAAP8AAAAAAAAAAAAAAAAAAAD/AAAAAAAPAAAAAAAAAAAP8AAAAAAAD/AAAAAAAAAAD/AAAAAA 131 | AA//AAAAAAAAAP8AAAAAAAAA//AAAAAAAA/wAAAAAAAAAAAAAAAAAAAPAAAAAAAAAAAAAAAAAAAP8AAA 132 | AAAAAAAADwAAAAAA/wAAAAAAAAAAAAD/AAAP/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 133 | AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/4AAAP+A 134 | AAD/wAAA/8AAAP/gAAD/4AAA+fAAAMD4AACAfAAAAH4AAAA+AAAADwAAAAMAAIAAgACAAAABwAAAAcAA 135 | AAHgAAAD4AAAA/AAAAfwAAAH8AAAD/gAAA/4AAAf/AAAP/wAAH/+AAH//gAH//4Af//+GH///Hj///z9 136 | //8oAAAAEAAAACAAAAABAAQAAAAAAIAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAAAgAAAgAAAAICAAIAA 137 | AACAAIAAgIAAAICAgADAwMAAAAD/AAD/AAAA//8A/wAAAP8A/wD//wAA////AAAAAAAAAAAAAAAAAAsL 138 | AAAAAAAAu7uwAAAAAAAAsLAAAAAAAAu7uwAAAAAAALCw8A8AAAAAAADwAAAAAAAAAPAAAAAAAAAA8AAA 139 | AAAAAA8AAAAAAAAADwAAAPAAAADwAAAAAAAAAAAAAAAAAADwAAAAAAAAAAAAAAAAAAAAAAAA+AAAAPgA 140 | AAD4AAAA/AAAAI4AAAAHAAAAAwAAAICAAACAAAAAwAEAAMABAADAAwAA4AMAAOAHAADwHwAA8n8AAA== 141 | 142 | 143 | -------------------------------------------------------------------------------- /SharpChess Game/Forms/frmWinBoard.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // Summary description for Form1. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess 27 | { 28 | #region Using 29 | 30 | using System.ComponentModel; 31 | using System.Drawing; 32 | using System.Resources; 33 | using System.Windows.Forms; 34 | 35 | #endregion 36 | 37 | /// 38 | /// Summary description for Form1. 39 | /// 40 | public class frmWinBoard : Form 41 | { 42 | #region Constants and Fields 43 | 44 | /// 45 | /// Required designer variable. 46 | /// 47 | private readonly Container components = null; 48 | 49 | /// 50 | /// The col direction. 51 | /// 52 | private ColumnHeader colDirection; 53 | 54 | /// 55 | /// The col message. 56 | /// 57 | private ColumnHeader colMessage; 58 | 59 | /// 60 | /// The lvw win board. 61 | /// 62 | private ListView lvwWinBoard; 63 | 64 | #endregion 65 | 66 | #region Constructors and Destructors 67 | 68 | /// 69 | /// Initializes a new instance of the class. 70 | /// 71 | public frmWinBoard() 72 | { 73 | // Required for Windows Form Designer support 74 | this.InitializeComponent(); 75 | } 76 | 77 | #endregion 78 | 79 | #region Delegates 80 | 81 | /// 82 | /// The delegatetype win board closed. 83 | /// 84 | public delegate void delegatetypeWinBoardClosed(); 85 | 86 | #endregion 87 | 88 | #region Public Events 89 | 90 | /// 91 | /// The win board closed event. 92 | /// 93 | public event delegatetypeWinBoardClosed WinBoardClosedEvent; 94 | 95 | #endregion 96 | 97 | #region Public Methods 98 | 99 | /// 100 | /// The log win board message. 101 | /// 102 | /// 103 | /// The str direction. 104 | /// 105 | /// 106 | /// The str message. 107 | /// 108 | public void LogWinBoardMessage(string strDirection, string strMessage) 109 | { 110 | string[] lvi = { strDirection, strMessage }; 111 | this.lvwWinBoard.Items.Add(new ListViewItem(lvi)); 112 | this.lvwWinBoard.EnsureVisible(this.lvwWinBoard.Items.Count - 1); 113 | } 114 | 115 | #endregion 116 | 117 | #region Methods 118 | 119 | /// 120 | /// Clean up any resources being used. 121 | /// 122 | /// 123 | /// The disposing. 124 | /// 125 | protected override void Dispose(bool disposing) 126 | { 127 | if (disposing) 128 | { 129 | if (this.components != null) 130 | { 131 | this.components.Dispose(); 132 | } 133 | } 134 | 135 | base.Dispose(disposing); 136 | } 137 | 138 | /// 139 | /// Required method for Designer support - do not modify 140 | /// the contents of this method with the code editor. 141 | /// 142 | private void InitializeComponent() 143 | { 144 | System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmWinBoard)); 145 | this.lvwWinBoard = new System.Windows.Forms.ListView(); 146 | this.colDirection = new System.Windows.Forms.ColumnHeader(); 147 | this.colMessage = new System.Windows.Forms.ColumnHeader(); 148 | this.SuspendLayout(); 149 | // 150 | // lvwWinBoard 151 | // 152 | this.lvwWinBoard.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 153 | this.colDirection, 154 | this.colMessage}); 155 | this.lvwWinBoard.Dock = System.Windows.Forms.DockStyle.Fill; 156 | this.lvwWinBoard.FullRowSelect = true; 157 | this.lvwWinBoard.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; 158 | this.lvwWinBoard.Location = new System.Drawing.Point(0, 0); 159 | this.lvwWinBoard.Name = "lvwWinBoard"; 160 | this.lvwWinBoard.Size = new System.Drawing.Size(248, 262); 161 | this.lvwWinBoard.TabIndex = 143; 162 | this.lvwWinBoard.View = System.Windows.Forms.View.Details; 163 | // 164 | // colDirection 165 | // 166 | this.colDirection.Text = "Dir"; 167 | this.colDirection.Width = 29; 168 | // 169 | // colMessage 170 | // 171 | this.colMessage.Text = "Message"; 172 | this.colMessage.Width = 199; 173 | // 174 | // frmWinBoard 175 | // 176 | this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); 177 | this.ClientSize = new System.Drawing.Size(248, 262); 178 | this.Controls.Add(this.lvwWinBoard); 179 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; 180 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 181 | this.Name = "frmWinBoard"; 182 | this.Text = "WinBoard Message Log"; 183 | this.Closing += new System.ComponentModel.CancelEventHandler(this.frmWinBoard_Closing); 184 | this.ResumeLayout(false); 185 | } 186 | 187 | /// 188 | /// The frm win board_ closing. 189 | /// 190 | /// 191 | /// The sender. 192 | /// 193 | /// 194 | /// The e. 195 | /// 196 | private void frmWinBoard_Closing(object sender, CancelEventArgs e) 197 | { 198 | e.Cancel = true; 199 | this.Hide(); 200 | this.WinBoardClosedEvent(); 201 | } 202 | 203 | #endregion 204 | } 205 | } -------------------------------------------------------------------------------- /SharpChess Game/Images/Logo/logo.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/Logo/logo.bmp -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Bishop_Black.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Bishop_Black.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Bishop_White.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Bishop_White.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/King_Black.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/King_Black.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/King_White.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/King_White.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Knight_Black.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Knight_Black.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Knight_White.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Knight_White.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Pawn_Black.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Pawn_Black.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Pawn_White.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Pawn_White.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Queen_Black.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Queen_Black.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Queen_White.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Queen_White.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Rook_Black.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Rook_Black.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/PieceGraphics/Rook_White.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/PieceGraphics/Rook_White.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/Computer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/Computer.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/FlipBoard.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/FlipBoard.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/Knight.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/Knight.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/MoveNow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/MoveNow.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/New.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/New.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/Open.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/Open.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/Pause.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/Pause.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/Play.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/Play.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/Redo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/Redo.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/RedoAll.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/RedoAll.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/Save.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/Save.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/Undo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/Undo.gif -------------------------------------------------------------------------------- /SharpChess Game/Images/ToolbarGraphics/UndoAll.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/Images/ToolbarGraphics/UndoAll.gif -------------------------------------------------------------------------------- /SharpChess Game/Properties/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /SharpChess Game/Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SharpChess.com 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SharpChess Game/SharpChessIcon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Game/SharpChessIcon.ico -------------------------------------------------------------------------------- /SharpChess Game/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/Main.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace SharpChess_Performance_Tester 2 | { 3 | partial class Main 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Main)); 32 | this.btnStart = new System.Windows.Forms.Button(); 33 | this.txtLog = new System.Windows.Forms.TextBox(); 34 | this.btnStop = new System.Windows.Forms.Button(); 35 | this.backgroundWorker = new System.ComponentModel.BackgroundWorker(); 36 | this.txtTestTimes = new System.Windows.Forms.TextBox(); 37 | this.label2 = new System.Windows.Forms.Label(); 38 | this.label3 = new System.Windows.Forms.Label(); 39 | this.label1 = new System.Windows.Forms.Label(); 40 | this.numSearchDepth = new System.Windows.Forms.NumericUpDown(); 41 | ((System.ComponentModel.ISupportInitialize)(this.numSearchDepth)).BeginInit(); 42 | this.SuspendLayout(); 43 | // 44 | // btnStart 45 | // 46 | this.btnStart.Location = new System.Drawing.Point(427, 395); 47 | this.btnStart.Name = "btnStart"; 48 | this.btnStart.Size = new System.Drawing.Size(75, 23); 49 | this.btnStart.TabIndex = 0; 50 | this.btnStart.Text = "&Start"; 51 | this.btnStart.UseVisualStyleBackColor = true; 52 | this.btnStart.Click += new System.EventHandler(this.btnStart_Click); 53 | // 54 | // txtLog 55 | // 56 | this.txtLog.Location = new System.Drawing.Point(12, 21); 57 | this.txtLog.Multiline = true; 58 | this.txtLog.Name = "txtLog"; 59 | this.txtLog.ReadOnly = true; 60 | this.txtLog.ScrollBars = System.Windows.Forms.ScrollBars.Both; 61 | this.txtLog.Size = new System.Drawing.Size(442, 368); 62 | this.txtLog.TabIndex = 1; 63 | // 64 | // btnStop 65 | // 66 | this.btnStop.Enabled = false; 67 | this.btnStop.Location = new System.Drawing.Point(508, 395); 68 | this.btnStop.Name = "btnStop"; 69 | this.btnStop.Size = new System.Drawing.Size(75, 23); 70 | this.btnStop.TabIndex = 2; 71 | this.btnStop.Text = "Sto&p"; 72 | this.btnStop.UseVisualStyleBackColor = true; 73 | this.btnStop.Click += new System.EventHandler(this.btnStop_Click); 74 | // 75 | // txtTestTimes 76 | // 77 | this.txtTestTimes.Location = new System.Drawing.Point(470, 21); 78 | this.txtTestTimes.Multiline = true; 79 | this.txtTestTimes.Name = "txtTestTimes"; 80 | this.txtTestTimes.ReadOnly = true; 81 | this.txtTestTimes.ScrollBars = System.Windows.Forms.ScrollBars.Both; 82 | this.txtTestTimes.Size = new System.Drawing.Size(112, 368); 83 | this.txtTestTimes.TabIndex = 5; 84 | // 85 | // label2 86 | // 87 | this.label2.AutoSize = true; 88 | this.label2.Location = new System.Drawing.Point(9, 5); 89 | this.label2.Name = "label2"; 90 | this.label2.Size = new System.Drawing.Size(115, 13); 91 | this.label2.TabIndex = 6; 92 | this.label2.Text = "SharpChess Messages"; 93 | // 94 | // label3 95 | // 96 | this.label3.AutoSize = true; 97 | this.label3.Location = new System.Drawing.Point(467, 5); 98 | this.label3.Name = "label3"; 99 | this.label3.Size = new System.Drawing.Size(59, 13); 100 | this.label3.TabIndex = 7; 101 | this.label3.Text = "Test Times"; 102 | // 103 | // label1 104 | // 105 | this.label1.AutoSize = true; 106 | this.label1.Location = new System.Drawing.Point(255, 400); 107 | this.label1.Name = "label1"; 108 | this.label1.Size = new System.Drawing.Size(76, 13); 109 | this.label1.TabIndex = 8; 110 | this.label1.Text = "Search Depth:"; 111 | // 112 | // numSearchDepth 113 | // 114 | this.numSearchDepth.Location = new System.Drawing.Point(337, 398); 115 | this.numSearchDepth.Maximum = new decimal(new int[] { 116 | 32, 117 | 0, 118 | 0, 119 | 0}); 120 | this.numSearchDepth.Minimum = new decimal(new int[] { 121 | 1, 122 | 0, 123 | 0, 124 | 0}); 125 | this.numSearchDepth.Name = "numSearchDepth"; 126 | this.numSearchDepth.Size = new System.Drawing.Size(35, 20); 127 | this.numSearchDepth.TabIndex = 9; 128 | this.numSearchDepth.Value = new decimal(new int[] { 129 | 5, 130 | 0, 131 | 0, 132 | 0}); 133 | // 134 | // Main 135 | // 136 | this.AcceptButton = this.btnStart; 137 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 138 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 139 | this.ClientSize = new System.Drawing.Size(594, 430); 140 | this.Controls.Add(this.numSearchDepth); 141 | this.Controls.Add(this.label1); 142 | this.Controls.Add(this.label3); 143 | this.Controls.Add(this.label2); 144 | this.Controls.Add(this.txtTestTimes); 145 | this.Controls.Add(this.btnStop); 146 | this.Controls.Add(this.txtLog); 147 | this.Controls.Add(this.btnStart); 148 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 149 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); 150 | this.Name = "Main"; 151 | this.Text = "SharpChess Performance Tester"; 152 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Main_FormClosing); 153 | this.Load += new System.EventHandler(this.Main_Load); 154 | ((System.ComponentModel.ISupportInitialize)(this.numSearchDepth)).EndInit(); 155 | this.ResumeLayout(false); 156 | this.PerformLayout(); 157 | 158 | } 159 | 160 | #endregion 161 | 162 | private System.Windows.Forms.Button btnStart; 163 | private System.Windows.Forms.TextBox txtLog; 164 | private System.Windows.Forms.Button btnStop; 165 | private System.ComponentModel.BackgroundWorker backgroundWorker; 166 | private System.Windows.Forms.TextBox txtTestTimes; 167 | private System.Windows.Forms.Label label2; 168 | private System.Windows.Forms.Label label3; 169 | private System.Windows.Forms.Label label1; 170 | private System.Windows.Forms.NumericUpDown numSearchDepth; 171 | } 172 | } 173 | 174 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/Main.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // The main. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess_Performance_Tester 27 | { 28 | #region Using 29 | 30 | using System; 31 | using System.Windows.Forms; 32 | 33 | #endregion 34 | 35 | /// 36 | /// The main. 37 | /// 38 | public partial class Main : Form 39 | { 40 | #region Constants and Fields 41 | 42 | /// 43 | /// The test rig. 44 | /// 45 | private TestRig testRig; 46 | 47 | #endregion 48 | 49 | #region Constructors and Destructors 50 | 51 | /// 52 | /// Initializes a new instance of the class. 53 | /// 54 | public Main() 55 | { 56 | this.InitializeComponent(); 57 | } 58 | 59 | #endregion 60 | 61 | #region Delegates 62 | 63 | /// 64 | /// The delegatetype add log message. 65 | /// 66 | /// 67 | /// The message. 68 | /// 69 | public delegate void delegatetypeAddLogMessage(string Message); 70 | 71 | #endregion 72 | 73 | #region Methods 74 | 75 | /// 76 | /// The add log message. 77 | /// 78 | /// 79 | /// The message. 80 | /// 81 | private void AddLogMessage(string message) 82 | { 83 | this.txtLog.Text += message + "\r\n"; 84 | if (message.Contains("movetime ")) 85 | { 86 | this.txtTestTimes.Text += message.Substring(29) + "\r\n"; 87 | this.StopTestUI(); 88 | } 89 | } 90 | 91 | /// 92 | /// Receive messages from the test rig, and append them to the message log display. 93 | /// 94 | /// 95 | /// TestRig object 96 | /// 97 | /// 98 | /// Message 99 | /// 100 | private void HandleTestRigMessageEvent(object sender, TestRig.MessageEventArgs e) 101 | { 102 | delegatetypeAddLogMessage AddMessageLogPointer = this.AddLogMessage; 103 | this.BeginInvoke(AddMessageLogPointer, e.Message); 104 | } 105 | 106 | /// 107 | /// The main_ form closing. 108 | /// 109 | /// 110 | /// The sender. 111 | /// 112 | /// 113 | /// The e. 114 | /// 115 | private void Main_FormClosing(object sender, FormClosingEventArgs e) 116 | { 117 | if (this.btnStop.Enabled) 118 | { 119 | this.testRig.StopTest(); 120 | } 121 | } 122 | 123 | /// 124 | /// The main_ load. 125 | /// 126 | /// 127 | /// The sender. 128 | /// 129 | /// 130 | /// The e. 131 | /// 132 | private void Main_Load(object sender, EventArgs e) 133 | { 134 | // Change ths SharpChess exe path here, if you want it to be somewhere more convenient. 135 | // this.testRig = new TestRig(@"..\..\..\SharpChess Game\bin\Release\SharpChess2.exe"); 136 | 137 | this.testRig = new TestRig(@"C:\Users\zass\Documents\Visual Studio 2013\Projects\SharpChess\SharpChess Game\bin\Release\SharpChess2.exe"); 138 | 139 | //C:\Users\zass\Documents\Visual Studio 2013\Projects\SharpChess\SharpChess Game\bin\Release 140 | this.testRig.RaiseMessageEvent += this.HandleTestRigMessageEvent; 141 | this.testRig.ReportStartupMessages(); 142 | } 143 | 144 | /// 145 | /// The stop test ui. 146 | /// 147 | private void StopTestUI() 148 | { 149 | this.testRig.StopTest(); 150 | this.btnStop.Enabled = false; 151 | this.btnStart.Enabled = true; 152 | this.numSearchDepth.Focus(); 153 | } 154 | 155 | /// 156 | /// The btn start_ click. 157 | /// 158 | /// 159 | /// The sender. 160 | /// 161 | /// 162 | /// The e. 163 | /// 164 | private void btnStart_Click(object sender, EventArgs e) 165 | { 166 | this.txtLog.Clear(); 167 | this.btnStart.Enabled = false; 168 | this.btnStop.Enabled = true; 169 | this.testRig.SearchDepth = (uint)this.numSearchDepth.Value; 170 | this.testRig.StartTest(); 171 | } 172 | 173 | /// 174 | /// The btn stop_ click. 175 | /// 176 | /// 177 | /// The sender. 178 | /// 179 | /// 180 | /// The e. 181 | /// 182 | private void btnStop_Click(object sender, EventArgs e) 183 | { 184 | this.StopTestUI(); 185 | } 186 | 187 | #endregion 188 | } 189 | } -------------------------------------------------------------------------------- /SharpChess Performance Tester/Main.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 125 | 126 | AAABAAEAEBAAAAAAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAA 127 | AAD///8B////Af///wH///8B////AQAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA 128 | //8AAP//////Af///wH///8B////Af///wEAAP//AAD//wAA//8AAP//AP///wAA//8A////AAD//wAA 129 | //8AAP//AAD//////wH///8B////Af///wH///8BAAD//wAA//8AAP//AP///wD///8A////AP///wD/ 130 | //8AAP//AAD//wAA//////8B////Af///wH///8B////Af///wEAAP//AAD//wAA//8AAP//AP///wAA 131 | //8A////AAD//wAA//8AAP//////AQAA//8AAP//AAD//////wH///8B////AQAA//8AAP//AP///wD/ 132 | //8A////AP///wD///8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//////Af///wH///8BAAD//wAA 133 | //8A////AAD//wD///8AAP//////AQAA//8AAP//////AQAA//8AAP//AAD//wAA//////8B////AQAA 134 | //8AAP//AAD//wAA//8AAP//AAD//////wEAAP//////AQAA//8AAP//AAD//wAA//8AAP//AAD//wAA 135 | //////8BAAD//wAA//8AAP//AAD//wAA//////8BAAD//////wEAAP//AAD//wAA//8AAP//AAD//wAA 136 | //8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//////AQAA//////8B////AQAA//8AAP//AAD//wAA 137 | //8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//////AQAA//////8B////Af///wEAAP//AAD//wAA 138 | //8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//////wEAAP//////Af///wH///8BAAD//wAA 139 | //////8BAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//////wEAAP//////Af///wH///8B////Af// 140 | /wEAAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//////wH///8B////Af// 141 | /wH///8BAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//////wEAAP//AAD//////wH///8B////Af// 142 | /wH///8B////Af///wEAAP//AAD//wAA//8AAP//AAD//wAA//8AAP//////Af///wH///8B////Af// 143 | /wH///8B////Af///wH///8BAAD//wAA//////8BAAD//wAA//////8B////Af///wH///8B////Af// 144 | /wH///8BAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA 145 | //8AAP//AAD//w== 146 | 147 | 148 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/Program.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // The program. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess_Performance_Tester 27 | { 28 | #region Using 29 | 30 | using System; 31 | using System.Windows.Forms; 32 | 33 | #endregion 34 | 35 | /// 36 | /// The program. 37 | /// 38 | internal static class Program 39 | { 40 | #region Methods 41 | 42 | /// 43 | /// The main entry point for the application. 44 | /// 45 | [STAThread] 46 | private static void Main() 47 | { 48 | Application.EnableVisualStyles(); 49 | Application.SetCompatibleTextRenderingDefault(false); 50 | Application.Run(new Main()); 51 | } 52 | 53 | #endregion 54 | } 55 | } -------------------------------------------------------------------------------- /SharpChess Performance Tester/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // AssemblyInfo.cs 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | #region Using 27 | 28 | using System.Reflection; 29 | using System.Runtime.InteropServices; 30 | 31 | #endregion 32 | 33 | // General Information about an assembly is controlled through the following 34 | // set of attributes. Change these attribute values to modify the information 35 | // associated with an assembly. 36 | [assembly: AssemblyTitle("SharpChess Performance Tester")] 37 | [assembly: AssemblyDescription("")] 38 | [assembly: AssemblyConfiguration("")] 39 | [assembly: AssemblyCompany("Microsoft")] 40 | [assembly: AssemblyProduct("SharpChess Performance Tester")] 41 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 42 | [assembly: AssemblyTrademark("")] 43 | [assembly: AssemblyCulture("")] 44 | 45 | // Setting ComVisible to false makes the types in this assembly not visible 46 | // to COM components. If you need to access a type in this assembly from 47 | // COM, set the ComVisible attribute to true on that type. 48 | [assembly: ComVisible(false)] 49 | 50 | // The following GUID is for the ID of the typelib if this project is exposed to COM 51 | [assembly: Guid("fa564a03-b5e8-4484-b339-6117e29c2072")] 52 | 53 | // Version information for an assembly consists of the following four values: 54 | // Major Version 55 | // Minor Version 56 | // Build Number 57 | // Revision 58 | // You can specify all the values or you can default the Build and Revision Numbers 59 | // by using the '*' as shown below: 60 | // [assembly: AssemblyVersion("1.0.*")] 61 | [assembly: AssemblyVersion("1.0.0.0")] 62 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /SharpChess Performance Tester/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.239 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SharpChess_Performance_Tester.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SharpChess_Performance_Tester.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.239 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SharpChess_Performance_Tester.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SharpChess.com 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/SharpChess Performance Tester.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {18879EF5-0FAB-47C0-B07A-E7217DBC8A08} 9 | WinExe 10 | Properties 11 | SharpChess_Performance_Tester 12 | SharpChess Performance Tester 13 | v4.0 14 | Client 15 | 512 16 | 17 | 18 | x86 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | x86 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Form 51 | 52 | 53 | Main.cs 54 | 55 | 56 | 57 | 58 | 59 | Main.cs 60 | 61 | 62 | ResXFileCodeGenerator 63 | Resources.Designer.cs 64 | Designer 65 | 66 | 67 | True 68 | Resources.resx 69 | True 70 | 71 | 72 | 73 | SettingsSingleFileGenerator 74 | Settings.Designer.cs 75 | 76 | 77 | True 78 | Settings.settings 79 | True 80 | 81 | 82 | 83 | 84 | 85 | 86 | 93 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/SharpChess Performance Tester.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual C# Express 2010 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpChess Performance Tester", "SharpChess Performance Tester.csproj", "{18879EF5-0FAB-47C0-B07A-E7217DBC8A08}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|x86 = Debug|x86 9 | Release|x86 = Release|x86 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {18879EF5-0FAB-47C0-B07A-E7217DBC8A08}.Debug|x86.ActiveCfg = Debug|x86 13 | {18879EF5-0FAB-47C0-B07A-E7217DBC8A08}.Debug|x86.Build.0 = Debug|x86 14 | {18879EF5-0FAB-47C0-B07A-E7217DBC8A08}.Release|x86.ActiveCfg = Release|x86 15 | {18879EF5-0FAB-47C0-B07A-E7217DBC8A08}.Release|x86.Build.0 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/SharpChessIcon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Performance Tester/SharpChessIcon.ico -------------------------------------------------------------------------------- /SharpChess Performance Tester/SharpChessIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess Performance Tester/SharpChessIcon.png -------------------------------------------------------------------------------- /SharpChess Performance Tester/TestPosition.sharpchess: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /SharpChess Performance Tester/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /SharpChess Solution.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpChess", "SharpChess Game\SharpChess.csproj", "{F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0BDEDD50-6D5C-4D77-8A78-6080FA116D76}" 9 | ProjectSection(SolutionItems) = preProject 10 | GNU_GPL_Licence.txt = GNU_GPL_Licence.txt 11 | Local.testsettings = Local.testsettings 12 | SharpChess Game\Images\Logo\logo.bmp = SharpChess Game\Images\Logo\logo.bmp 13 | README.txt = README.txt 14 | Settings.StyleCop = Settings.StyleCop 15 | SharpChess Solution.vsmdi = SharpChess Solution.vsmdi 16 | TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings 17 | EndProjectSection 18 | EndProject 19 | Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "SharpChess Setup", "SharpChess Setup\SharpChess Setup.vdproj", "{972AC84C-F7E2-4239-80CA-17032B8EA991}" 20 | EndProject 21 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpChess.Model", "SharpChess.Model\SharpChess.Model.csproj", "{EE301A37-33A9-4B7A-BE08-D001057610CD}" 22 | EndProject 23 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpChess.Model.Tests", "SharpChess.Model.Tests\SharpChess.Model.Tests.csproj", "{7A6D5A21-2856-48C1-B602-B2F575C202F6}" 24 | EndProject 25 | Global 26 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 27 | Debug|Any CPU = Debug|Any CPU 28 | Debug|Mixed Platforms = Debug|Mixed Platforms 29 | Debug|x86 = Debug|x86 30 | Release|Any CPU = Release|Any CPU 31 | Release|Mixed Platforms = Release|Mixed Platforms 32 | Release|x86 = Release|x86 33 | EndGlobalSection 34 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 35 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 36 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Debug|Any CPU.Build.0 = Debug|Any CPU 37 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 38 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 39 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Debug|x86.ActiveCfg = Debug|Any CPU 40 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 43 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Release|Mixed Platforms.Build.0 = Release|Any CPU 44 | {F5FD2F27-6DCB-453C-B018-0AC8D4BC4109}.Release|x86.ActiveCfg = Release|Any CPU 45 | {972AC84C-F7E2-4239-80CA-17032B8EA991}.Debug|Any CPU.ActiveCfg = Debug 46 | {972AC84C-F7E2-4239-80CA-17032B8EA991}.Debug|Mixed Platforms.ActiveCfg = Debug 47 | {972AC84C-F7E2-4239-80CA-17032B8EA991}.Debug|x86.ActiveCfg = Debug 48 | {972AC84C-F7E2-4239-80CA-17032B8EA991}.Release|Any CPU.ActiveCfg = Release 49 | {972AC84C-F7E2-4239-80CA-17032B8EA991}.Release|Mixed Platforms.ActiveCfg = Release 50 | {972AC84C-F7E2-4239-80CA-17032B8EA991}.Release|x86.ActiveCfg = Release 51 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 52 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Debug|Any CPU.Build.0 = Debug|Any CPU 53 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 54 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 55 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Debug|x86.ActiveCfg = Debug|Any CPU 56 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 59 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Release|Mixed Platforms.Build.0 = Release|Any CPU 60 | {EE301A37-33A9-4B7A-BE08-D001057610CD}.Release|x86.ActiveCfg = Release|Any CPU 61 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 62 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Debug|Any CPU.Build.0 = Debug|Any CPU 63 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU 64 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU 65 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Debug|x86.ActiveCfg = Debug|Any CPU 66 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Release|Any CPU.ActiveCfg = Release|Any CPU 67 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Release|Any CPU.Build.0 = Release|Any CPU 68 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU 69 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Release|Mixed Platforms.Build.0 = Release|Any CPU 70 | {7A6D5A21-2856-48C1-B602-B2F575C202F6}.Release|x86.ActiveCfg = Release|Any CPU 71 | EndGlobalSection 72 | GlobalSection(SolutionProperties) = preSolution 73 | HideSolutionNode = FALSE 74 | EndGlobalSection 75 | GlobalSection(TestCaseManagementSettings) = postSolution 76 | CategoryFile = SharpChess Solution.vsmdi 77 | EndGlobalSection 78 | EndGlobal 79 | -------------------------------------------------------------------------------- /SharpChess Tests/SharpChess Tests/GameXTest.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // This is a test class for GameTest and is intended 7 | // to contain all GameTest Unit Tests 8 | // 9 | // -------------------------------------------------------------------------------------------------------------------- 10 | 11 | #region License 12 | 13 | // SharpChess 14 | // Copyright (C) 2012 SharpChess.com 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // This program is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | // GNU General Public License for more details. 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program. If not, see . 25 | #endregion 26 | 27 | namespace SharpChess_Tests 28 | { 29 | #region Using 30 | 31 | using System; 32 | 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | using SharpChess.Model; 36 | 37 | #endregion 38 | 39 | /// 40 | /// This is a test class for GameTest and is intended 41 | /// to contain all GameTest Unit Tests 42 | /// 43 | [TestClass] 44 | public class GameXTest 45 | { 46 | #region Public Properties 47 | 48 | /// 49 | /// Gets or sets the test context which provides 50 | /// information about and functionality for the current test run. 51 | /// 52 | public TestContext TestContext { get; set; } 53 | 54 | #endregion 55 | 56 | // You can use the following additional attributes as you write your tests: 57 | // Use ClassInitialize to run code before running the first test in the class 58 | // [ClassInitialize()] 59 | // public static void MyClassInitialize(TestContext testContext) 60 | // { 61 | // } 62 | // Use ClassCleanup to run code after all tests in a class have run 63 | // [ClassCleanup()] 64 | // public static void MyClassCleanup() 65 | // { 66 | // } 67 | // Use TestInitialize to run code before running each test 68 | // [TestInitialize()] 69 | // public void MyTestInitialize() 70 | // { 71 | // } 72 | // Use TestCleanup to run code after each test has run 73 | // [TestCleanup()] 74 | // public void MyTestCleanup() 75 | // { 76 | // } 77 | #region Public Methods 78 | 79 | /// 80 | /// A test for Move Ordering - Mid game 81 | /// 82 | [TestMethod] 83 | public void MoveOrdering_MidGame() 84 | { 85 | int positions = this.NodeCountTest("r2qk2r/ppp2ppp/2b5/4N3/1b1Pp3/8/PPP1QPPP/R1B2RK1 b k - 1 11", 5); 86 | 87 | // Assert.IsTrue(positions == 52931); Before finding pawn king hash score b-u-g. 88 | // Assert.IsTrue(positions == 94138); Before all captures in quiesence. 89 | // Assert.IsTrue(positions == 89310); Before reinstating extensions/reductions 90 | // Assert.IsTrue(positions == 58090); Dont reduce PV node. 91 | // Assert.IsTrue(positions == 58090); Before MVV/LVA if SEE returns zero. 92 | // Assert.IsTrue(positions == 54573); Before history * 100 93 | // Assert.AreEqual(49641, positions); Less nodes without PVS, but more time WTF! 94 | // Assert.AreEqual(53728, positions); Before losing capture ignored in quiescense. 95 | // Assert.AreEqual(50205, positions); Clear history and killer moves at the start of each iteration. 96 | // Assert.AreEqual(48483, positions); Add LMR, and feature enabling 97 | // Assert.IsTrue(positions == 33033 || positions == 33055); Moved reduction into own method. 98 | Assert.IsTrue(positions == 33080 || positions == 33102); 99 | } 100 | 101 | /// 102 | /// A test for Move Ordering - at the start of a game - no moves played. 103 | /// 104 | [TestMethod] 105 | public void MoveOrdering_Opening() 106 | { 107 | int positions = this.NodeCountTest(string.Empty, 5); 108 | Assert.AreEqual(11226, positions); 109 | } 110 | 111 | 112 | /// 113 | /// A test for Move Ordering - in the end game with a posible promotion 114 | /// 115 | [TestMethod] 116 | public void MoveOrdering_EndGameWithPromotion() 117 | { 118 | int positions = this.NodeCountTest("8/2R2pk1/2P5/2r5/1p6/1P2Pq2/8/2K1B3 w - - 5 44", 5); 119 | Assert.AreEqual(34579, positions); 120 | } 121 | 122 | /// 123 | /// A test to confirm that the eval (score) function hasn't unexpectedly changed. 124 | /// 125 | [TestMethod] 126 | public void ScoreEvalHasntChanged() 127 | { 128 | const string Fen = "r2qk2r/ppp2ppp/2b5/4N3/1b1Pp3/8/PPP1QPPP/R1B2RK1 b k - 1 11"; 129 | Game_Accessor.NewInternal(Fen); 130 | Game_Accessor.MaximumSearchDepth = 3; 131 | Game_Accessor.ClockFixedTimePerMove = new TimeSpan(0, 10, 0); // 10 minute max 132 | Game_Accessor.UseRandomOpeningMoves = false; 133 | Game_Accessor.PlayerToPlay.Brain.Think(); 134 | 135 | Assert.AreEqual(-141, Game.PlayerToPlay.Score); 136 | } 137 | #endregion 138 | 139 | private int NodeCountTest(string fen, int depth) 140 | { 141 | Game_Accessor.NewInternal(fen); 142 | Game_Accessor.MaximumSearchDepth = depth; 143 | Game_Accessor.ClockFixedTimePerMove = new TimeSpan(0, 10, 0); // 10 minute max 144 | Game_Accessor.UseRandomOpeningMoves = false; 145 | Game_Accessor.PlayerToPlay.Brain.Think(); 146 | // TimeSpan elpased = Game_Accessor.PlayerToPlay.Brain.ThinkingTimeElpased; 147 | return Game_Accessor.PlayerToPlay.Brain.Search.PositionsSearchedThisTurn; 148 | } 149 | } 150 | } -------------------------------------------------------------------------------- /SharpChess Tests/SharpChess Tests/HashTableCheckTest.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // This is a test class for GameTest and is intended 7 | // to contain all GameTest Unit Tests 8 | // 9 | // -------------------------------------------------------------------------------------------------------------------- 10 | 11 | #region License 12 | 13 | // SharpChess 14 | // Copyright (C) 2012 SharpChess.com 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // This program is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | // GNU General Public License for more details. 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program. If not, see . 25 | #endregion 26 | 27 | namespace SharpChess_Tests 28 | { 29 | #region Using 30 | 31 | using System; 32 | 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | using SharpChess.Model; 36 | using SharpChess.Model.AI; 37 | 38 | #endregion 39 | 40 | /// 41 | /// This is a test class for GameTest and is intended 42 | /// to contain all GameTest Unit Tests 43 | /// 44 | [TestClass] 45 | public class HashTableCheckTest 46 | { 47 | #region Public Properties 48 | 49 | /// 50 | /// Gets or sets the test context which provides 51 | /// information about and functionality for the current test run. 52 | /// 53 | public TestContext TestContext { get; set; } 54 | 55 | #endregion 56 | 57 | // You can use the following additional attributes as you write your tests: 58 | // Use ClassInitialize to run code before running the first test in the class 59 | // [ClassInitialize()] 60 | // public static void MyClassInitialize(TestContext testContext) 61 | // { 62 | // } 63 | // Use ClassCleanup to run code after all tests in a class have run 64 | // [ClassCleanup()] 65 | // public static void MyClassCleanup() 66 | // { 67 | // } 68 | // Use TestInitialize to run code before running each test 69 | // [TestInitialize()] 70 | // public void MyTestInitialize() 71 | // { 72 | // } 73 | // Use TestCleanup to run code after each test has run 74 | // [TestCleanup()] 75 | // public void MyTestCleanup() 76 | // { 77 | // } 78 | #region Public Methods 79 | 80 | /// 81 | /// A test for Move Ordering - at the start of a game - no moves played. 82 | /// 83 | [TestMethod] 84 | public void HashTableCheck_Opening() 85 | { 86 | int positions = this.NodeCountTest("", 5); 87 | int h = HashTableCheck.Hits; 88 | int o = HashTableCheck.Overwrites; 89 | int p = HashTableCheck.Probes; 90 | int w = HashTableCheck.Writes; 91 | } 92 | 93 | /// 94 | /// A test for Move Ordering - at the start of a game - no moves played. 95 | /// 96 | [TestMethod] 97 | public void HashTableCheck_Ending() 98 | { 99 | int positions = this.NodeCountTest("8/2R2pk1/2P5/2r5/1p6/1P2Pq2/8/2K1B3 w - - 5 44", 5); 100 | int h = HashTableCheck.Hits; 101 | int o = HashTableCheck.Overwrites; 102 | int p = HashTableCheck.Probes; 103 | int w = HashTableCheck.Writes; 104 | } 105 | 106 | #endregion 107 | 108 | private int NodeCountTest(string fen, int depth) 109 | { 110 | Game_Accessor.NewInternal(fen); 111 | Game_Accessor.MaximumSearchDepth = depth; 112 | Game_Accessor.ClockFixedTimePerMove = new TimeSpan(0, 10, 0); // 10 minute max 113 | Game_Accessor.UseRandomOpeningMoves = false; 114 | Game_Accessor.PlayerToPlay.Brain.Think(); 115 | // TimeSpan elpased = Game_Accessor.PlayerToPlay.Brain.ThinkingTimeElpased; 116 | return Game_Accessor.PlayerToPlay.Brain.Search.PositionsSearchedThisTurn; 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /SharpChess Tests/SharpChess Tests/MovesTest.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // Summary description for UnitTest1 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess_Tests 27 | { 28 | #region Using 29 | 30 | using Microsoft.VisualStudio.TestTools.UnitTesting; 31 | 32 | using SharpChess; 33 | using SharpChess.Model; 34 | 35 | #endregion 36 | 37 | /// 38 | /// Summary description for UnitTest1 39 | /// 40 | [TestClass] 41 | public class MovesTest 42 | { 43 | #region Public Properties 44 | 45 | /// 46 | /// Gets or sets the test context which provides 47 | /// information about and functionality for the current test run. 48 | /// 49 | public TestContext TestContext { get; set; } 50 | 51 | #endregion 52 | 53 | // You can use the following additional attributes as you write your tests: 54 | // Use ClassInitialize to run code before running the first test in the class 55 | // [ClassInitialize()] 56 | // public static void MyClassInitialize(TestContext testContext) { } 57 | // Use ClassCleanup to run code after all tests in a class have run 58 | // [ClassCleanup()] 59 | // public static void MyClassCleanup() { } 60 | // Use TestInitialize to run code before running each test 61 | // [TestInitialize()] 62 | // public void MyTestInitialize() { } 63 | // Use TestCleanup to run code after each test has run 64 | // [TestCleanup()] 65 | // public void MyTestCleanup() { } 66 | #region Public Methods 67 | 68 | /// 69 | /// Test that moves are sorted by score 70 | /// 71 | [TestMethod] 72 | public void CanSortByScore() 73 | { 74 | } 75 | 76 | /// 77 | /// A test for SortByScore. Tests that moves are sorted in descending order. 78 | /// 79 | [TestMethod] 80 | public void SortByScoreTest() 81 | { 82 | Moves moves = new Moves(); 83 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0)); 84 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3)); 85 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 1)); 86 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3)); 87 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 4)); 88 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0)); 89 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 6)); 90 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 2)); 91 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3)); 92 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 8)); 93 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 5)); 94 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 6)); 95 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 7)); 96 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 8)); 97 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0)); 98 | 99 | moves.SortByScore(); 100 | 101 | for (int i = 0; i < moves.Count - 1; i++) 102 | { 103 | Assert.IsTrue(moves[i].Score >= moves[i + 1].Score); 104 | } 105 | } 106 | 107 | #endregion 108 | } 109 | } -------------------------------------------------------------------------------- /SharpChess Tests/SharpChess Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // AssemblyInfo.cs 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | #region Using 27 | 28 | using System.Reflection; 29 | using System.Runtime.InteropServices; 30 | 31 | #endregion 32 | 33 | // General Information about an assembly is controlled through the following 34 | // set of attributes. Change these attribute values to modify the information 35 | // associated with an assembly. 36 | [assembly: AssemblyTitle("SharpChess Tests")] 37 | [assembly: AssemblyDescription("")] 38 | [assembly: AssemblyConfiguration("")] 39 | [assembly: AssemblyCompany("Microsoft")] 40 | [assembly: AssemblyProduct("SharpChess Tests")] 41 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 42 | [assembly: AssemblyTrademark("")] 43 | [assembly: AssemblyCulture("")] 44 | 45 | // Setting ComVisible to false makes the types in this assembly not visible 46 | // to COM components. If you need to access a type in this assembly from 47 | // COM, set the ComVisible attribute to true on that type. 48 | [assembly: ComVisible(false)] 49 | 50 | // The following GUID is for the ID of the typelib if this project is exposed to COM 51 | [assembly: Guid("7b3bc342-9fdc-43ec-8d72-a53699957fc3")] 52 | 53 | // Version information for an assembly consists of the following four values: 54 | // Major Version 55 | // Minor Version 56 | // Build Number 57 | // Revision 58 | // You can specify all the values or you can default the Build and Revision Numbers 59 | // by using the '*' as shown below: 60 | [assembly: AssemblyVersion("1.0.0.0")] 61 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /SharpChess Tests/SharpChess Tests/Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SharpChess.com 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SharpChess Tests/SharpChess Tests/SharpChess Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 7 | 8 | 2.0 9 | {4D01805A-A5DE-4CD2-B343-C4775B71066A} 10 | Library 11 | Properties 12 | SharpChess_Tests 13 | SharpChess Tests 14 | v4.0 15 | 512 16 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 3.5 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | False 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | {EE301A37-33A9-4B7A-BE08-D001057610CD} 68 | SharpChess.Model 69 | 70 | 71 | 72 | 79 | -------------------------------------------------------------------------------- /SharpChess Tests/SharpChess Tests/Test References/SharpChess2.accessor: -------------------------------------------------------------------------------- 1 | SharpChess.Model.dll 2 | Desktop 3 | -------------------------------------------------------------------------------- /SharpChess.Model.Tests/GameTest.cs: -------------------------------------------------------------------------------- 1 | using SharpChess.Model; 2 | using Microsoft.VisualStudio.TestTools.UnitTesting; 3 | using System; 4 | using System.Xml; 5 | 6 | namespace SharpChess.Model.Tests 7 | { 8 | 9 | 10 | /// 11 | ///This is a test class for GameTest and is intended 12 | ///to contain all GameTest Unit Tests 13 | /// 14 | [TestClass()] 15 | public class GameTest 16 | { 17 | private TestContext testContextInstance; 18 | 19 | /// 20 | ///Gets or sets the test context which provides 21 | ///information about and functionality for the current test run. 22 | /// 23 | public TestContext TestContext 24 | { 25 | get 26 | { 27 | return testContextInstance; 28 | } 29 | set 30 | { 31 | testContextInstance = value; 32 | } 33 | } 34 | 35 | #region Additional test attributes 36 | // 37 | //You can use the following additional attributes as you write your tests: 38 | // 39 | //Use ClassInitialize to run code before running the first test in the class 40 | //[ClassInitialize()] 41 | //public static void MyClassInitialize(TestContext testContext) 42 | //{ 43 | //} 44 | // 45 | //Use ClassCleanup to run code after all tests in a class have run 46 | //[ClassCleanup()] 47 | //public static void MyClassCleanup() 48 | //{ 49 | //} 50 | // 51 | //Use TestInitialize to run code before running each test 52 | //[TestInitialize()] 53 | //public void MyTestInitialize() 54 | //{ 55 | //} 56 | // 57 | //Use TestCleanup to run code after each test has run 58 | //[TestCleanup()] 59 | //public void MyTestCleanup() 60 | //{ 61 | //} 62 | // 63 | #endregion 64 | 65 | 66 | #region Public Methods 67 | 68 | /// 69 | /// A test for Move Ordering - Mid game 70 | /// 71 | [TestMethod] 72 | public void MoveOrdering_MidGame() 73 | { 74 | int positions = this.NodeCountTest("r2qk2r/ppp2ppp/2b5/4N3/1b1Pp3/8/PPP1QPPP/R1B2RK1 b k - 1 11", 5); 75 | 76 | // Assert.IsTrue(positions == 52931); Before finding pawn king hash score b-u-g. 77 | // Assert.IsTrue(positions == 94138); Before all captures in quiesence. 78 | // Assert.IsTrue(positions == 89310); Before reinstating extensions/reductions 79 | // Assert.IsTrue(positions == 58090); Dont reduce PV node. 80 | // Assert.IsTrue(positions == 58090); Before MVV/LVA if SEE returns zero. 81 | // Assert.IsTrue(positions == 54573); Before history * 100 82 | // Assert.AreEqual(49641, positions); Less nodes without PVS, but more time WTF! 83 | // Assert.AreEqual(53728, positions); Before losing capture ignored in quiescense. 84 | // Assert.AreEqual(50205, positions); Clear history and killer moves at the start of each iteration. 85 | // Assert.AreEqual(48483, positions); Add LMR, and feature enabling 86 | // Assert.IsTrue(positions == 33033 || positions == 33055); Moved reduction into own method. 87 | Assert.IsTrue(positions == 33114 || positions == 33080 || positions == 34947 || positions == 34851); 88 | } 89 | 90 | /// 91 | /// A test for Move Ordering - at the start of a game - no moves played. 92 | /// 93 | [TestMethod] 94 | public void MoveOrdering_Opening() 95 | { 96 | int positions = this.NodeCountTest(string.Empty, 5); 97 | Assert.AreEqual(11203, positions); 98 | } 99 | 100 | 101 | /// 102 | /// A test for Move Ordering - in the end game with a posible promotion 103 | /// 104 | [TestMethod] 105 | public void MoveOrdering_EndGameWithPromotion() 106 | { 107 | int positions = this.NodeCountTest("8/2R2pk1/2P5/2r5/1p6/1P2Pq2/8/2K1B3 w - - 5 44", 5); 108 | Assert.AreEqual(31690, positions); 109 | } 110 | 111 | /// 112 | /// A test to confirm that the eval (score) function hasn't unexpectedly changed. 113 | /// 114 | [TestMethod] 115 | public void ScoreEvalHasntChanged() 116 | { 117 | const string Fen = "r2qk2r/ppp2ppp/2b5/4N3/1b1Pp3/8/PPP1QPPP/R1B2RK1 b k - 1 11"; 118 | Game_Accessor.NewInternal(Fen); 119 | Game_Accessor.MaximumSearchDepth = 3; 120 | Game_Accessor.ClockFixedTimePerMove = new TimeSpan(0, 10, 0); // 10 minute max 121 | Game_Accessor.UseRandomOpeningMoves = false; 122 | Game_Accessor.PlayerToPlay.Brain.Think(); 123 | 124 | Assert.AreEqual(-441, Game.PlayerToPlay.Score); 125 | } 126 | #endregion 127 | 128 | private int NodeCountTest(string fen, int depth) 129 | { 130 | Game_Accessor.NewInternal(fen); 131 | Game_Accessor.MaximumSearchDepth = depth; 132 | Game_Accessor.ClockFixedTimePerMove = new TimeSpan(0, 10, 0); // 10 minute max 133 | Game_Accessor.UseRandomOpeningMoves = false; 134 | Game_Accessor.PlayerToPlay.Brain.Think(); 135 | // TimeSpan elpased = Game_Accessor.PlayerToPlay.Brain.ThinkingTimeElpased; 136 | return Game_Accessor.PlayerToPlay.Brain.Search.PositionsSearchedThisTurn; 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /SharpChess.Model.Tests/HashTableCheckTest.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // This is a test class for GameTest and is intended 7 | // to contain all GameTest Unit Tests 8 | // 9 | // -------------------------------------------------------------------------------------------------------------------- 10 | 11 | #region License 12 | 13 | // SharpChess 14 | // Copyright (C) 2012 SharpChess.com 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // This program is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | // GNU General Public License for more details. 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program. If not, see . 25 | #endregion 26 | 27 | namespace SharpChess.Model.Tests 28 | { 29 | #region Using 30 | 31 | using System; 32 | 33 | using Microsoft.VisualStudio.TestTools.UnitTesting; 34 | 35 | using SharpChess.Model; 36 | using SharpChess.Model.AI; 37 | 38 | #endregion 39 | 40 | /// 41 | /// This is a test class for GameTest and is intended 42 | /// to contain all GameTest Unit Tests 43 | /// 44 | [TestClass] 45 | public class HashTableCheckTest 46 | { 47 | #region Public Properties 48 | 49 | /// 50 | /// Gets or sets the test context which provides 51 | /// information about and functionality for the current test run. 52 | /// 53 | public TestContext TestContext { get; set; } 54 | 55 | #endregion 56 | 57 | // You can use the following additional attributes as you write your tests: 58 | // Use ClassInitialize to run code before running the first test in the class 59 | // [ClassInitialize()] 60 | // public static void MyClassInitialize(TestContext testContext) 61 | // { 62 | // } 63 | // Use ClassCleanup to run code after all tests in a class have run 64 | // [ClassCleanup()] 65 | // public static void MyClassCleanup() 66 | // { 67 | // } 68 | // Use TestInitialize to run code before running each test 69 | // [TestInitialize()] 70 | // public void MyTestInitialize() 71 | // { 72 | // } 73 | // Use TestCleanup to run code after each test has run 74 | // [TestCleanup()] 75 | // public void MyTestCleanup() 76 | // { 77 | // } 78 | #region Public Methods 79 | 80 | /// 81 | /// A test for Move Ordering - at the start of a game - no moves played. 82 | /// 83 | [TestMethod] 84 | public void HashTableCheck_Opening() 85 | { 86 | int positions = this.NodeCountTest("", 5); 87 | int h = HashTableCheck.Hits; 88 | int o = HashTableCheck.Overwrites; 89 | int p = HashTableCheck.Probes; 90 | int w = HashTableCheck.Writes; 91 | } 92 | 93 | /// 94 | /// A test for Move Ordering - at the start of a game - no moves played. 95 | /// 96 | [TestMethod] 97 | public void HashTableCheck_Ending() 98 | { 99 | int positions = this.NodeCountTest("8/2R2pk1/2P5/2r5/1p6/1P2Pq2/8/2K1B3 w - - 5 44", 5); 100 | int h = HashTableCheck.Hits; 101 | int o = HashTableCheck.Overwrites; 102 | int p = HashTableCheck.Probes; 103 | int w = HashTableCheck.Writes; 104 | } 105 | 106 | 107 | /// 108 | /// ECM Test 109 | /// 110 | [TestMethod] 111 | public void TimerTest() 112 | { 113 | TimeSpan t = this.NodeCountTime("r4rk1/1b3Npp/p7/1p3Q2/3P4/1B2q3/P5PP/3n1R1K b", 5); 114 | Assert.IsTrue(t.Ticks <= 53174165); 115 | // Nodes: 11,298 116 | } 117 | 118 | #endregion 119 | 120 | private int NodeCountTest(string fen, int depth) 121 | { 122 | Game_Accessor.NewInternal(fen); 123 | Game_Accessor.MaximumSearchDepth = depth; 124 | Game_Accessor.ClockFixedTimePerMove = new TimeSpan(0, 10, 0); // 10 minute max 125 | Game_Accessor.UseRandomOpeningMoves = false; 126 | Game_Accessor.PlayerToPlay.Brain.Think(); 127 | // TimeSpan elpased = Game_Accessor.PlayerToPlay.Brain.ThinkingTimeElpased; 128 | return Game_Accessor.PlayerToPlay.Brain.Search.PositionsSearchedThisTurn; 129 | } 130 | 131 | private TimeSpan NodeCountTime(string fen, int depth) 132 | { 133 | Game_Accessor.NewInternal(fen); 134 | Game_Accessor.MaximumSearchDepth = depth; 135 | Game_Accessor.ClockFixedTimePerMove = new TimeSpan(0, 10, 0); // 10 minute max 136 | Game_Accessor.UseRandomOpeningMoves = false; 137 | System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch(); 138 | s.Start(); 139 | Game_Accessor.PlayerToPlay.Brain.Think(); 140 | s.Stop(); 141 | System.Diagnostics.Debug.WriteLine("elapsted = " + s.Elapsed); 142 | return s.Elapsed; 143 | // Console.Debug("asdafsd"); 144 | // // TimeSpan elpased = Game_Accessor.PlayerToPlay.Brain.ThinkingTimeElpased; 145 | // return Game_Accessor.PlayerToPlay.Brain.Search.PositionsSearchedThisTurn; 146 | } 147 | 148 | } 149 | } -------------------------------------------------------------------------------- /SharpChess.Model.Tests/MovesTest.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // Summary description for UnitTest1 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess.Model.Tests 27 | { 28 | #region Using 29 | 30 | using Microsoft.VisualStudio.TestTools.UnitTesting; 31 | 32 | using SharpChess; 33 | using SharpChess.Model; 34 | 35 | #endregion 36 | 37 | /// 38 | /// Summary description for UnitTest1 39 | /// 40 | [TestClass] 41 | public class MovesTest 42 | { 43 | #region Public Properties 44 | 45 | /// 46 | /// Gets or sets the test context which provides 47 | /// information about and functionality for the current test run. 48 | /// 49 | public TestContext TestContext { get; set; } 50 | 51 | #endregion 52 | 53 | // You can use the following additional attributes as you write your tests: 54 | // Use ClassInitialize to run code before running the first test in the class 55 | // [ClassInitialize()] 56 | // public static void MyClassInitialize(TestContext testContext) { } 57 | // Use ClassCleanup to run code after all tests in a class have run 58 | // [ClassCleanup()] 59 | // public static void MyClassCleanup() { } 60 | // Use TestInitialize to run code before running each test 61 | // [TestInitialize()] 62 | // public void MyTestInitialize() { } 63 | // Use TestCleanup to run code after each test has run 64 | // [TestCleanup()] 65 | // public void MyTestCleanup() { } 66 | #region Public Methods 67 | 68 | /// 69 | /// Test that moves are sorted by score 70 | /// 71 | [TestMethod] 72 | public void CanSortByScore() 73 | { 74 | } 75 | 76 | /// 77 | /// A test for SortByScore. Tests that moves are sorted in descending order. 78 | /// 79 | [TestMethod] 80 | public void SortByScoreTest() 81 | { 82 | /* 83 | Moves moves = new Moves(); 84 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0)); 85 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3)); 86 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 1)); 87 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3)); 88 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 4)); 89 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0)); 90 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 6)); 91 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 2)); 92 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 3)); 93 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 8)); 94 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 5)); 95 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 6)); 96 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 7)); 97 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 8)); 98 | moves.Add(new Move(0, 0, Move.MoveNames.NullMove, null, null, null, null, 0, 0)); 99 | 100 | moves.SortByScore(); 101 | 102 | for (int i = 0; i < moves.Count - 1; i++) 103 | { 104 | Assert.IsTrue(moves[i].Score >= moves[i + 1].Score); 105 | } 106 | * */ 107 | } 108 | 109 | #endregion 110 | } 111 | } -------------------------------------------------------------------------------- /SharpChess.Model.Tests/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SharpChess.Model.Tests")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SharpChess.Model.Tests")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("6a70ccb0-b6db-43a2-80f9-18879810b7aa")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /SharpChess.Model.Tests/SharpChess.Model.Tests.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 7 | 8 | 2.0 9 | {7A6D5A21-2856-48C1-B602-B2F575C202F6} 10 | Library 11 | Properties 12 | SharpChess.Model.Tests 13 | SharpChess.Model.Tests 14 | v4.0 15 | 512 16 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 3.5 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | False 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | {EE301A37-33A9-4B7A-BE08-D001057610CD} 67 | SharpChess.Model 68 | 69 | 70 | 71 | 78 | -------------------------------------------------------------------------------- /SharpChess.Model.Tests/Test References/SharpChess.Model.accessor: -------------------------------------------------------------------------------- 1 | SharpChess.Model.dll 2 | Desktop 3 | -------------------------------------------------------------------------------- /SharpChess.Model/AI/ForceImmediateMoveException.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // The force immediate move exception. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess.Model.AI 27 | { 28 | #region Using 29 | 30 | using System; 31 | 32 | #endregion 33 | 34 | /// 35 | /// The force immediate move exception. 36 | /// 37 | public class ForceImmediateMoveException : ApplicationException 38 | { 39 | } 40 | } -------------------------------------------------------------------------------- /SharpChess.Model/AI/HashTableCheck.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // The hash table (also know as Transposition table) specifically for check positions. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess.Model.AI 27 | { 28 | /// 29 | /// The hash table (also know as Transposition table) specifically for check positions. 30 | /// 31 | public static class HashTableCheck 32 | { 33 | #region Constants and Fields 34 | 35 | /// 36 | /// The m_ hash table size. 37 | /// 38 | private static uint hashTableSize; 39 | 40 | /// 41 | /// The m_arr hash entry. 42 | /// 43 | private static HashEntry[] hashTableEntries; 44 | 45 | #endregion 46 | 47 | #region Public Properties 48 | 49 | /// 50 | /// Gets the number of hash table Hits that have occured. 51 | /// 52 | public static int Hits { get; private set; } 53 | 54 | /// 55 | /// Gets the number of hash table Overwrites that have occured. 56 | /// 57 | public static int Overwrites { get; private set; } 58 | 59 | /// 60 | /// Gets the number of hash table Probes that have occured. 61 | /// 62 | public static int Probes { get; private set; } 63 | 64 | /// 65 | /// Gets the number of hash table Writes that have occured. 66 | /// 67 | public static int Writes { get; private set; } 68 | 69 | #endregion 70 | 71 | #region Public Methods 72 | 73 | /// 74 | /// Clears all entries in the hash table. 75 | /// 76 | public static void Clear() 77 | { 78 | ResetStats(); 79 | for (uint intIndex = 0; intIndex < hashTableSize; intIndex++) 80 | { 81 | hashTableEntries[intIndex].HashCodeA = 0; 82 | hashTableEntries[intIndex].HashCodeB = 0; 83 | hashTableEntries[intIndex].IsInCheck = false; 84 | } 85 | } 86 | 87 | /// 88 | /// Initialises the HashTable. 89 | /// 90 | public static void Initialise() 91 | { 92 | hashTableSize = Game.AvailableMegaBytes * 4000; 93 | hashTableEntries = new HashEntry[hashTableSize]; 94 | Clear(); 95 | } 96 | 97 | /// 98 | /// Checks if the player is in check for the specified position, and caches the result. 99 | /// 100 | /// 101 | /// Hash Code for Board position A 102 | /// 103 | /// 104 | /// Hash Code for Board position B 105 | /// 106 | /// 107 | /// The player. 108 | /// 109 | /// 110 | /// Returns whether the player in check. 111 | /// 112 | public static unsafe bool QueryandCachePlayerInCheckStatusForPosition(ulong hashCodeA, ulong hashCodeB, Player player) 113 | { 114 | fixed (HashEntry* phashBase = &hashTableEntries[0]) 115 | { 116 | if (player.Colour == Player.PlayerColourNames.Black) 117 | { 118 | hashCodeA |= 0x1; 119 | hashCodeB |= 0x1; 120 | } 121 | else 122 | { 123 | hashCodeA &= 0xFFFFFFFFFFFFFFFE; 124 | hashCodeB &= 0xFFFFFFFFFFFFFFFE; 125 | } 126 | 127 | Probes++; 128 | 129 | HashEntry* phashEntry = phashBase; 130 | phashEntry += (uint)(hashCodeA % hashTableSize); 131 | 132 | if (phashEntry->HashCodeA != hashCodeA || phashEntry->HashCodeB != hashCodeB) 133 | { 134 | if (phashEntry->HashCodeA != 0) 135 | { 136 | Overwrites++; 137 | } 138 | 139 | phashEntry->HashCodeA = hashCodeA; 140 | phashEntry->HashCodeB = hashCodeB; 141 | phashEntry->IsInCheck = player.DetermineCheckStatus(); 142 | Writes++; 143 | } 144 | else 145 | { 146 | Hits++; 147 | } 148 | 149 | return phashEntry->IsInCheck; 150 | } 151 | } 152 | 153 | /// 154 | /// The reset stats. 155 | /// 156 | public static void ResetStats() 157 | { 158 | Probes = 0; 159 | Hits = 0; 160 | Writes = 0; 161 | Overwrites = 0; 162 | } 163 | 164 | #endregion 165 | 166 | /// 167 | /// Reset hash table stats. 168 | /// 169 | private struct HashEntry 170 | { 171 | #region Constants and Fields 172 | 173 | /// 174 | /// The hash code a. 175 | /// 176 | public ulong HashCodeA; 177 | 178 | /// 179 | /// The hash code b. 180 | /// 181 | public ulong HashCodeB; 182 | 183 | /// 184 | /// The is in check. 185 | /// 186 | public bool IsInCheck; 187 | 188 | #endregion 189 | } 190 | } 191 | } -------------------------------------------------------------------------------- /SharpChess.Model/AI/History.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // Peter Hughes 4 | // 5 | // 6 | // Represents the History Heuristic used to improve moved ordering. 7 | // http://chessprogramming.wikispaces.com/History+Heuristic 8 | // 9 | // -------------------------------------------------------------------------------------------------------------------- 10 | 11 | #region License 12 | 13 | // SharpChess 14 | // Copyright (C) 2011 Peter Hughes 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // This program is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | // GNU General Public License for more details. 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program. If not, see . 25 | #endregion 26 | 27 | namespace SharpChess.Model.AI 28 | { 29 | /// 30 | /// Represents the History Heuristic used to improve moved ordering. 31 | /// http://chessprogramming.wikispaces.com/History+Heuristic 32 | /// 33 | public static class HistoryHeuristic 34 | { 35 | #region Constants and Fields 36 | 37 | /// 38 | /// History table entries for black. 39 | /// 40 | private static readonly int[,] HistoryTableEntriesforBlack = new int[Board.SquareCount, Board.SquareCount]; 41 | 42 | /// 43 | /// History table entries for white. 44 | /// 45 | private static readonly int[,] HistoryTableEntriesforWhite = new int[Board.SquareCount, Board.SquareCount]; 46 | 47 | #endregion 48 | 49 | #region Public Methods 50 | 51 | /// 52 | /// Clear all history heuristic values. 53 | /// 54 | public static void Clear() 55 | { 56 | for (int i = 0; i < Board.SquareCount; i++) 57 | { 58 | for (int j = 0; j < Board.SquareCount; j++) 59 | { 60 | HistoryTableEntriesforWhite[i, j] = 0; 61 | HistoryTableEntriesforBlack[i, j] = 0; 62 | } 63 | } 64 | } 65 | 66 | /// 67 | /// Record a new history entry. 68 | /// 69 | /// 70 | /// The player colour. 71 | /// 72 | /// 73 | /// The From square ordinal. 74 | /// 75 | /// 76 | /// The To square ordinal. 77 | /// 78 | /// 79 | /// The history heuristic weighting value. 80 | /// 81 | public static void Record(Player.PlayerColourNames colour, int ordinalFrom, int ordinalTo, int value) 82 | { 83 | // Disable if this feature when switched off. 84 | if (!Game.EnableHistoryHeuristic) 85 | { 86 | return; 87 | } 88 | 89 | if (colour == Player.PlayerColourNames.White) 90 | { 91 | HistoryTableEntriesforWhite[ordinalFrom, ordinalTo] += value; 92 | } 93 | else 94 | { 95 | HistoryTableEntriesforBlack[ordinalFrom, ordinalTo] += value; 96 | } 97 | } 98 | 99 | /// 100 | /// Retrieve a value from the History Heuristic table. 101 | /// 102 | /// 103 | /// The player colour. 104 | /// 105 | /// 106 | /// The From square ordinal. 107 | /// 108 | /// 109 | /// The To square ordinal. 110 | /// 111 | /// 112 | /// The history heuristic weighting value. 113 | /// 114 | public static int Retrieve(Player.PlayerColourNames colour, int ordinalFrom, int ordinalTo) 115 | { 116 | return colour == Player.PlayerColourNames.White ? HistoryTableEntriesforWhite[ordinalFrom, ordinalTo] : HistoryTableEntriesforBlack[ordinalFrom, ordinalTo]; 117 | } 118 | 119 | #endregion 120 | } 121 | } -------------------------------------------------------------------------------- /SharpChess.Model/AI/HistoryHeuristic.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // Represents the History Heuristic used to improve moved ordering. 7 | // http://chessprogramming.wikispaces.com/History+Heuristic 8 | // 9 | // -------------------------------------------------------------------------------------------------------------------- 10 | 11 | #region License 12 | 13 | // SharpChess 14 | // Copyright (C) 2012 SharpChess.com 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // This program is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | // GNU General Public License for more details. 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program. If not, see . 25 | #endregion 26 | 27 | namespace SharpChess.Model.AI 28 | { 29 | /// 30 | /// Represents the History Heuristic used to improve moved ordering. 31 | /// http://chessprogramming.wikispaces.com/History+Heuristic 32 | /// 33 | public static class HistoryHeuristic 34 | { 35 | #region Constants and Fields 36 | 37 | /// 38 | /// History table entries for black. 39 | /// 40 | private static readonly int[,] HistoryTableEntriesforBlack = new int[Board.SquareCount, Board.SquareCount]; 41 | 42 | /// 43 | /// History table entries for white. 44 | /// 45 | private static readonly int[,] HistoryTableEntriesforWhite = new int[Board.SquareCount, Board.SquareCount]; 46 | 47 | #endregion 48 | 49 | #region Public Methods 50 | 51 | /// 52 | /// Clear all history heuristic values. 53 | /// 54 | public static void Clear() 55 | { 56 | for (int i = 0; i < Board.SquareCount; i++) 57 | { 58 | for (int j = 0; j < Board.SquareCount; j++) 59 | { 60 | HistoryTableEntriesforWhite[i, j] = 0; 61 | HistoryTableEntriesforBlack[i, j] = 0; 62 | } 63 | } 64 | } 65 | 66 | /// 67 | /// Record a new history entry. 68 | /// 69 | /// 70 | /// The player colour. 71 | /// 72 | /// 73 | /// The From square ordinal. 74 | /// 75 | /// 76 | /// The To square ordinal. 77 | /// 78 | /// 79 | /// The history heuristic weighting value. 80 | /// 81 | public static void Record(Player.PlayerColourNames colour, int ordinalFrom, int ordinalTo, int value) 82 | { 83 | // Disable if this feature when switched off. 84 | if (!Game.EnableHistoryHeuristic) 85 | { 86 | return; 87 | } 88 | 89 | if (colour == Player.PlayerColourNames.White) 90 | { 91 | HistoryTableEntriesforWhite[ordinalFrom, ordinalTo] += value; 92 | } 93 | else 94 | { 95 | HistoryTableEntriesforBlack[ordinalFrom, ordinalTo] += value; 96 | } 97 | } 98 | 99 | /// 100 | /// Retrieve a value from the History Heuristic table. 101 | /// 102 | /// 103 | /// The player colour. 104 | /// 105 | /// 106 | /// The From square ordinal. 107 | /// 108 | /// 109 | /// The To square ordinal. 110 | /// 111 | /// 112 | /// The history heuristic weighting value. 113 | /// 114 | public static int Retrieve(Player.PlayerColourNames colour, int ordinalFrom, int ordinalTo) 115 | { 116 | return colour == Player.PlayerColourNames.White ? HistoryTableEntriesforWhite[ordinalFrom, ordinalTo] : HistoryTableEntriesforBlack[ordinalFrom, ordinalTo]; 117 | } 118 | 119 | #endregion 120 | } 121 | } -------------------------------------------------------------------------------- /SharpChess.Model/AI/KillerMoves.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // Represents the Killer Heuristic used to improve move ordering. 7 | // http://chessprogramming.wikispaces.com/Killer+Heuristic 8 | // 9 | // -------------------------------------------------------------------------------------------------------------------- 10 | 11 | #region License 12 | 13 | // SharpChess 14 | // Copyright (C) 2012 SharpChess.com 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // This program is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | // GNU General Public License for more details. 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program. If not, see . 25 | #endregion 26 | 27 | namespace SharpChess.Model.AI 28 | { 29 | /// 30 | /// Represents the Killer Heuristic used to improve move ordering. 31 | /// http://chessprogramming.wikispaces.com/Killer+Heuristic 32 | /// 33 | public static class KillerMoves 34 | { 35 | #region Constants and Fields 36 | 37 | /// 38 | /// List of primary (A) Killer Moves indexed by search depth. 39 | /// 40 | private static readonly Move[] PrimaryKillerMovesA = new Move[64]; 41 | 42 | /// 43 | /// List of secondary (B) Killer Moves indexed by search depth. 44 | /// 45 | private static readonly Move[] SecondaryKillerMovesB = new Move[64]; 46 | 47 | #endregion 48 | 49 | #region Constructors and Destructors 50 | 51 | /// 52 | /// Initializes static members of the class. 53 | /// 54 | static KillerMoves() 55 | { 56 | Clear(); 57 | } 58 | 59 | #endregion 60 | 61 | #region Public Methods 62 | 63 | /// 64 | /// The clear. 65 | /// 66 | public static void Clear() 67 | { 68 | for (int intIndex = 0; intIndex < 64; intIndex++) 69 | { 70 | PrimaryKillerMovesA[intIndex] = null; 71 | SecondaryKillerMovesB[intIndex] = null; 72 | } 73 | } 74 | 75 | /// 76 | /// Adds the move made to the appropriate killer move slot, if it's better than the current killer moves 77 | /// 78 | /// 79 | /// Search depth 80 | /// 81 | /// 82 | /// Move to be added 83 | /// 84 | public static void RecordPossibleKillerMove(int ply, Move moveMade) 85 | { 86 | // Disable if this feature when switched off. 87 | if (!Game.EnableKillerMoves) 88 | { 89 | return; 90 | } 91 | 92 | bool blnAssignedA = false; // Have we assign Slot A? 93 | 94 | Move moveKillerA = RetrieveA(ply); 95 | Move moveKillerB = RetrieveB(ply); 96 | 97 | if (moveKillerA == null) 98 | { 99 | // Slot A is blank, so put anything in it. 100 | AssignA(ply, moveMade); 101 | blnAssignedA = true; 102 | } 103 | else if ((moveMade.Score > moveKillerA.Score && !Move.MovesMatch(moveMade, moveKillerB)) || Move.MovesMatch(moveMade, moveKillerA)) 104 | { 105 | // Move's score is better than A and isn't B, or the move IS A, 106 | blnAssignedA = true; 107 | if (Move.MovesMatch(moveMade, moveKillerA)) 108 | { 109 | // Re-record move in Slot A, but only if it's better 110 | if (moveMade.Score > moveKillerA.Score) 111 | { 112 | AssignA(ply, moveMade); 113 | } 114 | } 115 | else 116 | { 117 | // Score is better than Slot A 118 | 119 | // transfer move in Slot A to Slot B... 120 | AssignB(ply, moveKillerA); 121 | 122 | // record move is Slot A 123 | AssignA(ply, moveMade); 124 | } 125 | 126 | moveKillerA = RetrieveA(ply); 127 | } 128 | 129 | // If the move wasn't assigned to Slot A, then see if it is good enough to go in Slot B, or if move IS B 130 | if (!blnAssignedA) 131 | { 132 | // Slot B is empty, so put anything in! 133 | if (moveKillerB == null) 134 | { 135 | AssignB(ply, moveMade); 136 | } 137 | else if (moveMade.Score > moveKillerB.Score) 138 | { 139 | // Score is better than Slot B, so 140 | // record move is Slot B 141 | AssignB(ply, moveMade); 142 | } 143 | 144 | moveKillerB = RetrieveB(ply); 145 | } 146 | 147 | // Finally check if B score is better than and A score, and if so swap. 148 | if (moveKillerA != null && moveKillerB != null && moveKillerB.Score > moveKillerA.Score) 149 | { 150 | Move swap = moveKillerA; 151 | AssignA(ply, moveKillerB); 152 | AssignB(ply, swap); 153 | } 154 | } 155 | 156 | /// 157 | /// Retrieve primary (A) killer move for specified search depth. 158 | /// 159 | /// 160 | /// Search depth (ply). 161 | /// 162 | /// 163 | /// Move for specified depth 164 | /// 165 | public static Move RetrieveA(int depth) 166 | { 167 | return PrimaryKillerMovesA[depth + 32]; 168 | } 169 | 170 | /// 171 | /// Retrieve secondary (B) killer move for specified search depth. 172 | /// 173 | /// 174 | /// Search depth (ply). 175 | /// 176 | /// 177 | /// Move for specified depth 178 | /// 179 | public static Move RetrieveB(int depth) 180 | { 181 | return SecondaryKillerMovesB[depth + 32]; 182 | } 183 | 184 | #endregion 185 | 186 | #region Methods 187 | 188 | /// 189 | /// Assign killer move A (primary) 190 | /// 191 | /// 192 | /// The search depth (ply). 193 | /// 194 | /// 195 | /// The move to assign. 196 | /// 197 | private static void AssignA(int depth, Move move) 198 | { 199 | PrimaryKillerMovesA[depth + 32] = move; 200 | } 201 | 202 | /// 203 | /// Assign killer move B (secondary) 204 | /// 205 | /// 206 | /// The search depth (ply). 207 | /// 208 | /// 209 | /// The move to assign. 210 | /// 211 | private static void AssignB(int depth, Move move) 212 | { 213 | SecondaryKillerMovesB[depth + 32] = move; 214 | } 215 | 216 | #endregion 217 | } 218 | } -------------------------------------------------------------------------------- /SharpChess.Model/FEN.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/SharpChess.Model/FEN.cs -------------------------------------------------------------------------------- /SharpChess.Model/IPieceTop.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // IPieceTop interface. The Piece class represents the base of a chess piece, on which different "tops" can be placed. 7 | // The Top of a piece will change when a piece is promoted. e.g. a Pawn is promoted to a Queen, or a Knight. 8 | // 9 | // -------------------------------------------------------------------------------------------------------------------- 10 | 11 | #region License 12 | 13 | // SharpChess 14 | // Copyright (C) 2012 SharpChess.com 15 | // This program is free software: you can redistribute it and/or modify 16 | // it under the terms of the GNU General Public License as published by 17 | // the Free Software Foundation, either version 3 of the License, or 18 | // (at your option) any later version. 19 | // This program is distributed in the hope that it will be useful, 20 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | // GNU General Public License for more details. 23 | // You should have received a copy of the GNU General Public License 24 | // along with this program. If not, see . 25 | #endregion 26 | 27 | namespace SharpChess.Model 28 | { 29 | /// 30 | /// IPieceTop interface. The class represents the base of a chess piece, on which different "tops" can be placed. 31 | /// The Top of a piece will change when a piece is promoted. e.g. a Pawn is promoted to a Queen, or a Knight. 32 | /// 33 | public interface IPieceTop 34 | { 35 | #region Public Properties 36 | 37 | /// 38 | /// Gets the Abbreviated name for the piece. 39 | /// 40 | string Abbreviation { get; } 41 | 42 | /// 43 | /// Gets the base . 44 | /// 45 | Piece Base { get; } 46 | 47 | /// 48 | /// Gets the BasicValue for this piece. e.g. 9 for Queen, 1 for a Pawn. 49 | /// 50 | int BasicValue { get; } 51 | 52 | /// 53 | /// Gets ImageIndex for the piece. 54 | /// 55 | int ImageIndex { get; } 56 | 57 | /// 58 | /// Gets a value indicating whether the piece can be captured. 59 | /// 60 | bool IsCapturable { get; } 61 | 62 | /// 63 | /// Gets the name of the piece. 64 | /// 65 | Piece.PieceNames Name { get; } 66 | 67 | /// 68 | /// Gets the positional score points of the piece. 69 | /// 70 | int PositionalPoints { get; } 71 | 72 | /// 73 | /// Gets the base score value for the piece e.g. 9000 for Queen, 1000 for a Pawn. 74 | /// 75 | int Value { get; } 76 | 77 | #endregion 78 | 79 | #region Public Methods 80 | 81 | /// 82 | /// The generate lazy moves. 83 | /// 84 | /// 85 | /// The moves. 86 | /// 87 | /// 88 | /// The moves type. 89 | /// 90 | void GenerateLazyMoves(Moves moves, Moves.MoveListNames movesType); 91 | 92 | bool CanAttackSquare(Square square); 93 | 94 | #endregion 95 | } 96 | } -------------------------------------------------------------------------------- /SharpChess.Model/Pieces.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // A list of pieces. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess.Model 27 | { 28 | #region Using 29 | 30 | using System.Collections; 31 | 32 | #endregion 33 | 34 | /// 35 | /// A list of pieces. 36 | /// 37 | public class Pieces : IEnumerable 38 | { 39 | #region Constants and Fields 40 | 41 | /// 42 | /// Internal ArrayList of pieces. 43 | /// 44 | private readonly ArrayList pieces = new ArrayList(); 45 | private static PieceSort sorter = new PieceSort(); 46 | 47 | #endregion 48 | 49 | #region Public Properties 50 | 51 | /// 52 | /// Gets Count. 53 | /// 54 | public int Count 55 | { 56 | get 57 | { 58 | return this.pieces.Count; 59 | } 60 | } 61 | 62 | #endregion 63 | 64 | #region Public Methods 65 | 66 | /// 67 | /// The add. 68 | /// 69 | /// 70 | /// The piece. 71 | /// 72 | public void Add(Piece piece) 73 | { 74 | this.pieces.Add(piece); 75 | } 76 | 77 | /// 78 | /// Return a close of this list. 79 | /// 80 | /// 81 | /// The clone. 82 | /// 83 | public object Clone() 84 | { 85 | return this.pieces.Clone(); 86 | } 87 | 88 | /// 89 | /// Get the enumerator for this list. 90 | /// 91 | /// 92 | /// The enumerator. 93 | /// 94 | public IEnumerator GetEnumerator() 95 | { 96 | return this.pieces.GetEnumerator(); 97 | } 98 | 99 | /// 100 | /// Searches for the specified piece and returns its index. 101 | /// 102 | /// 103 | /// The piece to search for. 104 | /// 105 | /// 106 | /// Index value of the found piece. or null if not found. 107 | /// 108 | public int IndexOf(Piece piece) 109 | { 110 | return this.pieces.IndexOf(piece); 111 | } 112 | 113 | /// 114 | /// Insert a piece into the list. at the specified index position. 115 | /// 116 | /// 117 | /// The ordinal index position where the piece will be inserted. 118 | /// 119 | /// 120 | /// The piece. 121 | /// 122 | public void Insert(int ordinal, Piece piece) 123 | { 124 | this.pieces.Insert(ordinal, piece); 125 | } 126 | 127 | /// 128 | /// Returns the piece at the specified index position in the list. 129 | /// 130 | /// 131 | /// Index position. 132 | /// 133 | /// 134 | /// The piece at the specified index. 135 | /// 136 | public Piece Item(int intIndex) 137 | { 138 | return (Piece)this.pieces[intIndex]; 139 | } 140 | 141 | /// 142 | /// Remove the piece from the list. 143 | /// 144 | /// 145 | /// The piece to remove. 146 | /// 147 | public void Remove(Piece piece) 148 | { 149 | this.pieces.Remove(piece); 150 | } 151 | 152 | /// 153 | /// The sort the pieces by their score value. 154 | /// 155 | public void SortByScore() 156 | { 157 | this.pieces.Sort(sorter); 158 | } 159 | 160 | #endregion 161 | } 162 | 163 | public class PieceSort : System.Collections.IComparer 164 | { 165 | public int Compare(System.Object a, System.Object b) 166 | { 167 | if (b == null) 168 | return 1; 169 | Piece x = (Piece)a; 170 | Piece y = (Piece)b; 171 | if (x.Value > y.Value) 172 | return 1; 173 | else if (x.Value < y.Value) 174 | return -1; 175 | else if (x.Value == y.Value) 176 | { 177 | if (y.Name == Piece.PieceNames.Knight) // bishops beat knights 178 | return 1; 179 | else 180 | return -1; 181 | } 182 | return 1; 183 | } 184 | } 185 | } -------------------------------------------------------------------------------- /SharpChess.Model/PlayerBlack.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // The player black. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess.Model 27 | { 28 | /// 29 | /// The player black. 30 | /// 31 | public class PlayerBlack : Player 32 | { 33 | #region Constructors and Destructors 34 | 35 | /// 36 | /// Initializes a new instance of the class. 37 | /// 38 | public PlayerBlack() 39 | { 40 | this.Colour = PlayerColourNames.Black; 41 | this.Intellegence = PlayerIntellegenceNames.Computer; 42 | 43 | this.SetPiecesAtStartingPositions(); 44 | } 45 | 46 | #endregion 47 | 48 | #region Public Properties 49 | 50 | /// 51 | /// Gets PawnAttackLeftOffset. 52 | /// 53 | public override int PawnAttackLeftOffset 54 | { 55 | get 56 | { 57 | return -17; 58 | } 59 | } 60 | 61 | /// 62 | /// Gets PawnAttackRightOffset. 63 | /// 64 | public override int PawnAttackRightOffset 65 | { 66 | get 67 | { 68 | return -15; 69 | } 70 | } 71 | 72 | /// 73 | /// Gets PawnForwardOffset. 74 | /// 75 | public override int PawnForwardOffset 76 | { 77 | get 78 | { 79 | return -16; 80 | } 81 | } 82 | 83 | #endregion 84 | 85 | #region Methods 86 | 87 | /// 88 | /// The set pieces at starting positions. 89 | /// 90 | protected override sealed void SetPiecesAtStartingPositions() 91 | { 92 | this.Pieces.Add(this.King = new Piece(Piece.PieceNames.King, this, 4, 7, Piece.PieceIdentifierCodes.BlackKing)); 93 | 94 | this.Pieces.Add(new Piece(Piece.PieceNames.Queen, this, 3, 7, Piece.PieceIdentifierCodes.BlackQueen)); 95 | 96 | this.Pieces.Add(new Piece(Piece.PieceNames.Rook, this, 0, 7, Piece.PieceIdentifierCodes.BlackQueensRook)); 97 | this.Pieces.Add(new Piece(Piece.PieceNames.Rook, this, 7, 7, Piece.PieceIdentifierCodes.BlackKingsRook)); 98 | 99 | this.Pieces.Add(new Piece(Piece.PieceNames.Bishop, this, 2, 7, Piece.PieceIdentifierCodes.BlackQueensBishop)); 100 | this.Pieces.Add(new Piece(Piece.PieceNames.Bishop, this, 5, 7, Piece.PieceIdentifierCodes.BlackKingsBishop)); 101 | 102 | this.Pieces.Add(new Piece(Piece.PieceNames.Knight, this, 1, 7, Piece.PieceIdentifierCodes.BlackQueensKnight)); 103 | this.Pieces.Add(new Piece(Piece.PieceNames.Knight, this, 6, 7, Piece.PieceIdentifierCodes.BlackKingsKnight)); 104 | 105 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 0, 6, Piece.PieceIdentifierCodes.BlackPawn1)); 106 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 1, 6, Piece.PieceIdentifierCodes.BlackPawn2)); 107 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 2, 6, Piece.PieceIdentifierCodes.BlackPawn3)); 108 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 3, 6, Piece.PieceIdentifierCodes.BlackPawn4)); 109 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 4, 6, Piece.PieceIdentifierCodes.BlackPawn5)); 110 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 5, 6, Piece.PieceIdentifierCodes.BlackPawn6)); 111 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 6, 6, Piece.PieceIdentifierCodes.BlackPawn7)); 112 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 7, 6, Piece.PieceIdentifierCodes.BlackPawn8)); 113 | } 114 | 115 | #endregion 116 | } 117 | } -------------------------------------------------------------------------------- /SharpChess.Model/PlayerClock.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // Player chess clock. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess.Model 27 | { 28 | #region Using 29 | 30 | using System; 31 | 32 | #endregion 33 | 34 | /// 35 | /// Player chess clock. 36 | /// 37 | public class PlayerClock 38 | { 39 | #region Constants and Fields 40 | 41 | #endregion 42 | 43 | #region Constructors and Destructors 44 | 45 | /// 46 | /// Initializes a new instance of the class. 47 | /// 48 | public PlayerClock() 49 | { 50 | this.Reset(); 51 | } 52 | 53 | #endregion 54 | 55 | #region Public Properties 56 | 57 | /// 58 | /// Gets a value that is used to automatically reset the "number of moves remaining" back to "Clock Max Moves", 59 | /// when the number of player moves exceeds "ClockMaxMoves". e.g. The clock is set at 120 moves in 60 minutes. 60 | /// At the beginning of the game we're in Control Period 1. If the player gets to move 121 then we move into Control Period 2. 61 | /// So the Control Period increments by 1, every 120 moves, effectively allowing play to continue, and the clock to 62 | /// continue functioning. 63 | /// 64 | public int ControlPeriod 65 | { 66 | get 67 | { 68 | return Game.ClockMaxMoves == 0 ? 1 : (Game.MoveNo / Game.ClockMaxMoves) + 1; 69 | } 70 | } 71 | 72 | /// 73 | /// Gets a value indicating whether the player's clock is ticking. 74 | /// A player's clock ticks during their turn, and and is suspended during their opponent's turn. 75 | /// 76 | public bool IsTicking { get; private set; } 77 | 78 | /// 79 | /// Gets the number of move that the player has remaining, when the clock has a move limit e.g. 120 moves in 60 minutes. 80 | /// When the remaining moves run out, then it is automatically re-extended (see ControlPeriod). 81 | /// 82 | public int MovesRemaining 83 | { 84 | get 85 | { 86 | // N-o-t-e the remaining moves count is auto-extended by the Control Period. 87 | int remainingMoves = Game.ClockMaxMoves * this.ControlPeriod; 88 | return Math.Max(remainingMoves - Game.MoveNo, 0); 89 | } 90 | } 91 | 92 | /// 93 | /// Gets or sets the players elapsed turn time. The clock ticks during the player's turn and is suspended during the opponents turn. 94 | /// 95 | public TimeSpan TimeElapsed { get; set; } 96 | 97 | /// 98 | /// Gets the clock's elapsed time suitable for textual display. 99 | /// 100 | public TimeSpan TimeElapsedDisplay 101 | { 102 | get 103 | { 104 | return this.IsTicking 105 | ? this.TimeElapsed + (DateTime.Now - this.TurnStartTime) 106 | : this.TimeElapsed; 107 | } 108 | } 109 | 110 | /// 111 | /// Gets player's remaining game time. 112 | /// 113 | public TimeSpan TimeRemaining 114 | { 115 | get 116 | { 117 | TimeSpan tsnRepeatingTimeLimit = 118 | new TimeSpan( 119 | (Game.ClockTime.Ticks * this.ControlPeriod) + (Game.ClockIncrementPerMove.Ticks * Game.MoveNo)); 120 | return tsnRepeatingTimeLimit - this.TimeElapsed; 121 | } 122 | } 123 | 124 | /// 125 | /// Gets the time when the current turn started. 126 | /// 127 | public DateTime TurnStartTime { get; private set; } 128 | 129 | #endregion 130 | 131 | #region Public Methods 132 | 133 | /// 134 | /// The resets the clock back to zero. 135 | /// 136 | public void Reset() 137 | { 138 | this.TimeElapsed = new TimeSpan(0, 0, 0); 139 | this.TurnStartTime = DateTime.Now; 140 | } 141 | 142 | /// 143 | /// Stop the clock and reset the turn start time. 144 | /// 145 | public void Revert() 146 | { 147 | this.IsTicking = false; 148 | this.TurnStartTime = DateTime.Now; 149 | } 150 | 151 | /// 152 | /// Start the clock. 153 | /// 154 | public void Start() 155 | { 156 | if (!this.IsTicking) 157 | { 158 | this.IsTicking = true; 159 | this.TurnStartTime = DateTime.Now; 160 | } 161 | } 162 | 163 | /// 164 | /// Stop the clock. 165 | /// 166 | public void Stop() 167 | { 168 | if (this.IsTicking) 169 | { 170 | this.IsTicking = false; 171 | this.TimeElapsed += DateTime.Now - this.TurnStartTime; 172 | } 173 | } 174 | 175 | #endregion 176 | } 177 | } -------------------------------------------------------------------------------- /SharpChess.Model/PlayerDebug.cs: -------------------------------------------------------------------------------- 1 | #region License 2 | 3 | // SharpChess 4 | // Copyright (C) 2011 Peter Hughes 5 | // 6 | // This program is free software: you can redistribute it and/or modify 7 | // it under the terms of the GNU General Public License as published by 8 | // the Free Software Foundation, either version 3 of the License, or 9 | // (at your option) any later version. 10 | // 11 | // This program is distributed in the hope that it will be useful, 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | // GNU General Public License for more details. 15 | // 16 | // You should have received a copy of the GNU General Public License 17 | // along with this program. If not, see . 18 | 19 | #endregion 20 | 21 | namespace SharpChess.Model 22 | { 23 | #region Using 24 | 25 | using System; 26 | using System.Diagnostics; 27 | using System.Text; 28 | 29 | #endregion 30 | 31 | /// 32 | /// Debug helper methods for the player class. 33 | /// 34 | public static class PlayerDebug 35 | { 36 | #region Constants and Fields 37 | 38 | /// 39 | /// Internal buffer to convert the PV to a string 40 | /// 41 | private static readonly StringBuilder m_strbPV = new StringBuilder(50); 42 | 43 | /// 44 | /// Number of iteration of AlphaBeta at the top level 45 | /// 46 | private static int m_iDbgIteration; 47 | 48 | /// 49 | /// Level of depth of the variation 50 | /// 51 | private static int m_iDbgLevel; 52 | 53 | /// 54 | /// Unambiguous descriptive variation after conversion of the PGN variation 55 | /// 56 | private static string m_strDbgLine = string.Empty; 57 | 58 | #endregion 59 | 60 | #region Methods 61 | 62 | /// 63 | /// Does the current position match the specified variation? 64 | /// 65 | /// the iteration and the variation. Ex: "5 Rb4b5 Pf4f5 Pe5f6" 66 | /// number positive or 0 of halfmove. Do not confuse with iDepth 67 | /// the current move at the beginning of the research 68 | /// Search depth. 69 | /// Max search depth. 70 | /// true if the variation is recognized otherwise false 71 | /// 72 | /// Must be called after moveThis.DoMove() in AlphaBeta 73 | /// 74 | private static bool DebugMatchLine( 75 | string strVariation, int iPly, Move moveThis, int intSearchDepth, int intMaxSearchDepth) 76 | { 77 | const int iSAN_LENGTH = 5; // Length of Abbreviation of the piece + From square + To square 78 | if (m_iDbgLevel == iPly) 79 | { 80 | // Is the level of depth of the variation reached? 81 | if (m_strDbgLine.Length == 0) 82 | { 83 | // Interpret dynamically the variation 84 | // In PlayerDebug version, strVariation contains unambiguous descriptive moves 85 | int indPos = 0; // Evaluate the number of iteration and parse the variation 86 | while (char.IsNumber(strVariation[indPos])) 87 | { 88 | indPos++; 89 | } 90 | 91 | m_iDbgIteration = Convert.ToInt32(strVariation.Substring(0, indPos)); 92 | m_strDbgLine = strVariation.Substring(indPos); // Parse the variation 93 | m_strDbgLine = m_strDbgLine.Replace(" ", string.Empty); // removing all whitespaces 94 | m_strDbgLine = m_strDbgLine.Replace("x", string.Empty); // removing all "x" 95 | } 96 | 97 | if (intSearchDepth == m_iDbgIteration) 98 | { 99 | // Number of iteration of AlphaBeta at the top level 100 | int indPiece = iPly * iSAN_LENGTH; // Index where begins the notation of the move 101 | int iLenVar = m_strDbgLine.Length; 102 | string strMoveDescr = moveThis.Piece.Abbreviation + moveThis.From.Name + moveThis.To.Name; 103 | if ((indPiece <= iLenVar - iSAN_LENGTH) 104 | && (strMoveDescr == m_strDbgLine.Substring(indPiece, iSAN_LENGTH))) 105 | { 106 | if (++m_iDbgLevel == iLenVar / iSAN_LENGTH) 107 | { 108 | // Number of moves in the variation 109 | m_iDbgLevel = intMaxSearchDepth + 1; // Do not recall PlayerDebug utility 110 | BoardDebug.DebugDisplay(); // Display the current position in the "Output Window" 111 | Debug.WriteLine("\nPosition after: " + strVariation); 112 | return true; // The current position matches the wished variation 113 | } 114 | } 115 | } 116 | } 117 | 118 | return false; 119 | } 120 | 121 | /// 122 | /// Break on the variation at the given iteration 123 | /// 124 | /// the positive or null ply of halfmove. Don't confuse with iDepth 125 | /// the current move 126 | /// Search depth. 127 | /// Max search depth. 128 | /// true if the position is reached otherwise false 129 | private static bool DebugMatchVariation(int iPly, Move moveThis, int intSearchDepth, int intMaxSearchDepth) 130 | { 131 | // Syntax of the string strVariation: Move1 Move2 ... 132 | #if !SKIP_MATCH_LINE 133 | 134 | // Add or remove the exclamation mark before SKIP_MATCH_LINE 135 | return DebugMatchLine( 136 | "5 Bb3a4 Bc8d7 Ba4xc6 Bd7xc6 Rf1e1 Bf8e7 Bc1d2", iPly, moveThis, intSearchDepth, intMaxSearchDepth); 137 | 138 | // The variation/line you want to debug! 139 | #else 140 | return false; 141 | 142 | // Do not break on the variation 143 | #endif 144 | 145 | // SKIP_MATCH_LINE 146 | } 147 | 148 | /// 149 | /// Convert the Principal Variation to a string 150 | /// 151 | /// the list of moves of the variation 152 | /// the string of the Principal Variation. Ex: 5 Bb3a4 Bc8d7 Ba4xc6 153 | private static string PvLine(Moves moveList) 154 | { 155 | if (moveList != null) 156 | { 157 | m_strbPV.Remove(0, m_strbPV.Length); 158 | for (int intIndex = 0; intIndex < moveList.Count; intIndex++) 159 | { 160 | Move move = moveList[intIndex]; 161 | if (move != null) 162 | { 163 | m_strbPV.Append(move.Piece.Abbreviation); 164 | m_strbPV.Append(move.From.Name); 165 | if (move.PieceCaptured != null) 166 | { 167 | m_strbPV.Append("x"); 168 | } 169 | 170 | m_strbPV.Append(move.To.Name); 171 | m_strbPV.Append(" "); 172 | } 173 | } 174 | } 175 | 176 | return m_strbPV.ToString(); 177 | } 178 | 179 | #endregion 180 | } 181 | } -------------------------------------------------------------------------------- /SharpChess.Model/PlayerWhite.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // The player white. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess.Model 27 | { 28 | /// 29 | /// The player white. 30 | /// 31 | public class PlayerWhite : Player 32 | { 33 | #region Constructors and Destructors 34 | 35 | /// 36 | /// Initializes a new instance of the class. 37 | /// 38 | public PlayerWhite() 39 | { 40 | this.Colour = PlayerColourNames.White; 41 | this.Intellegence = PlayerIntellegenceNames.Human; 42 | 43 | this.SetPiecesAtStartingPositions(); 44 | } 45 | 46 | #endregion 47 | 48 | #region Public Properties 49 | 50 | /// 51 | /// Gets PawnAttackLeftOffset. 52 | /// 53 | public override int PawnAttackLeftOffset 54 | { 55 | get 56 | { 57 | return 15; 58 | } 59 | } 60 | 61 | /// 62 | /// Gets PawnAttackRightOffset. 63 | /// 64 | public override int PawnAttackRightOffset 65 | { 66 | get 67 | { 68 | return 17; 69 | } 70 | } 71 | 72 | /// 73 | /// Gets PawnForwardOffset. 74 | /// 75 | public override int PawnForwardOffset 76 | { 77 | get 78 | { 79 | return 16; 80 | } 81 | } 82 | 83 | #endregion 84 | 85 | #region Methods 86 | 87 | /// 88 | /// The set pieces at starting positions. 89 | /// 90 | protected override sealed void SetPiecesAtStartingPositions() 91 | { 92 | this.Pieces.Add(this.King = new Piece(Piece.PieceNames.King, this, 4, 0, Piece.PieceIdentifierCodes.WhiteKing)); 93 | 94 | this.Pieces.Add(new Piece(Piece.PieceNames.Queen, this, 3, 0, Piece.PieceIdentifierCodes.WhiteQueen)); 95 | 96 | this.Pieces.Add(new Piece(Piece.PieceNames.Rook, this, 0, 0, Piece.PieceIdentifierCodes.WhiteQueensRook)); 97 | this.Pieces.Add(new Piece(Piece.PieceNames.Rook, this, 7, 0, Piece.PieceIdentifierCodes.WhiteKingsRook)); 98 | 99 | this.Pieces.Add(new Piece(Piece.PieceNames.Bishop, this, 2, 0, Piece.PieceIdentifierCodes.WhiteQueensBishop)); 100 | this.Pieces.Add(new Piece(Piece.PieceNames.Bishop, this, 5, 0, Piece.PieceIdentifierCodes.WhiteKingsBishop)); 101 | 102 | this.Pieces.Add(new Piece(Piece.PieceNames.Knight, this, 1, 0, Piece.PieceIdentifierCodes.WhiteQueensKnight)); 103 | this.Pieces.Add(new Piece(Piece.PieceNames.Knight, this, 6, 0, Piece.PieceIdentifierCodes.WhiteKingsKnight)); 104 | 105 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 0, 1, Piece.PieceIdentifierCodes.WhitePawn1)); 106 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 1, 1, Piece.PieceIdentifierCodes.WhitePawn2)); 107 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 2, 1, Piece.PieceIdentifierCodes.WhitePawn3)); 108 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 3, 1, Piece.PieceIdentifierCodes.WhitePawn4)); 109 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 4, 1, Piece.PieceIdentifierCodes.WhitePawn5)); 110 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 5, 1, Piece.PieceIdentifierCodes.WhitePawn6)); 111 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 6, 1, Piece.PieceIdentifierCodes.WhitePawn7)); 112 | this.Pieces.Add(new Piece(Piece.PieceNames.Pawn, this, 7, 1, Piece.PieceIdentifierCodes.WhitePawn8)); 113 | } 114 | 115 | #endregion 116 | } 117 | } -------------------------------------------------------------------------------- /SharpChess.Model/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // AssemblyInfo.cs 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | using System.Reflection; 27 | using System.Runtime.CompilerServices; 28 | using System.Runtime.InteropServices; 29 | 30 | // General Information about an assembly is controlled through the following 31 | // set of attributes. Change these attribute values to modify the information 32 | // associated with an assembly. 33 | [assembly: AssemblyTitle("SharpChess.Model")] 34 | [assembly: AssemblyDescription("C# Chess Game Engine")] 35 | [assembly: AssemblyConfiguration("")] 36 | [assembly: AssemblyCompany("SharpChess.com")] 37 | [assembly: AssemblyProduct("SharpChess")] 38 | [assembly: AssemblyCopyright("Copyright © 2012")] 39 | [assembly: AssemblyTrademark("")] 40 | [assembly: AssemblyCulture("")] 41 | 42 | // Setting ComVisible to false makes the types in this assembly not visible 43 | // to COM components. If you need to access a type in this assembly from 44 | // COM, set the ComVisible attribute to true on that type. 45 | [assembly: ComVisible(false)] 46 | 47 | // The following GUID is for the ID of the typelib if this project is exposed to COM 48 | [assembly: Guid("337ef881-bac9-43ca-87cd-91af07d1f0c9")] 49 | 50 | // Version information for an assembly consists of the following four values: 51 | // 52 | // Major Version 53 | // Minor Version 54 | // Build Number 55 | // Revision 56 | // 57 | // You can specify all the values or you can default the Build and Revision Numbers 58 | // by using the '*' as shown below: 59 | // [assembly: AssemblyVersion("1.0.*")] 60 | [assembly: AssemblyVersion("2.6.9")] 61 | [assembly: AssemblyFileVersion("2.6.9")] 62 | -------------------------------------------------------------------------------- /SharpChess.Model/SharpChess.Model.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {EE301A37-33A9-4B7A-BE08-D001057610CD} 9 | Library 10 | Properties 11 | SharpChess.Model 12 | SharpChess.Model 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | true 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | true 25 | ..\Docs\SharpChess.Model.XML 26 | AnyCPU 27 | false 28 | MinimumRecommendedRules.ruleset 29 | false 30 | 31 | 32 | none 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | true 39 | false 40 | 41 | 42 | AnyCPU 43 | false 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 100 | -------------------------------------------------------------------------------- /SharpChess.Model/Squares.cs: -------------------------------------------------------------------------------- 1 | // -------------------------------------------------------------------------------------------------------------------- 2 | // 3 | // SharpChess.com 4 | // 5 | // 6 | // The squares. 7 | // 8 | // -------------------------------------------------------------------------------------------------------------------- 9 | 10 | #region License 11 | 12 | // SharpChess 13 | // Copyright (C) 2012 SharpChess.com 14 | // This program is free software: you can redistribute it and/or modify 15 | // it under the terms of the GNU General Public License as published by 16 | // the Free Software Foundation, either version 3 of the License, or 17 | // (at your option) any later version. 18 | // This program is distributed in the hope that it will be useful, 19 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | // GNU General Public License for more details. 22 | // You should have received a copy of the GNU General Public License 23 | // along with this program. If not, see . 24 | #endregion 25 | 26 | namespace SharpChess.Model 27 | { 28 | #region Using 29 | 30 | using System.Collections; 31 | 32 | #endregion 33 | 34 | /// 35 | /// The squares. 36 | /// 37 | public class Squares : IEnumerable 38 | { 39 | #region Constants and Fields 40 | 41 | /// 42 | /// The m_col squares. 43 | /// 44 | private readonly ArrayList squareList = new ArrayList(32); 45 | 46 | #endregion 47 | 48 | #region Public Properties 49 | 50 | /// 51 | /// Gets the number of squares in the list. 52 | /// 53 | public int Count 54 | { 55 | get 56 | { 57 | return this.squareList.Count; 58 | } 59 | } 60 | 61 | #endregion 62 | 63 | #region Public Methods 64 | 65 | /// 66 | /// Adds a new square to the list. 67 | /// 68 | /// 69 | /// The square to add. 70 | /// 71 | public void Add(Square square) 72 | { 73 | this.squareList.Add(square); 74 | } 75 | 76 | /// 77 | /// The get enumerator. 78 | /// 79 | /// 80 | /// The enumerator. 81 | /// 82 | public IEnumerator GetEnumerator() 83 | { 84 | return this.squareList.GetEnumerator(); 85 | } 86 | 87 | /// 88 | /// Searches for the specified square and returns its index. 89 | /// 90 | /// 91 | /// The piece to search for. 92 | /// 93 | /// 94 | /// Index value of the found square. or null if not found. 95 | /// 96 | public int IndexOf(Square square) 97 | { 98 | return this.squareList.IndexOf(square); 99 | } 100 | 101 | /// 102 | /// Insert a sqaure into the list. at the specified index position. 103 | /// 104 | /// 105 | /// The ordinal index position where the square will be inserted. 106 | /// 107 | /// 108 | /// The piece. 109 | /// 110 | public void Insert(int ordinal, Square square) 111 | { 112 | this.squareList.Insert(ordinal, square); 113 | } 114 | 115 | /// 116 | /// Returns the square at the specified index position in the list. 117 | /// 118 | /// 119 | /// Index position. 120 | /// 121 | /// 122 | /// The square at the specified index. 123 | /// 124 | public Square Item(int intIndex) 125 | { 126 | return (Square)this.squareList[intIndex]; 127 | } 128 | 129 | /// 130 | /// Remove the square from the list. 131 | /// 132 | /// 133 | /// The piece to remove. 134 | /// 135 | public void Remove(Square square) 136 | { 137 | this.squareList.Remove(square); 138 | } 139 | 140 | #endregion 141 | } 142 | } -------------------------------------------------------------------------------- /UpgradeLog.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/UpgradeLog.htm -------------------------------------------------------------------------------- /UpgradeLog2.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/UpgradeLog2.htm -------------------------------------------------------------------------------- /UpgradeLog3.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PeterHughes/SharpChess/e5290e732a5f3fff29f9d309fc2dd7a6bd167a9a/UpgradeLog3.htm --------------------------------------------------------------------------------