Advertisement
Ivo123

Untitled

Sep 10th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 154.03 KB | None | 0 0
  1. // at the end ::: normalize sound and release timers for mode PCvsPC; set starting with mode Player vs PC; normalize random for draw; arrange the "Others" variables;
  2. // missings "en passant" for all game modes
  3. // missings "material, repetition and fifty-rule" draws for both PC modes
  4. // materials (for draw) da sledi i za dvata PC moda !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  5. // reduce FullPrint() (at draw, resign, ...)
  6.  
  7. using System;
  8. using System.IO;
  9. using System.Text;
  10. using System.Security;
  11. using System.Threading;
  12. using System.Speech.Synthesis;
  13. using System.Collections.Generic;
  14. using System.Media;
  15.  
  16. public class Chessmaster
  17. {
  18.     #region Variables
  19.  
  20.         #region Console
  21.  
  22.         #region Size
  23.  
  24.     public static int consoleWidth = 153;
  25.     public static int consoleHeight = 32;
  26.  
  27.         #endregion
  28.  
  29.         #region Colors
  30.  
  31.     public static ConsoleColor colorOfDefaultBackground = ConsoleColor.Black;
  32.     public static ConsoleColor colorOfDefaultForeground = ConsoleColor.White;
  33.  
  34.     public static ConsoleColor colorOfOuterFrameBackground = ConsoleColor.DarkGray;
  35.     public static ConsoleColor colorOfOuterFrameForeground = ConsoleColor.White;
  36.  
  37.     public static ConsoleColor colorOfInternalFrame = ConsoleColor.Black;
  38.  
  39.     public static ConsoleColor colorOfWhiteFields = ConsoleColor.DarkGray;
  40.     public static ConsoleColor colorOfBlackFields = ConsoleColor.Black;
  41.  
  42.     public static ConsoleColor colorOfWhiteFigures = ConsoleColor.White;
  43.     public static ConsoleColor colorOfBlackFigures = ConsoleColor.Red;
  44.  
  45.     public static ConsoleColor colorOfMovesBackground = ConsoleColor.Black;
  46.     public static ConsoleColor colorOfMovesForeground = ConsoleColor.White;
  47.  
  48.     public static ConsoleColor colorOfTakensWhiteFigureBackground = ConsoleColor.DarkGray;
  49.     public static ConsoleColor colorOfTakensWhiteFigureForeground = ConsoleColor.White;
  50.     public static ConsoleColor colorOfTakensBlackFigureBackground = ConsoleColor.DarkGray;
  51.     public static ConsoleColor colorOfTakensBlackFigureForeground = ConsoleColor.Red;
  52.  
  53.     public static ConsoleColor colorOfTheEndingMoveBackground = ConsoleColor.Black;
  54.     public static ConsoleColor colorOfTheEndingMoveForeground = ConsoleColor.Red;
  55.  
  56.     public static ConsoleColor colorOfBottomHelpBackground = ConsoleColor.Black;
  57.     public static ConsoleColor colorOfBottomHelpForeground = ConsoleColor.Yellow;
  58.  
  59.     //Ivelin
  60.     public static ConsoleColor backgroundColor = ConsoleColor.Black;
  61.     public static ConsoleColor foregroundColorWhileNotChosen = ConsoleColor.Yellow;
  62.     public static ConsoleColor foregroundColorForCurrentMainText = ConsoleColor.Red;
  63.     public static ConsoleColor foregroundColorWhileChosen = ConsoleColor.Green;
  64.     public static ConsoleColor colorForPrinting = ConsoleColor.Green;
  65.     public static ConsoleColor arrows = ConsoleColor.Yellow;
  66.     public static ConsoleColor blueColor = ConsoleColor.Blue;
  67.     public static ConsoleColor colorForFirstText = ConsoleColor.Magenta;
  68.     private static ConsoleColor colorOfOuterFrameBackgroundMenu = ConsoleColor.Blue;
  69.     private static ConsoleColor colorOfOuterFrameForegroundMenu = ConsoleColor.Blue;
  70.     //
  71.  
  72.         #endregion
  73.  
  74.         #endregion
  75.  
  76.         #region Read Move
  77.  
  78.     public static string gotMove = "";
  79.  
  80.     public static Queue<char> readMove = new Queue<char>();
  81.     public static string specialFigures = "NBRQK";
  82.     public static string allColumns = "abcdefgh";
  83.  
  84.     public static string someCastle = "O-O";
  85.     public static string castleKingsideFree = "O-O";
  86.     public static string castleKingsideCheck = "O-O+";
  87.     public static string castleKingsideDraw = "O-O=";
  88.     public static string castleKingsideCheckmate = "O-O#";
  89.     public static string castleQueensideFree = "O-O-O";
  90.     public static string castleQueensideCheck = "O-O-O+";
  91.     public static string castleQueensideDraw = "O-O-O=";
  92.     public static string castleQueensideCheckmate = "O-O-O#";
  93.     public enum Castles { noCastle, castleKingsideFree, castleKingsideCheck, castleKingsideDraw, castleKingsideCheckmate, castleQueensideFree, castleQueensideCheck, castleQueensideDraw, castleQueensideCheckmate };
  94.     public static Castles castle;
  95.     public static int castleRow;
  96.     public static int indexOfCastleRook;
  97.     public static List<List<bool>> castlePossibility = new List<List<bool>>();
  98.     public static bool castleKingside = false;
  99.     public static bool castleQueenside = false;
  100.  
  101.     public static List<List<List<int>>> savePositions = new List<List<List<int>>>();
  102.  
  103.     public static bool takes;
  104.  
  105.     public static States give;
  106.     public static string resign = ".";
  107.  
  108.     public static string pressed;
  109.  
  110.     public static string uglyMoveList;
  111.     public static string[] uglyMoveListArray; // zanulqvai go na 2-te mesta!, ako moje
  112.  
  113.         #endregion
  114.  
  115.         #region Figure's Units
  116.  
  117.     public const int whiteDecimals = 10;
  118.     public const int blackDecimals = 30;
  119.     public const int kingUnits = 6;
  120.     public const int queenUnits = 5;
  121.     public const int rookUnits = 4;
  122.     public const int bishopUnits = 3;
  123.     public const int nightUnits = 2;
  124.     public const int pawnUnits = 1;
  125.  
  126.     public const int whiteKing = whiteDecimals + kingUnits;
  127.     public const int blackKing = blackDecimals + kingUnits;
  128.     public const int whiteRook = whiteDecimals + rookUnits;
  129.     public const int blackRook = blackDecimals + rookUnits;
  130.  
  131.     public const int whiteKingPlusNight = 2 * whiteDecimals + kingUnits + nightUnits;
  132.     public const int blackKingPlusNight = 2 * blackDecimals + kingUnits + nightUnits;
  133.     public const int whiteKingPlusBishop = 2 * whiteDecimals + kingUnits + bishopUnits;
  134.     public const int blackKingPlusBishop = 2 * blackDecimals + kingUnits + bishopUnits;
  135.  
  136.     public const int baseMaterial = 8 * pawnUnits + 2 * (nightUnits + bishopUnits + rookUnits) + queenUnits + kingUnits;
  137.     public const int fullWhiteMaterial = 16 * whiteDecimals + baseMaterial;
  138.     public const int fullBlackMaterial = 16 * blackDecimals + baseMaterial;
  139.  
  140.         #endregion
  141.  
  142.         #region Battlefield
  143.  
  144.     public static int[,] battlefield = new int[8, 8];
  145.     public static List<List<List<int>>> figures = new List<List<List<int>>>();
  146.     public static List<int> materials = new List<int>();
  147.     public enum States { Free, Check, Draw, Checkmate, Resign };
  148.     public static List<List<string>> lastMoves = new List<List<string>>();
  149.  
  150.         #endregion
  151.  
  152.         #region Players
  153.  
  154.     public static int playWith = 0;
  155.     public static int oppositePlayWith = 1 - playWith;
  156.     public static string changePlayWith = "c";
  157.  
  158.     public static int playerToMove = 0;
  159.     public static int oppositePlayer = 1;
  160.  
  161.     public static States realState = States.Free;
  162.  
  163.     public static int currentMove = 0;
  164.  
  165.         #endregion
  166.  
  167.         #region Talking
  168.  
  169.     public static StringBuilder sentence = new StringBuilder();
  170.  
  171.         #endregion
  172.  
  173.         #region Game modes
  174.  
  175.     public enum GameModes { PlayerVsComputer = 0, PlayerVsPlayer = 1, ComputerVsComputer = 2, CheckMoveList = 3 };
  176.     public static GameModes gameMode = GameModes.PlayerVsComputer;  // by instancing
  177.     public static string changeGameModeByEventually;
  178.     public static int changeGameModeBy;
  179.     public static bool hadNewGame = false;
  180.  
  181.     public static List<string> gameModes = new List<string>() { "1", "2", "0", "3" };
  182.  
  183.         #endregion
  184.  
  185.         #region Print
  186.  
  187.     public static int nextWhiteToMove;
  188.  
  189.     public static List<int> lookingAngles = new List<int>();
  190.     public static int lookingAngle;
  191.  
  192.     public static string emptyBlackboardRow = new string(' ', 104);
  193.  
  194.     public static string outerHorizontalEmptyEnds = new string(' ', 4);
  195.     public static string outerHorizontalEmptyMiddle = new string(' ', 40);
  196.     public static string outerHorizontalEmpty = new string(' ', 48);
  197.     public static string outerEmptyByVertical = new string(' ', 3);
  198.     public static List<string> outerHorizontalTextLine = new List<string>() { "      a    b    c    d    e    f    g    h      ",
  199.                                                                               "      1    2    3    4    5    6    7    8      ",
  200.                                                                               "      h    g    f    e    d    c    b    a      ",
  201.                                                                               "      8    7    6    5    4    3    2    1      " };
  202.     public static string internalHorizontalEmpty = new string(' ', 42);
  203.     public static int outerHorizontalSymbolByVertical;
  204.     public static string fieldEmptyByHorizontal = new string(' ', 5);
  205.     public static int figureInField;
  206.  
  207.     public static List<string> rotations = new List<string>() { "d", "r", "t", "l" };
  208.     public static int rotate;
  209.  
  210.     public static bool blindfold = false;
  211.     public static string changeBlindfold = "b";
  212.  
  213.     public static bool sound = true;
  214.     public static string changeSound = "s";
  215.  
  216.     public static string bottomHelp = string.Format("Start new game with Players: {0}, {1}, {2}, {3} (check move list)   Change pieces: {4}",
  217.                                                                         gameModes[0], gameModes[1], gameModes[2], gameModes[3], changePlayWith);
  218.     public static string topHelp = string.Format("g5xh6 e7-e8=N+ d2xc1=B= Ra4-h4# Qd4:g1 Kf3xe2 0-0 0-0-0 =? =  Rotations: {0},{1},{2},{3} Blindfold: {4} Sound: {5}",
  219.                                                                                                 rotations[0], rotations[1], rotations[2], rotations[3], changeBlindfold, changeSound);
  220.  
  221.     public static string playAgain = "Choose and start a new game...";
  222.  
  223.         #endregion
  224.  
  225.         #region Timers
  226.  
  227.     public static DateTime startTime;
  228.  
  229.     public static int timeBeforeFirstMoveFromList = 1500;
  230.     public static int timeAfterRotationOrBlindfoldChangeBeforeNextMoveFromListOrPC = 1500;
  231.     public static int timeBeforeNextMoveFromList = 2000;
  232.     public static bool hadRotation = false;
  233.     public static bool hadBlindfoldChange = false;
  234.  
  235.     public static int timeBetweenPrintMoveAndMoveFigure = 500;
  236.  
  237.     public static int timePCThinksMove = 2000;
  238.  
  239.         #endregion
  240.  
  241.         #region Counters
  242.  
  243.     public static int i;
  244.     public static int j;
  245.     public static int k;
  246.  
  247.     public static int whitePawn;
  248.     public static int rowOfWhiteSpecialFigure;
  249.     public static int rowOfWhitePawn;
  250.     public static int columnOfWhitePawn;
  251.     public static int blackPawn;
  252.     public static int rowOfBlackSpecialFigure;
  253.     public static int rowOfBlackPawn;
  254.     public static int columnOfBlackPawn;
  255.  
  256.     public static int ro;
  257.     public static int col;
  258.     public static int mov;
  259.     public static int colon;
  260.  
  261.         #endregion
  262.  
  263.         #region Others
  264.  
  265.     public static bool exchange = false;
  266.     public static int exchangeWith = 0;
  267.  
  268.     public static bool oppositeCheck;
  269.     public static bool oppositeAvoid;
  270.  
  271.     public static List<List<int>> lookOnlyThisPositions = new List<List<int>>();
  272.     public static int figureIndex;
  273.  
  274.     public static bool willBeUnderCheck = false;
  275.  
  276.     public static int king;
  277.     public static int kingRow;
  278.     public static int kingColumn;
  279.     public static int oppositeKing;
  280.     public static int oppositeKingRow;
  281.     public static int oppositeKingColumn;
  282.     public static int rook;
  283.     public static int theRow;
  284.     public static int rowChange;
  285.     public static int theColumn;
  286.     public static int columnChange;
  287.     public static int figureRow;
  288.     public static int figureColumn;
  289.  
  290.     public static int theField;
  291.  
  292.     public static int rowMovement;
  293.     public static int columnMovement;
  294.  
  295.     public static bool makeNextCheck;
  296.  
  297.     public static bool canJump;
  298.  
  299.     public static List<string> moveList = new List<string>();
  300.  
  301.     public static string choise;
  302.    
  303.     //
  304.  
  305.     public static int firstOfExchangeKind;
  306.  
  307.     //public static string giveDraw;
  308.     public static string draw = "=";
  309.     public static string question = "?";
  310.     public static string answer = "=";
  311.     public static string refuse = "-";
  312.     //public static string stalemate = "S";
  313.     //public static string fiftyMove = "F";
  314.     //public static string repetition = "Re";
  315.     //public static string bothFlagsDown = "T";
  316.     //public static string insufficientMaterial = "M";
  317.     public static string drawQuestion = draw + question;
  318.     public static string drawAnswer = answer;
  319.     public static string drawAnswerRefuse = refuse;
  320.     public static string drawByAgreement = draw + question + answer;
  321.     //public static string drawByFiftyMove = draw + fiftyMove;
  322.     //public static string drawByRepetition = draw + repetition;
  323.     //public static string drawByBothFlagsDown = draw + bothFlagsDown;
  324.     //public static string drawByInsufficientMaterial = draw + insufficientMaterial;
  325.  
  326.     public static List<List<int>> takenFigures = new List<List<int>>();
  327.     public static int[] nextTakenFigure = new int[2] { 0, 0 };
  328.     public static int takenColor;
  329.  
  330.     public static List<List<List<int>>> possibleMoves = new List<List<List<int>>>();
  331.  
  332.     public static int toThisField;
  333.  
  334.     public static int thisKing;
  335.     public static int otherKing;
  336.  
  337.     public static Random randomGenerator = new Random();
  338.     public static int randomIndex;
  339.     public static int randomOnePossibleMovement;
  340.     public static int randomTakesSymbol;
  341.     public static int randomResign = 1;
  342.     public static int randomResignFrom = 1000;
  343.     public static int randomAcceptDrawByAgreement = 4;
  344.     public static int randomAcceptDrawByAgreementFrom = 100;
  345.     public static int randomOffersDrawByAgreement = 4;
  346.     public static int randomOffersDrawByAgreementFrom = 100;
  347.     public static int randomDrawByMaterial = 100;                   // testing
  348.     public static int randomDrawByMaterialFrom = 100;
  349.     public static int randomDrawByRepetition = 50;
  350.     public static int randomDrawByRepetitionFrom = 100;
  351.     public static int randomDrawByFiftyRule = 50;
  352.     public static int randomDrawByFiftyRuleFrom = 100;
  353.  
  354.     public static StringBuilder buildTextOfMove = new StringBuilder();
  355.  
  356.     public static StringBuilder saveCurrentBattlefield = new StringBuilder();
  357.     public static List<string> saveBattlefields = new List<string>();
  358.     public static List<int> matches = new List<int>();
  359.     public static int maxMatches = 0;
  360.     public static int maxMatchesEventually = 0;
  361.     public static int indexOfCurrentBattlefield;
  362.  
  363.         #endregion
  364.  
  365.         #region Zeroizing
  366.  
  367.     public static bool zeroizePrints = false;
  368.     public static bool zeroizeWaits = false;
  369.     public static bool zeroizeSounds = false;
  370.  
  371.         #endregion
  372.  
  373.     #endregion
  374.  
  375.     #region Main function
  376.  
  377.     public static void Main()
  378.     {
  379.         MenuAtFirstPage();
  380.     }
  381.  
  382.     # region Menu
  383.  
  384.     //Play();
  385.     private static void MenuAtFirstPage()
  386.     {
  387.         switch (showHelpOrPlayTheGame())
  388.         {
  389.             case 1:
  390.                 do
  391.                 {
  392.                     playingSoundWhenStartingTheGame();
  393.                     Play();
  394.                 } while (true);
  395.             case 2:
  396.                 HelpMenu();
  397.                 break;
  398.             default:
  399.                 break;
  400.         }
  401.     }
  402.  
  403.     private static void HelpMenu()
  404.     {
  405.         Console.BackgroundColor = backgroundColor;
  406.         Console.Clear();
  407.  
  408.         string things = "<   >";
  409.         string numberOne = "1";
  410.         string numberTwo = "2";
  411.         string firtstPage = "Page 1";
  412.         string secondPage = "Page 2";
  413.         string startingGameMessage = "Press Enter for starting your game";
  414.         string[] exampleFirstPage = new string[15]{
  415.             "There are four types of game. To change, you must type the numbers from 0 to 3!",
  416.             "- PC vs. PC (button '0')",
  417.             "- Player vs. PC (button '1')",
  418.             "- Player vs. Player (button '2')",
  419.             "- Check move list (button '3')",
  420.             "\n",
  421.             "Show / Hide figures (blinfold) - button 'b'",
  422.             "Stop / Start sound - button 's'",
  423.             "\n",
  424.             "There are three difficult levels - Amateur, Master, Nightmare.",
  425.             "difficult Amateur - button 'a'",
  426.             "difficult Master - button 'm'",
  427.             "difficult Nightmare - button 'n'",
  428.             "\n",
  429.             "You can rotate the gaming table: 'r'(right), 'l'(left), 't'(top), 'd'(down)",};
  430.  
  431.         string[] exampleSecondPage = new string[18]{
  432.             "Example: We have a4:b5 ",
  433.             "\n",
  434.             "a - the number of the column that current figure stays on",
  435.             "It can be a, b, c, d, e, f, g, h.",
  436.             "\n",
  437.             "4 - the number of the row that current figure stays on",
  438.             "It can be 1, 2, 3, 4, 5, 6, 7, 8.",
  439.             "\n",
  440.             "':' means that we will get a figure ('x' can also be used).",
  441.             "The enemy's figure that we will get stays on b5.",
  442.             "a4:b5 will move our figure to column 'b' and row 5 and will get",
  443.             "the enemy's figure.",
  444.             "\n",
  445.             "If you want to earn a new figure you must write '=' and the figure you want.",
  446.             "'=' without special figure after it means that you give a stalemate.",
  447.             "\n",
  448.             "If you want to give a check you must write '+'. ",
  449.             "For checkmate you must write '#'." };
  450.  
  451.         //First page
  452.         Console.ForegroundColor = foregroundColorWhileNotChosen;
  453.         Console.SetCursorPosition(74, 1);
  454.         Console.WriteLine(firtstPage);
  455.         Console.ForegroundColor = foregroundColorForCurrentMainText;
  456.         Console.SetCursorPosition(61, 28);
  457.         Console.WriteLine(startingGameMessage);
  458.         Console.ForegroundColor = foregroundColorWhileNotChosen;
  459.         Console.SetCursorPosition(75, 30);
  460.         Console.WriteLine(things);
  461.         Console.SetCursorPosition(76, 30);
  462.         Console.ForegroundColor = foregroundColorWhileChosen;
  463.         Console.WriteLine(numberOne);
  464.         Console.SetCursorPosition(78, 30);
  465.         Console.ForegroundColor = foregroundColorWhileNotChosen;
  466.         Console.WriteLine(numberTwo);
  467.  
  468.         Console.ForegroundColor = foregroundColorWhileChosen;
  469.         for (int i = 0; i < exampleFirstPage.Length; i++)
  470.         {
  471.             Console.SetCursorPosition(77 - exampleFirstPage[i].Length / 2, i + 3);
  472.             Console.WriteLine(exampleFirstPage[i]);
  473.         }
  474.  
  475.         int counter = 1;
  476.         ConsoleKeyInfo keyInfo;
  477.         while ((keyInfo = Console.ReadKey(true)).Key != ConsoleKey.Escape)
  478.         {
  479.             switch (keyInfo.Key)
  480.             {
  481.                 case ConsoleKey.Enter:
  482.                     do
  483.                     {
  484.                         playingSoundWhenStartingTheGame();
  485.                         Play();
  486.                     } while (true);
  487.                 case ConsoleKey.LeftArrow:
  488.                     playingSoundWhenPressingButton();
  489.                     counter--;
  490.                     break;
  491.                 case ConsoleKey.RightArrow:
  492.                     playingSoundWhenPressingButton();
  493.                     counter++;
  494.                     break;
  495.             }
  496.  
  497.             if (counter == 3)
  498.             {
  499.                 counter = 1;
  500.             }
  501.             if (counter == 0)
  502.             {
  503.                 counter = 2;
  504.             }
  505.  
  506.             if (counter == 1)
  507.             {
  508.                 Console.Clear();
  509.                 Console.ForegroundColor = foregroundColorWhileNotChosen;
  510.                 Console.SetCursorPosition(74, 1);
  511.                 Console.WriteLine(firtstPage);
  512.                 Console.ForegroundColor = foregroundColorForCurrentMainText;
  513.                 Console.SetCursorPosition(61, 28);
  514.                 Console.WriteLine(startingGameMessage);
  515.                 Console.ForegroundColor = foregroundColorWhileNotChosen;
  516.                 Console.SetCursorPosition(75, 30);
  517.                 Console.WriteLine(things);
  518.                 Console.SetCursorPosition(76, 30);
  519.                 Console.ForegroundColor = foregroundColorWhileChosen;
  520.                 Console.WriteLine(numberOne);
  521.                 Console.SetCursorPosition(78, 30);
  522.                 Console.ForegroundColor = foregroundColorWhileNotChosen;
  523.                 Console.WriteLine(numberTwo);
  524.  
  525.                 Console.ForegroundColor = foregroundColorWhileChosen;
  526.                 for (int i = 0; i < exampleFirstPage.Length; i++)
  527.                 {
  528.                     Console.SetCursorPosition(77 - exampleFirstPage[i].Length / 2, i + 3);
  529.                     Console.WriteLine(exampleFirstPage[i]);
  530.                 }
  531.             }
  532.  
  533.             if (counter == 2)
  534.             {
  535.                 Console.Clear();
  536.                 Console.SetCursorPosition(74, 1);
  537.                 Console.ForegroundColor = foregroundColorWhileNotChosen;
  538.                 Console.WriteLine(secondPage);
  539.                 Console.ForegroundColor = foregroundColorForCurrentMainText;
  540.                 Console.SetCursorPosition(61, 28);
  541.                 Console.WriteLine(startingGameMessage);
  542.                 Console.ForegroundColor = foregroundColorWhileNotChosen;
  543.                 Console.SetCursorPosition(75, 30);
  544.                 Console.WriteLine(things);
  545.                 Console.SetCursorPosition(76, 30);
  546.                 Console.ForegroundColor = foregroundColorWhileNotChosen;
  547.                 Console.WriteLine(numberOne);
  548.                 Console.SetCursorPosition(78, 30);
  549.                 Console.ForegroundColor = foregroundColorWhileChosen;
  550.                 Console.WriteLine(numberTwo);
  551.  
  552.                 Console.ForegroundColor = foregroundColorWhileChosen;
  553.                 for (int i = 0; i < exampleSecondPage.Length; i++)
  554.                 {
  555.                     Console.SetCursorPosition(77 - exampleSecondPage[i].Length / 2, i + 3);
  556.                     Console.WriteLine(exampleSecondPage[i]);
  557.                 }
  558.             }
  559.         }
  560.     }
  561.  
  562.     private static void PrintingOuterFrame()
  563.     {
  564.         Console.SetWindowSize(154, 32);
  565.         Console.Clear();
  566.         Console.SetBufferSize(Console.WindowWidth, 32);
  567.         string outerEmptyByVertical = new string(' ', 3);
  568.         string outerEmptyByHorizontal = new string(' ', Console.BufferWidth);
  569.         string outerEmptyByHorizontalAnotherColor = new string(' ', Console.BufferWidth - 6);
  570.         for (int i = 0; i < Console.BufferHeight - 1; i++)
  571.         {
  572.             Console.BackgroundColor = colorOfOuterFrameBackgroundMenu;
  573.             Console.ForegroundColor = colorOfOuterFrameForegroundMenu;
  574.             Console.SetCursorPosition(0, i);
  575.             Console.WriteLine(outerEmptyByVertical);
  576.             Console.SetCursorPosition(Console.BufferWidth - 3, i);
  577.             Console.WriteLine(outerEmptyByVertical);
  578.         }
  579.  
  580.         for (int i = 0; i < 2; i++)
  581.         {
  582.             Console.BackgroundColor = colorOfOuterFrameBackgroundMenu;
  583.             Console.ForegroundColor = colorOfOuterFrameForegroundMenu;
  584.             Console.SetCursorPosition(3, i);
  585.             Console.WriteLine(outerEmptyByHorizontal);
  586.         }
  587.  
  588.         Console.SetCursorPosition(3, 3);
  589.         Console.WriteLine(outerEmptyByHorizontalAnotherColor);
  590.         Console.SetCursorPosition(3, 5);
  591.         Console.WriteLine(outerEmptyByHorizontalAnotherColor);
  592.         Console.SetCursorPosition(3, 2);
  593.         Console.WriteLine(outerEmptyByHorizontalAnotherColor);
  594.         Console.SetCursorPosition(3, 28);
  595.         Console.WriteLine(outerEmptyByHorizontalAnotherColor);
  596.         Console.SetCursorPosition(3, 30);
  597.         Console.WriteLine(outerEmptyByHorizontalAnotherColor);
  598.         Console.SetCursorPosition(0, 30);
  599.         Console.WriteLine(outerEmptyByVertical);
  600.         Console.SetCursorPosition(151, 30);
  601.         Console.WriteLine(outerEmptyByVertical);
  602.         Console.BackgroundColor = colorForPrinting;
  603.         Console.ForegroundColor = colorOfOuterFrameForegroundMenu;
  604.         Console.SetCursorPosition(3, 2);
  605.         Console.WriteLine(outerEmptyByHorizontalAnotherColor);
  606.         Console.SetCursorPosition(3, 29);
  607.         Console.WriteLine(outerEmptyByHorizontalAnotherColor);
  608.     }
  609.  
  610.     private static int showHelpOrPlayTheGame()
  611.     {
  612.         Console.SetBufferSize(155, 32);
  613.         Console.CursorVisible = false;
  614.         PrintingOuterFrame();
  615.         string firstText = "Start the game";
  616.         string secondText = "How To Play?";
  617.  
  618.         Console.BackgroundColor = backgroundColor;
  619.         Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2 - 2);
  620.         Console.ForegroundColor = foregroundColorWhileChosen;
  621.         Console.WriteLine(firstText);
  622.         Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2);
  623.         Console.ForegroundColor = foregroundColorWhileNotChosen;
  624.         Console.WriteLine(secondText);
  625.  
  626.         int startGameOrShowHelp = 1;
  627.         ConsoleKeyInfo keyInfo;
  628.         while ((keyInfo = Console.ReadKey(true)).Key != ConsoleKey.Escape)
  629.         {
  630.             switch (keyInfo.Key)
  631.             {
  632.                 case ConsoleKey.Enter:
  633.                     playingSoundWhenPressingButton();
  634.                     return startGameOrShowHelp;
  635.                 case ConsoleKey.UpArrow:
  636.                     playingSoundWhenPressingButton();
  637.                     startGameOrShowHelp--;
  638.                     break;
  639.  
  640.                 case ConsoleKey.DownArrow:
  641.                     playingSoundWhenPressingButton();
  642.                     startGameOrShowHelp++;
  643.                     break;
  644.             }
  645.  
  646.             switch (startGameOrShowHelp)
  647.             {
  648.                 case 1:
  649.                     Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2 - 2);
  650.                     Console.ForegroundColor = foregroundColorWhileChosen;
  651.                     Console.WriteLine(firstText);
  652.                     Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2);
  653.                     Console.ForegroundColor = foregroundColorWhileNotChosen;
  654.                     Console.WriteLine(secondText);
  655.                     break;
  656.                 case 2:
  657.                     Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2 - 2);
  658.                     Console.ForegroundColor = foregroundColorWhileNotChosen;
  659.                     Console.WriteLine(firstText);
  660.                     Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2);
  661.                     Console.ForegroundColor = foregroundColorWhileChosen;
  662.                     Console.WriteLine(secondText);
  663.                     break;
  664.                 case 0:
  665.                     startGameOrShowHelp = 2;
  666.                     Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2 - 2);
  667.                     Console.ForegroundColor = foregroundColorWhileNotChosen;
  668.                     Console.WriteLine(firstText);
  669.                     Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2);
  670.                     Console.ForegroundColor = foregroundColorWhileChosen;
  671.                     Console.WriteLine(secondText);
  672.                     break;
  673.                 case 3:
  674.                     startGameOrShowHelp = 1;
  675.                     Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2 - 2);
  676.                     Console.ForegroundColor = foregroundColorWhileChosen;
  677.                     Console.WriteLine(firstText);
  678.                     Console.SetCursorPosition(Console.BufferWidth / 3 + 19, Console.BufferHeight / 2);
  679.                     Console.ForegroundColor = foregroundColorWhileNotChosen;
  680.                     Console.WriteLine(secondText);
  681.                     break;
  682.                 default:
  683.                     break;
  684.             }
  685.         }
  686.         return startGameOrShowHelp;
  687.     }
  688.  
  689.     private static void playingSoundWhenPressingButton()
  690.     {
  691.         using (SoundPlayer player = new SoundPlayer(@"../../sound.wav"))
  692.         {
  693.             player.Play();
  694.         }
  695.     }
  696.  
  697.     private static void playingSoundWhenStartingTheGame()
  698.     {
  699.         using (SoundPlayer player = new SoundPlayer(@"../../startingTheGame.wav"))
  700.         {
  701.             player.Play();
  702.         }
  703.     }
  704.  
  705.     # endregion
  706.  
  707.     #endregion
  708.  
  709.     #region Initials
  710.  
  711.     public static void StartingPosition()
  712.     {
  713.         #region Console
  714.  
  715.         Console.CursorVisible = false;
  716.         Console.WindowWidth = consoleWidth;
  717.         Console.BufferWidth = consoleWidth;
  718.         Console.WindowHeight = consoleHeight;
  719.         Console.BufferHeight = consoleHeight;
  720.         Console.BackgroundColor = colorOfMovesBackground;
  721.         Console.ForegroundColor = colorOfMovesForeground;
  722.         Console.Clear();
  723.         Console.SetCursorPosition(0, 0);
  724.  
  725.         #endregion
  726.  
  727.         #region Game modes
  728.  
  729.         hadNewGame = false;
  730.  
  731.         #endregion
  732.  
  733.         #region Read move
  734.  
  735.         gotMove = "";
  736.         readMove.Clear();
  737.  
  738.         takes = false;
  739.         exchange = false;
  740.         exchangeWith = 0;
  741.  
  742.         give = States.Free;
  743.         realState = States.Free;
  744.  
  745.         buildTextOfMove.Clear();
  746.  
  747.         #endregion
  748.  
  749.         #region Check for check
  750.  
  751.         willBeUnderCheck = false;
  752.  
  753.         #endregion
  754.  
  755.         #region Castle
  756.  
  757.         castleKingside = false;
  758.         castleQueenside = false;
  759.  
  760.         #endregion
  761.  
  762.         #region Players
  763.  
  764.         playWith = 0;
  765.         oppositePlayWith = 1 - playWith;
  766.  
  767.         playerToMove = 0;
  768.         oppositePlayer = 1 - playerToMove;
  769.  
  770.         #endregion
  771.  
  772.         #region Blindfold
  773.  
  774.         blindfold = false;
  775.  
  776.         #endregion
  777.  
  778.         #region Sound and talking
  779.  
  780.         sound = true;
  781.         sentence.Clear();
  782.  
  783.         #endregion
  784.  
  785.         #region Taken figures
  786.  
  787.         nextTakenFigure[0] = 0;
  788.         nextTakenFigure[1] = 0;
  789.  
  790.         #endregion
  791.  
  792.         #region Save battlefields
  793.  
  794.         saveCurrentBattlefield.Clear();
  795.         saveBattlefields.Clear();
  796.         matches.Clear();
  797.         maxMatches = 0;
  798.         maxMatchesEventually = 0;
  799.  
  800.         #endregion
  801.  
  802.         #region Zeroizing
  803.  
  804.         zeroizePrints = false;
  805.         zeroizeWaits = false;
  806.         zeroizeSounds = false;
  807.  
  808.         #endregion
  809.  
  810.         #region Table
  811.  
  812.         battlefield[0, 0] = battlefield[0, 7] = whiteDecimals + rookUnits;
  813.         battlefield[0, 1] = battlefield[0, 6] = whiteDecimals + nightUnits;
  814.         battlefield[0, 2] = battlefield[0, 5] = whiteDecimals + bishopUnits;
  815.         battlefield[0, 3] = whiteDecimals + queenUnits;
  816.         battlefield[0, 4] = whiteDecimals + kingUnits;
  817.  
  818.         for (col = 0; col <= 7; col++)
  819.         {
  820.             battlefield[1, col] = whiteDecimals + pawnUnits;
  821.             battlefield[6, col] = blackDecimals + pawnUnits;
  822.         }
  823.  
  824.         for (ro = 2; ro <= 5; ro++)
  825.             for (col = 0; col <= 7; col++)
  826.                 battlefield[ro, col] = 0;
  827.  
  828.         battlefield[7, 0] = battlefield[7, 7] = blackDecimals + rookUnits;
  829.         battlefield[7, 1] = battlefield[7, 6] = blackDecimals + nightUnits;
  830.         battlefield[7, 2] = battlefield[7, 5] = blackDecimals + bishopUnits;
  831.         battlefield[7, 3] = blackDecimals + queenUnits;
  832.         battlefield[7, 4] = blackDecimals + kingUnits;
  833.  
  834.         #endregion
  835.  
  836.         #region Figures
  837.  
  838.         figures.Clear();
  839.  
  840.             #region White
  841.  
  842.         figures.Add(new List<List<int>>(0));
  843.  
  844.         figures[0].Add(new List<int>(0));
  845.         figures[0].Add(new List<int>(1));
  846.         figures[0].Add(new List<int>(2));
  847.  
  848.         figures[0][0].Add(whiteDecimals + kingUnits);
  849.         figures[0][0].Add(whiteDecimals + queenUnits);
  850.         figures[0][0].Add(whiteDecimals + rookUnits);
  851.         figures[0][0].Add(whiteDecimals + rookUnits);
  852.         figures[0][0].Add(whiteDecimals + bishopUnits);
  853.         figures[0][0].Add(whiteDecimals + bishopUnits);
  854.         figures[0][0].Add(whiteDecimals + nightUnits);
  855.         figures[0][0].Add(whiteDecimals + nightUnits);
  856.         for (whitePawn = 0; whitePawn <= 7; whitePawn++)
  857.             figures[0][0].Add(whiteDecimals + pawnUnits);
  858.  
  859.         for (rowOfWhiteSpecialFigure = 0; rowOfWhiteSpecialFigure <= 7; rowOfWhiteSpecialFigure++)
  860.             figures[0][1].Add(0);
  861.         for (rowOfWhitePawn = 0; rowOfWhitePawn <= 7; rowOfWhitePawn++)
  862.             figures[0][1].Add(1);
  863.  
  864.         figures[0][2].Add(4);
  865.         figures[0][2].Add(3);
  866.         figures[0][2].Add(0);
  867.         figures[0][2].Add(7);
  868.         figures[0][2].Add(2);
  869.         figures[0][2].Add(5);
  870.         figures[0][2].Add(1);
  871.         figures[0][2].Add(6);
  872.         for (columnOfWhitePawn = 0; columnOfWhitePawn <= 7; columnOfWhitePawn++)
  873.             figures[0][2].Add(columnOfWhitePawn);
  874.  
  875.             #endregion
  876.  
  877.             #region Black
  878.  
  879.         figures.Add(new List<List<int>>(1));
  880.  
  881.         figures[1].Add(new List<int>(0));
  882.         figures[1].Add(new List<int>(1));
  883.         figures[1].Add(new List<int>(2));
  884.  
  885.         figures[1][0].Add(blackDecimals + kingUnits);
  886.         figures[1][0].Add(blackDecimals + queenUnits);
  887.         figures[1][0].Add(blackDecimals + rookUnits);
  888.         figures[1][0].Add(blackDecimals + rookUnits);
  889.         figures[1][0].Add(blackDecimals + bishopUnits);
  890.         figures[1][0].Add(blackDecimals + bishopUnits);
  891.         figures[1][0].Add(blackDecimals + nightUnits);
  892.         figures[1][0].Add(blackDecimals + nightUnits);
  893.         for (blackPawn = 0; blackPawn <= 7; blackPawn++)
  894.             figures[1][0].Add(blackDecimals + pawnUnits);
  895.  
  896.         for (rowOfBlackSpecialFigure = 0; rowOfBlackSpecialFigure <= 7; rowOfBlackSpecialFigure++)
  897.             figures[1][1].Add(7);
  898.         for (rowOfBlackPawn = 0; rowOfBlackPawn <= 7; rowOfBlackPawn++)
  899.             figures[1][1].Add(6);
  900.  
  901.         figures[1][2].Add(4);
  902.         figures[1][2].Add(3);
  903.         figures[1][2].Add(0);
  904.         figures[1][2].Add(7);
  905.         figures[1][2].Add(2);
  906.         figures[1][2].Add(5);
  907.         figures[1][2].Add(1);
  908.         figures[1][2].Add(6);
  909.         for (columnOfBlackPawn = 0; columnOfBlackPawn <= 7; columnOfBlackPawn++)
  910.             figures[1][2].Add(columnOfBlackPawn);
  911.  
  912.             #endregion
  913.  
  914.             #region Materials
  915.        
  916.         materials.Clear();
  917.  
  918.         materials.Add(fullWhiteMaterial);
  919.         materials.Add(fullBlackMaterial);
  920.  
  921.             #endregion
  922.  
  923.             #region Taken figures
  924.  
  925.         takenFigures.Clear();
  926.  
  927.         takenFigures.Add(new List<int>());
  928.         takenFigures.Add(new List<int>());
  929.  
  930.             #endregion
  931.  
  932.         #endregion
  933.  
  934.         #region Looking angles
  935.  
  936.         lookingAngles.Clear();
  937.  
  938.         lookingAngles.Add(0);
  939.         if (gameMode == GameModes.PlayerVsPlayer)
  940.             lookingAngles.Add(2);
  941.         else
  942.             lookingAngles.Add(0);
  943.  
  944.         #endregion
  945.  
  946.         #region Moves
  947.  
  948.         currentMove = 0;
  949.  
  950.         moveList.Clear();
  951.  
  952.         possibleMoves.Clear();
  953.  
  954.             #region Last moves
  955.  
  956.         lastMoves.Clear();
  957.  
  958.         lastMoves.Add(new List<string>(0));
  959.         lastMoves.Add(new List<string>(1));
  960.  
  961.             #endregion
  962.  
  963.             #region Save positions
  964.  
  965.         savePositions.Clear();
  966.  
  967.         savePositions.Add(new List<List<int>>(0));
  968.         savePositions.Add(new List<List<int>>(1));
  969.  
  970.         savePositions[0].Add(new List<int>(0));
  971.         savePositions[0].Add(new List<int>(1));
  972.  
  973.         savePositions[1].Add(new List<int>(0));
  974.         savePositions[1].Add(new List<int>(1));
  975.  
  976.         savePositions[0][0].Add(0);
  977.         savePositions[0][0].Add(0);
  978.         savePositions[0][0].Add(0);
  979.         savePositions[0][0].Add(0);
  980.  
  981.         savePositions[0][1].Add(0);
  982.         savePositions[0][1].Add(0);
  983.         savePositions[0][1].Add(0);
  984.         savePositions[0][1].Add(0);
  985.  
  986.         savePositions[1][0].Add(0);
  987.         savePositions[1][0].Add(0);
  988.         savePositions[1][0].Add(0);
  989.         savePositions[1][0].Add(0);
  990.  
  991.         savePositions[1][1].Add(0);
  992.         savePositions[1][1].Add(0);
  993.         savePositions[1][1].Add(0);
  994.         savePositions[1][1].Add(0);
  995.  
  996.             #endregion
  997.  
  998.             #region Look only this positions
  999.        
  1000.         lookOnlyThisPositions.Clear();
  1001.  
  1002.         lookOnlyThisPositions.Add(new List<int>(0));
  1003.         lookOnlyThisPositions.Add(new List<int>(1));
  1004.         lookOnlyThisPositions.Add(new List<int>(2));
  1005.  
  1006.             #endregion
  1007.  
  1008.             #region Castle
  1009.  
  1010.         castlePossibility.Clear();
  1011.  
  1012.         castlePossibility.Add(new List<bool>(0));
  1013.         castlePossibility.Add(new List<bool>(1));
  1014.  
  1015.         castlePossibility[0].Add(true);
  1016.         castlePossibility[0].Add(true);
  1017.         castlePossibility[0].Add(true);
  1018.  
  1019.         castlePossibility[1].Add(true);
  1020.         castlePossibility[1].Add(true);
  1021.         castlePossibility[1].Add(true);
  1022.  
  1023.             #endregion
  1024.  
  1025.         #endregion
  1026.     }
  1027.  
  1028.     public static bool FillMoveList()
  1029.     {
  1030.         try
  1031.         {
  1032.             using (StreamReader readRawMoveList = new StreamReader("rawMoveList.txt", Encoding.GetEncoding("windows-1251")))
  1033.             {
  1034.                 uglyMoveList = readRawMoveList.ReadToEnd();
  1035.             }
  1036.  
  1037.             uglyMoveListArray = uglyMoveList.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  1038.             moveList.Clear();
  1039.             for (i = 0; i < uglyMoveListArray.Length; i++)
  1040.                 if (5 <= uglyMoveListArray[i].Length)
  1041.                     moveList.Add(uglyMoveListArray[i]);
  1042.  
  1043.             using (StreamWriter makeReadyMoveList = new StreamWriter("readyMoveList.txt", false, Encoding.GetEncoding("windows-1251")))
  1044.             {
  1045.                 for (i = 0; i < moveList.Count - 1; i++)
  1046.                     makeReadyMoveList.WriteLine(moveList[i]);
  1047.  
  1048.                 makeReadyMoveList.Write(moveList[moveList.Count - 1]);
  1049.             }
  1050.  
  1051.             //moveList.Clear();
  1052.             //using (StreamReader readReadyMoveList = new StreamReader("readyMoveList.txt", Encoding.GetEncoding("windows-1251")))
  1053.             //{
  1054.             //    string line;
  1055.  
  1056.             //    do
  1057.             //    {
  1058.             //        line = readReadyMoveList.ReadLine();
  1059.             //        if (line == null)
  1060.             //            break;
  1061.  
  1062.             //        moveList.Add(line);
  1063.             //    } while (true);
  1064.             //}
  1065.  
  1066.             if (moveList.Count < 1)
  1067.             {
  1068.                 Console.WriteLine("The move list file is empty!");
  1069.                 return false;
  1070.             }
  1071.  
  1072.             return true;
  1073.         }
  1074.         catch (ArgumentNullException)
  1075.         {
  1076.             Console.WriteLine("The path to move list file is null!");
  1077.             return false;
  1078.         }
  1079.         catch (ArgumentException)
  1080.         {
  1081.             Console.WriteLine("The path to move list file is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars!");
  1082.             return false;
  1083.         }
  1084.         catch (PathTooLongException)
  1085.         {
  1086.             Console.WriteLine("The specified path to move list file, move list file, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters!");
  1087.             return false;
  1088.         }
  1089.         catch (FileNotFoundException)
  1090.         {
  1091.             Console.WriteLine("The to move list file specified in path was not found!");
  1092.             return false;
  1093.         }
  1094.         catch (DirectoryNotFoundException)
  1095.         {
  1096.             Console.WriteLine("The specified to move list file is invalid (for example, it is on an unmapped drive)!");
  1097.             return false;
  1098.         }
  1099.         catch (IOException)
  1100.         {
  1101.             Console.WriteLine("An I/O error occurred while opening a file!");
  1102.             return false;
  1103.         }
  1104.         catch (UnauthorizedAccessException)
  1105.         {
  1106.             Console.WriteLine("The path specified a file that is read-only.\n"
  1107.                             + "-or-\n"
  1108.                             + "This operation is not supported on the current platform.\n"
  1109.                             + "-or-\n"
  1110.                             + "path specified a directory.\n"
  1111.                             + "-or- \n"
  1112.                             + "The caller does not have the required permission!");
  1113.             return false;
  1114.         }
  1115.         catch (NotSupportedException)
  1116.         {
  1117.             Console.WriteLine("The path is in an invalid format!");
  1118.             return false;
  1119.         }
  1120.         catch (SecurityException)
  1121.         {
  1122.             Console.WriteLine("The caller does not have the required permission!");
  1123.             return false;
  1124.         }
  1125.         catch
  1126.         {
  1127.             Console.WriteLine("Fatal Error!");
  1128.             return false;
  1129.         }
  1130.     }
  1131.  
  1132.     #endregion
  1133.  
  1134.     #region Print
  1135.  
  1136.     public static void FullPrint()
  1137.     {
  1138.         Console.CursorVisible = false;
  1139.         Console.BackgroundColor = colorOfDefaultBackground;
  1140.         Console.ForegroundColor = colorOfDefaultForeground;
  1141.         Console.Clear();
  1142.         PrintBattlefield(lookingAngles[playerToMove]);
  1143.         PrintLastMoves();
  1144.     }
  1145.  
  1146.     public static void PrintBattlefield(int angleOfLooking)
  1147.     {
  1148.         if (blindfold)
  1149.         {
  1150.             Console.CursorVisible = false;
  1151.             Console.SetCursorPosition(0, 0);
  1152.             Console.BackgroundColor = colorOfOuterFrameBackground;
  1153.             Console.ForegroundColor = colorOfOuterFrameForeground;
  1154.             Console.WriteLine(outerHorizontalEmpty);
  1155.             Console.WriteLine(outerHorizontalTextLine[angleOfLooking]);
  1156.             Console.WriteLine(outerHorizontalEmpty);
  1157.             Console.Write(outerEmptyByVertical);
  1158.             Console.BackgroundColor = colorOfInternalFrame;
  1159.             Console.Write(internalHorizontalEmpty);
  1160.             Console.BackgroundColor = colorOfOuterFrameBackground;
  1161.             Console.WriteLine(outerEmptyByVertical);
  1162.  
  1163.             for (i = 7; i >= 0; i--)
  1164.             {
  1165.                 switch (angleOfLooking)
  1166.                 {
  1167.                     case 0: { outerHorizontalSymbolByVertical = i + 49; break; }
  1168.                     case 1: { outerHorizontalSymbolByVertical = 104 - i; break; }
  1169.                     case 2: { outerHorizontalSymbolByVertical = 56 - i; break; }
  1170.                     case 3: { outerHorizontalSymbolByVertical = i + 97; break; }
  1171.                     default: break;
  1172.                 }
  1173.  
  1174.                 for (k = 0; k <= 2; k++)
  1175.                 {
  1176.                     Console.BackgroundColor = colorOfOuterFrameBackground;
  1177.                     Console.ForegroundColor = colorOfOuterFrameForeground;
  1178.                     Console.Write(" {0} ", k == 1 ? (char)outerHorizontalSymbolByVertical : ' ');
  1179.                     Console.BackgroundColor = colorOfInternalFrame;
  1180.                     Console.Write(" ");
  1181.                     for (j = 0; j <= 7; j++)
  1182.                     {
  1183.                         if ((i + j + angleOfLooking + 1) % 2 == 0)
  1184.                             Console.BackgroundColor = colorOfWhiteFields;
  1185.                         else
  1186.                             Console.BackgroundColor = colorOfBlackFields;
  1187.  
  1188.                         Console.Write(fieldEmptyByHorizontal);
  1189.                     }
  1190.  
  1191.                     Console.BackgroundColor = colorOfInternalFrame;
  1192.                     Console.Write(" ");
  1193.                     Console.BackgroundColor = colorOfOuterFrameBackground;
  1194.                     Console.ForegroundColor = colorOfOuterFrameForeground;
  1195.                     Console.WriteLine(" {0} ", k == 1 ? (char)outerHorizontalSymbolByVertical : ' ');
  1196.                 }
  1197.             }
  1198.  
  1199.             Console.Write(outerEmptyByVertical);
  1200.             Console.BackgroundColor = colorOfInternalFrame;
  1201.             Console.Write(internalHorizontalEmpty);
  1202.             Console.BackgroundColor = colorOfOuterFrameBackground;
  1203.             Console.WriteLine(outerEmptyByVertical);
  1204.             Console.WriteLine(outerHorizontalEmpty);
  1205.             Console.WriteLine(outerHorizontalTextLine[angleOfLooking]);
  1206.             Console.Write(outerHorizontalEmpty);
  1207.         }
  1208.         else
  1209.         {
  1210.             switch (angleOfLooking)
  1211.             {
  1212.                 case 0: { nextTakenFigure[0] = 0; nextTakenFigure[1] = 15; break; }
  1213.                 case 1: { nextTakenFigure[0] = 15; nextTakenFigure[1] = 0; break; }
  1214.                 case 2: { nextTakenFigure[0] = 15; nextTakenFigure[1] = 0; break; }
  1215.                 case 3: { nextTakenFigure[0] = 0; nextTakenFigure[1] = 15; break; }
  1216.                 default: break;
  1217.             }
  1218.  
  1219.             Console.CursorVisible = false;
  1220.             Console.SetCursorPosition(0, 0);
  1221.             Console.BackgroundColor = colorOfOuterFrameBackground;
  1222.             Console.ForegroundColor = colorOfOuterFrameForeground;
  1223.             Console.Write(outerHorizontalEmptyEnds);
  1224.             switch (angleOfLooking)
  1225.             {
  1226.                 case 1:
  1227.                     {
  1228.                         for (i = 0; i < 40; i++)
  1229.                         {
  1230.                             if ((i % 5 != 1) && (i % 5 != 3))
  1231.                                 Console.Write(" ");
  1232.                             else
  1233.                             {
  1234.                                 if (nextTakenFigure[0] < takenFigures[0].Count)
  1235.                                 {
  1236.                                     Console.BackgroundColor = colorOfTakensWhiteFigureBackground;
  1237.                                     Console.ForegroundColor = colorOfTakensWhiteFigureForeground;
  1238.                                     Console.Write(TakenFigure(takenFigures[0][nextTakenFigure[0]]));
  1239.                                     Console.BackgroundColor = colorOfOuterFrameBackground;
  1240.                                     Console.ForegroundColor = colorOfOuterFrameForeground;
  1241.                                 }
  1242.                                 else
  1243.                                     Console.Write(" ");
  1244.  
  1245.                                 nextTakenFigure[0]--;
  1246.                             }
  1247.                         }
  1248.  
  1249.                         break;
  1250.                     }
  1251.                 case 3:
  1252.                     {
  1253.                         for (i = 0; i < 40; i++)
  1254.                         {
  1255.                             if ((i % 5 != 1) && (i % 5 != 3))
  1256.                                 Console.Write(" ");
  1257.                             else
  1258.                             {
  1259.                                 if (nextTakenFigure[1] < takenFigures[1].Count)
  1260.                                 {
  1261.                                     Console.BackgroundColor = colorOfTakensWhiteFigureBackground;
  1262.                                     Console.ForegroundColor = colorOfTakensWhiteFigureForeground;
  1263.                                     Console.Write(TakenFigure(takenFigures[1][nextTakenFigure[1]]));
  1264.                                     Console.BackgroundColor = colorOfOuterFrameBackground;
  1265.                                     Console.ForegroundColor = colorOfOuterFrameForeground;
  1266.                                 }
  1267.                                 else
  1268.                                     Console.Write(" ");
  1269.  
  1270.                                 nextTakenFigure[1]--;
  1271.                             }
  1272.                         }
  1273.  
  1274.                         break;
  1275.                     }
  1276.                 default: { Console.Write(outerHorizontalEmptyMiddle); break; }
  1277.             }
  1278.  
  1279.             Console.WriteLine(outerHorizontalEmptyEnds);
  1280.             Console.WriteLine(outerHorizontalTextLine[angleOfLooking]);
  1281.             Console.WriteLine(outerHorizontalEmpty);
  1282.             Console.Write(outerEmptyByVertical);
  1283.             Console.BackgroundColor = colorOfInternalFrame;
  1284.             Console.Write(internalHorizontalEmpty);
  1285.             Console.BackgroundColor = colorOfOuterFrameBackground;
  1286.             Console.WriteLine(outerEmptyByVertical);
  1287.  
  1288.             for (i = 7; i >= 0; i--)
  1289.             {
  1290.                 switch (angleOfLooking)
  1291.                 {
  1292.                     case 0: { outerHorizontalSymbolByVertical = i + 49; break; }
  1293.                     case 1: { outerHorizontalSymbolByVertical = 104 - i; break; }
  1294.                     case 2: { outerHorizontalSymbolByVertical = 56 - i; break; }
  1295.                     case 3: { outerHorizontalSymbolByVertical = i + 97; break; }
  1296.                     default: break;
  1297.                 }
  1298.  
  1299.                 for (k = 0; k <= 2; k++)
  1300.                 {
  1301.                     Console.BackgroundColor = colorOfOuterFrameBackground;
  1302.                     Console.ForegroundColor = colorOfOuterFrameForeground;
  1303.                     if (k == 1)
  1304.                         Console.Write(" ");
  1305.                     else
  1306.                     {
  1307.                         switch (angleOfLooking)
  1308.                         {
  1309.                             case 0:
  1310.                                 {
  1311.                                     if (nextTakenFigure[0] < takenFigures[0].Count)
  1312.                                     {
  1313.                                         Console.BackgroundColor = colorOfTakensWhiteFigureBackground;
  1314.                                         Console.ForegroundColor = colorOfTakensWhiteFigureForeground;
  1315.                                         Console.Write(TakenFigure(takenFigures[0][nextTakenFigure[0]]));
  1316.                                         Console.BackgroundColor = colorOfOuterFrameBackground;
  1317.                                         Console.ForegroundColor = colorOfOuterFrameForeground;
  1318.                                     }
  1319.                                     else
  1320.                                         Console.Write(" ");
  1321.  
  1322.                                     nextTakenFigure[0]++;
  1323.                                     break;
  1324.                                 }
  1325.                             case 2:
  1326.                                 {
  1327.                                     if (nextTakenFigure[1] < takenFigures[1].Count)
  1328.                                     {
  1329.                                         Console.BackgroundColor = colorOfTakensBlackFigureBackground;
  1330.                                         Console.ForegroundColor = colorOfTakensBlackFigureForeground;
  1331.                                         Console.Write(TakenFigure(takenFigures[1][nextTakenFigure[1]]));
  1332.                                         Console.BackgroundColor = colorOfOuterFrameBackground;
  1333.                                         Console.ForegroundColor = colorOfOuterFrameForeground;
  1334.                                     }
  1335.                                     else
  1336.                                         Console.Write(" ");
  1337.  
  1338.                                     nextTakenFigure[1]++;
  1339.                                     break;
  1340.                                 }
  1341.                             default: { Console.Write(" "); break; }
  1342.                         }
  1343.                     }
  1344.  
  1345.                     Console.Write("{0} ", k == 1 ? (char)outerHorizontalSymbolByVertical : ' ');
  1346.                     Console.BackgroundColor = colorOfInternalFrame;
  1347.                     Console.Write(" ");
  1348.                     for (j = 0; j <= 7; j++)
  1349.                     {
  1350.                         switch (angleOfLooking)
  1351.                         {
  1352.                             case 0: { figureInField = battlefield[i, j]; break; }
  1353.                             case 1: { figureInField = battlefield[j, 7 - i]; break; }
  1354.                             case 2: { figureInField = battlefield[7 - i, 7 - j]; break; }
  1355.                             case 3: { figureInField = battlefield[7 - j, i]; break; }
  1356.                             default: break;
  1357.                         }
  1358.  
  1359.                         if ((i + j + angleOfLooking + 1) % 2 == 0)
  1360.                             Console.BackgroundColor = colorOfWhiteFields;
  1361.                         else
  1362.                             Console.BackgroundColor = colorOfBlackFields;
  1363.  
  1364.                         if (k == 1)
  1365.                             Console.Write("  {0}  ", Figure(figureInField));
  1366.                         else
  1367.                             Console.Write(fieldEmptyByHorizontal);
  1368.                     }
  1369.  
  1370.                     Console.BackgroundColor = colorOfInternalFrame;
  1371.                     Console.Write(" ");
  1372.                     Console.BackgroundColor = colorOfOuterFrameBackground;
  1373.                     Console.ForegroundColor = colorOfOuterFrameForeground;
  1374.                     Console.Write(" {0}", k == 1 ? (char)outerHorizontalSymbolByVertical : ' ');
  1375.                     if (k == 1)
  1376.                         Console.WriteLine(" ");
  1377.                     else
  1378.                     {
  1379.                         switch (angleOfLooking)
  1380.                         {
  1381.                             case 0:
  1382.                                 {
  1383.                                     if (nextTakenFigure[1] < takenFigures[1].Count)
  1384.                                     {
  1385.                                         Console.BackgroundColor = colorOfTakensBlackFigureBackground;
  1386.                                         Console.ForegroundColor = colorOfTakensBlackFigureForeground;
  1387.                                         Console.WriteLine(TakenFigure(takenFigures[1][nextTakenFigure[1]]));
  1388.                                         Console.BackgroundColor = colorOfOuterFrameBackground;
  1389.                                         Console.ForegroundColor = colorOfOuterFrameForeground;
  1390.                                     }
  1391.                                     else
  1392.                                         Console.WriteLine(" ");
  1393.  
  1394.                                     nextTakenFigure[1]--;
  1395.                                     break;
  1396.                                 }
  1397.                             case 2:
  1398.                                 {
  1399.                                     if (nextTakenFigure[0] < takenFigures[0].Count)
  1400.                                     {
  1401.                                         Console.BackgroundColor = colorOfTakensWhiteFigureBackground;
  1402.                                         Console.ForegroundColor = colorOfTakensWhiteFigureForeground;
  1403.                                         Console.WriteLine(TakenFigure(takenFigures[0][nextTakenFigure[0]]));
  1404.                                         Console.BackgroundColor = colorOfOuterFrameBackground;
  1405.                                         Console.ForegroundColor = colorOfOuterFrameForeground;
  1406.                                     }
  1407.                                     else
  1408.                                         Console.WriteLine(" ");
  1409.  
  1410.                                     nextTakenFigure[0]--;
  1411.                                     break;
  1412.                                 }
  1413.                             default: { Console.WriteLine(" "); break; }
  1414.                         }
  1415.                     }
  1416.                 }
  1417.             }
  1418.  
  1419.             Console.Write(outerEmptyByVertical);
  1420.             Console.BackgroundColor = colorOfInternalFrame;
  1421.             Console.Write(internalHorizontalEmpty);
  1422.             Console.BackgroundColor = colorOfOuterFrameBackground;
  1423.             Console.WriteLine(outerEmptyByVertical);
  1424.             Console.WriteLine(outerHorizontalEmpty);
  1425.             Console.WriteLine(outerHorizontalTextLine[angleOfLooking]);
  1426.             Console.Write(outerHorizontalEmptyEnds);
  1427.             switch (angleOfLooking)
  1428.             {
  1429.                 case 1:
  1430.                     {
  1431.                         for (i = 0; i < 40; i++)
  1432.                         {
  1433.                             if ((i % 5 != 1) && (i % 5 != 3))
  1434.                                 Console.Write(" ");
  1435.                             else
  1436.                             {
  1437.                                 if (nextTakenFigure[1] < takenFigures[1].Count)
  1438.                                 {
  1439.                                     Console.BackgroundColor = colorOfTakensWhiteFigureBackground;
  1440.                                     Console.ForegroundColor = colorOfTakensWhiteFigureForeground;
  1441.                                     Console.Write(TakenFigure(takenFigures[1][nextTakenFigure[1]]));
  1442.                                     Console.BackgroundColor = colorOfOuterFrameBackground;
  1443.                                     Console.ForegroundColor = colorOfOuterFrameForeground;
  1444.                                 }
  1445.                                 else
  1446.                                     Console.Write(" ");
  1447.  
  1448.                                 nextTakenFigure[1]++;
  1449.                             }
  1450.                         }
  1451.  
  1452.                         break;
  1453.                     }
  1454.                 case 3:
  1455.                     {
  1456.                         for (i = 0; i < 40; i++)
  1457.                         {
  1458.                             if ((i % 5 != 1) && (i % 5 != 3))
  1459.                                 Console.Write(" ");
  1460.                             else
  1461.                             {
  1462.                                 if (nextTakenFigure[0] < takenFigures[0].Count)
  1463.                                 {
  1464.                                     Console.BackgroundColor = colorOfTakensWhiteFigureBackground;
  1465.                                     Console.ForegroundColor = colorOfTakensWhiteFigureForeground;
  1466.                                     Console.Write(TakenFigure(takenFigures[0][nextTakenFigure[0]]));
  1467.                                     Console.BackgroundColor = colorOfOuterFrameBackground;
  1468.                                     Console.ForegroundColor = colorOfOuterFrameForeground;
  1469.                                 }
  1470.                                 else
  1471.                                     Console.Write(" ");
  1472.  
  1473.                                 nextTakenFigure[0]++;
  1474.                             }
  1475.                         }
  1476.  
  1477.                         break;
  1478.                     }
  1479.                 default: { Console.Write(outerHorizontalEmptyMiddle); break; }
  1480.             }
  1481.  
  1482.             Console.Write(outerHorizontalEmptyEnds);
  1483.         }
  1484.     }
  1485.  
  1486.     public static char Figure(int field)
  1487.     {
  1488.         if ((figures[0][0][0] - kingUnits < field) && (field <= figures[0][0][0]))
  1489.             Console.ForegroundColor = colorOfWhiteFigures;
  1490.         else
  1491.             Console.ForegroundColor = colorOfBlackFigures;
  1492.  
  1493.         switch (field % 10)
  1494.         {
  1495.             case 0: return ' ';
  1496.             case 1: return 'p';
  1497.             case 2: return 'N';
  1498.             case 3: return 'B';
  1499.             case 4: return 'R';
  1500.             case 5: return 'Q';
  1501.             case 6: return 'K';
  1502.             default: return ' ';
  1503.         }
  1504.     }
  1505.  
  1506.     public static char TakenFigure(int field)
  1507.     {
  1508.         if ((figures[0][0][0] - kingUnits < field) && (field <= figures[0][0][0]))
  1509.             Console.ForegroundColor = colorOfWhiteFigures;
  1510.         else
  1511.             Console.ForegroundColor = colorOfBlackFigures;
  1512.  
  1513.         switch (field % 10)
  1514.         {
  1515.             case 0: return ' ';
  1516.             case 1: return 'p';
  1517.             case 2: return 'N';
  1518.             case 3: return 'B';
  1519.             case 4: return 'R';
  1520.             case 5: return 'Q';
  1521.             case 6: return 'K';
  1522.             default: return ' ';
  1523.         }
  1524.     }
  1525.  
  1526.     public static void PrintLastMoves(bool makesClean = false)
  1527.     {
  1528.         if (makesClean)
  1529.             ClearMovesBlackboard();
  1530.  
  1531.         Console.BackgroundColor = colorOfBottomHelpBackground;
  1532.         Console.ForegroundColor = colorOfBottomHelpForeground;
  1533.         Console.SetCursorPosition(49, 0);
  1534.         Console.Write(topHelp);
  1535.         Console.SetCursorPosition(49, 31);
  1536.         Console.Write("Current mode: {0}   {1}", gameModes[(int)gameMode], bottomHelp);
  1537.  
  1538.         nextWhiteToMove = 0;
  1539.         Console.BackgroundColor = colorOfMovesBackground;
  1540.         Console.ForegroundColor = colorOfMovesForeground;
  1541.         if (0 < lastMoves[0].Count)
  1542.         {
  1543.             if (lastMoves[0].Count < 120)
  1544.             {
  1545.                 for (i = 0; i < lastMoves[0].Count; i++)
  1546.                 {
  1547.                     nextWhiteToMove = i + 1;
  1548.                     Console.SetCursorPosition(49 + (i / 30) * 26, 1 + (i % 30));
  1549.                     if (i < 90)
  1550.                         Console.Write("{0,2}. ", (i + 1));
  1551.                     else
  1552.                         Console.Write("{0,3}. ", (i + 1));
  1553.  
  1554.                     // promqnata ot sledva6tiq komentar e ottuk do nego
  1555.  
  1556.                     if (i < lastMoves[0].Count - 1)
  1557.                     {
  1558.                         Console.Write("{0, -11}", lastMoves[0][i]);
  1559.                         if (i < lastMoves[1].Count)
  1560.                             Console.Write("{0}", lastMoves[1][i]);
  1561.                     }
  1562.                     else
  1563.                     {
  1564.                         if ((realState == States.Free) || (realState == States.Check))
  1565.                         {
  1566.                             Console.Write("{0, -11}", lastMoves[0][i]);
  1567.                             if (i < lastMoves[1].Count)
  1568.                                 Console.Write("{0}", lastMoves[1][i]);
  1569.                         }
  1570.                         else
  1571.                         {
  1572.                             if (lastMoves[1].Count < lastMoves[0].Count)
  1573.                             {
  1574.                                 PreparingForPrintOfTheEndingMove();
  1575.                                 Console.Write("{0, -11}", lastMoves[0][i]);
  1576.                             }
  1577.                             else
  1578.                             {
  1579.                                 Console.Write("{0, -11}", lastMoves[0][i]);
  1580.                                 PreparingForPrintOfTheEndingMove();
  1581.                                 Console.Write("{0}", lastMoves[1][i]);
  1582.                             }
  1583.                         }
  1584.                     }
  1585.  
  1586.                     //Console.Write("{0, -11}", lastMoves[0][i]);
  1587.                     //if (i < lastMoves[1].Count)
  1588.                     //    Console.Write("{0}", lastMoves[1][i]);
  1589.                 }
  1590.  
  1591.                 if (gameMode != GameModes.CheckMoveList)
  1592.                     Console.CursorVisible = true;
  1593.  
  1594.                 // dobaveno uslovie i za realState
  1595.                 if ((gameMode != GameModes.CheckMoveList) && (lastMoves[0].Count == lastMoves[1].Count) && ((realState == States.Free) || (realState == States.Check)))
  1596.                 {
  1597.                     Console.SetCursorPosition(49 + (nextWhiteToMove / 30) * 26, 1 + (nextWhiteToMove % 30));
  1598.                     if (nextWhiteToMove < 90)
  1599.                         Console.Write("{0,2}. ", nextWhiteToMove + 1);
  1600.                     else
  1601.                         Console.Write("{0,3}. ", nextWhiteToMove + 1);
  1602.  
  1603.                     Console.CursorVisible = true;
  1604.                 }
  1605.             }
  1606.             else
  1607.             {
  1608.                 mov = lastMoves[0].Count;
  1609.                 colon = 0;
  1610.                 for (i = mov - mov % 30 - 90; i < lastMoves[0].Count; i++)
  1611.                 {
  1612.                     nextWhiteToMove = colon + 1;
  1613.                     Console.SetCursorPosition(49 + (colon / 30) * 26, 1 + (i % 30));
  1614.                     colon++;
  1615.                     if (i < 90)
  1616.                         Console.Write("{0,2}. ", (i + 1));
  1617.                     else
  1618.                         Console.Write("{0,3}. ", (i + 1));
  1619.  
  1620.                     if (i < lastMoves[0].Count - 1)
  1621.                     {
  1622.                         Console.Write("{0, -11}", lastMoves[0][i]);
  1623.                         if (i < lastMoves[1].Count)
  1624.                             Console.Write("{0}", lastMoves[1][i]);
  1625.                     }
  1626.                     else
  1627.                     {
  1628.                         if ((realState == States.Free) || (realState == States.Check))
  1629.                         {
  1630.                             Console.Write("{0, -11}", lastMoves[0][i]);
  1631.                             if (i < lastMoves[1].Count)
  1632.                                 Console.Write("{0}", lastMoves[1][i]);
  1633.                         }
  1634.                         else
  1635.                         {
  1636.                             if (lastMoves[1].Count < lastMoves[0].Count)
  1637.                             {
  1638.                                 PreparingForPrintOfTheEndingMove();
  1639.                                 Console.Write("{0, -11}", lastMoves[0][i]);
  1640.                             }
  1641.                             else
  1642.                             {
  1643.                                 Console.Write("{0, -11}", lastMoves[0][i]);
  1644.                                 PreparingForPrintOfTheEndingMove();
  1645.                                 Console.Write("{0}", lastMoves[1][i]);
  1646.                             }
  1647.                         }
  1648.                     }
  1649.                 }
  1650.  
  1651.                 if (gameMode != GameModes.CheckMoveList)
  1652.                     Console.CursorVisible = true;
  1653.  
  1654.                 if ((gameMode != GameModes.CheckMoveList) && (lastMoves[0].Count == lastMoves[1].Count) && ((realState == States.Free) || (realState == States.Check)))
  1655.                 {
  1656.                     Console.SetCursorPosition(49 + (nextWhiteToMove / 30) * 26, 1 + (nextWhiteToMove % 30));
  1657.                     if (nextWhiteToMove < 90)
  1658.                         Console.Write("{0,2}. ", nextWhiteToMove + 1);
  1659.                     else
  1660.                         Console.Write("{0,3}. ", nextWhiteToMove + 1);
  1661.  
  1662.                     Console.CursorVisible = true;
  1663.                 }
  1664.             }
  1665.         }
  1666.         else
  1667.         {
  1668.             if (gameMode != GameModes.CheckMoveList)
  1669.             {
  1670.                 Console.SetCursorPosition(49, 1);
  1671.                 Console.Write("{0,2}. ", (1));
  1672.                 Console.CursorVisible = true;
  1673.             }
  1674.         }
  1675.  
  1676.         if ((realState == States.Draw) || (realState == States.Checkmate) || (realState == States.Resign))
  1677.             Console.CursorVisible = false;
  1678.     }
  1679.  
  1680.     public static void ClearMovesBlackboard()
  1681.     {
  1682.         Console.CursorVisible = false;
  1683.         Console.BackgroundColor = colorOfMovesBackground;
  1684.         Console.ForegroundColor = colorOfMovesForeground;
  1685.         for (i = 0; i <= 31; i++)
  1686.         {
  1687.             Console.SetCursorPosition(48, i);
  1688.             Console.Write(emptyBlackboardRow);
  1689.         }
  1690.     }
  1691.  
  1692.     public static void PreparingForPrintOfTheEndingMove()
  1693.     {
  1694.         Console.CursorVisible = false;
  1695.         Console.BackgroundColor = colorOfTheEndingMoveBackground;
  1696.         Console.ForegroundColor = colorOfTheEndingMoveForeground;
  1697.     }
  1698.  
  1699.     #endregion
  1700.  
  1701.     #region Game Modes
  1702.  
  1703.     public static void Play()
  1704.     {
  1705.         //gameMode = GameModes.PlayerVsPlayer;
  1706.         //gameMode = GameModes.CheckMoveList;
  1707.         //gameMode = GameModes.PlayerVsComputer;
  1708.         //gameMode = GameModes.ComputerVsComputer;
  1709.  
  1710.         switch (gameMode)
  1711.         {
  1712.             case GameModes.PlayerVsComputer: { PlayerVsComputer(); break; }
  1713.             case GameModes.CheckMoveList: { CheckMoveList(); break; }
  1714.             case GameModes.PlayerVsPlayer: { PlayerVsPlayer(); break; }
  1715.             case GameModes.ComputerVsComputer: { ComputerVsComputer(); break; }
  1716.             default: break;
  1717.         }
  1718.  
  1719.         Ending();
  1720.     }
  1721.  
  1722.     public static void PlayerVsComputer()
  1723.     {
  1724.         StartingPosition();
  1725.         while ((realState != States.Draw) && (realState != States.Checkmate) && (realState != States.Resign))
  1726.         {
  1727.             NextPCMove();
  1728.             if (hadNewGame)
  1729.                 return;
  1730.  
  1731.             if (realState != States.Resign)
  1732.                 ChangePlayerToMove();
  1733.         }
  1734.     }
  1735.  
  1736.     public static void PlayerVsPlayer()
  1737.     {
  1738.         StartingPosition();
  1739.         while ((realState != States.Draw) && (realState != States.Checkmate) && (realState != States.Resign))
  1740.         {
  1741.             NextMove();
  1742.             if (hadNewGame)
  1743.                 return;
  1744.  
  1745.             if (realState != States.Resign) // in original this condition is not necessary and table'll rotate at the end
  1746.                 ChangePlayerToMove();
  1747.         }
  1748.     }
  1749.  
  1750.     public static void ComputerVsComputer()
  1751.     {
  1752.         StartingPosition();
  1753.         //sound = false;
  1754.         while ((realState != States.Draw) && (realState != States.Checkmate) && (realState != States.Resign))
  1755.         {
  1756.             NextOnlyPCsMove();
  1757.             if (hadNewGame)
  1758.                 return;
  1759.  
  1760.             if (realState != States.Resign)
  1761.                 ChangePlayerToMove();
  1762.         }
  1763.     }
  1764.  
  1765.     public static void CheckMoveList()
  1766.     {
  1767.         StartingPosition();
  1768.         if (!FillMoveList())
  1769.             return;
  1770.  
  1771.         //startTime = DateTime.Now;
  1772.         PrintBattlefield(lookingAngles[playerToMove]);
  1773.         while ((realState != States.Draw) && (realState != States.Checkmate) && (realState != States.Resign))
  1774.         {
  1775.             NextMoveFromList(moveList[currentMove]);
  1776.             if (hadNewGame)
  1777.                 return;
  1778.  
  1779.             ChangePlayerToMove();
  1780.         }
  1781.  
  1782.         FullPrint();
  1783.         Console.CursorVisible = false;
  1784.         //Console.SetCursorPosition(50, 31);
  1785.         //Console.Write("{0}", DateTime.Now - startTime);
  1786.     }
  1787.  
  1788.     public static void Ending()
  1789.     {
  1790.         if (!hadNewGame)
  1791.         {
  1792.             Console.CursorVisible = false;
  1793.             Console.SetCursorPosition(48, 0);
  1794.             Console.BackgroundColor = colorOfDefaultBackground;
  1795.             Console.ForegroundColor = colorOfDefaultForeground;
  1796.             Console.Write(emptyBlackboardRow);
  1797.             Console.SetCursorPosition(49, 0);
  1798.             Console.Write(playAgain);
  1799.             Console.CursorVisible = true;
  1800.             changeGameModeByEventually = Console.ReadLine();
  1801.             changeGameModeBy = gameModes.IndexOf(changeGameModeByEventually);
  1802.             if (changeGameModeBy != -1)
  1803.                 gameMode = (GameModes)changeGameModeBy;
  1804.         }
  1805.     }
  1806.  
  1807.     #endregion
  1808.  
  1809.     #region Players' moves
  1810.  
  1811.     public static void NextOnlyPCsMoveOldVersion()
  1812.     {
  1813.         FullPrint();
  1814.         Console.CursorVisible = true;
  1815.         //Thread.Sleep(timePCThinksMove);
  1816.  
  1817.         if (Console.KeyAvailable)
  1818.         {
  1819.             PrintLastMoves(true);
  1820.             pressed = Console.ReadKey().KeyChar.ToString();
  1821.             Console.CursorVisible = false;
  1822.             hadRotation = false;
  1823.             hadBlindfoldChange = false;
  1824.  
  1825.             #region Start new game immediately
  1826.  
  1827.             hadNewGame = false;
  1828.             changeGameModeByEventually = pressed;
  1829.             changeGameModeBy = gameModes.IndexOf(changeGameModeByEventually);
  1830.             if (changeGameModeBy != -1)
  1831.             {
  1832.                 gameMode = (GameModes)changeGameModeBy;
  1833.                 hadNewGame = true;
  1834.             }
  1835.  
  1836.             #endregion
  1837.  
  1838.             #region Table rotation
  1839.  
  1840.             else if (rotations.IndexOf(pressed) != -1)
  1841.             {
  1842.                 Rotate(oppositePlayer, pressed);
  1843.                 hadRotation = true;
  1844.                 ChangePlayerToMove();
  1845.                 FullPrint();
  1846.                 Console.CursorVisible = false;
  1847.             }
  1848.  
  1849.             #endregion
  1850.  
  1851.             #region Blindfold
  1852.  
  1853.             else if (pressed == changeBlindfold)
  1854.             {
  1855.                 blindfold = !blindfold;
  1856.                 hadBlindfoldChange = true;
  1857.                 FullPrint();
  1858.                 Console.CursorVisible = false;
  1859.                 ChangePlayerToMove();
  1860.             }
  1861.  
  1862.             #endregion
  1863.  
  1864.             #region Sound
  1865.  
  1866.             else if (pressed == changeSound)
  1867.             {
  1868.                 sound = !sound;
  1869.                 PrintLastMoves(true);
  1870.                 Console.CursorVisible = false;
  1871.                 ChangePlayerToMove();
  1872.             }
  1873.  
  1874.             #endregion
  1875.  
  1876.             if (hadRotation || hadBlindfoldChange)
  1877.                 Thread.Sleep(timeAfterRotationOrBlindfoldChangeBeforeNextMoveFromListOrPC);
  1878.  
  1879.             return;
  1880.         }
  1881.  
  1882.         FindAllPossibleMoves();
  1883.         ChoosePossibleMove();
  1884.         gotMove = buildTextOfMove.ToString();
  1885.         Console.Write(gotMove);
  1886.         Console.CursorVisible = false;
  1887.  
  1888.         AddCastleRestrictions();
  1889.         realState = give;
  1890.  
  1891.         //Thread.Sleep(timeBetweenPrintMoveAndMoveFigure);
  1892.         PrintBattlefield(lookingAngles[playerToMove]);
  1893.         if (sound)
  1894.             SayMove(MakeSentence());
  1895.  
  1896.         currentMove++;
  1897.         lastMoves[playerToMove].Add(gotMove);
  1898.  
  1899.         //if (gotMove == drawQuestion)
  1900.         //{
  1901.         //    PrintLastMoves();
  1902.         //    Console.Write(drawQuestion);
  1903.         //    if (Console.ReadLine() == drawAnswer)
  1904.         //    {
  1905.         //        currentMove++;
  1906.         //        gotMove = drawByAgreement;
  1907.         //        lastMoves[playerToMove].Add(gotMove);
  1908.         //        realState = give;
  1909.         //        SayMove();
  1910.         //    }
  1911.         //}
  1912.     }
  1913.  
  1914.     public static void NextOnlyPCsMove()
  1915.     {
  1916.         FullPrint();
  1917.         Console.CursorVisible = true;
  1918.         Thread.Sleep(timePCThinksMove);
  1919.         //Thread.Sleep(50);
  1920.         if (Console.KeyAvailable)
  1921.         {
  1922.             PrintLastMoves(true);
  1923.             pressed = Console.ReadKey().KeyChar.ToString();
  1924.             Console.CursorVisible = false;
  1925.             hadRotation = false;
  1926.             hadBlindfoldChange = false;
  1927.  
  1928.             #region Start new game immediately
  1929.  
  1930.             hadNewGame = false;
  1931.             changeGameModeByEventually = pressed;
  1932.             changeGameModeBy = gameModes.IndexOf(changeGameModeByEventually);
  1933.             if (changeGameModeBy != -1)
  1934.             {
  1935.                 gameMode = (GameModes)changeGameModeBy;
  1936.                 hadNewGame = true;
  1937.             }
  1938.  
  1939.             #endregion
  1940.  
  1941.             #region Table rotation
  1942.  
  1943.             else if (rotations.IndexOf(pressed) != -1)
  1944.             {
  1945.                 Rotate(oppositePlayer, pressed);
  1946.                 hadRotation = true;
  1947.                 ChangePlayerToMove();
  1948.                 FullPrint();
  1949.                 Console.CursorVisible = false;
  1950.             }
  1951.  
  1952.             #endregion
  1953.  
  1954.             #region Blindfold
  1955.  
  1956.             else if (pressed == changeBlindfold)
  1957.             {
  1958.                 blindfold = !blindfold;
  1959.                 hadBlindfoldChange = true;
  1960.                 FullPrint();
  1961.                 Console.CursorVisible = false;
  1962.                 ChangePlayerToMove();
  1963.             }
  1964.  
  1965.             #endregion
  1966.  
  1967.             #region Sound
  1968.  
  1969.             else if (pressed == changeSound)
  1970.             {
  1971.                 sound = !sound;
  1972.                 PrintLastMoves(true);
  1973.                 Console.CursorVisible = false;
  1974.                 ChangePlayerToMove();
  1975.             }
  1976.  
  1977.             #endregion
  1978.  
  1979.             if (hadRotation || hadBlindfoldChange)
  1980.                 Thread.Sleep(timeAfterRotationOrBlindfoldChangeBeforeNextMoveFromListOrPC);
  1981.  
  1982.             return;
  1983.         }
  1984.  
  1985.         if (gotMove == drawQuestion)
  1986.         {
  1987.             FullPrint();
  1988.             Console.Write(drawQuestion);
  1989.             Console.CursorVisible = true;
  1990.             Thread.Sleep(timePCThinksMove);
  1991.             if (randomGenerator.Next(1, randomAcceptDrawByAgreementFrom + 1) <= randomAcceptDrawByAgreement)
  1992.             {
  1993.                 currentMove++;
  1994.                 gotMove = drawByAgreement;
  1995.                 lastMoves[playerToMove].Add(gotMove);
  1996.                 give = States.Draw;
  1997.                 realState = give;
  1998.                 FullPrint();
  1999.                 if (sound)
  2000.                     SayMove(MakeSentence());
  2001.  
  2002.                 return;
  2003.             }
  2004.             else
  2005.             {
  2006.                 Console.Write(drawAnswerRefuse);
  2007.                 Console.CursorVisible = false;
  2008.                 if (sound)
  2009.                     SayMove(string.Format("{0}{1}", playWith == 0 ? "Black" : "White", " refuse draw by agreement!"));
  2010.             }
  2011.  
  2012.             return;
  2013.         }
  2014.  
  2015.         if (randomGenerator.Next(1, randomResignFrom + 1) <= randomResign)
  2016.         {
  2017.             Console.Write(gotMove);
  2018.             Console.CursorVisible = false;
  2019.             gotMove = resign;
  2020.             currentMove++;
  2021.             lastMoves[playerToMove].Add(gotMove);
  2022.             give = States.Resign;
  2023.             realState = give;
  2024.             FullPrint();
  2025.             if (sound)
  2026.                 SayMove(MakeSentence());
  2027.  
  2028.             return;
  2029.         }
  2030.  
  2031.         if (randomGenerator.Next(1, randomOffersDrawByAgreementFrom + 1) <= randomOffersDrawByAgreement)
  2032.         {
  2033.             Console.Write(drawQuestion);
  2034.             Console.CursorVisible = false;
  2035.             if (sound)
  2036.                 SayMove(string.Format("{0}{1}", playWith == 0 ? "Black" : "White", " offers draw by agreement!"));
  2037.  
  2038.             Console.CursorVisible = true;
  2039.             if (randomGenerator.Next(1, randomAcceptDrawByAgreementFrom + 1) <= randomAcceptDrawByAgreement)
  2040.             {
  2041.                 Console.CursorVisible = false;
  2042.                 gotMove = drawByAgreement;
  2043.                 currentMove++;
  2044.                 lastMoves[playerToMove].Add(gotMove);
  2045.                 give = States.Draw;
  2046.                 realState = give;
  2047.                 FullPrint();
  2048.                 if (sound)
  2049.                     SayMove(string.Format("{0}{1}", playWith == 0 ? "White" : "Black", "  accepts draw by agreement!"));
  2050.  
  2051.                 return;
  2052.             }
  2053.             else
  2054.                 ChangePlayerToMove();
  2055.  
  2056.             return;
  2057.         }
  2058.  
  2059.         FindAllPossibleMoves();
  2060.         ChoosePossibleMove();
  2061.         gotMove = buildTextOfMove.ToString();
  2062.         //Console.Write(gotMove);
  2063.         Console.CursorVisible = false;
  2064.         realState = give;
  2065.         if ((realState == States.Draw) || (realState == States.Resign))
  2066.         {
  2067.             currentMove++;
  2068.             lastMoves[playerToMove].Add(gotMove);
  2069.             FullPrint();
  2070.             if (sound)
  2071.                 SayMove(MakeSentence());
  2072.  
  2073.             return;
  2074.         }
  2075.  
  2076.         Console.Write(gotMove);
  2077.         Console.CursorVisible = false;
  2078.         Thread.Sleep(timeBetweenPrintMoveAndMoveFigure);
  2079.         PrintBattlefield(lookingAngles[playerToMove]);
  2080.         if (sound)
  2081.             SayMove(MakeSentence());
  2082.  
  2083.         AddCastleRestrictions();
  2084.         currentMove++;
  2085.         lastMoves[playerToMove].Add(gotMove);
  2086.     }
  2087.  
  2088.     public static void NextPCMove()
  2089.     {
  2090.         #region Player's move
  2091.  
  2092.         if (playerToMove == playWith)
  2093.         {
  2094.             do
  2095.             {
  2096.                 if ((0 < currentMove)
  2097.                 && ((gotMove != changeBlindfold) && (lookingAngles[0] == lookingAngles[1]))
  2098.                         || (gotMove == changeSound))
  2099.                     PrintLastMoves(makesClean: true);
  2100.                 else
  2101.                     FullPrint();
  2102.  
  2103.                 gotMove = Console.ReadLine();
  2104.                 Console.CursorVisible = false;
  2105.                 if (currentMove == 0)
  2106.                 {
  2107.                     if (gotMove == changePlayWith)
  2108.                     {
  2109.                         oppositePlayWith = playWith;
  2110.                         playWith = 1 - playWith;
  2111.                         lookingAngles[playerToMove] = lookingAngles[oppositePlayer] = 2 * playWith;
  2112.                         FullPrint();
  2113.                         Console.Write(gotMove);
  2114.                         Console.CursorVisible = false;
  2115.                         ChangePlayerToMove();
  2116.                         break;
  2117.                     }
  2118.                     else
  2119.                     {
  2120.                         FullPrint();
  2121.                         Console.Write(gotMove);
  2122.                         Console.CursorVisible = false;
  2123.                     }
  2124.                 }
  2125.  
  2126.                 #region Start new game immediately
  2127.  
  2128.                 hadNewGame = false;
  2129.                 changeGameModeByEventually = gotMove;
  2130.                 changeGameModeBy = gameModes.IndexOf(changeGameModeByEventually);
  2131.                 if (changeGameModeBy != -1)
  2132.                 {
  2133.                     gameMode = (GameModes)changeGameModeBy;
  2134.                     hadNewGame = true;
  2135.                     return;
  2136.                 }
  2137.  
  2138.                 #endregion
  2139.  
  2140.                 #region Table rotation
  2141.  
  2142.                 if (rotations.IndexOf(gotMove) != -1)
  2143.                 {
  2144.                     Rotate(playerToMove, gotMove);
  2145.                     PrintBattlefield(lookingAngles[playerToMove]);
  2146.                     ChangePlayerToMove();
  2147.                     return;
  2148.                 }
  2149.  
  2150.                 #endregion
  2151.  
  2152.                 #region Blindfold
  2153.  
  2154.                 if (gotMove == changeBlindfold)
  2155.                 {
  2156.                     blindfold = !blindfold;
  2157.                     ChangePlayerToMove();
  2158.                     return;
  2159.                 }
  2160.  
  2161.                 #endregion
  2162.  
  2163.                 #region Sound
  2164.  
  2165.                 if (gotMove == changeSound)
  2166.                 {
  2167.                     sound = !sound;
  2168.                     ChangePlayerToMove();
  2169.                     return;
  2170.                 }
  2171.  
  2172.                 #endregion
  2173.  
  2174.                 if (ReadMove() && IsLegalMove())
  2175.                 {
  2176.                     if ((realState == States.Draw) || (realState == States.Resign))
  2177.                     {
  2178.                         currentMove++;
  2179.                         lastMoves[playerToMove].Add(gotMove);
  2180.                         FullPrint();
  2181.                         if (sound)
  2182.                             SayMove(MakeSentence());
  2183.  
  2184.                         return;
  2185.                     }
  2186.  
  2187.                     Thread.Sleep(timeBetweenPrintMoveAndMoveFigure);
  2188.                     PrintBattlefield(lookingAngles[playerToMove]);
  2189.                     if (sound)
  2190.                         SayMove(MakeSentence());
  2191.  
  2192.                     if (gotMove == drawQuestion)
  2193.                     {
  2194.                         FullPrint();
  2195.                         Console.Write(drawQuestion);
  2196.                         Console.CursorVisible = true;
  2197.                         Thread.Sleep(timePCThinksMove);
  2198.                         if (randomGenerator.Next(1, randomAcceptDrawByAgreementFrom + 1) <= randomAcceptDrawByAgreement)
  2199.                         {
  2200.                             currentMove++;
  2201.                             gotMove = drawByAgreement;
  2202.                             lastMoves[playerToMove].Add(gotMove);
  2203.                             give = States.Draw;
  2204.                             realState = give;
  2205.                             FullPrint();
  2206.                             if (sound)
  2207.                                 SayMove(MakeSentence());
  2208.  
  2209.                             break;
  2210.                         }
  2211.                         else
  2212.                         {
  2213.                             Console.Write(drawAnswerRefuse);
  2214.                             Console.CursorVisible = false;
  2215.                             if (sound)
  2216.                                 SayMove(string.Format("{0}{1}", playWith == 0 ? "Black" : "White", " refuse draw by agreement!"));
  2217.                         }
  2218.  
  2219.                         continue;
  2220.                     }
  2221.  
  2222.                     AddCastleRestrictions();
  2223.                     currentMove++;
  2224.                     lastMoves[playerToMove].Add(gotMove);
  2225.                     realState = give;
  2226.                     break;
  2227.                 }
  2228.             } while (true);
  2229.         }
  2230.  
  2231.         #endregion
  2232.  
  2233.         #region PC's move
  2234.  
  2235.         else
  2236.         {
  2237.             FullPrint();
  2238.             Console.CursorVisible = true;
  2239.             Thread.Sleep(timePCThinksMove);
  2240.             if (randomGenerator.Next(1, randomResignFrom + 1) <= randomResign)
  2241.             {
  2242.                 Console.Write(gotMove);
  2243.                 Console.CursorVisible = false;
  2244.                 gotMove = resign;
  2245.                 currentMove++;
  2246.                 lastMoves[playerToMove].Add(gotMove);
  2247.                 give = States.Resign;
  2248.                 realState = give;
  2249.                 FullPrint();
  2250.                 if (sound)
  2251.                     SayMove(MakeSentence());
  2252.  
  2253.                 return;
  2254.             }
  2255.  
  2256.             if (randomGenerator.Next(1, randomOffersDrawByAgreementFrom + 1) <= randomOffersDrawByAgreement)
  2257.             {
  2258.                 Console.Write(drawQuestion);
  2259.                 Console.CursorVisible = false;
  2260.                 if (sound)
  2261.                     SayMove(string.Format("{0}{1}", playWith == 0 ? "Black" : "White", " offers draw by agreement!"));
  2262.  
  2263.                 Console.CursorVisible = true;
  2264.                 if (Console.ReadLine() == drawAnswer)
  2265.                 {
  2266.                     Console.CursorVisible = false;
  2267.                     gotMove = drawByAgreement;
  2268.                     currentMove++;
  2269.                     lastMoves[playerToMove].Add(gotMove);
  2270.                     give = States.Draw;
  2271.                     realState = give;
  2272.                     FullPrint();
  2273.                     if (sound)
  2274.                         SayMove(string.Format("{0}{1}", playWith == 0 ? "White" : "Black", "  accepts draw by agreement!"));
  2275.  
  2276.                     return;
  2277.                 }
  2278.                 else
  2279.                     ChangePlayerToMove();
  2280.  
  2281.                 return;
  2282.             }
  2283.  
  2284.             FindAllPossibleMoves();
  2285.             ChoosePossibleMove();
  2286.             gotMove = buildTextOfMove.ToString();
  2287.             Console.Write(gotMove);
  2288.             Console.CursorVisible = false;
  2289.             Thread.Sleep(timeBetweenPrintMoveAndMoveFigure);
  2290.             PrintBattlefield(lookingAngles[playerToMove]);
  2291.             if (sound)
  2292.                 SayMove(MakeSentence());
  2293.  
  2294.             if (gotMove == drawQuestion)
  2295.             {
  2296.                 FullPrint();
  2297.                 Console.Write(drawQuestion);
  2298.                 Console.CursorVisible = true;
  2299.                 Thread.Sleep(timePCThinksMove);
  2300.                 if (Console.ReadLine() == drawAnswer)
  2301.                 {
  2302.                     currentMove++;
  2303.                     gotMove = drawByAgreement;
  2304.                     lastMoves[playerToMove].Add(gotMove);
  2305.                     realState = give;
  2306.                     if (sound)
  2307.                         SayMove(MakeSentence());
  2308.                 }
  2309.             }
  2310.  
  2311.             AddCastleRestrictions();
  2312.             currentMove++;
  2313.             lastMoves[playerToMove].Add(gotMove);
  2314.             realState = give;
  2315.         }
  2316.  
  2317.         #endregion
  2318.     }
  2319.  
  2320.     public static void NextMoveFromList(string giveMove)
  2321.     {
  2322.         do
  2323.         {
  2324.             if (currentMove == 0)
  2325.                 Thread.Sleep(timeBeforeFirstMoveFromList);
  2326.  
  2327.             if (Console.KeyAvailable)
  2328.             {
  2329.                 PrintLastMoves(true);
  2330.                 pressed = Console.ReadKey().KeyChar.ToString();
  2331.                 Console.CursorVisible = false;
  2332.                 hadRotation = false;
  2333.                 hadBlindfoldChange = false;
  2334.  
  2335.                 #region Start new game immediately
  2336.  
  2337.                 hadNewGame = false;
  2338.                 changeGameModeByEventually = pressed;
  2339.                 changeGameModeBy = gameModes.IndexOf(changeGameModeByEventually);
  2340.                 if (changeGameModeBy != -1)
  2341.                 {
  2342.                     gameMode = (GameModes)changeGameModeBy;
  2343.                     hadNewGame = true;
  2344.                 }
  2345.  
  2346.                 #endregion
  2347.  
  2348.                 #region Table rotation
  2349.  
  2350.                 else if (rotations.IndexOf(pressed) != -1)
  2351.                 {
  2352.                     Rotate(oppositePlayer, pressed);
  2353.                     hadRotation = true;
  2354.                     ChangePlayerToMove();
  2355.                     FullPrint();
  2356.                     Console.CursorVisible = false;
  2357.                 }
  2358.  
  2359.                 #endregion
  2360.  
  2361.                 #region Blindfold
  2362.  
  2363.                 else if (pressed == changeBlindfold)
  2364.                 {
  2365.                     blindfold = !blindfold;
  2366.                     hadBlindfoldChange = true;
  2367.                     FullPrint();
  2368.                     Console.CursorVisible = false;
  2369.                     ChangePlayerToMove();
  2370.                 }
  2371.  
  2372.                 #endregion
  2373.  
  2374.                 #region Sound
  2375.  
  2376.                 else if (pressed == changeSound)
  2377.                 {
  2378.                     sound = !sound;
  2379.                     PrintLastMoves(true);
  2380.                     Console.CursorVisible = false;
  2381.                     ChangePlayerToMove();
  2382.                 }
  2383.  
  2384.                 #endregion
  2385.  
  2386.                 if (hadRotation || hadBlindfoldChange)
  2387.                     Thread.Sleep(timeAfterRotationOrBlindfoldChangeBeforeNextMoveFromListOrPC);
  2388.  
  2389.                 return;
  2390.             }
  2391.             else
  2392.             {
  2393.                 if (currentMove == 0)
  2394.                     PrintBattlefield(lookingAngles[playerToMove]);
  2395.  
  2396.                 gotMove = giveMove;
  2397.                 if (ReadMove() && IsLegalMove())
  2398.                 {
  2399.                     AddCastleRestrictions();
  2400.                     currentMove++;
  2401.                     lastMoves[playerToMove].Add(gotMove);
  2402.                     realState = give;
  2403.                     ///////////////////////FullPrint();
  2404.                     PrintLastMoves(true);
  2405.                     Console.CursorVisible = false;
  2406.                     Thread.Sleep(timeBetweenPrintMoveAndMoveFigure);
  2407.                     PrintBattlefield(lookingAngles[playerToMove]);
  2408.                     if (sound)
  2409.                         SayMove(MakeSentence());
  2410.  
  2411.                     Thread.Sleep(timeBeforeNextMoveFromList);
  2412.                     break;
  2413.                 }
  2414.             }
  2415.         } while (true);
  2416.     }
  2417.  
  2418.     public static void NextMove()
  2419.     {
  2420.         do
  2421.         {
  2422.             if ((0 < currentMove)
  2423.                 && ((gotMove != changeBlindfold) && (lookingAngles[0] == lookingAngles[1]))
  2424.                         || (gotMove == changeSound))
  2425.                 PrintLastMoves(makesClean: true);
  2426.             else
  2427.                 FullPrint();
  2428.  
  2429.             gotMove = Console.ReadLine();
  2430.             Console.CursorVisible = false;
  2431.  
  2432.             #region Start new game immediately
  2433.  
  2434.             hadNewGame = false;
  2435.             changeGameModeByEventually = gotMove;
  2436.             changeGameModeBy = gameModes.IndexOf(changeGameModeByEventually);
  2437.             if (changeGameModeBy != -1)
  2438.             {
  2439.                 gameMode = (GameModes)changeGameModeBy;
  2440.                 hadNewGame = true;
  2441.                 return;
  2442.             }
  2443.  
  2444.             #endregion
  2445.  
  2446.             #region Table rotation
  2447.  
  2448.             if (rotations.IndexOf(gotMove) != -1)
  2449.             {
  2450.                 Rotate(playerToMove, gotMove);
  2451.                 PrintBattlefield(lookingAngles[playerToMove]);
  2452.                 ChangePlayerToMove();
  2453.                 return;
  2454.             }
  2455.  
  2456.             #endregion
  2457.  
  2458.             #region Blindfold
  2459.  
  2460.             if (gotMove == changeBlindfold)
  2461.             {
  2462.                 blindfold = !blindfold;
  2463.                 ChangePlayerToMove();
  2464.                 return;
  2465.             }
  2466.  
  2467.             #endregion
  2468.  
  2469.             #region Sound
  2470.  
  2471.             if (gotMove == changeSound)
  2472.             {
  2473.                 sound = !sound;
  2474.                 ChangePlayerToMove();
  2475.                 return;
  2476.             }
  2477.  
  2478.             #endregion
  2479.  
  2480.             if (ReadMove() && IsLegalMove())
  2481.             {
  2482.                 if ((realState == States.Draw) || (realState == States.Resign))
  2483.                 {
  2484.                     currentMove++;
  2485.                     lastMoves[playerToMove].Add(gotMove);
  2486.                     FullPrint();
  2487.                     if (sound)
  2488.                         SayMove(MakeSentence());
  2489.  
  2490.                     return;
  2491.                 }
  2492.  
  2493.                 Thread.Sleep(timeBetweenPrintMoveAndMoveFigure);
  2494.                 PrintBattlefield(lookingAngles[playerToMove]);
  2495.                 if (sound)
  2496.                     SayMove(MakeSentence());
  2497.  
  2498.                 if (gotMove == drawQuestion)
  2499.                 {
  2500.                     FullPrint();
  2501.                     Console.Write(drawQuestion);
  2502.                     if (Console.ReadLine() == drawAnswer)
  2503.                     {
  2504.                         currentMove++;
  2505.                         gotMove = drawByAgreement;
  2506.                         lastMoves[playerToMove].Add(gotMove);
  2507.                         give = States.Draw;
  2508.                         realState = give;
  2509.                         FullPrint();
  2510.                         if (sound)
  2511.                             SayMove(MakeSentence());
  2512.  
  2513.                         break;
  2514.                     }
  2515.  
  2516.                     continue;
  2517.                 }
  2518.  
  2519.                 AddCastleRestrictions();
  2520.                 currentMove++;
  2521.                 lastMoves[playerToMove].Add(gotMove);
  2522.                 realState = give;
  2523.                 break;
  2524.             }
  2525.         } while (true);
  2526.     }
  2527.  
  2528.     public static bool ReadMove()
  2529.     {
  2530.         takes = false;
  2531.         exchange = false;
  2532.  
  2533.         #region Resign
  2534.  
  2535.         if (gotMove == resign)
  2536.         {
  2537.             give = States.Resign;
  2538.             realState = give;
  2539.             return true;
  2540.         }
  2541.  
  2542.         #endregion
  2543.  
  2544.         #region Draw
  2545.  
  2546.         #region Draw by agreement
  2547.  
  2548.         if ((gotMove == drawQuestion)
  2549.                 && ((gameMode == GameModes.PlayerVsPlayer) || (gameMode == GameModes.PlayerVsComputer) || (gameMode == GameModes.ComputerVsComputer)))
  2550.         {
  2551.             give = States.Draw;
  2552.             return true;
  2553.         }
  2554.  
  2555.         if ((gotMove == drawByAgreement) && (gameMode == GameModes.CheckMoveList))
  2556.         {
  2557.             give = States.Draw;
  2558.             return true;
  2559.         }
  2560.  
  2561.         #endregion
  2562.  
  2563.         #region Draw by insufficient material, by repetition and by fifty-rule
  2564.  
  2565.         if (gotMove == draw)
  2566.         {
  2567.             if ((((materials[0] == whiteKing) || (materials[0] == whiteKingPlusNight) || (materials[0] == whiteKingPlusBishop))
  2568.                     && ((materials[1] == blackKing) || (materials[1] == blackKingPlusNight) || (materials[1] == blackKingPlusBishop)))
  2569.                 || ((3 <= maxMatchesEventually)
  2570.                 || (50 <= saveBattlefields.Count)))
  2571.             {
  2572.                 give = States.Draw;
  2573.                 return true;
  2574.             }
  2575.             else
  2576.                 return false;
  2577.         }
  2578.  
  2579.         #endregion
  2580.  
  2581.         #endregion
  2582.  
  2583.         #region Castle
  2584.  
  2585.         castle = Castles.noCastle;
  2586.         if (gotMove.IndexOf(someCastle) != -1)
  2587.         {
  2588.             if (gotMove == castleKingsideFree)
  2589.             {
  2590.                 give = States.Free;
  2591.                 castle = Castles.castleKingsideFree;
  2592.                 return castleKingside = true;
  2593.             }
  2594.             else if (gotMove == castleKingsideCheck)
  2595.             {
  2596.                 give = States.Check;
  2597.                 castle = Castles.castleKingsideCheck;
  2598.                 return castleKingside = true;
  2599.             }
  2600.             else if (gotMove == castleKingsideDraw)
  2601.             {
  2602.                 give = States.Draw;
  2603.                 castle = Castles.castleKingsideDraw;
  2604.                 return castleKingside = true;
  2605.             }
  2606.             else if (gotMove == castleKingsideCheckmate)
  2607.             {
  2608.                 give = States.Checkmate;
  2609.                 castle = Castles.castleKingsideCheckmate;
  2610.                 return castleKingside = true;
  2611.             }
  2612.             else if (gotMove == castleQueensideFree)
  2613.             {
  2614.                 give = States.Free;
  2615.                 castle = Castles.castleQueensideFree;
  2616.                 return castleQueenside = true;
  2617.             }
  2618.             else if (gotMove == castleQueensideCheck)
  2619.             {
  2620.                 give = States.Check;
  2621.                 castle = Castles.castleQueensideCheck;
  2622.                 return castleQueenside = true;
  2623.             }
  2624.             else if (gotMove == castleQueensideDraw)
  2625.             {
  2626.                 give = States.Draw;
  2627.                 castle = Castles.castleQueensideDraw;
  2628.                 return castleQueenside = true;
  2629.             }
  2630.             else if (gotMove == castleQueensideCheckmate)
  2631.             {
  2632.                 give = States.Checkmate;
  2633.                 castle = Castles.castleQueensideCheckmate;
  2634.                 return castleQueenside = true;
  2635.             }
  2636.             else
  2637.                 return false;
  2638.         }
  2639.  
  2640.         #endregion
  2641.  
  2642.         #region General inspection by length of gotMove
  2643.  
  2644.         if ((gotMove.Length < 5) || (9 < gotMove.Length))
  2645.             return false;
  2646.  
  2647.         #endregion
  2648.  
  2649.         #region Creating of current queue
  2650.  
  2651.         readMove.Clear();
  2652.         for (i = 0; i < gotMove.Length; i++)
  2653.             readMove.Enqueue(gotMove[i]);
  2654.  
  2655.         #endregion
  2656.  
  2657.         #region Player's to move catch the figure
  2658.  
  2659.         savePositions[playerToMove][0][0] = specialFigures.IndexOf(readMove.Peek());
  2660.         if (savePositions[playerToMove][0][0] != -1)
  2661.         {
  2662.             if (playerToMove == 0)
  2663.                 savePositions[playerToMove][0][0] += whiteDecimals + nightUnits;
  2664.             else
  2665.                 savePositions[playerToMove][0][0] += blackDecimals + nightUnits;
  2666.  
  2667.             readMove.Dequeue();
  2668.             if (readMove.Count < 5)
  2669.                 return false;
  2670.         }
  2671.         else
  2672.         {
  2673.             if (playerToMove == 0)
  2674.                 savePositions[playerToMove][0][0] = whiteDecimals + pawnUnits;
  2675.             else
  2676.                 savePositions[playerToMove][0][0] = blackDecimals + pawnUnits;
  2677.         }
  2678.  
  2679.         #endregion
  2680.  
  2681.         #region from field with column
  2682.  
  2683.         savePositions[playerToMove][0][2] = allColumns.IndexOf(readMove.Peek());
  2684.         if (savePositions[playerToMove][0][2] == -1)
  2685.             return false;
  2686.  
  2687.         readMove.Dequeue();
  2688.  
  2689.         #endregion
  2690.  
  2691.         #region and row
  2692.  
  2693.         savePositions[playerToMove][0][1] = (int)readMove.Peek() - 49;
  2694.         if ((savePositions[playerToMove][0][1] < 0) || (7 < savePositions[playerToMove][0][1]))
  2695.             return false;
  2696.  
  2697.         readMove.Dequeue();
  2698.  
  2699.         #endregion
  2700.  
  2701.         #region and moves it to (and takes the figure on)
  2702.  
  2703.         if ((readMove.Peek() == 'x') || (readMove.Peek() == ':'))
  2704.             takes = true;
  2705.         else if (readMove.Peek() != '-')
  2706.             return false;
  2707.  
  2708.         readMove.Dequeue();
  2709.  
  2710.         #endregion
  2711.  
  2712.         #region field with column
  2713.  
  2714.         savePositions[playerToMove][1][2] = allColumns.IndexOf(readMove.Peek());
  2715.         if (savePositions[playerToMove][1][2] == -1)
  2716.             return false;
  2717.  
  2718.         readMove.Dequeue();
  2719.  
  2720.         #endregion
  2721.  
  2722.         #region and row
  2723.  
  2724.         savePositions[playerToMove][1][1] = (int)readMove.Peek() - 49;
  2725.         if ((savePositions[playerToMove][1][1] < 0) || (7 < savePositions[playerToMove][1][1]))
  2726.             return false;
  2727.  
  2728.         savePositions[playerToMove][1][0] = battlefield[savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]];
  2729.  
  2730.         #endregion
  2731.  
  2732.         #region (exchange pawn with...) and give...
  2733.  
  2734.         readMove.Dequeue();
  2735.         if (readMove.Count == 0)
  2736.         {
  2737.             give = States.Free;
  2738.             return true;
  2739.         }
  2740.         else if (readMove.Count == 1)
  2741.         {
  2742.             if (readMove.Peek() == '#')
  2743.                 give = States.Checkmate;
  2744.             else if (readMove.Peek() == '+')
  2745.                 give = States.Check;
  2746.             else if (readMove.Peek() == '=')
  2747.                 give = States.Draw;
  2748.             else
  2749.                 return false;
  2750.  
  2751.             return true;
  2752.         }
  2753.         else if ((readMove.Count == 2) || (readMove.Count == 3))
  2754.         {
  2755.             if (readMove.Peek() != '=')
  2756.                 return false;
  2757.  
  2758.             readMove.Dequeue();
  2759.             exchangeWith = specialFigures.IndexOf(readMove.Peek());
  2760.             if (exchangeWith == -1)
  2761.                 return false;
  2762.  
  2763.             exchange = true;
  2764.             exchangeWith += figures[playerToMove][0][0] - kingUnits + nightUnits;
  2765.             if (readMove.Count == 1)
  2766.                 return true;
  2767.  
  2768.             readMove.Dequeue();
  2769.             if (readMove.Peek() == '#')
  2770.                 give = States.Checkmate;
  2771.             else if (readMove.Peek() == '+')
  2772.                 give = States.Check;
  2773.             else if (readMove.Peek() == '=')
  2774.                 give = States.Draw;
  2775.             else
  2776.                 return false;
  2777.  
  2778.             return true;
  2779.         }
  2780.         else
  2781.             return false;
  2782.  
  2783.         #endregion
  2784.     }
  2785.  
  2786.     public static bool Rotate(int player, string lastGotMove)
  2787.     {
  2788.         for (rotate = 0; rotate < rotations.Count; rotate++)
  2789.             if (lastGotMove == rotations[rotate])
  2790.             {
  2791.                 lookingAngle = lookingAngles[player];
  2792.                 switch (rotate)
  2793.                 {
  2794.                     case 0: { lookingAngle = 2 * player; break; }
  2795.                     case 1: { lookingAngle++; break; }
  2796.                     case 2: { lookingAngle = 2 * player + 2; break; }
  2797.                     case 3: { lookingAngle += 3; break; }
  2798.                     default: break;
  2799.                 }
  2800.  
  2801.                 if (3 < lookingAngle)
  2802.                     lookingAngle -= 4;
  2803.  
  2804.                 lookingAngles[player] = lookingAngle;
  2805.                 if ((gameMode == GameModes.PlayerVsComputer) || (gameMode == GameModes.ComputerVsComputer) || (gameMode == GameModes.CheckMoveList))
  2806.                     lookingAngles[1 - player] = lookingAngle;
  2807.  
  2808.                 return true;
  2809.             }
  2810.  
  2811.         return false;
  2812.     }
  2813.  
  2814.     public static bool IsLegalMove()
  2815.     {
  2816.         if (give == States.Resign)
  2817.             return true;
  2818.  
  2819.         if (((gameMode == GameModes.PlayerVsPlayer) || (gameMode == GameModes.PlayerVsComputer) || (gameMode == GameModes.ComputerVsComputer))
  2820.                 && (gotMove == drawQuestion))
  2821.             return true;
  2822.  
  2823.         if ((gameMode == GameModes.CheckMoveList) && (gotMove == drawByAgreement))
  2824.             return true;
  2825.  
  2826.         if ((gotMove == draw)
  2827.                 && ((materials[0] == whiteKing) || (materials[0] == whiteKingPlusNight) || (materials[0] == whiteKingPlusBishop))
  2828.                     && ((materials[1] == blackKing) || (materials[1] == blackKingPlusNight) || (materials[1] == blackKingPlusBishop)))
  2829.         {
  2830.             give = States.Draw;
  2831.             realState = give;
  2832.             return true;
  2833.         }
  2834.  
  2835.         if (castle != Castles.noCastle)
  2836.         {
  2837.             if (!CastlePossibility())
  2838.                 return false;
  2839.  
  2840.             makeNextCheck = true;
  2841.         }
  2842.         else
  2843.         {
  2844.             if (((savePositions[playerToMove][0][1] == savePositions[playerToMove][1][1]) && (savePositions[playerToMove][0][2] == savePositions[playerToMove][1][2]))
  2845.                     || (battlefield[savePositions[playerToMove][0][1], savePositions[playerToMove][0][2]] != savePositions[playerToMove][0][0])
  2846.                         || (!takes && (battlefield[savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]] != 0)))
  2847.                 return false;
  2848.  
  2849.             if (takes
  2850.                     && ((battlefield[savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]] <= figures[oppositePlayer][0][0] - kingUnits)
  2851.                         || (figures[oppositePlayer][0][0] <= battlefield[savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]])))
  2852.                 return false;
  2853.  
  2854.             canJump = true;
  2855.             switch (savePositions[playerToMove][0][0] % 10)
  2856.             {
  2857.                 case kingUnits: { canJump = JumpOfKing(playerToMove, savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]); break; }
  2858.                 case queenUnits: { canJump = JumpOfQueen(savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]); break; }
  2859.                 case rookUnits: { canJump = JumpOfRook(savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]); break; }
  2860.                 case bishopUnits: { canJump = JumpOfBishop(savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]); break; }
  2861.                 case nightUnits: { canJump = JumpOfNight(savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]); break; }
  2862.                 case pawnUnits: { canJump = JumpOfPawn(playerToMove, savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2], takes, exchange); break; }
  2863.                 default: break;
  2864.             }
  2865.  
  2866.             if (!canJump)
  2867.                 return false;
  2868.  
  2869.             savePositions[playerToMove][0][3] = ReturnIndexOfFigure(playerToMove, savePositions[playerToMove][0][1], savePositions[playerToMove][0][2]);
  2870.             figures[playerToMove][1][savePositions[playerToMove][0][3]] = savePositions[playerToMove][1][1];
  2871.             figures[playerToMove][2][savePositions[playerToMove][0][3]] = savePositions[playerToMove][1][2];
  2872.             if (takes)
  2873.             {
  2874.                 savePositions[playerToMove][1][3] = ReturnIndexOfFigure(oppositePlayer, savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]);
  2875.                 materials[oppositePlayer] -= figures[oppositePlayer][0][savePositions[playerToMove][1][3]];
  2876.                 takenFigures[oppositePlayer].Add(figures[oppositePlayer][0][savePositions[playerToMove][1][3]]);
  2877.                 RemoveFigureAtPosition(oppositePlayer, savePositions[playerToMove][1][3]);
  2878.             }
  2879.  
  2880.             if (exchange)
  2881.             {
  2882.                 materials[playerToMove] += exchangeWith - figures[playerToMove][0][savePositions[playerToMove][0][3]];
  2883.                 figures[playerToMove][0][savePositions[playerToMove][0][3]] = exchangeWith;
  2884.                 MakeMove(0, savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], exchangeWith, savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]);
  2885.             }
  2886.             else
  2887.                 MakeMove(0, savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], savePositions[playerToMove][0][0], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]);
  2888.  
  2889.             makeNextCheck = !Checks(playerToMove);
  2890.         }
  2891.  
  2892.         if (makeNextCheck)
  2893.         {
  2894.             if ((give == States.Draw)
  2895.                     && ((materials[0] == whiteKing) || (materials[0] == whiteKingPlusNight) || (materials[0] == whiteKingPlusBishop))
  2896.                         && ((materials[1] == blackKing) || (materials[1] == blackKingPlusNight) || (materials[1] == blackKingPlusBishop)))
  2897.             {
  2898.                 realState = give;
  2899.                 return true;
  2900.             }
  2901.  
  2902.             oppositeCheck = Checks(oppositePlayer);
  2903.             if ((((give == States.Free) || (give == States.Draw)) && oppositeCheck)
  2904.                     || (((give == States.Check) || (give == States.Checkmate)) && !oppositeCheck))
  2905.                 makeNextCheck = false;
  2906.             else
  2907.             {
  2908.                 oppositeAvoid = OppositeAvoid();
  2909.                 if (((give == States.Checkmate) && oppositeAvoid)
  2910.                         || (((give == States.Free) || (give == States.Check)) && !oppositeAvoid))
  2911.                     makeNextCheck = false;
  2912.  
  2913.                 if ((give == States.Draw) && oppositeAvoid)
  2914.                 {
  2915.                     if ((savePositions[playerToMove][0][0] % 10 == pawnUnits) || takes)
  2916.                         makeNextCheck = false;
  2917.                     else
  2918.                     {
  2919.                         SaveCurrentBattlefield(false);
  2920.                         if ((3 <= maxMatchesEventually) || (50 <= saveBattlefields.Count))
  2921.                         {
  2922.                             maxMatches = maxMatchesEventually;
  2923.                             realState = give;
  2924.                             return true;
  2925.                         }
  2926.                         else
  2927.                         {
  2928.                             saveBattlefields.RemoveAt(saveBattlefields.Count - 1);
  2929.                             matches.RemoveAt(matches.Count - 1);
  2930.                             makeNextCheck = false;
  2931.                         }
  2932.                     }
  2933.                 }
  2934.             }
  2935.         }
  2936.  
  2937.         if (makeNextCheck)
  2938.         {
  2939.             if ((savePositions[playerToMove][0][0] % 10 == pawnUnits) || takes)
  2940.                 ClearAllSavedBattlefields();
  2941.             else
  2942.                 SaveCurrentBattlefield(true);
  2943.         }
  2944.  
  2945.         if (!makeNextCheck)
  2946.         {
  2947.             if (castle != Castles.noCastle)
  2948.             {
  2949.                 figures[playerToMove][2][0] = 4;
  2950.                 if ((castle == Castles.castleKingsideFree) || (castle == Castles.castleKingsideCheck) || (castle == Castles.castleKingsideDraw) || (castle == Castles.castleKingsideCheckmate))
  2951.                 {
  2952.                     MakeMove(0, castleRow, 6, king, castleRow, 4);
  2953.                     MakeMove(0, castleRow, 5, king - kingUnits + rookUnits, castleRow, 7);
  2954.                     figures[playerToMove][2][indexOfCastleRook] = 7;
  2955.                 }
  2956.                 else
  2957.                 {
  2958.                     MakeMove(0, castleRow, 2, king, castleRow, 4);
  2959.                     MakeMove(0, castleRow, 3, king - kingUnits + rookUnits, castleRow, 0);
  2960.                     figures[playerToMove][2][indexOfCastleRook] = 0;
  2961.                 }
  2962.             }
  2963.             else
  2964.             {
  2965.                 figures[playerToMove][0][savePositions[playerToMove][0][3]] = savePositions[playerToMove][0][0];
  2966.                 figures[playerToMove][1][savePositions[playerToMove][0][3]] = savePositions[playerToMove][0][1];
  2967.                 figures[playerToMove][2][savePositions[playerToMove][0][3]] = savePositions[playerToMove][0][2];
  2968.                 MakeMove(savePositions[playerToMove][0][0], savePositions[playerToMove][0][1], savePositions[playerToMove][0][2], savePositions[playerToMove][1][0], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]);
  2969.                 if (takes)
  2970.                 {
  2971.                     AddFigureAtPosition(oppositePlayer, savePositions[playerToMove][1][3], savePositions[playerToMove][1][0], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2]);
  2972.                     materials[oppositePlayer] += figures[oppositePlayer][0][savePositions[playerToMove][1][3]];
  2973.                     takenFigures[oppositePlayer].RemoveAt(takenFigures[oppositePlayer].Count - 1);
  2974.                 }
  2975.  
  2976.                 if (exchange)
  2977.                     materials[playerToMove] -= exchangeWith - figures[playerToMove][0][savePositions[playerToMove][0][3]];
  2978.             }
  2979.         }
  2980.  
  2981.         return makeNextCheck;
  2982.     }
  2983.  
  2984.     public static void ClearAllSavedBattlefields()
  2985.     {
  2986.         saveBattlefields.Clear();
  2987.         matches.Clear();
  2988.         maxMatches = 0;
  2989.     }
  2990.  
  2991.     public static void SaveCurrentBattlefield(bool rightMove)
  2992.     {
  2993.         saveCurrentBattlefield.Clear();
  2994.         for (i = 0; i <= 7; i++)
  2995.             for (j = 0; j <= 7; j++)
  2996.                 saveCurrentBattlefield.Append(battlefield[i, j]);
  2997.  
  2998.         saveBattlefields.Add(saveCurrentBattlefield.ToString());
  2999.         matches.Add(0);
  3000.         indexOfCurrentBattlefield = saveBattlefields.Count - 1;
  3001.         for (k = 0; k <= indexOfCurrentBattlefield; k++)
  3002.             if (saveBattlefields[indexOfCurrentBattlefield] == saveBattlefields[k])
  3003.                 matches[k]++;
  3004.  
  3005.         maxMatchesEventually = maxMatches;
  3006.         for (k = 0; k < matches.Count; k++)
  3007.             if (rightMove)
  3008.             {
  3009.                 if (maxMatches < matches[k])
  3010.                     maxMatches = matches[k];
  3011.             }
  3012.             else
  3013.             {
  3014.                 if (maxMatchesEventually < matches[k])
  3015.                     maxMatchesEventually = matches[k];
  3016.             }
  3017.     }
  3018.  
  3019.         #region Castle
  3020.  
  3021.     public static bool CastlePossibility()
  3022.     {
  3023.         if (realState != States.Free)
  3024.             return false;
  3025.  
  3026.         king = figures[playerToMove][0][0];
  3027.         if (playerToMove == 0)
  3028.             castleRow = 0;
  3029.         else
  3030.             castleRow = 7;
  3031.  
  3032.         if ((castle == Castles.castleKingsideFree) || (castle == Castles.castleKingsideCheck) || (castle == Castles.castleKingsideDraw) || (castle == Castles.castleKingsideCheckmate))
  3033.         {
  3034.             if (!(castlePossibility[playerToMove][0] && castlePossibility[playerToMove][1]))
  3035.                 return false;
  3036.  
  3037.             if ((battlefield[castleRow, 5] != 0) || (battlefield[castleRow, 6] != 0))
  3038.                 return false;
  3039.  
  3040.             MakeMove(0, castleRow, 4, king, castleRow, 5);
  3041.             figures[playerToMove][2][0] = 5;
  3042.             if (Checks(playerToMove))
  3043.             {
  3044.                 MakeMove(0, castleRow, 5, king, castleRow, 4);
  3045.                 figures[playerToMove][2][0] = 4;
  3046.                 return false;
  3047.             }
  3048.  
  3049.             MakeMove(0, castleRow, 5, king, castleRow, 6);
  3050.             figures[playerToMove][2][0] = 6;
  3051.             if (Checks(playerToMove))
  3052.             {
  3053.                 MakeMove(0, castleRow, 6, king, castleRow, 4);
  3054.                 figures[playerToMove][2][0] = 4;
  3055.                 return false;
  3056.             }
  3057.  
  3058.             MakeMove(0, castleRow, 7, king - kingUnits + rookUnits, castleRow, 5);
  3059.             indexOfCastleRook = ReturnIndexOfFigure(playerToMove, castleRow, 7);
  3060.             figures[playerToMove][2][indexOfCastleRook] = 5;
  3061.         }
  3062.         else
  3063.         {
  3064.             if (!(castlePossibility[playerToMove][0] && castlePossibility[playerToMove][2]))
  3065.                 return false;
  3066.  
  3067.             if ((battlefield[castleRow, 3] != 0) || (battlefield[castleRow, 2] != 0) || (battlefield[castleRow, 1] != 0))
  3068.                 return false;
  3069.  
  3070.             MakeMove(0, castleRow, 4, king, castleRow, 3);
  3071.             figures[playerToMove][2][0] = 3;
  3072.             if (Checks(playerToMove))
  3073.             {
  3074.                 MakeMove(0, castleRow, 3, king, castleRow, 4);
  3075.                 figures[playerToMove][2][0] = 4;
  3076.                 return false;
  3077.             }
  3078.  
  3079.             MakeMove(0, castleRow, 3, king, castleRow, 2);
  3080.             figures[playerToMove][2][0] = 2;
  3081.             if (Checks(playerToMove))
  3082.             {
  3083.                 MakeMove(0, castleRow, 2, king, castleRow, 4);
  3084.                 figures[playerToMove][2][0] = 4;
  3085.                 return false;
  3086.             }
  3087.  
  3088.             MakeMove(0, castleRow, 0, king - kingUnits + rookUnits, castleRow, 3);
  3089.             indexOfCastleRook = ReturnIndexOfFigure(playerToMove, castleRow, 0);
  3090.             figures[playerToMove][2][indexOfCastleRook] = 3;
  3091.         }
  3092.  
  3093.         return true;
  3094.     }
  3095.  
  3096.     public static void AddCastleRestrictions()
  3097.     {
  3098.         if (battlefield[0, 4] != whiteKing)
  3099.             castlePossibility[0][0] = false;
  3100.         else if (battlefield[0, 7] != whiteRook)
  3101.             castlePossibility[0][1] = false;
  3102.         else if (battlefield[0, 0] != whiteRook)
  3103.             castlePossibility[0][2] = false;
  3104.  
  3105.         if (battlefield[7, 4] != blackKing)
  3106.             castlePossibility[1][0] = false;
  3107.         else if (battlefield[7, 7] != blackRook)
  3108.             castlePossibility[1][1] = false;
  3109.         else if (battlefield[7, 0] != blackRook)
  3110.             castlePossibility[1][2] = false;
  3111.     }
  3112.  
  3113.         #endregion
  3114.  
  3115.     public static int ReturnIndexOfFigure(int player, int onRow, int onColumn)
  3116.     {
  3117.         for (i = 0; i < figures[player][0].Count; i++)
  3118.             if ((figures[player][1][i] == onRow) && (figures[player][2][i] == onColumn))
  3119.                 return i;
  3120.  
  3121.         return -1;
  3122.     }
  3123.  
  3124.         #region Jumps
  3125.  
  3126.     public static bool JumpOfKing(int player, int fromRow, int fromColumn, int toRow, int toColumn)
  3127.     {
  3128.         if ((-1 <= toRow - fromRow) && (toRow - fromRow <= 1) && (-1 <= toColumn - fromColumn) && (toColumn - fromColumn <= 1)
  3129.                 && ((toRow - figures[1 - player][1][0] < -1) || (1 < toRow - figures[1 - player][1][0]) || (toColumn - figures[1 - player][2][0] < -1) || (1 < toColumn - figures[1 - player][2][0])))
  3130.             return true;
  3131.         else
  3132.             return false;
  3133.     }
  3134.  
  3135.     public static bool JumpOfQueen(int fromRow, int fromColumn, int toRow, int toColumn)
  3136.     {
  3137.         return (JumpOfRook(fromRow, fromColumn, toRow, toColumn) || JumpOfBishop(fromRow, fromColumn, toRow, toColumn));
  3138.     }
  3139.  
  3140.     public static bool JumpOfRook(int fromRow, int fromColumn, int toRow, int toColumn)
  3141.     {
  3142.         if (toRow == fromRow)
  3143.         {
  3144.             if (toColumn < fromColumn)
  3145.             {
  3146.                 for (j = toColumn + 1; j < fromColumn; j++)
  3147.                     if (battlefield[toRow, j] != 0)
  3148.                         return false;
  3149.             }
  3150.             else
  3151.                 for (j = fromColumn + 1; j < toColumn; j++)
  3152.                     if (battlefield[toRow, j] != 0)
  3153.                         return false;
  3154.         }
  3155.         else if (toColumn == fromColumn)
  3156.         {
  3157.             if (toRow < fromRow)
  3158.             {
  3159.                 for (i = toRow + 1; i < fromRow; i++)
  3160.                     if (battlefield[i, toColumn] != 0)
  3161.                         return false;
  3162.             }
  3163.             else
  3164.                 for (i = fromRow + 1; i < toRow; i++)
  3165.                     if (battlefield[i, toColumn] != 0)
  3166.                         return false;
  3167.         }
  3168.  
  3169.         return true;
  3170.     }
  3171.  
  3172.     public static bool JumpOfBishop(int fromRow, int fromColumn, int toRow, int toColumn)
  3173.     {
  3174.         if ((toRow == fromRow) || (toColumn == fromColumn))
  3175.             return false;
  3176.  
  3177.         if ((int)Math.Abs(toRow - fromRow) != (int)Math.Abs(toColumn - fromColumn))
  3178.             return false;
  3179.  
  3180.         columnChange = 1;
  3181.         if (toRow < fromRow)
  3182.         {
  3183.             if (toColumn > fromColumn)
  3184.                 columnChange = -1;
  3185.  
  3186.             for (i = toRow + 1; i < fromRow; i++)
  3187.                 if (battlefield[i, toColumn + (i - toRow) * columnChange] != 0)
  3188.                     return false;
  3189.         }
  3190.         else
  3191.         {
  3192.             if (toColumn < fromColumn)
  3193.                 columnChange = -1;
  3194.  
  3195.             for (i = fromRow + 1; i < toRow; i++)
  3196.                 if (battlefield[i, fromColumn + (i - fromRow) * columnChange] != 0)
  3197.                     return false;
  3198.         }
  3199.  
  3200.         return true;
  3201.     }
  3202.  
  3203.     public static bool JumpOfNight(int fromRow, int fromColumn, int toRow, int toColumn)
  3204.     {
  3205.         if (((toRow == fromRow - 2) && (toColumn == fromColumn - 1))
  3206.                 || ((toRow == fromRow - 2) && (toColumn == fromColumn + 1))
  3207.                 || ((toRow == fromRow - 1) && (toColumn == fromColumn - 2))
  3208.                 || ((toRow == fromRow - 1) && (toColumn == fromColumn + 2))
  3209.                 || ((toRow == fromRow + 1) && (toColumn == fromColumn - 2))
  3210.                 || ((toRow == fromRow + 1) && (toColumn == fromColumn + 2))
  3211.                 || ((toRow == fromRow + 2) && (toColumn == fromColumn - 1))
  3212.                 || ((toRow == fromRow + 2) && (toColumn == fromColumn + 1)))
  3213.             return true;
  3214.         else
  3215.             return false;
  3216.     }
  3217.  
  3218.     public static bool JumpOfPawn(int player, int fromR, int fromColumn, int toRow, int toColumn, bool taking = false, bool exchanging = false)
  3219.     {
  3220.         if ((toRow == fromR) || (toColumn - fromColumn < -1) || (1 < toColumn - fromColumn) || (toRow - fromR < -2) || (2 < toRow - fromR))
  3221.             return false;
  3222.  
  3223.         if (taking && (toColumn == fromColumn))
  3224.             return false;
  3225.  
  3226.         if (!taking && (toColumn != fromColumn))
  3227.             return false;
  3228.  
  3229.         if (taking && ((toRow - fromR == 2) || (toRow - fromR == -2)))
  3230.             return false;
  3231.  
  3232.         if (player == 0)
  3233.         {
  3234.             if (toRow < fromR)
  3235.                 return false;
  3236.  
  3237.             if ((toRow - fromR == 2) && (toColumn != fromColumn))
  3238.                 return false;
  3239.  
  3240.             if ((fromR != 1) && (toRow - fromR == 2))
  3241.                 return false;
  3242.  
  3243.             if (taking && (toRow - fromR == 2))
  3244.                 return false;
  3245.  
  3246.             if ((toRow - fromR == 2) && (battlefield[fromR + 1, fromColumn] != 0))
  3247.                 return false;
  3248.  
  3249.             if (exchanging && toRow < 7)
  3250.                 return false;
  3251.  
  3252.             if ((toRow == 7) && !exchanging)
  3253.                 return false;
  3254.         }
  3255.         else
  3256.         {
  3257.             if (toRow > fromR)
  3258.                 return false;
  3259.  
  3260.             if ((fromR - toRow == 2) && (toColumn != fromColumn))
  3261.                 return false;
  3262.  
  3263.             if ((fromR != 6) && (fromR - toRow == 2))
  3264.                 return false;
  3265.  
  3266.             if (taking && (fromR - toRow == 2))
  3267.                 return false;
  3268.  
  3269.             if ((fromR - toRow == 2) && (battlefield[fromR - 1, fromColumn] != 0))
  3270.                 return false;
  3271.  
  3272.             if (exchanging && 0 < toRow)
  3273.                 return false;
  3274.  
  3275.             if ((toRow == 0) && !exchanging)
  3276.                 return false;
  3277.         }
  3278.  
  3279.         return true;
  3280.     }
  3281.  
  3282.         #endregion
  3283.  
  3284.         #region Talking
  3285.  
  3286.     public static string MakeSentence()
  3287.     {
  3288.         sentence.Clear();
  3289.         if (playerToMove == 0)
  3290.             sentence.Append("White ");
  3291.         else
  3292.             sentence.Append("Black ");
  3293.  
  3294.         if (give == States.Resign)
  3295.             sentence.Append("- Resigns!");
  3296.         else if ((gotMove == drawQuestion)
  3297.                     && ((gameMode == GameModes.PlayerVsPlayer) || (gameMode == GameModes.PlayerVsComputer) || (gameMode == GameModes.ComputerVsComputer)))
  3298.             sentence.Append("wants Draw ?");
  3299.         else if (gotMove == drawByAgreement)
  3300.         {
  3301.             sentence.Clear();
  3302.             if (playerToMove == 0)
  3303.                 sentence.Append("Black accepts draw by agreement!");
  3304.             else
  3305.                 sentence.Append("White accepts draw by agreement!");
  3306.         }
  3307.         else
  3308.         {
  3309.             if (castle != Castles.noCastle)
  3310.             {
  3311.                 if ((castle == Castles.castleKingsideFree) || (castle == Castles.castleKingsideCheck) || (castle == Castles.castleKingsideDraw) || (castle == Castles.castleKingsideCheckmate))
  3312.                     sentence.Append("makes castle kingside");
  3313.                 else
  3314.                     sentence.Append("makes castle queenside");
  3315.             }
  3316.             else
  3317.             {
  3318.                 switch (savePositions[playerToMove][0][0] % 10)
  3319.                 {
  3320.                     case kingUnits: { sentence.Append("king on "); break; }
  3321.                     case queenUnits: { sentence.Append("queen on "); break; }
  3322.                     case rookUnits: { sentence.Append("rook on "); break; }
  3323.                     case bishopUnits: { sentence.Append("bishop on "); break; }
  3324.                     case nightUnits: { sentence.Append("night on "); break; }
  3325.                     case pawnUnits: { sentence.Append("pawn on "); break; }
  3326.                     default: break;
  3327.                 }
  3328.  
  3329.                 sentence.Append((char)(savePositions[playerToMove][0][2] + 97));
  3330.                 sentence.Append(" " + (savePositions[playerToMove][0][1] + 1));
  3331.                 if (takes)
  3332.                     sentence.Append(" takes");
  3333.                 else
  3334.                     sentence.Append(" moves to");
  3335.  
  3336.                 sentence.Append(" " + (char)(savePositions[playerToMove][1][2] + 97));
  3337.                 sentence.Append(" " + (savePositions[playerToMove][1][1] + 1));
  3338.                 if (exchange)
  3339.                 {
  3340.                     sentence.Append(" and exchanges with ");
  3341.                     switch (exchangeWith % 10)
  3342.                     {
  3343.                         case kingUnits: { sentence.Append("king"); break; }
  3344.                         case queenUnits: { sentence.Append("queen"); break; }
  3345.                         case rookUnits: { sentence.Append("rook"); break; }
  3346.                         case bishopUnits: { sentence.Append("bishop"); break; }
  3347.                         case nightUnits: { sentence.Append("night"); break; }
  3348.                         case pawnUnits: { sentence.Append("pawn"); break; }
  3349.                         default: break;
  3350.                     }
  3351.                 }
  3352.             }
  3353.  
  3354.             switch (give)
  3355.             {
  3356.                 case States.Free: { sentence.Append("."); break; }
  3357.                 case States.Check: { sentence.Append(" - Check!"); break; }
  3358.                 case States.Draw: { sentence.Append(" - Draw!"); break; }
  3359.                 case States.Checkmate: { sentence.Append(" - Checkmate!"); break; }
  3360.                 default: break;
  3361.             }
  3362.         }
  3363.  
  3364.         return sentence.ToString();
  3365.     }
  3366.  
  3367.     public static void SayMove(string sayThis)
  3368.     {
  3369.         using (SpeechSynthesizer say = new SpeechSynthesizer())
  3370.         {
  3371.             say.SetOutputToDefaultAudioDevice();
  3372.             say.Rate = 0;
  3373.             //say.Volume = 100;
  3374.             say.Speak(sayThis);
  3375.         }
  3376.     }
  3377.  
  3378.         #endregion
  3379.  
  3380.     #endregion
  3381.  
  3382.     #region Make move
  3383.  
  3384.     public static void MakeMove(int fromFigure, int fromRow, int fromColumn, int toFigure, int toRow, int toColumn)
  3385.     {
  3386.         battlefield[fromRow, fromColumn] = fromFigure;
  3387.         battlefield[toRow, toColumn] = toFigure;
  3388.     }
  3389.  
  3390.     #endregion
  3391.  
  3392.     #region Check for check
  3393.  
  3394.     public static bool Checks(int player)
  3395.     {
  3396.         oppositeKing = figures[1 - player][0][0];
  3397.         kingRow = figures[player][1][0];
  3398.         kingColumn = figures[player][2][0];
  3399.  
  3400.         #region Queen and Rook
  3401.  
  3402.         for (theRow = kingRow - 1; (0 <= theRow) && (theRow <= 7); theRow--)
  3403.             if (battlefield[theRow, kingColumn] != 0)
  3404.             {
  3405.                 if ((oppositeKing - battlefield[theRow, kingColumn] == kingUnits - queenUnits)
  3406.                         || (oppositeKing - battlefield[theRow, kingColumn] == kingUnits - rookUnits))
  3407.                     return true;
  3408.  
  3409.                 break;
  3410.             }
  3411.  
  3412.         for (theRow = kingRow + 1; (0 <= theRow) && (theRow <= 7); theRow++)
  3413.             if (battlefield[theRow, kingColumn] != 0)
  3414.             {
  3415.                 if ((oppositeKing - battlefield[theRow, kingColumn] == kingUnits - queenUnits)
  3416.                         || (oppositeKing - battlefield[theRow, kingColumn] == kingUnits - rookUnits))
  3417.                     return true;
  3418.  
  3419.                 break;
  3420.             }
  3421.  
  3422.         for (theColumn = kingColumn - 1; (0 <= theColumn) && (theColumn <= 7); theColumn--)
  3423.             if (battlefield[kingRow, theColumn] != 0)
  3424.             {
  3425.                 if ((oppositeKing - battlefield[kingRow, theColumn] == kingUnits - queenUnits)
  3426.                         || (oppositeKing - battlefield[kingRow, theColumn] == kingUnits - rookUnits))
  3427.                     return true;
  3428.  
  3429.                 break;
  3430.             }
  3431.  
  3432.         for (theColumn = kingColumn + 1; (0 <= theColumn) && (theColumn <= 7); theColumn++)
  3433.             if (battlefield[kingRow, theColumn] != 0)
  3434.             {
  3435.                 if ((oppositeKing - battlefield[kingRow, theColumn] == kingUnits - queenUnits)
  3436.                         || (oppositeKing - battlefield[kingRow, theColumn] == kingUnits - rookUnits))
  3437.                     return true;
  3438.  
  3439.                 break;
  3440.             }
  3441.  
  3442.         #endregion
  3443.  
  3444.         #region Queen and Bishop
  3445.  
  3446.         theColumn = kingColumn;
  3447.         columnChange = -1;
  3448.         for (theRow = kingRow - 1; 0 <= theRow; theRow--)
  3449.         {
  3450.             theColumn += columnChange;
  3451.             if (theColumn < 0)
  3452.                 break;
  3453.  
  3454.             if (battlefield[theRow, theColumn] != 0)
  3455.             {
  3456.                 if ((oppositeKing - battlefield[theRow, theColumn] == kingUnits - queenUnits)
  3457.                     || (oppositeKing - battlefield[theRow, theColumn] == kingUnits - bishopUnits))
  3458.                     return true;
  3459.  
  3460.                 break;
  3461.             }
  3462.         }
  3463.  
  3464.         theColumn = kingColumn;
  3465.         columnChange = 1;
  3466.         for (theRow = kingRow - 1; 0 <= theRow; theRow--)
  3467.         {
  3468.             theColumn += columnChange;
  3469.             if (7 < theColumn)
  3470.                 break;
  3471.  
  3472.             if (battlefield[theRow, theColumn] != 0)
  3473.             {
  3474.                 if ((oppositeKing - battlefield[theRow, theColumn] == kingUnits - queenUnits)
  3475.                     || (oppositeKing - battlefield[theRow, theColumn] == kingUnits - bishopUnits))
  3476.                     return true;
  3477.  
  3478.                 break;
  3479.             }
  3480.         }
  3481.  
  3482.         theColumn = kingColumn;
  3483.         columnChange = -1;
  3484.         for (theRow = kingRow + 1; theRow <= 7; theRow++)
  3485.         {
  3486.             theColumn += columnChange;
  3487.             if (theColumn < 0)
  3488.                 break;
  3489.  
  3490.             if (battlefield[theRow, theColumn] != 0)
  3491.             {
  3492.                 if ((oppositeKing - battlefield[theRow, theColumn] == kingUnits - queenUnits)
  3493.                     || (oppositeKing - battlefield[theRow, theColumn] == kingUnits - bishopUnits))
  3494.                     return true;
  3495.  
  3496.                 break;
  3497.             }
  3498.         }
  3499.  
  3500.         theColumn = kingColumn;
  3501.         columnChange = 1;
  3502.         for (theRow = kingRow + 1; theRow <= 7; theRow++)
  3503.         {
  3504.             theColumn += columnChange;
  3505.             if (7 < theColumn)
  3506.                 break;
  3507.  
  3508.             if (battlefield[theRow, theColumn] != 0)
  3509.             {
  3510.                 if ((oppositeKing - battlefield[theRow, theColumn] == kingUnits - queenUnits)
  3511.                     || (oppositeKing - battlefield[theRow, theColumn] == kingUnits - bishopUnits))
  3512.                     return true;
  3513.  
  3514.                 break;
  3515.             }
  3516.         }
  3517.  
  3518.         #endregion
  3519.  
  3520.         #region Night
  3521.  
  3522.         if ((0 <= kingRow - 2) && (0 <= kingColumn - 1) && (oppositeKing - battlefield[kingRow - 2, kingColumn - 1] == kingUnits - nightUnits))
  3523.             return true;
  3524.  
  3525.         if ((0 <= kingRow - 1) && (0 <= kingColumn - 2) && (oppositeKing - battlefield[kingRow - 1, kingColumn - 2] == kingUnits - nightUnits))
  3526.             return true;
  3527.  
  3528.         if ((kingRow + 1 <= 7) && (0 <= kingColumn - 2) && (oppositeKing - battlefield[kingRow + 1, kingColumn - 2] == kingUnits - nightUnits))
  3529.             return true;
  3530.  
  3531.         if ((kingRow + 2 <= 7) && (0 <= kingColumn - 1) && (oppositeKing - battlefield[kingRow + 2, kingColumn - 1] == kingUnits - nightUnits))
  3532.             return true;
  3533.  
  3534.         if ((kingRow + 2 <= 7) && (kingColumn + 1 <= 7) && (oppositeKing - battlefield[kingRow + 2, kingColumn + 1] == kingUnits - nightUnits))
  3535.             return true;
  3536.  
  3537.         if ((kingRow + 1 <= 7) && (kingColumn + 2 <= 7) && (oppositeKing - battlefield[kingRow + 1, kingColumn + 2] == kingUnits - nightUnits))
  3538.             return true;
  3539.  
  3540.         if ((0 <= kingRow - 1) && (kingColumn + 2 <= 7) && (oppositeKing - battlefield[kingRow - 1, kingColumn + 2] == kingUnits - nightUnits))
  3541.             return true;
  3542.  
  3543.         if ((0 <= kingRow - 2) && (kingColumn + 1 <= 7) && (oppositeKing - battlefield[kingRow - 2, kingColumn + 1] == kingUnits - nightUnits))
  3544.             return true;
  3545.  
  3546.         #endregion
  3547.  
  3548.         #region Pawn
  3549.  
  3550.         if (battlefield[kingRow, kingColumn] == whiteDecimals + kingUnits)
  3551.         {
  3552.             if ((kingRow + 1 <= 7) && (0 <= kingColumn - 1) && (oppositeKing - battlefield[kingRow + 1, kingColumn - 1] == kingUnits - pawnUnits))
  3553.                 return true;
  3554.  
  3555.             if ((kingRow + 1 <= 7) && (kingColumn + 1 <= 7) && (oppositeKing - battlefield[kingRow + 1, kingColumn + 1] == kingUnits - pawnUnits))
  3556.                 return true;
  3557.         }
  3558.         else
  3559.         {
  3560.             if ((0 <= kingRow - 1) && (0 <= kingColumn - 1) && (oppositeKing - battlefield[kingRow - 1, kingColumn - 1] == kingUnits - pawnUnits))
  3561.                 return true;
  3562.  
  3563.             if ((0 <= kingRow - 1) && (kingColumn + 1 <= 7) && (oppositeKing - battlefield[kingRow - 1, kingColumn + 1] == kingUnits - pawnUnits))
  3564.                 return true;
  3565.         }
  3566.  
  3567.         #endregion
  3568.  
  3569.         return false;
  3570.     }
  3571.  
  3572.     #endregion
  3573.  
  3574.     #region Opposite's Chance
  3575.  
  3576.     public static bool OppositeAvoid()
  3577.     {
  3578.         for (figureIndex = 0; figureIndex < figures[oppositePlayer][0].Count; figureIndex++)
  3579.         {
  3580.             ClearAllFieldsForLooking();
  3581.             if (IsThereLegalMoveThisFigure())
  3582.                 return true;
  3583.         }
  3584.  
  3585.         return false;
  3586.     }
  3587.  
  3588.     public static bool IsThereLegalMoveThisFigure()
  3589.     {
  3590.         SaveOppositePositionsWithoutRealTakes(oppositePlayer, 0, figures[oppositePlayer][0][figureIndex], figures[oppositePlayer][1][figureIndex], figures[oppositePlayer][2][figureIndex]);
  3591.  
  3592.         king = figures[playerToMove][0][0];
  3593.         oppositeKing = figures[oppositePlayer][0][0];
  3594.  
  3595.         thisKing = oppositeKing;
  3596.         otherKing = king;
  3597.  
  3598.         figureRow = savePositions[oppositePlayer][0][1];
  3599.         figureColumn = savePositions[oppositePlayer][0][2];
  3600.  
  3601.         switch (figures[oppositePlayer][0][figureIndex] % 10)
  3602.         {
  3603.             case kingUnits: return LegalMovesThisKing(true);
  3604.             case queenUnits: return LegalMovesThisQueen(true);
  3605.             case rookUnits: return LegalMovesThisRook(true);
  3606.             case bishopUnits: return LegalMovesThisBishop(true);
  3607.             case nightUnits: return LegalMovesThisNight(true);
  3608.             case pawnUnits: return LegalMovesThisPawn(true);
  3609.             default: return false;
  3610.         }
  3611.     }
  3612.  
  3613.     #endregion
  3614.  
  3615.     #region Legal moves on this figure
  3616.  
  3617.     public static bool LegalMovesThisKing(bool stopAtFirstMeeting)
  3618.     {
  3619.         if (stopAtFirstMeeting)
  3620.         {
  3621.             KingMovement(playerToMove);
  3622.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3623.                 if (TryMakeMoveThisKing(oppositePlayer, toThisField))
  3624.                     return true;
  3625.         }
  3626.         else
  3627.         {
  3628.             KingMovement(oppositePlayer);
  3629.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3630.                 if (TryMakeMoveThisKing(playerToMove, toThisField))
  3631.                     AddPossibleMove();
  3632.         }
  3633.  
  3634.         return false;
  3635.     }
  3636.  
  3637.     public static bool LegalMovesThisQueen(bool stopAtFirstMeeting)
  3638.     {
  3639.         QeenMovement();
  3640.         if (stopAtFirstMeeting)
  3641.         {
  3642.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3643.                 if (TryMakeMoveNotKing(oppositePlayer, toThisField))
  3644.                     return true;
  3645.         }
  3646.         else
  3647.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3648.                 if (TryMakeMoveNotKing(playerToMove, toThisField))
  3649.                     AddPossibleMove();
  3650.  
  3651.         return false;
  3652.     }
  3653.  
  3654.     public static bool LegalMovesThisRook(bool stopAtFirstMeeting)
  3655.     {
  3656.         RookMovement();
  3657.         if (stopAtFirstMeeting)
  3658.         {
  3659.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3660.                 if (TryMakeMoveNotKing(oppositePlayer, toThisField))
  3661.                     return true;
  3662.         }
  3663.         else
  3664.         {
  3665.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3666.                 if (TryMakeMoveNotKing(playerToMove, toThisField))
  3667.                     AddPossibleMove();
  3668.         }
  3669.  
  3670.         return false;
  3671.     }
  3672.  
  3673.     public static bool LegalMovesThisBishop(bool stopAtFirstMeeting)
  3674.     {
  3675.         BishopMovement();
  3676.         if (stopAtFirstMeeting)
  3677.         {
  3678.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3679.                 if (TryMakeMoveNotKing(oppositePlayer, toThisField))
  3680.                     return true;
  3681.         }
  3682.         else
  3683.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3684.                 if (TryMakeMoveNotKing(playerToMove, toThisField))
  3685.                     AddPossibleMove();
  3686.  
  3687.         return false;
  3688.     }
  3689.  
  3690.     public static bool LegalMovesThisNight(bool stopAtFirstMeeting)
  3691.     {
  3692.         NightMovement();
  3693.         if (stopAtFirstMeeting)
  3694.         {
  3695.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3696.                 if (TryMakeMoveNotKing(oppositePlayer, toThisField))
  3697.                     return true;
  3698.         }
  3699.         else
  3700.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3701.                 if (TryMakeMoveNotKing(playerToMove, toThisField))
  3702.                     AddPossibleMove();
  3703.  
  3704.         return false;
  3705.     }
  3706.  
  3707.     public static bool LegalMovesThisPawn(bool stopAtFirstMeeting)
  3708.     {
  3709.         if (stopAtFirstMeeting)
  3710.         {
  3711.             PawnMovement(oppositePlayer);
  3712.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3713.                 if (TryMakeMoveNotKing(oppositePlayer, toThisField))
  3714.                     return true;
  3715.         }
  3716.         else
  3717.         {
  3718.             PawnMovement(playerToMove);
  3719.             for (toThisField = 0; toThisField < lookOnlyThisPositions[0].Count; toThisField++)
  3720.                 if (TryMakeMoveNotKing(playerToMove, toThisField))
  3721.                     AddPossibleMove();
  3722.         }
  3723.  
  3724.         return false;
  3725.     }
  3726.  
  3727.     public static bool TryMakeMoveThisKing(int player, int toThisField)
  3728.     {
  3729.         SaveOppositePositionsWithoutRealTakes(player, 1, lookOnlyThisPositions[0][toThisField], lookOnlyThisPositions[1][toThisField], lookOnlyThisPositions[2][toThisField]);
  3730.         figures[player][1][0] = savePositions[player][1][1];
  3731.         figures[player][2][0] = savePositions[player][1][2];
  3732.         MakeMove(0, savePositions[player][0][1], savePositions[player][0][2], savePositions[player][0][0], savePositions[player][1][1], savePositions[player][1][2]);
  3733.         willBeUnderCheck = Checks(player);
  3734.         figures[player][1][0] = savePositions[player][0][1];
  3735.         figures[player][2][0] = savePositions[player][0][2];
  3736.         MakeMove(savePositions[player][0][0], savePositions[player][0][1], savePositions[player][0][2], savePositions[player][1][0], savePositions[player][1][1], savePositions[player][1][2]);
  3737.         return !willBeUnderCheck;
  3738.     }
  3739.  
  3740.     public static bool TryMakeMoveNotKing(int player, int toThisField)
  3741.     {
  3742.         SaveOppositePositionsWithoutRealTakes(player, 1, lookOnlyThisPositions[0][toThisField], lookOnlyThisPositions[1][toThisField], lookOnlyThisPositions[2][toThisField]);
  3743.         MakeMove(0, savePositions[player][0][1], savePositions[player][0][2], savePositions[player][0][0], savePositions[player][1][1], savePositions[player][1][2]);
  3744.         willBeUnderCheck = Checks(player);
  3745.         MakeMove(savePositions[player][0][0], savePositions[player][0][1], savePositions[player][0][2], savePositions[player][1][0], savePositions[player][1][1], savePositions[player][1][2]);
  3746.         return !willBeUnderCheck;
  3747.     }
  3748.  
  3749.     public static void SaveOppositePositionsWithoutRealTakes(int player, int fromOrTo, int figure, int row, int column)
  3750.     {
  3751.         savePositions[player][fromOrTo][0] = figure;
  3752.         savePositions[player][fromOrTo][1] = row;
  3753.         savePositions[player][fromOrTo][2] = column;
  3754.     }
  3755.  
  3756.     #endregion
  3757.  
  3758.     #region Movements
  3759.  
  3760.     public static void KingMovement(int player)
  3761.     {
  3762.         kingRow = figures[player][1][0];
  3763.         kingColumn = figures[player][2][0];
  3764.         for (rowChange = -1; rowChange <= 1; rowChange++)
  3765.             for (columnChange = -1; columnChange <= 1; columnChange++)
  3766.                 if (!((rowChange == 0) && (columnChange == 0)))
  3767.                 {
  3768.                     rowMovement = figureRow + rowChange;
  3769.                     columnMovement = figureColumn + columnChange;
  3770.                     if ((0 <= rowMovement) && (rowMovement <= 7) && (0 <= columnMovement) && (columnMovement <= 7))
  3771.                     {
  3772.                         theField = battlefield[rowMovement, columnMovement];
  3773.                         if (((theField <= thisKing - kingUnits) || (thisKing < theField))
  3774.                                 && (theField != otherKing)
  3775.                                     && ((rowMovement - kingRow < -1) || (1 < rowMovement - kingRow) || (columnMovement - kingColumn < -1) || (1 < columnMovement - kingColumn)))
  3776.                             AddFieldForLooking(theField, rowMovement, columnMovement);
  3777.                     }
  3778.                 }
  3779.     }
  3780.  
  3781.     public static void QeenMovement()
  3782.     {
  3783.         RookMovement();
  3784.         BishopMovement();
  3785.     }
  3786.  
  3787.     public static void RookMovement()
  3788.     {
  3789.         rowMovement = figureRow;
  3790.         for (columnMovement = figureColumn - 1; 0 <= columnMovement; columnMovement--)
  3791.         {
  3792.             theField = battlefield[rowMovement, columnMovement];
  3793.             if (theField == 0)
  3794.                 AddFieldForLooking(theField, rowMovement, columnMovement);
  3795.             else
  3796.             {
  3797.                 if ((otherKing - kingUnits < theField) && (theField < otherKing))
  3798.                     AddFieldForLooking(theField, rowMovement, columnMovement);
  3799.  
  3800.                 break;
  3801.             }
  3802.         }
  3803.  
  3804.         for (columnMovement = figureColumn + 1; columnMovement <= 7; columnMovement++)
  3805.         {
  3806.             theField = battlefield[rowMovement, columnMovement];
  3807.             if (theField == 0)
  3808.                 AddFieldForLooking(theField, rowMovement, columnMovement);
  3809.             else
  3810.             {
  3811.                 if ((otherKing - kingUnits < theField) && (theField < otherKing))
  3812.                     AddFieldForLooking(theField, rowMovement, columnMovement);
  3813.  
  3814.                 break;
  3815.             }
  3816.         }
  3817.  
  3818.         columnMovement = figureColumn;
  3819.         for (rowMovement = figureRow - 1; 0 <= rowMovement; rowMovement--)
  3820.         {
  3821.             theField = battlefield[rowMovement, columnMovement];
  3822.             if (theField == 0)
  3823.                 AddFieldForLooking(theField, rowMovement, columnMovement);
  3824.             else
  3825.             {
  3826.                 if ((otherKing - kingUnits < theField) && (theField < otherKing))
  3827.                     AddFieldForLooking(theField, rowMovement, columnMovement);
  3828.  
  3829.                 break;
  3830.             }
  3831.         }
  3832.  
  3833.         for (rowMovement = figureRow + 1; rowMovement <= 7; rowMovement++)
  3834.         {
  3835.             theField = battlefield[rowMovement, columnMovement];
  3836.             if (theField == 0)
  3837.                 AddFieldForLooking(theField, rowMovement, columnMovement);
  3838.             else
  3839.             {
  3840.                 if ((otherKing - kingUnits < theField) && (theField < otherKing))
  3841.                     AddFieldForLooking(theField, rowMovement, columnMovement);
  3842.  
  3843.                 break;
  3844.             }
  3845.         }
  3846.     }
  3847.  
  3848.     public static void BishopMovement()
  3849.     {
  3850.         BishopMovementAdding(-1, -1);
  3851.         BishopMovementAdding(-1, 1);
  3852.         BishopMovementAdding(1, -1);
  3853.         BishopMovementAdding(1, 1);
  3854.     }
  3855.  
  3856.     public static void BishopMovementAdding(int rChange, int cChange)
  3857.     {
  3858.         columnMovement = figureColumn;
  3859.         for (rowMovement = figureRow + rChange; (0 <= rowMovement) && (rowMovement <= 7); rowMovement += rChange)
  3860.         {
  3861.             columnMovement += cChange;
  3862.             if ((0 <= columnMovement) && (columnMovement <= 7))
  3863.             {
  3864.                 theField = battlefield[rowMovement, columnMovement];
  3865.                 if (theField == 0)
  3866.                     AddFieldForLooking(theField, rowMovement, columnMovement);
  3867.                 else
  3868.                 {
  3869.                     if ((otherKing - kingUnits < theField) && (theField < otherKing))
  3870.                         AddFieldForLooking(theField, rowMovement, columnMovement);
  3871.  
  3872.                     break;
  3873.                 }
  3874.             }
  3875.             else
  3876.                 break;
  3877.         }
  3878.     }
  3879.  
  3880.     public static void NightMovement()
  3881.     {
  3882.         NightMovementAdding(figureRow - 2, figureColumn - 1);
  3883.         NightMovementAdding(figureRow - 2, figureColumn + 1);
  3884.         NightMovementAdding(figureRow - 1, figureColumn - 2);
  3885.         NightMovementAdding(figureRow - 1, figureColumn + 2);
  3886.         NightMovementAdding(figureRow + 1, figureColumn - 2);
  3887.         NightMovementAdding(figureRow + 1, figureColumn + 2);
  3888.         NightMovementAdding(figureRow + 2, figureColumn - 1);
  3889.         NightMovementAdding(figureRow + 2, figureColumn + 1);
  3890.  
  3891.         //for (rowChange = -2; rowChange <= 2; rowChange++)
  3892.         //{
  3893.         //    rowMovement = figureRow + rowChange;
  3894.         //    if ((0 <= rowMovement) && (rowMovement <= 7))
  3895.         //        for (columnChange = -2; columnChange <= 2; columnChange++)
  3896.         //        {
  3897.         //            columnMovement = figureColumn + columnChange;
  3898.         //            theField = battlefield[rowMovement, columnMovement];
  3899.         //            if ((0 <= columnMovement) && (columnMovement <= 7)
  3900.         //                && (rowChange * rowChange + columnChange * columnChange == 5)
  3901.         //                    && ((theField <= oppositeKing - kingUnits) || (oppositeKing < theField))
  3902.         //                        && (theField != king))
  3903.         //                AddFieldForLooking(theField, rowMovement, columnMovement);
  3904.         //        }
  3905.         //}
  3906.     }
  3907.  
  3908.     public static void NightMovementAdding(int rMovement, int cMovement)
  3909.     {
  3910.         if ((0 <= rMovement) && (rMovement <= 7) && (0 <= cMovement) && (cMovement <= 7))
  3911.         {
  3912.             theField = battlefield[rMovement, cMovement];
  3913.             if (((theField <= thisKing - kingUnits) || (thisKing < theField))
  3914.                     && (theField != otherKing))
  3915.                 AddFieldForLooking(theField, rMovement, cMovement);
  3916.         }
  3917.     }
  3918.  
  3919.     public static void PawnMovement(int player)
  3920.     {
  3921.         if (player == 0)
  3922.             rowChange = 1;
  3923.         else
  3924.             rowChange = -1;
  3925.  
  3926.         rowMovement = figureRow + rowChange;
  3927.         if ((0 <= rowMovement) && (rowMovement <= 7))
  3928.         {
  3929.             for (columnChange = -1; columnChange <= 1; columnChange++)
  3930.             {
  3931.                 columnMovement = figureColumn + columnChange;
  3932.                 if ((0 <= columnMovement) && (columnMovement <= 7))
  3933.                 {
  3934.                     theField = battlefield[rowMovement, columnMovement];
  3935.                     if (columnMovement != figureColumn)
  3936.                     {
  3937.                         if ((otherKing - kingUnits < theField) && (theField < otherKing))
  3938.                             AddFieldForLooking(theField, rowMovement, columnMovement);
  3939.                     }
  3940.                     else
  3941.                     {
  3942.                         if (theField == 0)
  3943.                         {
  3944.                             AddFieldForLooking(theField, rowMovement, columnMovement);
  3945.                             if (((player == 0) && (figureRow == 1)) || ((player == 1) && (figureRow == 6)))
  3946.                             {
  3947.                                 rowMovement += rowChange;
  3948.                                 theField = battlefield[rowMovement, columnMovement];
  3949.                                 if (theField == 0)
  3950.                                     AddFieldForLooking(theField, rowMovement, columnMovement);
  3951.  
  3952.                                 rowMovement -= rowChange;
  3953.                             }
  3954.                         }
  3955.                     }
  3956.                 }
  3957.             }
  3958.         }
  3959.     }
  3960.  
  3961.     #endregion
  3962.  
  3963.     #region Looking array
  3964.  
  3965.     public static void ClearAllFieldsForLooking()
  3966.     {
  3967.         lookOnlyThisPositions[0].Clear();
  3968.         lookOnlyThisPositions[1].Clear();
  3969.         lookOnlyThisPositions[2].Clear();
  3970.     }
  3971.  
  3972.     public static void AddFieldForLooking(int figure, int row, int column)
  3973.     {
  3974.         lookOnlyThisPositions[0].Add(figure);
  3975.         lookOnlyThisPositions[1].Add(row);
  3976.         lookOnlyThisPositions[2].Add(column);
  3977.     }
  3978.  
  3979.     #endregion
  3980.  
  3981.     #region Artificial Intelligence
  3982.  
  3983.     public static void FindAllPossibleMoves()
  3984.     {
  3985.         ClearAllPossibleMoves();
  3986.         for (figureIndex = 0; figureIndex < figures[playerToMove][0].Count; figureIndex++)
  3987.         {
  3988.             ClearAllFieldsForLooking();
  3989.  
  3990.             possibleMoves.Add(new List<List<int>>());
  3991.             possibleMoves[figureIndex].Add(new List<int>() { figureIndex, figures[playerToMove][0][figureIndex], figures[playerToMove][1][figureIndex], figures[playerToMove][2][figureIndex] });
  3992.  
  3993.             SaveOppositePositionsWithoutRealTakes(playerToMove, 0, figures[playerToMove][0][figureIndex], figures[playerToMove][1][figureIndex], figures[playerToMove][2][figureIndex]);
  3994.             savePositions[playerToMove][0][3] = figureIndex;
  3995.  
  3996.             king = figures[playerToMove][0][0];
  3997.             oppositeKing = figures[oppositePlayer][0][0];
  3998.  
  3999.             figureRow = savePositions[playerToMove][0][1];
  4000.             figureColumn = savePositions[playerToMove][0][2];
  4001.  
  4002.             thisKing = king;
  4003.             otherKing = oppositeKing;
  4004.  
  4005.             switch (figures[playerToMove][0][figureIndex] % 10)
  4006.             {
  4007.                 case kingUnits: LegalMovesThisKing(false); break;
  4008.                 case queenUnits: LegalMovesThisQueen(false); break;
  4009.                 case rookUnits: LegalMovesThisRook(false); break;
  4010.                 case bishopUnits: LegalMovesThisBishop(false); break;
  4011.                 case nightUnits: LegalMovesThisNight(false); break;
  4012.                 case pawnUnits: LegalMovesThisPawn(false); break;
  4013.                 default: break;
  4014.             }
  4015.         }
  4016.  
  4017.         for (i = possibleMoves.Count - 1; 0 <= i; i--)
  4018.             if (possibleMoves[i].Count < 2)
  4019.                 possibleMoves.RemoveAt(i);
  4020.     }
  4021.  
  4022.     public static void ClearAllPossibleMoves()
  4023.     {
  4024.         possibleMoves.Clear();
  4025.     }
  4026.  
  4027.     public static void AddPossibleMove()
  4028.     {
  4029.         possibleMoves[figureIndex].Add(new List<int>() { figureIndex, savePositions[playerToMove][1][0], savePositions[playerToMove][1][1], savePositions[playerToMove][1][2] });
  4030.     }
  4031.  
  4032.     public static void ChoosePossibleMove()
  4033.     {
  4034.         takes = false;
  4035.         exchange = false;
  4036.  
  4037.         randomIndex = randomGenerator.Next(0, possibleMoves.Count);
  4038.         randomOnePossibleMovement = randomGenerator.Next(1, possibleMoves[randomIndex].Count);
  4039.         if (possibleMoves[randomIndex][randomOnePossibleMovement][1] != 0)
  4040.         {
  4041.             takes = true;
  4042.             savePositions[playerToMove][1][3] = ReturnIndexOfFigure(oppositePlayer, possibleMoves[randomIndex][randomOnePossibleMovement][2], possibleMoves[randomIndex][randomOnePossibleMovement][3]);
  4043.             materials[oppositePlayer] -= figures[oppositePlayer][0][savePositions[playerToMove][1][3]];
  4044.             takenFigures[oppositePlayer].Add(figures[oppositePlayer][0][savePositions[playerToMove][1][3]]);
  4045.             RemoveFigureAtPosition(oppositePlayer, savePositions[playerToMove][1][3]);
  4046.         }
  4047.  
  4048.         MakeMove(0, possibleMoves[randomIndex][0][2], possibleMoves[randomIndex][0][3], possibleMoves[randomIndex][0][1], possibleMoves[randomIndex][randomOnePossibleMovement][2], possibleMoves[randomIndex][randomOnePossibleMovement][3]);
  4049.         figures[playerToMove][1][possibleMoves[randomIndex][0][0]] = possibleMoves[randomIndex][randomOnePossibleMovement][2];
  4050.         figures[playerToMove][2][possibleMoves[randomIndex][0][0]] = possibleMoves[randomIndex][randomOnePossibleMovement][3];
  4051.         if ((figures[playerToMove][0][possibleMoves[randomIndex][0][0]] == figures[playerToMove][0][0] - kingUnits + pawnUnits)
  4052.             && (((playerToMove == 0) && (figures[playerToMove][1][possibleMoves[randomIndex][0][0]] == 7))
  4053.                 || ((playerToMove == 1) && (figures[playerToMove][1][possibleMoves[randomIndex][0][0]] == 0))))
  4054.         {
  4055.             exchange = true;
  4056.             exchangeWith = randomGenerator.Next(figures[playerToMove][0][0] - kingUnits + pawnUnits + 1, figures[playerToMove][0][0]);
  4057.             battlefield[possibleMoves[randomIndex][randomOnePossibleMovement][2], possibleMoves[randomIndex][randomOnePossibleMovement][3]] = exchangeWith;
  4058.             figures[playerToMove][0][possibleMoves[randomIndex][0][0]] = exchangeWith;
  4059.             materials[playerToMove] += exchangeWith - (figures[playerToMove][0][0] - kingUnits) - pawnUnits;
  4060.         }
  4061.  
  4062.         if (Checks(oppositePlayer))
  4063.         {
  4064.             if (OppositeAvoid())
  4065.                 give = States.Check;
  4066.             else
  4067.                 give = States.Checkmate;
  4068.         }
  4069.         else
  4070.         {
  4071.             if (OppositeAvoid())
  4072.                 give = States.Free;
  4073.             else
  4074.                 give = States.Draw;
  4075.         }
  4076.  
  4077.         BuildTextOfMove();
  4078.     }
  4079.  
  4080.     public static void BuildTextOfMove()
  4081.     {
  4082.         buildTextOfMove.Clear();
  4083.         buildTextOfMove.Append(FigureSign(possibleMoves[randomIndex][0][1]));
  4084.         buildTextOfMove.Append((char)(possibleMoves[randomIndex][0][3] + 97));
  4085.         buildTextOfMove.Append((possibleMoves[randomIndex][0][2] + 1));
  4086.         if (takes)
  4087.         {
  4088.             randomTakesSymbol = randomGenerator.Next(0, 2);
  4089.             buildTextOfMove.Append(string.Format(randomTakesSymbol == 0 ? "x" : ":"));
  4090.         }
  4091.         else
  4092.             buildTextOfMove.Append("-");
  4093.  
  4094.         buildTextOfMove.Append((char)(possibleMoves[randomIndex][randomOnePossibleMovement][3] + 97));
  4095.         buildTextOfMove.Append((possibleMoves[randomIndex][randomOnePossibleMovement][2] + 1));
  4096.         if (exchange)
  4097.             buildTextOfMove.Append("=" + FigureSign(exchangeWith));
  4098.  
  4099.         if (give == States.Check)
  4100.             buildTextOfMove.Append("+");
  4101.         else if (give == States.Checkmate)
  4102.             buildTextOfMove.Append("#");
  4103.         else if (give == States.Draw)
  4104.             buildTextOfMove.Append("=");
  4105.  
  4106.         savePositions[playerToMove][0][0] = possibleMoves[randomIndex][0][1];
  4107.         savePositions[playerToMove][0][1] = possibleMoves[randomIndex][0][2];
  4108.         savePositions[playerToMove][0][2] = possibleMoves[randomIndex][0][3];
  4109.         savePositions[playerToMove][1][1] = possibleMoves[randomIndex][randomOnePossibleMovement][2];
  4110.         savePositions[playerToMove][1][2] = possibleMoves[randomIndex][randomOnePossibleMovement][3];
  4111.     }
  4112.  
  4113.     public static string FigureSign(int figure)
  4114.     {
  4115.         switch (figure % 10)
  4116.         {
  4117.             case nightUnits: return "N";
  4118.             case bishopUnits: return "B";
  4119.             case rookUnits: return "R";
  4120.             case queenUnits: return "Q";
  4121.             case kingUnits: return "K";
  4122.             default: return "";
  4123.         }
  4124.     }
  4125.  
  4126.     #endregion
  4127.  
  4128.     #region Players' figures
  4129.  
  4130.     //public static void MoveFigure(int player, int figure, int row, int column)
  4131.     //{
  4132.     //    for (i = 0; i < figures[player][0].Count; i++)
  4133.     //        if ((figures[player][0][i] == figure) && (figures[player][1][i] == row) && (figures[player][2][i] == column))
  4134.     //        {
  4135.     //            figures[player][1][i] = row;
  4136.     //            figures[player][2][i] = column;
  4137.     //            break;
  4138.     //        }
  4139.     //}
  4140.  
  4141.     //public static void RemoveFigure(int player, int figure, int row, int column)
  4142.     //{
  4143.     //    for (i = 0; i < figures[player][0].Count; i++)
  4144.     //        if ((figures[player][0][i] == figure) && (figures[player][1][i] == row) && (figures[player][2][i] == column))
  4145.     //        {
  4146.     //            RemoveFigureAtPosition(player, i);
  4147.     //            break;
  4148.     //        }
  4149.     //}
  4150.  
  4151.     public static void RemoveFigureAtPosition(int player, int index)
  4152.     {
  4153.         figures[player][0].RemoveAt(index);
  4154.         figures[player][1].RemoveAt(index);
  4155.         figures[player][2].RemoveAt(index);
  4156.     }
  4157.  
  4158.     //public static void AddFigure(int player, int figure, int row, int column)
  4159.     //{
  4160.     //    firstOfExchangeKind = figures[player][0].Count;
  4161.     //    for (i = 0; i < figures[player][0].Count; i++)
  4162.     //        if (figures[player][0][i] <= figure)
  4163.     //        {
  4164.     //            firstOfExchangeKind = i;
  4165.     //            break;
  4166.     //        }
  4167.  
  4168.     //    AddFigureAtPosition(player, firstOfExchangeKind, figure, row, column);
  4169.     //}
  4170.  
  4171.     public static void AddFigureAtPosition(int player, int index, int figure, int row, int column)
  4172.     {
  4173.         figures[player][0].Insert(index, figure);
  4174.         figures[player][1].Insert(index, row);
  4175.         figures[player][2].Insert(index, column);
  4176.     }
  4177.  
  4178.     #endregion
  4179.  
  4180.     #region Change player to move
  4181.  
  4182.     public static void ChangePlayerToMove()
  4183.     {
  4184.         oppositePlayer = playerToMove;
  4185.         playerToMove = 1 - playerToMove;
  4186.     }
  4187.  
  4188.     #endregion
  4189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement