Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 446.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. //using System.Linq;
  7. using System.Text;
  8. // No need for threading (maybe in future versions)
  9. //using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. // Added presentationCore.dll reference
  12. using System.Windows.Input;
  13. using System.IO;
  14.  
  15. // Additional changes in HuoChess Windows 8:
  16. // - Remove ComputerMove(Skakiera); from Enter_Move() function!
  17.  
  18. namespace HuoChessW8
  19. {
  20. public partial class Form1 : Form
  21. {
  22. // Parameter which determined the weight of danger in the counting of the score of positions
  23.  
  24. //v0.95
  25. //public static int humanDangerParameter = 0;
  26. //public static int computerDangerParameter = 1;
  27.  
  28. public static int playerClicks;
  29. public static int playerClick_X;
  30. public static int playerClick_Y;
  31. public static int i_MouseIsIn;
  32. public static int j_MouseIsIn;
  33. public static int rankClicked;
  34. public static String columnClicked;
  35. //public static String[,] RSkakiera = new String[8, 8];
  36. // the chessboard (=skakiera in Greek)
  37. //public static String[,] Skakiera = new String[8, 8]; // Δήλωση πίνακα που αντιπροσωπεύει τη σκακιέρα
  38.  
  39. public Form1()
  40. {
  41. InitializeComponent();
  42. }
  43.  
  44. private void button_exit_Click(object sender, EventArgs e)
  45. {
  46. this.Close();
  47. }
  48.  
  49. private void skakiera_Click(object sender, EventArgs e)
  50. {
  51. MessageBox.Show("skakiera clicked");
  52. }
  53.  
  54.  
  55. //2012: redraw the pictureboxes
  56. private void RedrawTheSkakiera(string[,] RSkakiera)
  57. {
  58. //Form1 huoForm = new Form1();
  59. string piecePath = "";
  60. string path = Directory.GetCurrentDirectory();
  61.  
  62. for (int i = 0; i <= 7; i++)
  63. {
  64. for (int j = 0; j <= 7; j++)
  65. {
  66. piecePath = "";
  67.  
  68. if (RSkakiera[(i), (j)].CompareTo("White Pawn") == 0)
  69. piecePath = "\\Resources\\WPawn.gif";
  70. else if (RSkakiera[(i), (j)].CompareTo("White Rook") == 0)
  71. piecePath = "\\Resources\\WRook.gif";
  72. else if (RSkakiera[(i), (j)].CompareTo("White Knight") == 0)
  73. piecePath = "\\Resources\\WKnight.gif";
  74. else if (RSkakiera[(i), (j)].CompareTo("White Bishop") == 0)
  75. piecePath = "\\Resources\\WBishop.gif";
  76. else if (RSkakiera[(i), (j)].CompareTo("White Queen") == 0)
  77. piecePath = "\\Resources\\WQueen.gif";
  78. else if (RSkakiera[(i), (j)].CompareTo("White King") == 0)
  79. piecePath = "\\Resources\\WKing.gif";
  80. else if (RSkakiera[(i), (j)].CompareTo("Black Pawn") == 0)
  81. piecePath = "\\Resources\\BPawn.gif";
  82. else if (RSkakiera[(i), (j)].CompareTo("Black Rook") == 0)
  83. piecePath = "\\Resources\\BRook.gif";
  84. else if (RSkakiera[(i), (j)].CompareTo("Black Knight") == 0)
  85. piecePath = "\\Resources\\BKnight.gif";
  86. else if (RSkakiera[(i), (j)].CompareTo("Black Bishop") == 0)
  87. piecePath = "\\Resources\\BBishop.gif";
  88. else if (RSkakiera[(i), (j)].CompareTo("Black Queen") == 0)
  89. piecePath = "\\Resources\\BQueen.gif";
  90. else if (RSkakiera[(i), (j)].CompareTo("Black King") == 0)
  91. piecePath = "\\Resources\\BKing.gif";
  92. else if (RSkakiera[(i), (j)].CompareTo("") == 0)
  93. piecePath = "\\Resources\\nothing.gif";
  94.  
  95. if ((i == 0) & (j == 0))
  96. pictureBoxA1.Load(string.Concat(path, piecePath));
  97. else if ((i == 0) & (j == 1))
  98. pictureBoxA2.Load(string.Concat(path, piecePath));
  99. else if ((i == 0) & (j == 2))
  100. pictureBoxA3.Load(string.Concat(path, piecePath));
  101. else if ((i == 0) & (j == 3))
  102. pictureBoxA4.Load(string.Concat(path, piecePath));
  103. else if ((i == 0) & (j == 4))
  104. pictureBoxA5.Load(string.Concat(path, piecePath));
  105. else if ((i == 0) & (j == 5))
  106. pictureBoxA6.Load(string.Concat(path, piecePath));
  107. else if ((i == 0) & (j == 6))
  108. pictureBoxA7.Load(string.Concat(path, piecePath));
  109. else if ((i == 0) & (j == 7))
  110. pictureBoxA8.Load(string.Concat(path, piecePath));
  111.  
  112. else if ((i == 1) & (j == 0))
  113. pictureBoxB1.Load(string.Concat(path, piecePath));
  114. else if ((i == 1) & (j == 1))
  115. pictureBoxB2.Load(string.Concat(path, piecePath));
  116. else if ((i == 1) & (j == 2))
  117. pictureBoxB3.Load(string.Concat(path, piecePath));
  118. else if ((i == 1) & (j == 3))
  119. pictureBoxB4.Load(string.Concat(path, piecePath));
  120. else if ((i == 1) & (j == 4))
  121. pictureBoxB5.Load(string.Concat(path, piecePath));
  122. else if ((i == 1) & (j == 5))
  123. pictureBoxB6.Load(string.Concat(path, piecePath));
  124. else if ((i == 1) & (j == 6))
  125. pictureBoxB7.Load(string.Concat(path, piecePath));
  126. else if ((i == 1) & (j == 7))
  127. pictureBoxB8.Load(string.Concat(path, piecePath));
  128.  
  129. else if ((i == 2) & (j == 0))
  130. pictureBoxC1.Load(string.Concat(path, piecePath));
  131. else if ((i == 2) & (j == 1))
  132. pictureBoxC2.Load(string.Concat(path, piecePath));
  133. else if ((i == 2) & (j == 2))
  134. pictureBoxC3.Load(string.Concat(path, piecePath));
  135. else if ((i == 2) & (j == 3))
  136. pictureBoxC4.Load(string.Concat(path, piecePath));
  137. else if ((i == 2) & (j == 4))
  138. pictureBoxC5.Load(string.Concat(path, piecePath));
  139. else if ((i == 2) & (j == 5))
  140. pictureBoxC6.Load(string.Concat(path, piecePath));
  141. else if ((i == 2) & (j == 6))
  142. pictureBoxC7.Load(string.Concat(path, piecePath));
  143. else if ((i == 2) & (j == 7))
  144. pictureBoxC8.Load(string.Concat(path, piecePath));
  145.  
  146. else if ((i == 3) & (j == 0))
  147. pictureBoxD1.Load(string.Concat(path, piecePath));
  148. else if ((i == 3) & (j == 1))
  149. pictureBoxD2.Load(string.Concat(path, piecePath));
  150. else if ((i == 3) & (j == 2))
  151. pictureBoxD3.Load(string.Concat(path, piecePath));
  152. else if ((i == 3) & (j == 3))
  153. pictureBoxD4.Load(string.Concat(path, piecePath));
  154. else if ((i == 3) & (j == 4))
  155. pictureBoxD5.Load(string.Concat(path, piecePath));
  156. else if ((i == 3) & (j == 5))
  157. pictureBoxD6.Load(string.Concat(path, piecePath));
  158. else if ((i == 3) & (j == 6))
  159. pictureBoxD7.Load(string.Concat(path, piecePath));
  160. else if ((i == 3) & (j == 7))
  161. pictureBoxD8.Load(string.Concat(path, piecePath));
  162.  
  163. else if ((i == 4) & (j == 0))
  164. pictureBoxE1.Load(string.Concat(path, piecePath));
  165. else if ((i == 4) & (j == 1))
  166. pictureBoxE2.Load(string.Concat(path, piecePath));
  167. else if ((i == 4) & (j == 2))
  168. pictureBoxE3.Load(string.Concat(path, piecePath));
  169. else if ((i == 4) & (j == 3))
  170. pictureBoxE4.Load(string.Concat(path, piecePath));
  171. else if ((i == 4) & (j == 4))
  172. pictureBoxE5.Load(string.Concat(path, piecePath));
  173. else if ((i == 4) & (j == 5))
  174. pictureBoxE6.Load(string.Concat(path, piecePath));
  175. else if ((i == 4) & (j == 6))
  176. pictureBoxE7.Load(string.Concat(path, piecePath));
  177. else if ((i == 4) & (j == 7))
  178. pictureBoxE8.Load(string.Concat(path, piecePath));
  179.  
  180. else if ((i == 5) & (j == 0))
  181. pictureBoxF1.Load(string.Concat(path, piecePath));
  182. else if ((i == 5) & (j == 1))
  183. pictureBoxF2.Load(string.Concat(path, piecePath));
  184. else if ((i == 5) & (j == 2))
  185. pictureBoxF3.Load(string.Concat(path, piecePath));
  186. else if ((i == 5) & (j == 3))
  187. pictureBoxF4.Load(string.Concat(path, piecePath));
  188. else if ((i == 5) & (j == 4))
  189. pictureBoxF5.Load(string.Concat(path, piecePath));
  190. else if ((i == 5) & (j == 5))
  191. pictureBoxF6.Load(string.Concat(path, piecePath));
  192. else if ((i == 5) & (j == 6))
  193. pictureBoxF7.Load(string.Concat(path, piecePath));
  194. else if ((i == 5) & (j == 7))
  195. pictureBoxF8.Load(string.Concat(path, piecePath));
  196.  
  197. else if ((i == 6) & (j == 0))
  198. pictureBoxG1.Load(string.Concat(path, piecePath));
  199. else if ((i == 6) & (j == 1))
  200. pictureBoxG2.Load(string.Concat(path, piecePath));
  201. else if ((i == 6) & (j == 2))
  202. pictureBoxG3.Load(string.Concat(path, piecePath));
  203. else if ((i == 6) & (j == 3))
  204. pictureBoxG4.Load(string.Concat(path, piecePath));
  205. else if ((i == 6) & (j == 4))
  206. pictureBoxG5.Load(string.Concat(path, piecePath));
  207. else if ((i == 6) & (j == 5))
  208. pictureBoxG6.Load(string.Concat(path, piecePath));
  209. else if ((i == 6) & (j == 6))
  210. pictureBoxG7.Load(string.Concat(path, piecePath));
  211. else if ((i == 6) & (j == 7))
  212. pictureBoxG8.Load(string.Concat(path, piecePath));
  213.  
  214. else if ((i == 7) & (j == 0))
  215. pictureBoxH1.Load(string.Concat(path, piecePath));
  216. else if ((i == 7) & (j == 1))
  217. pictureBoxH2.Load(string.Concat(path, piecePath));
  218. else if ((i == 7) & (j == 2))
  219. pictureBoxH3.Load(string.Concat(path, piecePath));
  220. else if ((i == 7) & (j == 3))
  221. pictureBoxH4.Load(string.Concat(path, piecePath));
  222. else if ((i == 7) & (j == 4))
  223. pictureBoxH5.Load(string.Concat(path, piecePath));
  224. else if ((i == 7) & (j == 5))
  225. pictureBoxH6.Load(string.Concat(path, piecePath));
  226. else if ((i == 7) & (j == 6))
  227. pictureBoxH7.Load(string.Concat(path, piecePath));
  228. else if ((i == 7) & (j == 7))
  229. pictureBoxH8.Load(string.Concat(path, piecePath));
  230. }
  231. }
  232.  
  233.  
  234. Application.DoEvents();
  235.  
  236.  
  237. //MessageBox.Show("before changing 21");
  238. //string whole_path = string.Concat(path, "\\Resources\\WKing.gif");
  239. //pictureBoxD4.Load(whole_path);
  240. //pictureBoxD4.Show();
  241. //MessageBox.Show("is it drawn?");
  242. //pictureBoxD4.Show();
  243. //Invalidate();
  244. }
  245.  
  246. class HuoChess_main
  247. {
  248. // HuoChessConsole.cpp : main project file.
  249.  
  250. /////////////////////////////////////////////
  251. // Huo Chess //
  252. // version: 0.82 //
  253. // Changes from version 0.81: Removed the //
  254. // ComputerMove functions and used a //
  255. // template function to create all new //
  256. // ComputerMove functions I need. //
  257. // Changes from version 0.722: Changed the //
  258. // ComputerMove, HumanMove, CountScore, //
  259. // ElegxosOrthotitas functions. //
  260. // Changes from verion 0.721: removed some //
  261. // useless code and added the variable //
  262. // thinking depth (depending on the piece //
  263. // the opponent moves) (see parts marked //
  264. // with "2009 version 1 change") //
  265. // Changes from version 0.6: Added more //
  266. // thinking depths //
  267. // Year: 2008 //
  268. // Place: Earth - Greece //
  269. // Programmed by Spiros I. Kakos (huo) //
  270. // License: TOTALLY FREEWARE! //
  271. // Do anything you want with it! //
  272. // Spread the knowledge! //
  273. // Fix its bugs! //
  274. // Sell it (if you can...)! //
  275. // Call me for help! //
  276. // Site: www.kakos.com.gr //
  277. // www.kakos.eu //
  278. /////////////////////////////////////////////
  279.  
  280. // Icon created with : http://www.rw-designer.com/online_icon_maker.php
  281. // Algorithm analysis: http://www.codeproject.com/KB/game/cpp_microchess.aspx
  282.  
  283. ///////////////////////////////////////////////////////////////////////////////////////////
  284. // MAIN ALGORITHM
  285. // 1. ComputerMove: Scans the chessboard and makes all possible moves.
  286. // 2. CheckMove: It checks the legality and correctness of these possible moves.
  287. // 3. (if thinking depth not reached) => call HumanMove
  288. // 4. HumanMove2: Checks and finds the possible answers of the human opponent for the next move.
  289. // 5. ComputerMove2: Scans the chessboard and makes all possible moves at the next thinking level.
  290. // 6. CheckMove: It checks the legality and correctness of these possible moves.
  291. // 7. (if thinking depth not reached) => call HumanMove for the next level of thinking
  292. // 8. HumanMove4: Checks and finds the possible answers of the human opponent for the next move.
  293. // 9. ComputerMove4: Scans the chessboard and makes all possible moves at the next thinking level.
  294. // 10. CheckMove: It checks the legality and correctness of these possible moves.
  295. // 11. (if thinking depth reached) => record the score of the final position.
  296. // 12. (if score of position the best so far) => record the move as best move!
  297. // 13. The algorithm continues until all possible moves are scanned.
  298. // SET huo_debug to TRUE to see live the progress of the computer thought!
  299. // FIND us at Codeproject (www.codeproject.com) or MSDN Code Gallery!
  300. // ---------------------------------------------------------------------------
  301. // The score before every human opponents move and after any human opponents move are stored in the
  302. // Temp_Score_Move_1_human (i.e. the score after the first move of the H/Y and before the 1st move of human
  303. // while at the 2nd -ply of computer thinking), Temp_Score_Move_2, etc variables.
  304. // ---------------------------------------------------------------------------
  305. // At every level of thinking, the scores are stored in the NodesAnalysis table. This table is used for the
  306. // implementation of the MiniMax algorithm.
  307. ////////////////////////////////////////////////////////////////////////////////////////////
  308.  
  309.  
  310. //public:
  311. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  312. // DECLARE VARIABLES
  313. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  314.  
  315. //public static StreamWriter huo_sw1 = new StreamWriter("Thought_Process.txt", true);
  316.  
  317. public static String NextLine;
  318. public static string FinalPositions;
  319.  
  320. public static bool Danger_for_piece;
  321. public static String[,] Skakiera_Dangerous_Squares = new String[8, 8];
  322. public static int[,] Number_of_defenders = new int[8, 8];
  323. public static int[,] Number_of_attackers = new int[8, 8];
  324. public static int[,] Attackers_coordinates_column = new int[8, 8];
  325. public static int[,] Attackers_coordinates_rank = new int[8, 8];
  326. public static int[,] Value_of_defenders = new int[8, 8];
  327. public static int[,] Value_of_attackers = new int[8, 8];
  328. public static int[,] Exception_defender_column = new int[8, 8];
  329. public static int[,] Exception_defender_rank = new int[8, 8];
  330.  
  331. // Parameter which determined the weight of danger in the counting of the score of positions
  332. //v0.95
  333. public static int humanDangerParameter = 0;
  334. public static int computerDangerParameter = 1;
  335.  
  336. // 2011 START
  337. //public static bool danger_penalty;
  338. //public static bool danger_penalty_human;
  339. public static bool possibility_to_eat_back;
  340.  
  341. //public static int Destination_Piece_Value;
  342. //public static int Moving_Piece_Value;
  343.  
  344. //public static double Temp_Score_Human_before_0;
  345. //v0.96
  346. public static double Temp_Score_Move_0;
  347. public static double Temp_Score_Move_1_human;
  348. public static double Temp_Score_Move_2;
  349. public static double Temp_Score_Move_3_human;
  350. public static double Temp_Score_Move_4;
  351. public static double Temp_Score_Move_5_human;
  352. public static double Temp_Score_Move_6;
  353. //public static double Temp_Score_Human_before_8;
  354. //public static double Temp_Score_Human_after_8;
  355. //public static double Temp_Score_Human_before_10;
  356. //public static double Temp_Score_Human_after_10;
  357. //public static double Temp_Score_Human_before_12;
  358. //public static double Temp_Score_Human_after_12;
  359. //public static double Temp_Score_Human_before_14;
  360. //public static double Temp_Score_Human_after_14;
  361. //public static double Temp_Score_Human_before_16;
  362. //public static double Temp_Score_Human_after_16;
  363. //public static double Temp_Score_Human_before_18;
  364. //public static double Temp_Score_Human_after_18;
  365. //public static double Temp_Score_Human_before_20;
  366. //public static double Temp_Score_Human_after_20;
  367.  
  368. //public static bool Human_Stupid_Move_2_penalty;
  369. //public static bool Human_Stupid_Move_4_penalty;
  370. //public static bool Human_Stupid_Move_6_penalty;
  371. //public static bool Human_Stupid_Move_8_penalty;
  372. //public static bool Human_Stupid_Move_10_penalty;
  373. //public static bool Human_Stupid_Move_12_penalty;
  374. //public static bool Human_Stupid_Move_14_penalty;
  375. //public static bool Human_Stupid_Move_16_penalty;
  376. //public static bool Human_Stupid_Move_18_penalty;
  377. //public static bool Human_Stupid_Move_20_penalty;
  378.  
  379. // This array will hold the minimax analysis nodes skakos
  380. // 2012 change: int -> double
  381. public static double[, ,] NodesAnalysis = new double[1000000, 26, 2];
  382. public static int Nodes_Total_count;
  383. //v0.96
  384. public static int NodeLevel_0_count;
  385. public static int NodeLevel_1_count;
  386. public static int NodeLevel_2_count;
  387. public static int NodeLevel_3_count;
  388. public static int NodeLevel_4_count;
  389. public static int NodeLevel_5_count;
  390. public static int NodeLevel_6_count;
  391. public static int NodeLevel_7_count;
  392. public static int NodeLevel_8_count;
  393. public static int NodeLevel_9_count;
  394. public static int NodeLevel_10_count;
  395. public static int NodeLevel_11_count;
  396. public static int NodeLevel_12_count;
  397. public static int NodeLevel_13_count;
  398. public static int NodeLevel_14_count;
  399. public static int NodeLevel_15_count;
  400. public static int NodeLevel_16_count;
  401. public static int NodeLevel_17_count;
  402. public static int NodeLevel_18_count;
  403. public static int NodeLevel_19_count;
  404. public static int NodeLevel_20_count;
  405. // 2011 END
  406.  
  407. ///////////////////
  408. // 2009 v4 change
  409. ///////////////////
  410.  
  411. // if human eats a piece, then make the square a preferred target!!!
  412. public static int target_column;
  413. public static int target_row;
  414. //public static String target_piece;
  415.  
  416. // v0.82
  417. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_2 = new HuoChess_main();
  418. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_4 = new HuoChess_main();
  419. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_6 = new HuoChess_main();
  420. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_8 = new HuoChess_main();
  421. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_10 = new HuoChess_main();
  422. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_12 = new HuoChess_main();
  423. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_14 = new HuoChess_main();
  424. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_16 = new HuoChess_main();
  425. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_18 = new HuoChess_main();
  426. public static HuoChessW8.Form1.HuoChess_main HuoChess_new_depth_20 = new HuoChess_main();
  427. // v0.82
  428. ///////////////////
  429. // 2009 v4 change
  430. ///////////////////
  431.  
  432. // UNCOMMENT TO SHOW THINKING TIME!
  433. // (this and the other commands that use 'start' variable to record thinking time...)
  434. // public static int start;
  435.  
  436. // the chessboard (=skakiera in Greek)
  437. public static String[,] Skakiera = new String[8, 8]; // Δήλωση πίνακα που αντιπροσωπεύει τη σκακιέρα
  438.  
  439. // CODE FOR COMPARISON
  440. public static int number_of_moves_analysed;
  441.  
  442. // Variable to note if the computer moves its piece to a square threatened by a pawn
  443. //public static bool knight_pawn_threat;
  444. //public static bool bishop_pawn_threat;
  445. //public static bool rook_pawn_threat;
  446. //public static bool queen_pawn_threat;
  447. //public static bool checked_for_pawn_threats;
  448.  
  449. // Variable which determines of the program will show the inner
  450. // thinking process of the AI. Good for educational purposes!!!
  451. // UNCOMMENT TO SHOW INNER THINKING MECHANISM!
  452. //bool huo_debug;
  453.  
  454. // Arrays to use in ComputerMove function
  455. // Changed in version 0.5
  456. // Penalty for moving the only piece that defends a square to that square (thus leavind the defender
  457. // alone in the square he once defended, defenceless!)
  458. // This penalty is also used to indicate that the computer loses its Queen with the move analyzed
  459. public static bool Danger_penalty;
  460. //bool LoseQueen_penalty;
  461. // Penalty for moving your piece to a square that the human opponent can hit with more power than the computer.
  462. //public static bool Attackers_penalty;
  463. // Penalty if the pieces of the human defending a square in which the computer movies in, have much less
  464. // value than the pieces the computer has to support the attack on that square
  465. //public static bool Defenders_value_penalty;
  466.  
  467. public static String m_PlayerColor;
  468. public static String m_ComputerLevel = "Kakos";
  469. public static String m_WhoPlays;
  470. public static String m_WhichColorPlays;
  471. public static String MovingPiece;
  472.  
  473. // variable to store temporarily the piece that is moving
  474. public static String ProsorinoKommati;
  475. public static String ProsorinoKommati_KingCheck;
  476.  
  477. // variables to check the legality of the move
  478. public static bool exit_elegxos_nomimothtas = false;
  479. public static int h;
  480. public static int p;
  481. public static int how_to_move_Rank;
  482. public static int how_to_move_Column;
  483. //public static int hhh;
  484.  
  485. // NEW
  486. //public static int kopa = 1;
  487. public static bool KingCheck = false;
  488.  
  489. // coordinates of the starting square of the move
  490. public static String m_StartingColumn;
  491. public static int m_StartingRank;
  492. public static String m_FinishingColumn;
  493. public static int m_FinishingRank;
  494.  
  495. // variable for en passant moves
  496. public static bool enpassant_occured;
  497.  
  498. // move number
  499. public static int Move;
  500.  
  501. // variable to show if promotion of a pawn occured
  502. public static bool Promotion_Occured = false;
  503.  
  504. // variable to show if castrling occured
  505. public static bool Castling_Occured = false;
  506.  
  507. // variables to help find out if it is legal for the computer to perform castling
  508. public static bool White_King_Moved = false;
  509. public static bool Black_King_Moved = false;
  510. public static bool White_Rook_a1_Moved = false;
  511. public static bool White_Rook_h1_Moved = false;
  512. public static bool Black_Rook_a8_Moved = false;
  513. public static bool Black_Rook_h8_Moved = false;
  514. public static bool Can_Castle_Big_White;
  515. public static bool Can_Castle_Big_Black;
  516. public static bool Can_Castle_Small_White;
  517. public static bool Can_Castle_Small_Black;
  518.  
  519. public static bool go_for_it;
  520.  
  521. // variables to show where the kings are in the chessboard
  522. public static int WhiteKingColumn;
  523. public static int WhiteKingRank;
  524. public static int BlackKingColumn;
  525. public static int BlackKingRank;
  526.  
  527. // variables to show if king is in check
  528. public static bool WhiteKingCheck;
  529. public static bool BlackKingCheck;
  530.  
  531. // variables to show if there is a possibility for mate
  532. //public static bool WhiteMate = false;
  533. //public static bool BlackMate = false;
  534. //public static bool Mate;
  535.  
  536. // variable to show if a move is found for the hy to do
  537. public static bool Best_Move_Found;
  538.  
  539. // variables to help find if a king is under check.
  540. // (see CheckForWhiteCheck and CheckForBlackCheck functions)
  541. public static bool DangerFromRight;
  542. public static bool DangerFromLeft;
  543. public static bool DangerFromUp;
  544. public static bool DangerFromDown;
  545. public static bool DangerFromUpRight;
  546. public static bool DangerFromDownRight;
  547. public static bool DangerFromUpLeft;
  548. public static bool DangerFromDownLeft;
  549.  
  550. // initial coordinates of the two kings
  551. // (see CheckForWhiteCheck and CheckForBlackCheck functions)
  552. public static int StartingWhiteKingColumn;
  553. public static int StartingWhiteKingRank;
  554. public static int StartingBlackKingColumn;
  555. public static int StartingBlackKingRank;
  556.  
  557. // column number inserted by the user
  558. public static int m_StartingColumnNumber;
  559. public static int m_FinishingColumnNumber;
  560.  
  561. ///////////////////////////////////////////////////////////////////////////////////////////////////
  562. // Μεταβλητές για τον έλεγχο της "ορθότητας" και της "νομιμότητας" μιας κίνησης του χρήστη
  563. ///////////////////////////////////////////////////////////////////////////////////////////////////
  564.  
  565. // variable for the correctness of the move
  566. public static bool m_OrthotitaKinisis;
  567. // variable for the legality of the move
  568. public static bool m_NomimotitaKinisis;
  569. // has the user entered a wrong column?
  570. public static bool m_WrongColumn;
  571.  
  572. // variables for 'For' loops
  573. public static int i;
  574. public static int j;
  575.  
  576. public static int ApophasiXristi = 1;
  577.  
  578. //////////////////////////////////////
  579. // Computer Thought
  580. //////////////////////////////////////
  581. // Chessboards used for the computer throught
  582. public static String[,] Skakiera_Move_0 = new String[8, 8]; // Δήλωση πίνακα που αντιπροσωπεύει τη σκακιέρα
  583. public static String[,] Skakiera_Move_After = new String[8, 8];
  584. public static String[,] Skakiera_Thinking = new String[8, 8];
  585. //static array<String, 2> Skakiera_Move_After = new array<String, 2>(8,8); // Δήλωση πίνακα που αντιπροσωπεύει τη σκακιέρα
  586. //static array<String, 2> Skakiera_Thinking = new array<String, 2>(8,8); // Δήλωση πίνακα που χρησιμοποιείται στη σκέψη του υπολογιστή.
  587. // rest of variables used for computer thought
  588. public static double Best_Move_Score;
  589. public static double Current_Move_Score;
  590. public static int Best_Move_StartingColumnNumber;
  591. public static int Best_Move_FinishingColumnNumber;
  592. public static int Best_Move_StartingRank;
  593. public static int Best_Move_FinishingRank;
  594. public static int Move_Analyzed;
  595. public static bool Stop_Analyzing;
  596. public static int Thinking_Depth;
  597. //public static int Thinking_Depth_temp; // used when human eats a piece of the computer
  598. public static int m_StartingColumnNumber_HY;
  599. public static int m_FinishingColumnNumber_HY;
  600. public static int m_StartingRank_HY;
  601. public static int m_FinishingRank_HY;
  602. public static bool First_Call;
  603. public static String Who_Is_Analyzed;
  604. public static String MovingPiece_HY;
  605.  
  606. // for writing the computer move
  607. public static String HY_Starting_Column_Text;
  608. public static String HY_Finishing_Column_Text;
  609.  
  610. // chessboard to store the chessboard squares where it is dangerous
  611. // for the HY to move a piece
  612. // SEE function ComputerMove!
  613. //static array<String, 2> Skakiera_Dangerous_Squares = new array<String, 2>(8,8); // Δήλωση πίνακα που αντιπροσωπεύει τη σκακιέρα
  614.  
  615. // variables which help find the best move of the human-opponent
  616. // during the HY thought analysis
  617. //public static String[,] Skakiera_Human_Move_0 = new String[8, 8];
  618. //public static String[,] Skakiera_Human_Thinking = new String[8, 8];
  619. //static array<String, 2> Skakiera_Human_Move_0 = new array<String, 2>(8,8);
  620. //static array<String, 2> Skakiera_Human_Thinking = new array<String, 2>(8,8);
  621. public static bool First_Call_Human_Thought;
  622. // 2009 version 1 change
  623. //public static int iii_Human;
  624. //public static int jjj_Human;
  625. public static String MovingPiece_Human = "";
  626. public static int m_StartingColumnNumber_Human = 1;
  627. public static int m_FinishingColumnNumber_Human = 1;
  628. public static int m_StartingRank_Human = 1;
  629. public static int m_FinishingRank_Human = 1;
  630. //public static double Current_Human_Move_Score;
  631. //public static double Best_Human_Move_Score;
  632. //public static int Best_Move_Human_StartingColumnNumber;
  633. //public static int Best_Move_Human_FinishingColumnNumber;
  634. //public static int Best_Move_Human_StartingRank;
  635. //public static int Best_Move_Human_FinishingRank;
  636. //public static bool Best_Human_Move_Found;
  637.  
  638. // does the HY eats the queen of his opponent with the move it analyzes?
  639. // Changed in version 0.5
  640. public static bool eat_queen;
  641.  
  642. // where the player can perform en passant
  643. public static int enpassant_possible_target_rank;
  644. public static int enpassant_possible_target_column;
  645.  
  646. // is there a possible mate?
  647. public static bool Human_is_in_check;
  648. public static bool Possible_mate;
  649.  
  650. // does the HY moves its King with the move it is analyzing?
  651. public static bool moving_the_king;
  652.  
  653. public static int choise_of_user;
  654. //private static string test_starting_column;
  655. //private static string test_finishing_column;
  656.  
  657. ///////////////////////////////////////////////////////////////////////////////////////////////////
  658. // END OF VARIABLES DECLARATION
  659. ///////////////////////////////////////////////////////////////////////////////////////////////////
  660.  
  661. public static void Main_Console()
  662. {
  663. /////////////////////
  664. // Setup game
  665. /////////////////////
  666.  
  667. //String the_choise_of_user = Console.ReadLine();
  668.  
  669. //if ((the_choise_of_user.CompareTo("w") == 0) || (the_choise_of_user.CompareTo("W") == 0))
  670. //{
  671. // m_PlayerColor = "White";
  672. // m_WhoPlays = "Human";
  673. //}
  674. //else if ((the_choise_of_user.CompareTo("b") == 0) || (the_choise_of_user.CompareTo("B") == 0))
  675. //{
  676. // m_PlayerColor = "Black";
  677. // m_WhoPlays = "HY";
  678. //}
  679.  
  680. /////////////////////////////////////////////////////////////////////////
  681. // CHANGE Thinking_Depth TO HAVE MORE THINKING DEPTHS
  682. // BUT REMEMBER TO ALSO UNCOMMENT ComputerMove4,6,8 functions and
  683. // the respective part in HumanMove function that calls them!
  684. /////////////////////////////////////////////////////////////////////////
  685. // ΠΡΟΣΟΧΗ: Αν βάλω τον υπολογιστή να σκεφτεί σε βάθος 1 κίνησης
  686. // (ήτοι Thinking_Depth = 0), τότε ΔΕΝ σκέφτεται σωστά! Αυτό συμβαίνει
  687. // διότι η HumanMove πρέπει να κληθεί τουλάχιστον μία φορά για να
  688. // ολοκληρωθεί σωστά τουλάχιστον ένας πλήρης κύκλος σκέψης του ΗΥ.
  689. /////////////////////////////////////////////////////////////////////////
  690.  
  691. //Thinking_Depth = 20;
  692. // MiniMax algorithm currently only utilizes 8-ply thinking depth
  693. // Add more "for loops" in the required section in ComputerMove to allow more deep thinking
  694. // However remember that the NodesAnalysis table has a limit!!! (and so does the memory)
  695. // Thinking depth must be ζυγός number because the nodes are recorded only in the Analyze_Computer functions!
  696. //QQQ1
  697. Thinking_Depth = 2;
  698.  
  699. ////////////////////////////////////////////////////////////
  700. // SHOW THE INNER THINKING PROCESS OF THE COMPUTER?
  701. // GOOD FOR EDUCATIONAL PURPOSES!
  702. // SET huo_debug to TRUE to show inner thinking process!
  703. ////////////////////////////////////////////////////////////
  704. //Console.Write("Show thinking process (y/n)? ");
  705. //the_choise_of_user = Console.ReadLine();
  706. //if((the_choise_of_user.CompareTo("y") == 0)||(the_choise_of_user.CompareTo("Y") == 0))
  707. // huo_debug = true;
  708. //else if((the_choise_of_user.CompareTo("n") == 0)||(the_choise_of_user.CompareTo("N") == 0))
  709. // huo_debug = false;
  710.  
  711. MessageBox.Show("\nHuo Chess v0.961 by Spiros I.Kakos (huo) [2014] - C# Edition\n\nCURRENT EXPERIMENT: Depth 2 (Minimax Algorithm)\n\nWhat about a nice game of chess?", "Huo Chess W8", MessageBoxButtons.OK, MessageBoxIcon.Information);
  712.  
  713. // initial values
  714. //White_King_Moved = false;
  715. //Black_King_Moved = false;
  716. //White_Rook_a1_Moved = false;
  717. //White_Rook_h1_Moved = false;
  718. //Black_Rook_a8_Moved = false;
  719. //Black_Rook_h8_Moved = false;
  720. //Can_Castle_Big_White = true;
  721. //Can_Castle_Big_Black = true;
  722. //Can_Castle_Small_White = true;
  723. //Can_Castle_Small_Black = true;
  724. Move = 0;
  725. m_WhichColorPlays = "White";
  726.  
  727. // fix startup position
  728. Starting_position();
  729.  
  730. // if it is the turn of HY to play, then call the respective function
  731. // to implement HY thought
  732.  
  733. //bool exit_game = false;
  734.  
  735. //2012:do
  736. //2012:{
  737.  
  738. if (m_WhoPlays.CompareTo("HY") == 0)
  739. {
  740. // call HY Thought function
  741. Move = 0;
  742.  
  743. if (Move == 0)
  744. {
  745. //MessageBox.Show("");
  746. //MessageBox.Show("Press to let me start thinking...");
  747. }
  748.  
  749. Move_Analyzed = 0;
  750. Stop_Analyzing = false;
  751. First_Call = true;
  752. Best_Move_Found = false;
  753. Who_Is_Analyzed = "HY";
  754.  
  755.  
  756. //----------------CHECK DANGER---------------------------------------
  757. // Find the dangerous squares in the chessboard, where if the HY
  758. // moves its piece, it will immediately (or most probably) loose it.
  759.  
  760. for (i = 0; i <= 7; i++)
  761. {
  762. for (j = 0; j <= 7; j++)
  763. {
  764. Skakiera_Dangerous_Squares[i, j] = "";
  765. }
  766. }
  767.  
  768. // Changed in version 0.5
  769. // Initialize variables for finfind the dangerous squares
  770. for (int di = 0; di <= 7; di++)
  771. {
  772. for (int dj = 0; dj <= 7; dj++)
  773. {
  774. Number_of_attackers[di, dj] = 0;
  775. Number_of_defenders[di, dj] = 0;
  776. Value_of_attackers[di, dj] = 0;
  777. //2012 added Attackers_coordinates table
  778. Attackers_coordinates_column[di, dj] = 0;
  779. Attackers_coordinates_rank[di, dj] = 0;
  780. Value_of_defenders[di, dj] = 0;
  781. Exception_defender_column[di, dj] = -9;
  782. Exception_defender_rank[di, dj] = -9;
  783. }
  784. }
  785.  
  786. FindAttackers(Skakiera);
  787. FindDefenders(Skakiera);
  788.  
  789. //-----------------------------------------------------------------------
  790.  
  791. ComputerMove(Skakiera);
  792.  
  793. // 2012: Make player clicks zero so as to wait again for the player to click his moves with the mouse
  794. m_WhoPlays = "Human";
  795. playerClicks = 0;
  796. }
  797. //2012:else if (m_WhoPlays.CompareTo("Human") == 0)
  798. //2012:{
  799. ////////////////////////////
  800. // Human enters his move
  801. ////////////////////////////
  802. //MessageBox.Show("Enter your move by pressing the keys");
  803.  
  804. //MessageBox.Show("");
  805. //Console.Write("Starting column (A to H)...");
  806. //m_StartingColumn = Console.ReadLine().ToUpper();
  807. //Console.Write("Starting rank (1 to 8).....");
  808. //m_StartingRank = Int32.Parse(Console.ReadLine());
  809. //Console.Write("Finishing column (A to H)...");
  810. //m_FinishingColumn = Console.ReadLine().ToUpper();
  811. //Console.Write("Finishing rank (1 to 8).....");
  812. //m_FinishingRank = Int32.Parse(Console.ReadLine());
  813.  
  814. //////////////////////////////////////////////////////////////////////////////
  815.  
  816. // show the move entered
  817.  
  818. // 2012
  819. //huoMove = String.Concat(m_StartingColumn, m_StartingRank.ToString(), " > ");
  820. //huoMove = String.Concat(huoMove, m_FinishingColumn, m_FinishingRank.ToString());
  821. //MessageBox.Show(huoMove);
  822.  
  823. ////StreamWriter huo_sw3 = new StreamWriter("game.txt", true);
  824. ////huo_sw3.WriteLine(huoMove);
  825. ////huo_sw3.Close();
  826.  
  827. //MessageBox.Show("");
  828. //MessageBox.Show("Thinking...");
  829.  
  830. //// check the move entered by the human for correctness (='Orthotita' in Greek)
  831. //// and legality (='Nomimotita' in Greek)
  832. //Enter_move();
  833. //2012:}
  834.  
  835. //2012:} while (exit_game == false);
  836.  
  837. }
  838.  
  839.  
  840.  
  841. public static bool CheckForBlackCheck(string[,] BCSkakiera)
  842. {
  843. // TODO: Add your control notification handler code here
  844.  
  845. bool KingCheck;
  846.  
  847. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  848. // Εύρεση των συντεταγμένων του βασιλιά.
  849. // Αν σε κάποιο τετράγωνο βρεθεί ότι υπάρχει ένας βασιλιάς, τότε απλά καταγράφεται η τιμή του εν λόγω
  850. // τετραγώνου στις αντίστοιχες μεταβλητές που δηλώνουν τη στήλη και τη γραμμή στην οποία υπάρχει μαύρος
  851. // βασιλιάς.
  852. // ΠΡΟΣΟΧΗ: Γράφω (i+1) αντί για i και (j+1) αντί για j γιατί το πρώτο στοιχείο του πίνακα BCSkakiera[(8),(8)]
  853. // είναι το BCSkakiera[(0),(0)] και ΟΧΙ το BCSkakiera[(1),(1)]!
  854. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  855.  
  856. for (i = 0; i <= 7; i++)
  857. {
  858. for (j = 0; j <= 7; j++)
  859. {
  860.  
  861. if (BCSkakiera[(i), (j)].CompareTo("Black King") == 0)
  862. {
  863. BlackKingColumn = (i + 1);
  864. BlackKingRank = (j + 1);
  865. }
  866.  
  867. }
  868. }
  869.  
  870. ///////////////////////////////////////////////////////////////
  871. // Έλεγχος του αν ο μαύρος βασιλιάς υφίσταται "σαχ"
  872. ///////////////////////////////////////////////////////////////
  873.  
  874. KingCheck = false;
  875.  
  876. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  877. // Ελέγχουμε αρχικά αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΤΑ ΔΕΞΙΑ ΤΟΥ. Για να μην βγούμε έξω από τα
  878. // όρια της BCSkakiera[(8),(8)] έχουμε προσθέσει τον έλεγχο (BlackKingColumn + 1) <= 8 στο "if". Αρχικά ο "κίνδυνος"
  879. // από τα "δεξιά" είναι υπαρκτός, άρα DangerFromRight = true. Ωστόσο αν βρεθεί ότι στα δεξιά του μαύρου βασι-
  880. // λιά υπάρχει κάποιο μαύρο κομμάτι, τότε δεν είναι δυνατόν ο εν λόγω βασιλιάς να υφίσταται σαχ από τα δεξιά
  881. // του (αφού θα "προστατεύεται" από το κομμάτι ιδίου χρώματος), οπότε η DangerFromRight = false και ο έλεγχος
  882. // για απειλές από τα δεξιά σταματάει (για αυτό και έχω προσθέσει την προϋπόθεση (DangerFromRight == true) στα
  883. // "if" που κάνουν αυτόν τον έλεγχο).
  884. // Αν όμως δεν υπάρχει κανένα μαύρο κομμάτι δεξιά του βασιλιά για να τον προστατεύει, τότε συνεχίζει να
  885. // υπάρχει πιθανότητα να απειλείται ο βασιλιάς από τα δεξιά του, οπότε ο έλεγχος συνεχίζεται.
  886. // Σημείωση: Ο έλεγχος γίνεται για πιθανό σαχ από πύργο ή βασίλισσα αντίθετου χρώματος.
  887. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  888.  
  889. DangerFromRight = true;
  890.  
  891. for (int klopa = 1; klopa <= 7; klopa++)
  892. {
  893. if (((BlackKingColumn + klopa) <= 8) && (DangerFromRight == true))
  894. {
  895. if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("White Rook") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("White Queen") == 0))
  896. KingCheck = true;
  897. else if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("Black Pawn") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("Black Rook") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("Black Knight") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("Black Bishop") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("Black Queen") == 0))
  898. DangerFromRight = false;
  899. else if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("White Pawn") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("White Knight") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("White Bishop") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - 1)].CompareTo("White King") == 0))
  900. DangerFromRight = false;
  901. }
  902. }
  903.  
  904.  
  905.  
  906. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  907. // Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΤΑ ΑΡΙΣΤΕΡΑ ΤΟΥ (από πύργο ή βασίλισσα).
  908. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  909.  
  910. DangerFromLeft = true;
  911.  
  912. for (int klopa = 1; klopa <= 7; klopa++)
  913. {
  914. if (((BlackKingColumn - klopa) >= 1) && (DangerFromLeft == true))
  915. {
  916. if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("White Rook") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("White Queen") == 0))
  917. KingCheck = true;
  918. else if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("Black Pawn") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("Black Rook") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("Black Knight") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("Black Bishop") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("Black Queen") == 0))
  919. DangerFromLeft = false;
  920. else if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("White Pawn") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("White Knight") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("White Bishop") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - 1)].CompareTo("White King") == 0))
  921. DangerFromLeft = false;
  922. }
  923. }
  924.  
  925.  
  926.  
  927. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  928. // Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΠΑΝΩ (από πύργο ή βασίλισσα).
  929. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  930.  
  931.  
  932. DangerFromUp = true;
  933.  
  934. for (int klopa = 1; klopa <= 7; klopa++)
  935. {
  936. if (((BlackKingRank + klopa) <= 8) && (DangerFromUp == true))
  937. {
  938. if ((BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("White Rook") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("White Queen") == 0))
  939. KingCheck = true;
  940. else if ((BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Pawn") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Rook") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Knight") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Bishop") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Queen") == 0))
  941. DangerFromUp = false;
  942. else if ((BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("White Pawn") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("White Knight") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("White Bishop") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank + klopa - 1)].CompareTo("White King") == 0))
  943. DangerFromUp = false;
  944. }
  945. }
  946.  
  947.  
  948.  
  949. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  950. // Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΚΑΤΩ (από πύργο ή βασίλισσα).
  951. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  952.  
  953. DangerFromDown = true;
  954.  
  955. for (int klopa = 1; klopa <= 7; klopa++)
  956. {
  957. if (((BlackKingRank - klopa) >= 1) && (DangerFromDown == true))
  958. {
  959. if ((BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("White Rook") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("White Queen") == 0))
  960. KingCheck = true;
  961. else if ((BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Pawn") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Rook") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Knight") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Bishop") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Queen") == 0))
  962. DangerFromDown = false;
  963. else if ((BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("White Pawn") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("White Knight") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("White Bishop") == 0) || (BCSkakiera[(BlackKingColumn - 1), (BlackKingRank - klopa - 1)].CompareTo("White King") == 0))
  964. DangerFromDown = false;
  965. }
  966. }
  967.  
  968.  
  969.  
  970. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  971. // Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΠΑΝΩ-ΔΕΞΙΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
  972. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  973.  
  974. DangerFromUpRight = true;
  975.  
  976. for (int klopa = 1; klopa <= 7; klopa++)
  977. {
  978. if (((BlackKingColumn + klopa) <= 8) && ((BlackKingRank + klopa) <= 8) && (DangerFromUpRight == true))
  979. {
  980. if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Bishop") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Queen") == 0))
  981. KingCheck = true;
  982. else if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Pawn") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Rook") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Knight") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Bishop") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Queen") == 0))
  983. DangerFromUpRight = false;
  984. else if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Pawn") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Rook") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Knight") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White King") == 0))
  985. DangerFromUpRight = false;
  986. }
  987. }
  988.  
  989.  
  990.  
  991. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  992. // Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΚΑΤΩ-ΑΡΙΣΤΕΡΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
  993. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  994.  
  995. DangerFromDownLeft = true;
  996.  
  997. for (int klopa = 1; klopa <= 7; klopa++)
  998. {
  999. if (((BlackKingColumn - klopa) >= 1) && ((BlackKingRank - klopa) >= 1) && (DangerFromDownLeft == true))
  1000. {
  1001. if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Bishop") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Queen") == 0))
  1002. KingCheck = true;
  1003. else if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Pawn") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Rook") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Knight") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Bishop") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Queen") == 0))
  1004. DangerFromDownLeft = false;
  1005. else if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Pawn") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Rook") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Knight") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White King") == 0))
  1006. DangerFromDownLeft = false;
  1007. }
  1008. }
  1009.  
  1010.  
  1011. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1012. // Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΚΑΤΩ-ΔΕΞΙΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
  1013. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1014.  
  1015. DangerFromDownRight = true;
  1016.  
  1017. for (int klopa = 1; klopa <= 7; klopa++)
  1018. {
  1019. if (((BlackKingColumn + klopa) <= 8) && ((BlackKingRank - klopa) >= 1) && (DangerFromDownRight == true))
  1020. {
  1021. if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Bishop") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Queen") == 0))
  1022. KingCheck = true;
  1023. else if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Pawn") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Rook") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Knight") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Bishop") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("Black Queen") == 0))
  1024. DangerFromDownRight = false;
  1025. else if ((BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Pawn") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Rook") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White Knight") == 0) || (BCSkakiera[(BlackKingColumn + klopa - 1), (BlackKingRank - klopa - 1)].CompareTo("White King") == 0))
  1026. DangerFromDownRight = false;
  1027. }
  1028. }
  1029.  
  1030.  
  1031.  
  1032. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1033. // Έλεγχος αν υπάρχει κίνδυνος για το μαύρο βασιλιά ΑΠΟ ΠΑΝΩ-ΑΡΙΣΤΕΡΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
  1034. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1035.  
  1036. DangerFromUpLeft = true;
  1037.  
  1038. for (int klopa = 1; klopa <= 7; klopa++)
  1039. {
  1040. if (((BlackKingColumn - klopa) >= 1) && ((BlackKingRank + klopa) <= 8) && (DangerFromUpLeft == true))
  1041. {
  1042. if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Bishop") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Queen") == 0))
  1043. KingCheck = true;
  1044. else if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Pawn") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Rook") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Knight") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Bishop") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("Black Queen") == 0))
  1045. DangerFromUpLeft = false;
  1046. else if ((BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Pawn") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Rook") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White Knight") == 0) || (BCSkakiera[(BlackKingColumn - klopa - 1), (BlackKingRank + klopa - 1)].CompareTo("White King") == 0))
  1047. DangerFromUpLeft = false;
  1048. }
  1049. }
  1050.  
  1051.  
  1052. //////////////////////////////////////////////////////////////////////////
  1053. // Έλεγχος για το αν ο μαύρος βασιλιάς απειλείται από πιόνι.
  1054. //////////////////////////////////////////////////////////////////////////
  1055.  
  1056. if (((BlackKingColumn + 1) <= 8) && ((BlackKingRank - 1) >= 1))
  1057. {
  1058. if (BCSkakiera[(BlackKingColumn + 1 - 1), (BlackKingRank - 1 - 1)].CompareTo("White Pawn") == 0)
  1059. {
  1060. KingCheck = true;
  1061. }
  1062. }
  1063.  
  1064.  
  1065. if (((BlackKingColumn - 1) >= 1) && ((BlackKingRank - 1) >= 1))
  1066. {
  1067. if (BCSkakiera[(BlackKingColumn - 1 - 1), (BlackKingRank - 1 - 1)].CompareTo("White Pawn") == 0)
  1068. {
  1069. KingCheck = true;
  1070. }
  1071. }
  1072.  
  1073.  
  1074. ///////////////////////////////////////////////////////////////////////
  1075. // Έλεγχος για το αν ο μαύρος βασιλιάς απειλείται από ίππο.
  1076. ///////////////////////////////////////////////////////////////////////
  1077.  
  1078. if (((BlackKingColumn + 1) <= 8) && ((BlackKingRank + 2) <= 8))
  1079. if (BCSkakiera[(BlackKingColumn + 1 - 1), (BlackKingRank + 2 - 1)].CompareTo("White Knight") == 0)
  1080. KingCheck = true;
  1081.  
  1082. if (((BlackKingColumn + 2) <= 8) && ((BlackKingRank - 1) >= 1))
  1083. if (BCSkakiera[(BlackKingColumn + 2 - 1), (BlackKingRank - 1 - 1)].CompareTo("White Knight") == 0)
  1084. KingCheck = true;
  1085.  
  1086. if (((BlackKingColumn + 1) <= 8) && ((BlackKingRank - 2) >= 1))
  1087. if (BCSkakiera[(BlackKingColumn + 1 - 1), (BlackKingRank - 2 - 1)].CompareTo("White Knight") == 0)
  1088. KingCheck = true;
  1089.  
  1090. if (((BlackKingColumn - 1) >= 1) && ((BlackKingRank - 2) >= 1))
  1091. if (BCSkakiera[(BlackKingColumn - 1 - 1), (BlackKingRank - 2 - 1)].CompareTo("White Knight") == 0)
  1092. KingCheck = true;
  1093.  
  1094. if (((BlackKingColumn - 2) >= 1) && ((BlackKingRank - 1) >= 1))
  1095. if (BCSkakiera[(BlackKingColumn - 2 - 1), (BlackKingRank - 1 - 1)].CompareTo("White Knight") == 0)
  1096. KingCheck = true;
  1097.  
  1098. if (((BlackKingColumn - 2) >= 1) && ((BlackKingRank + 1) <= 8))
  1099. if (BCSkakiera[(BlackKingColumn - 2 - 1), (BlackKingRank + 1 - 1)].CompareTo("White Knight") == 0)
  1100. KingCheck = true;
  1101.  
  1102. if (((BlackKingColumn - 1) >= 1) && ((BlackKingRank + 2) <= 8))
  1103. if (BCSkakiera[(BlackKingColumn - 1 - 1), (BlackKingRank + 2 - 1)].CompareTo("White Knight") == 0)
  1104. KingCheck = true;
  1105.  
  1106. if (((BlackKingColumn + 2) <= 8) && ((BlackKingRank + 1) <= 8))
  1107. if (BCSkakiera[(BlackKingColumn + 2 - 1), (BlackKingRank + 1 - 1)].CompareTo("White Knight") == 0)
  1108. KingCheck = true;
  1109.  
  1110. return KingCheck;
  1111. }
  1112.  
  1113.  
  1114.  
  1115. public static bool CheckForBlackMate(string[,] BMSkakiera)
  1116. {
  1117. // TODO: Add your control notification handler code here
  1118.  
  1119. bool Mate;
  1120.  
  1121. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  1122. // Μεταβλητή που χρησιμεύει στον έλεγχο για το αν υπάρχει ματ (βλ. συναρτήσεις CheckForWhiteMate() και
  1123. // CheckForBlackMate()).
  1124. // Αναλυτικότερα, το πρόγραμμα ελέγχει αν αρχικά υπάρχει σαχ και, αν υπάρχει, ελέγχει αν αυτό το
  1125. // σαχ μπορεί να αποφευχθεί με τη μετακίνηση του υπό απειλή βασιλιά σε κάποιο γειτονικό τετράγωνο.
  1126. // Η μεταβλητή καταγράφει το αν συνεχίζει να υπάρχει πιθανότητα να υπάρχει ματ στη σκακιέρα.
  1127. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  1128.  
  1129. bool DangerForMate;
  1130.  
  1131. ////////////////////////////////////////////////////////////
  1132. // Έλεγχος του αν υπάρχει "ματ" στον μαύρο βασιλιά
  1133. ////////////////////////////////////////////////////////////
  1134.  
  1135. Mate = false;
  1136. DangerForMate = true; // Αρχικά, προφανώς υπάρχει πιθανότητα να υπάρχει ματ στη σκακιέρα.
  1137. // Αν, ωστόσο, κάποια στιγμή βρεθεί ότι αν ο βασιλιάς μπορεί να μετακινηθεί
  1138. // σε ένα διπλανό τετράγωνο και να πάψει να υφίσταται σαχ, τότε παύει να
  1139. // υπάρχει πιθανότητα να υπάρχει ματ (προφανώς) και η μεταβλητή παίρνει την
  1140. // τιμή false.
  1141.  
  1142.  
  1143. //////////////////////////////////////////////////////////////
  1144. // Εύρεση των αρχικών συντεταγμένων του βασιλιά
  1145. //////////////////////////////////////////////////////////////
  1146.  
  1147. for (i = 0; i <= 7; i++)
  1148. {
  1149. for (j = 0; j <= 7; j++)
  1150. {
  1151.  
  1152. if (BMSkakiera[(i), (j)].CompareTo("Black King") == 0)
  1153. {
  1154. StartingBlackKingColumn = (i + 1);
  1155. StartingBlackKingRank = (j + 1);
  1156. }
  1157.  
  1158. }
  1159. }
  1160.  
  1161.  
  1162. //////////////////////////////////////////////////
  1163. // Έλεγχος αν ο μαύρος βασιλιάς είναι ματ
  1164. //////////////////////////////////////////////////
  1165.  
  1166.  
  1167. if (m_WhichColorPlays.CompareTo("Black") == 0)
  1168. {
  1169.  
  1170. ////////////////////////////////////////////////
  1171. // Έλεγχος αν υπάρχει σαχ αυτή τη στιγμή
  1172. ////////////////////////////////////////////////
  1173.  
  1174. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1175.  
  1176. if (BlackKingCheck == false) // Αν αυτή τη στιγμή δεν υφίσταται σαχ, τότε να μη συνεχιστεί ο έλεγχος
  1177. DangerForMate = false; // καθώς ΔΕΝ συνεχίζει να υφίσταται πιθανότητα να υπάρχει ματ.
  1178.  
  1179. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1180. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο μαύρος βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1181. // προς τα πάνω
  1182. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1183.  
  1184. if (StartingBlackKingRank < 8)
  1185. {
  1186. MovingPiece = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)];
  1187. ProsorinoKommati = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1 + 1)];
  1188.  
  1189. if ((ProsorinoKommati.CompareTo("Black Queen") == 1) && (ProsorinoKommati.CompareTo("Black Rook") == 1) && (ProsorinoKommati.CompareTo("Black Knight") == 1) && (ProsorinoKommati.CompareTo("Black Bishop") == 1) && (ProsorinoKommati.CompareTo("Black Pawn") == 1) && (DangerForMate == true) && ((StartingBlackKingRank - 1 + 1) <= 7))
  1190. {
  1191.  
  1192. // (Προσωρινή) μετακίνηση του βασιλιά προς τα πάνω και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1193. // Ο έλεγχος γίνεται μόνο αν στο τετράγωνο που μετακινείται προσωρινά ο βασιλιάς δεν υπάρχει άλλο κομμάτι
  1194. // του ίδιου χρώματος που να τον εμποδίζει και αν, φυσικά, ο βασιλιάς δεν βγαίνει έξω από τη σκακιέρα με
  1195. // αυτή του την κίνηση και αν, προφανώς, συνεχίζει να υπάρχει πιθανότητα να ύπάρχει ματ (καθώς αν δεν
  1196. // υπάρχει τέτοια πιθανότητα, τότε ο έλεγχος είναι άχρηστος).
  1197.  
  1198. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = "";
  1199. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1 + 1)] = MovingPiece;
  1200. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1201.  
  1202. if (BlackKingCheck == false)
  1203. DangerForMate = false;
  1204.  
  1205. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1206. // σκοπούς του ελέγχου.
  1207.  
  1208. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1209. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1 + 1)] = ProsorinoKommati;
  1210.  
  1211. }
  1212.  
  1213. }
  1214.  
  1215.  
  1216. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1217. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο μαύρος βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1218. // προς τα πάνω-δεξιά
  1219. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1220.  
  1221. if ((StartingBlackKingColumn < 8) && (StartingBlackKingRank < 8))
  1222. {
  1223.  
  1224. MovingPiece = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)];
  1225. ProsorinoKommati = BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1 + 1)];
  1226.  
  1227. if ((ProsorinoKommati.CompareTo("Black Queen") == 1) && (ProsorinoKommati.CompareTo("Black Rook") == 1) && (ProsorinoKommati.CompareTo("Black Knight") == 1) && (ProsorinoKommati.CompareTo("Black Bishop") == 1) && (ProsorinoKommati.CompareTo("Black Pawn") == 1) && (DangerForMate == true) && ((StartingBlackKingRank - 1 + 1) <= 7) && ((StartingBlackKingColumn - 1 + 1) <= 7))
  1228. {
  1229.  
  1230. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1231.  
  1232. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = "";
  1233. BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1 + 1)] = MovingPiece;
  1234. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1235.  
  1236. if (BlackKingCheck == false)
  1237. DangerForMate = false;
  1238.  
  1239. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1240. // σκοπούς του ελέγχου.
  1241.  
  1242. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1243. BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1 + 1)] = ProsorinoKommati;
  1244.  
  1245. }
  1246.  
  1247. }
  1248.  
  1249.  
  1250. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1251. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο μαύρος βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1252. // προς τα δεξιά
  1253. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1254.  
  1255. if (StartingBlackKingColumn < 8)
  1256. {
  1257.  
  1258. MovingPiece = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)];
  1259. ProsorinoKommati = BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1)];
  1260.  
  1261. if ((ProsorinoKommati.CompareTo("Black Queen") == 1) && (ProsorinoKommati.CompareTo("Black Rook") == 1) && (ProsorinoKommati.CompareTo("Black Knight") == 1) && (ProsorinoKommati.CompareTo("Black Bishop") == 1) && (ProsorinoKommati.CompareTo("Black Pawn") == 1) && (DangerForMate == true) && ((StartingBlackKingColumn - 1 + 1) <= 7))
  1262. {
  1263.  
  1264. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1265.  
  1266. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = "";
  1267. BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1268. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1269.  
  1270. if (BlackKingCheck == false)
  1271. DangerForMate = false;
  1272.  
  1273. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1274. // σκοπούς του ελέγχου.
  1275.  
  1276. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1277. BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1)] = ProsorinoKommati;
  1278.  
  1279. }
  1280.  
  1281. }
  1282.  
  1283.  
  1284. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1285. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο μαύρος βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1286. // προς τα κάτω-δεξιά
  1287. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1288.  
  1289. if ((StartingBlackKingColumn < 8) && (StartingBlackKingRank > 1))
  1290. {
  1291.  
  1292. MovingPiece = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)];
  1293. ProsorinoKommati = BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1 - 1)];
  1294.  
  1295. if ((ProsorinoKommati.CompareTo("Black Queen") == 1) && (ProsorinoKommati.CompareTo("Black Rook") == 1) && (ProsorinoKommati.CompareTo("Black Knight") == 1) && (ProsorinoKommati.CompareTo("Black Bishop") == 1) && (ProsorinoKommati.CompareTo("Black Pawn") == 1) && (DangerForMate == true) && ((StartingBlackKingRank - 1 - 1) >= 0) && ((StartingBlackKingColumn - 1 + 1) <= 7))
  1296. {
  1297.  
  1298. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1299.  
  1300. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = "";
  1301. BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1 - 1)] = MovingPiece;
  1302. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1303.  
  1304. if (BlackKingCheck == false)
  1305. DangerForMate = false;
  1306.  
  1307. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1308. // σκοπούς του ελέγχου.
  1309.  
  1310. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1311. BMSkakiera[(StartingBlackKingColumn - 1 + 1), (StartingBlackKingRank - 1 - 1)] = ProsorinoKommati;
  1312.  
  1313. }
  1314.  
  1315. }
  1316.  
  1317.  
  1318. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1319. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο μαύρος βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1320. // προς τα κάτω
  1321. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1322.  
  1323. if (StartingBlackKingRank > 1)
  1324. {
  1325.  
  1326. MovingPiece = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)];
  1327. ProsorinoKommati = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1 - 1)];
  1328.  
  1329. if ((ProsorinoKommati.CompareTo("Black Queen") == 1) && (ProsorinoKommati.CompareTo("Black Rook") == 1) && (ProsorinoKommati.CompareTo("Black Knight") == 1) && (ProsorinoKommati.CompareTo("Black Bishop") == 1) && (ProsorinoKommati.CompareTo("Black Pawn") == 1) && (DangerForMate == true) && ((StartingBlackKingRank - 1 - 1) >= 0))
  1330. {
  1331.  
  1332. // (Προσωρινή) μετακίνηση του βασιλιά προς τα πάνω και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1333.  
  1334. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = "";
  1335. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1 - 1)] = MovingPiece;
  1336. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1337.  
  1338. if (BlackKingCheck == false)
  1339. DangerForMate = false;
  1340.  
  1341. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1342. // σκοπούς του ελέγχου.
  1343.  
  1344. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1345. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1 - 1)] = ProsorinoKommati;
  1346.  
  1347. }
  1348.  
  1349. }
  1350.  
  1351.  
  1352. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1353. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο μαύρος βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1354. // προς τα κάτω-αριστερά
  1355. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1356.  
  1357. if ((StartingBlackKingColumn > 1) && (StartingBlackKingRank > 1))
  1358. {
  1359.  
  1360. MovingPiece = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)];
  1361. ProsorinoKommati = BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1 - 1)];
  1362.  
  1363. if ((ProsorinoKommati.CompareTo("Black Queen") == 1) && (ProsorinoKommati.CompareTo("Black Rook") == 1) && (ProsorinoKommati.CompareTo("Black Knight") == 1) && (ProsorinoKommati.CompareTo("Black Bishop") == 1) && (ProsorinoKommati.CompareTo("Black Pawn") == 1) && (DangerForMate == true) && ((StartingBlackKingRank - 1 - 1) >= 0) && ((StartingBlackKingColumn - 1 - 1) >= 0))
  1364. {
  1365.  
  1366. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1367.  
  1368. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = "";
  1369. BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1 - 1)] = MovingPiece;
  1370. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1371.  
  1372. if (BlackKingCheck == false)
  1373. DangerForMate = false;
  1374.  
  1375. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1376. // σκοπούς του ελέγχου.
  1377.  
  1378. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1379. BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1 - 1)] = ProsorinoKommati;
  1380.  
  1381. }
  1382.  
  1383. }
  1384.  
  1385.  
  1386. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1387. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο μαύρος βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1388. // προς τα αριστερά
  1389. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1390.  
  1391. if (StartingBlackKingColumn > 1)
  1392. {
  1393.  
  1394. MovingPiece = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)];
  1395. ProsorinoKommati = BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1)];
  1396.  
  1397. if ((ProsorinoKommati.CompareTo("Black Queen") == 1) && (ProsorinoKommati.CompareTo("Black Rook") == 1) && (ProsorinoKommati.CompareTo("Black Knight") == 1) && (ProsorinoKommati.CompareTo("Black Bishop") == 1) && (ProsorinoKommati.CompareTo("Black Pawn") == 1) && (DangerForMate == true) && ((StartingBlackKingColumn - 1 - 1) >= 0))
  1398. {
  1399.  
  1400. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1401.  
  1402. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = "";
  1403. BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1404. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1405.  
  1406. if (BlackKingCheck == false)
  1407. DangerForMate = false;
  1408.  
  1409. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1410. // σκοπούς του ελέγχου.
  1411.  
  1412. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1413. BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1)] = ProsorinoKommati;
  1414.  
  1415. }
  1416.  
  1417. }
  1418.  
  1419.  
  1420. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1421. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο μαύρος βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1422. // προς τα πάνω-αριστερά
  1423. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1424.  
  1425. if ((StartingBlackKingColumn > 1) && (StartingBlackKingRank < 8))
  1426. {
  1427.  
  1428. MovingPiece = BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)];
  1429. ProsorinoKommati = BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1 + 1)];
  1430.  
  1431. if ((ProsorinoKommati.CompareTo("Black Queen") == 1) && (ProsorinoKommati.CompareTo("Black Rook") == 1) && (ProsorinoKommati.CompareTo("Black Knight") == 1) && (ProsorinoKommati.CompareTo("Black Bishop") == 1) && (ProsorinoKommati.CompareTo("Black Pawn") == 1) && (DangerForMate == true) && ((StartingBlackKingRank - 1 + 1) <= 7) && ((StartingBlackKingColumn - 1 - 1) >= 0))
  1432. {
  1433.  
  1434. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1435.  
  1436. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = "";
  1437. BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1 + 1)] = MovingPiece;
  1438. BlackKingCheck = CheckForBlackCheck(BMSkakiera);
  1439.  
  1440. if (BlackKingCheck == false)
  1441. DangerForMate = false;
  1442.  
  1443. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1444. // σκοπούς του ελέγχου.
  1445.  
  1446. BMSkakiera[(StartingBlackKingColumn - 1), (StartingBlackKingRank - 1)] = MovingPiece;
  1447. BMSkakiera[(StartingBlackKingColumn - 1 - 1), (StartingBlackKingRank - 1 + 1)] = ProsorinoKommati;
  1448.  
  1449. }
  1450.  
  1451. }
  1452.  
  1453. if (DangerForMate == true)
  1454. Mate = true;
  1455.  
  1456. }
  1457.  
  1458. return Mate;
  1459. }
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466. public static bool CheckForWhiteCheck(string[,] WCSkakiera)
  1467. {
  1468.  
  1469.  
  1470. // TODO: Add your control notification handler code here
  1471.  
  1472. bool KingCheck;
  1473.  
  1474. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1475. // Εύρεση των συντεταγμένων του βασιλιά.
  1476. // Αν σε κάποιο τετράγωνο βρεθεί ότι υπάρχει ένας βασιλιάς, τότε απλά καταγράφεται η τιμή του εν λόγω
  1477. // τετραγώνου στις αντίστοιχες μεταβλητές που δηλώνουν τη στήλη και τη γραμμή στην οποία υπάρχει λευκός
  1478. // βασιλιάς.
  1479. // ΠΡΟΣΟΧΗ: Γράφω (i+1) αντί για i και (j+1) αντί για j γιατί το πρώτο στοιχείο του πίνακα WCWCSkakiera[(8),(8)]
  1480. // είναι το WCSkakiera[(0),(0)] και ΟΧΙ το WCSkakiera[(1),(1)]!
  1481. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1482.  
  1483. for (i = 0; i <= 7; i++)
  1484. {
  1485. for (j = 0; j <= 7; j++)
  1486. {
  1487.  
  1488. if (WCSkakiera[(i), (j)].CompareTo("White King") == 0)
  1489. {
  1490. WhiteKingColumn = (i + 1);
  1491. WhiteKingRank = (j + 1);
  1492. }
  1493.  
  1494. }
  1495. }
  1496.  
  1497. ///////////////////////////////////////////////////////////////
  1498. // Έλεγχος του αν ο λευκός βασιλιάς υφίσταται "σαχ"
  1499. ///////////////////////////////////////////////////////////////
  1500.  
  1501. KingCheck = false;
  1502.  
  1503. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1504. // Ελέγχουμε αρχικά αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΤΑ ΔΕΞΙΑ ΤΟΥ. Για να μην βγούμε έξω από τα
  1505. // όρια της WCSkakiera[(8),(8)] έχουμε προσθέσει τον έλεγχο (WhiteKingColumn + 1) <= 8 στο "if". Αρχικά ο "κίνδυνος"
  1506. // από τα "δεξιά" είναι υπαρκτός, άρα DangerFromRight = true. Ωστόσο αν βρεθεί ότι στα δεξιά του λευκού βασι-
  1507. // λιά υπάρχει κάποιο λευκό κομμάτι, τότε δεν είναι δυνατόν ο εν λόγω βασιλιάς να υφίσταται σαχ από τα δεξιά
  1508. // του (αφού θα "προστατεύεται" από το κομμάτι ιδίου χρώματος), οπότε η DangerFromRight = false και ο έλεγχος
  1509. // για απειλές από τα δεξιά σταματάει (για αυτό και έχω προσθέσει την προϋπόθεση (DangerFromRight == true) στα
  1510. // "if" που κάνουν αυτόν τον έλεγχο).
  1511. // Αν όμως δεν υπάρχει κανένα λευκό κομμάτι δεξιά του βασιλιά για να τον προστατεύει, τότε συνεχίζει να
  1512. // υπάρχει πιθανότητα να απειλείται ο βασιλιάς από τα δεξιά του, οπότε ο έλεγχος συνεχίζεται.
  1513. // Σημείωση: Ο έλεγχος γίνεται για πιθανό σαχ από πύργο ή βασίλισσα αντίθετου χρώματος.
  1514. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1515.  
  1516. DangerFromRight = true;
  1517.  
  1518. for (int klopa = 1; klopa <= 7; klopa++)
  1519. {
  1520. if (((WhiteKingColumn + klopa) <= 8) && (DangerFromRight == true))
  1521. {
  1522. if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Rook") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Queen") == 0))
  1523. KingCheck = true;
  1524. else if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("White Pawn") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("White Rook") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("White Knight") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("White Bishop") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("White Queen") == 0))
  1525. DangerFromRight = false;
  1526. else if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Pawn") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Knight") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Bishop") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - 1)].CompareTo("Black King") == 0))
  1527. DangerFromRight = false;
  1528. }
  1529. }
  1530.  
  1531.  
  1532. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  1533. // Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΤΑ ΑΡΙΣΤΕΡΑ ΤΟΥ (από πύργο ή βασίλισσα).
  1534. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  1535.  
  1536. DangerFromLeft = true;
  1537.  
  1538. for (int klopa = 1; klopa <= 7; klopa++)
  1539. {
  1540. if (((WhiteKingColumn - klopa) >= 1) && (DangerFromLeft == true))
  1541. {
  1542. if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Rook") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Queen") == 0))
  1543. KingCheck = true;
  1544. else if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("White Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("White Rook") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("White Knight") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("White Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("White Queen") == 0))
  1545. DangerFromLeft = false;
  1546. else if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Knight") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("Black Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - 1)].CompareTo("Black King") == 0))
  1547. DangerFromLeft = false;
  1548. }
  1549. }
  1550.  
  1551.  
  1552. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  1553. // Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΠΑΝΩ (από πύργο ή βασίλισσα).
  1554. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  1555.  
  1556.  
  1557. DangerFromUp = true;
  1558.  
  1559. for (int klopa = 1; klopa <= 7; klopa++)
  1560. {
  1561. if (((WhiteKingRank + klopa) <= 8) && (DangerFromUp == true))
  1562. {
  1563. if ((WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Rook") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Queen") == 0))
  1564. KingCheck = true;
  1565. else if ((WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Rook") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Knight") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Queen") == 0))
  1566. DangerFromUp = false;
  1567. else if ((WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Knight") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black King") == 0))
  1568. DangerFromUp = false;
  1569. }
  1570. }
  1571.  
  1572.  
  1573. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  1574. // Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΚΑΤΩ (από πύργο ή βασίλισσα).
  1575. ///////////////////////////////////////////////////////////////////////////////////////////////////////
  1576.  
  1577. DangerFromDown = true;
  1578.  
  1579. for (int klopa = 1; klopa <= 7; klopa++)
  1580. {
  1581. if (((WhiteKingRank - klopa) >= 1) && (DangerFromDown == true))
  1582. {
  1583. if ((WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Rook") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Queen") == 0))
  1584. KingCheck = true;
  1585. else if ((WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Rook") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Knight") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Queen") == 0))
  1586. DangerFromDown = false;
  1587. else if ((WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Knight") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black King") == 0))
  1588. DangerFromDown = false;
  1589. }
  1590. }
  1591.  
  1592.  
  1593. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1594. // Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΠΑΝΩ-ΔΕΞΙΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
  1595. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1596.  
  1597. DangerFromUpRight = true;
  1598.  
  1599. for (int klopa = 1; klopa <= 7; klopa++)
  1600. {
  1601. if (((WhiteKingColumn + klopa) <= 8) && ((WhiteKingRank + klopa) <= 8) && (DangerFromUpRight == true))
  1602. {
  1603. if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Bishop") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Queen") == 0))
  1604. KingCheck = true;
  1605. else if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Pawn") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Rook") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Knight") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Bishop") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Queen") == 0))
  1606. DangerFromUpRight = false;
  1607. else if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Pawn") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Rook") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Knight") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black King") == 0))
  1608. DangerFromUpRight = false;
  1609. }
  1610. }
  1611.  
  1612.  
  1613. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1614. // Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΚΑΤΩ-ΑΡΙΣΤΕΡΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
  1615. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1616.  
  1617. DangerFromDownLeft = true;
  1618.  
  1619. for (int klopa = 1; klopa <= 7; klopa++)
  1620. {
  1621. if (((WhiteKingColumn - klopa) >= 1) && ((WhiteKingRank - klopa) >= 1) && (DangerFromDownLeft == true))
  1622. {
  1623. if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Queen") == 0))
  1624. KingCheck = true;
  1625. else if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Rook") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Knight") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Queen") == 0))
  1626. DangerFromDownLeft = false;
  1627. else if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Rook") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Knight") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black King") == 0))
  1628. DangerFromDownLeft = false;
  1629. }
  1630. }
  1631.  
  1632. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1633. // Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΚΑΤΩ-ΔΕΞΙΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
  1634. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1635.  
  1636. DangerFromDownRight = true;
  1637.  
  1638. for (int klopa = 1; klopa <= 7; klopa++)
  1639. {
  1640. if (((WhiteKingColumn + klopa) <= 8) && ((WhiteKingRank - klopa) >= 1) && (DangerFromDownRight == true))
  1641. {
  1642. if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Bishop") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Queen") == 0))
  1643. KingCheck = true;
  1644. else if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Pawn") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Rook") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Knight") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Bishop") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("White Queen") == 0))
  1645. DangerFromDownRight = false;
  1646. else if ((WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Pawn") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Rook") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black Knight") == 0) || (WCSkakiera[(WhiteKingColumn + klopa - 1), (WhiteKingRank - klopa - 1)].CompareTo("Black King") == 0))
  1647. DangerFromDownRight = false;
  1648. }
  1649. }
  1650.  
  1651.  
  1652. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1653. // Έλεγχος αν υπάρχει κίνδυνος για το λευκό βασιλιά ΑΠΟ ΠΑΝΩ-ΑΡΙΣΤΕΡΑ ΤΟΥ (από βασίλισσα ή αξιωματικό).
  1654. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1655.  
  1656. DangerFromUpLeft = true;
  1657.  
  1658. for (int klopa = 1; klopa <= 7; klopa++)
  1659. {
  1660. if (((WhiteKingColumn - klopa) >= 1) && ((WhiteKingRank + klopa) <= 8) && (DangerFromUpLeft == true))
  1661. {
  1662. if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Queen") == 0))
  1663. KingCheck = true;
  1664. else if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Rook") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Knight") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Bishop") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("White Queen") == 0))
  1665. DangerFromUpLeft = false;
  1666. else if ((WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Pawn") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Rook") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black Knight") == 0) || (WCSkakiera[(WhiteKingColumn - klopa - 1), (WhiteKingRank + klopa - 1)].CompareTo("Black King") == 0))
  1667. DangerFromUpLeft = false;
  1668. }
  1669. }
  1670.  
  1671.  
  1672.  
  1673. //////////////////////////////////////////////////////////////////////////
  1674. // Έλεγχος για το αν ο λευκός βασιλιάς απειλείται από πιόνι.
  1675. //////////////////////////////////////////////////////////////////////////
  1676.  
  1677. if (((WhiteKingColumn + 1) <= 8) && ((WhiteKingRank + 1) <= 8))
  1678. {
  1679. if (WCSkakiera[(WhiteKingColumn + 1 - 1), (WhiteKingRank + 1 - 1)].CompareTo("Black Pawn") == 0)
  1680. {
  1681. KingCheck = true;
  1682. }
  1683. }
  1684.  
  1685.  
  1686. if (((WhiteKingColumn - 1) >= 1) && ((WhiteKingRank + 1) <= 8))
  1687. {
  1688. if (WCSkakiera[(WhiteKingColumn - 1 - 1), (WhiteKingRank + 1 - 1)].CompareTo("Black Pawn") == 0)
  1689. {
  1690. KingCheck = true;
  1691. }
  1692. }
  1693.  
  1694.  
  1695. ///////////////////////////////////////////////////////////////////////
  1696. // Έλεγχος για το αν ο λευκός βασιλιάς απειλείται από ίππο.
  1697. ///////////////////////////////////////////////////////////////////////
  1698.  
  1699. if (((WhiteKingColumn + 1) <= 8) && ((WhiteKingRank + 2) <= 8))
  1700. if (WCSkakiera[(WhiteKingColumn + 1 - 1), (WhiteKingRank + 2 - 1)].CompareTo("Black Knight") == 0)
  1701. KingCheck = true;
  1702.  
  1703. if (((WhiteKingColumn + 2) <= 8) && ((WhiteKingRank - 1) >= 1))
  1704. if (WCSkakiera[(WhiteKingColumn + 2 - 1), (WhiteKingRank - 1 - 1)].CompareTo("Black Knight") == 0)
  1705. KingCheck = true;
  1706.  
  1707. if (((WhiteKingColumn + 1) <= 8) && ((WhiteKingRank - 2) >= 1))
  1708. if (WCSkakiera[(WhiteKingColumn + 1 - 1), (WhiteKingRank - 2 - 1)].CompareTo("Black Knight") == 0)
  1709. KingCheck = true;
  1710.  
  1711. if (((WhiteKingColumn - 1) >= 1) && ((WhiteKingRank - 2) >= 1))
  1712. if (WCSkakiera[(WhiteKingColumn - 1 - 1), (WhiteKingRank - 2 - 1)].CompareTo("Black Knight") == 0)
  1713. KingCheck = true;
  1714.  
  1715. if (((WhiteKingColumn - 2) >= 1) && ((WhiteKingRank - 1) >= 1))
  1716. if (WCSkakiera[(WhiteKingColumn - 2 - 1), (WhiteKingRank - 1 - 1)].CompareTo("Black Knight") == 0)
  1717. KingCheck = true;
  1718.  
  1719. if (((WhiteKingColumn - 2) >= 1) && ((WhiteKingRank + 1) <= 8))
  1720. if (WCSkakiera[(WhiteKingColumn - 2 - 1), (WhiteKingRank + 1 - 1)].CompareTo("Black Knight") == 0)
  1721. KingCheck = true;
  1722.  
  1723. if (((WhiteKingColumn - 1) >= 1) && ((WhiteKingRank + 2) <= 8))
  1724. if (WCSkakiera[(WhiteKingColumn - 1 - 1), (WhiteKingRank + 2 - 1)].CompareTo("Black Knight") == 0)
  1725. KingCheck = true;
  1726.  
  1727. if (((WhiteKingColumn + 2) <= 8) && ((WhiteKingRank + 1) <= 8))
  1728. if (WCSkakiera[(WhiteKingColumn + 2 - 1), (WhiteKingRank + 1 - 1)].CompareTo("Black Knight") == 0)
  1729. KingCheck = true;
  1730.  
  1731. return KingCheck;
  1732. }
  1733.  
  1734.  
  1735.  
  1736.  
  1737. public static bool CheckForWhiteMate(string[,] WMSkakiera)
  1738. {
  1739. // TODO: Add your control notification handler code here
  1740.  
  1741. bool Mate;
  1742.  
  1743. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  1744. // Μεταβλητή που χρησιμεύει στον έλεγχο για το αν υπάρχει ματ (βλ. συναρτήσεις CheckForWhiteMate() και
  1745. // CheckForBlackMate()).
  1746. // Αναλυτικότερα, το πρόγραμμα ελέγχει αν αρχικά υπάρχει σαχ και, αν υπάρχει, ελέγχει αν αυτό το
  1747. // σαχ μπορεί να αποφευχθεί με τη μετακίνηση του υπό απειλή βασιλιά σε κάποιο γειτονικό τετράγωνο.
  1748. // Η μεταβλητή καταγράφει το αν συνεχίζει να υπάρχει πιθανότητα να υπάρχει ματ στη σκακιέρα.
  1749. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  1750.  
  1751. bool DangerForMate;
  1752.  
  1753. ////////////////////////////////////////////////////////////
  1754. // Έλεγχος του αν υπάρχει "ματ" στον λευκό βασιλιά
  1755. ////////////////////////////////////////////////////////////
  1756.  
  1757. Mate = false;
  1758. DangerForMate = true; // Αρχικά, προφανώς υπάρχει πιθανότητα να υπάρχει ματ στη σκακιέρα.
  1759. // Αν, ωστόσο, κάποια στιγμή βρεθεί ότι αν ο βασιλιάς μπορεί να μετακινηθεί
  1760. // σε ένα διπλανό τετράγωνο και να πάψει να υφίσταται σαχ, τότε παύει να
  1761. // υπάρχει πιθανότητα να υπάρχει ματ (προφανώς) και η μεταβλητή παίρνει την
  1762. // τιμή false.
  1763.  
  1764.  
  1765. //////////////////////////////////////////////////////////////
  1766. // Εύρεση των αρχικών συντεταγμένων του βασιλιά
  1767. //////////////////////////////////////////////////////////////
  1768.  
  1769. for (i = 0; i <= 7; i++)
  1770. {
  1771. for (j = 0; j <= 7; j++)
  1772. {
  1773.  
  1774. if (WMSkakiera[(i), (j)].CompareTo("White King") == 0)
  1775. {
  1776. StartingWhiteKingColumn = (i + 1);
  1777. StartingWhiteKingRank = (j + 1);
  1778. }
  1779.  
  1780. }
  1781. }
  1782.  
  1783.  
  1784. //////////////////////////////////////////////////
  1785. // Έλεγχος αν ο λευκός βασιλιάς είναι ματ
  1786. //////////////////////////////////////////////////
  1787.  
  1788.  
  1789. if (m_WhichColorPlays.CompareTo("White") == 0)
  1790. {
  1791.  
  1792. ////////////////////////////////////////////////
  1793. // Έλεγχος αν υπάρχει σαχ αυτή τη στιγμή
  1794. ////////////////////////////////////////////////
  1795.  
  1796. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  1797.  
  1798. if (WhiteKingCheck == false) // Αν αυτή τη στιγμή δεν υφίσταται σαχ, τότε να μη συνεχιστεί ο έλεγχος
  1799. DangerForMate = false; // καθώς ΔΕΝ συνεχίζει να υφίσταται πιθανότητα να υπάρχει ματ.
  1800.  
  1801. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1802. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο λευκός βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1803. // προς τα πάνω
  1804. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1805.  
  1806. if (StartingWhiteKingRank < 8)
  1807. {
  1808.  
  1809. MovingPiece = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)];
  1810. ProsorinoKommati = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1 + 1)];
  1811.  
  1812. if ((ProsorinoKommati.CompareTo("White Queen") == 1) && (ProsorinoKommati.CompareTo("White Rook") == 1) && (ProsorinoKommati.CompareTo("White Knight") == 1) && (ProsorinoKommati.CompareTo("White Bishop") == 1) && (ProsorinoKommati.CompareTo("White Pawn") == 1) && (DangerForMate == true) && ((StartingWhiteKingRank - 1 + 1) <= 7))
  1813. {
  1814.  
  1815. // (Προσωρινή) μετακίνηση του βασιλιά προς τα πάνω και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1816. // Ο έλεγχος γίνεται μόνο αν στο τετράγωνο που μετακινείται προσωρινά ο βασιλιάς δεν υπάρχει άλλο κομμάτι
  1817. // του ίδιου χρώματος που να τον εμποδίζει και αν, φυσικά, ο βασιλιάς δεν βγαίνει έξω από τη σκακιέρα με
  1818. // αυτή του την κίνηση και αν, προφανώς, συνεχίζει να υπάρχει πιθανότητα να ύπάρχει ματ (καθώς αν δεν
  1819. // υπάρχει τέτοια πιθανότητα, τότε ο έλεγχος είναι άχρηστος).
  1820.  
  1821. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = "";
  1822. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1 + 1)] = MovingPiece;
  1823. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  1824.  
  1825. if (WhiteKingCheck == false)
  1826. DangerForMate = false;
  1827.  
  1828. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1829. // σκοπούς του ελέγχου.
  1830.  
  1831. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  1832. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1 + 1)] = ProsorinoKommati;
  1833.  
  1834. }
  1835.  
  1836. }
  1837.  
  1838.  
  1839. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1840. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο λευκός βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1841. // προς τα πάνω-δεξιά
  1842. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1843.  
  1844. if ((StartingWhiteKingColumn < 8) && (StartingWhiteKingRank < 8))
  1845. {
  1846.  
  1847. MovingPiece = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)];
  1848. ProsorinoKommati = WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1 + 1)];
  1849.  
  1850. if ((ProsorinoKommati.CompareTo("White Queen") == 1) && (ProsorinoKommati.CompareTo("White Rook") == 1) && (ProsorinoKommati.CompareTo("White Knight") == 1) && (ProsorinoKommati.CompareTo("White Bishop") == 1) && (ProsorinoKommati.CompareTo("White Pawn") == 1) && (DangerForMate == true) && ((StartingWhiteKingRank - 1 + 1) <= 7) && ((StartingWhiteKingColumn - 1 + 1) <= 7))
  1851. {
  1852.  
  1853. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1854.  
  1855. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = "";
  1856. WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1 + 1)] = MovingPiece;
  1857. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  1858.  
  1859. if (WhiteKingCheck == false)
  1860. DangerForMate = false;
  1861.  
  1862. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1863. // σκοπούς του ελέγχου.
  1864.  
  1865. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  1866. WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1 + 1)] = ProsorinoKommati;
  1867.  
  1868. }
  1869.  
  1870. }
  1871.  
  1872.  
  1873. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1874. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο λευκός βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1875. // προς τα δεξιά
  1876. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1877.  
  1878. if (StartingWhiteKingColumn < 8)
  1879. {
  1880.  
  1881. MovingPiece = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)];
  1882. ProsorinoKommati = WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1)];
  1883.  
  1884. if ((ProsorinoKommati.CompareTo("White Queen") == 1) && (ProsorinoKommati.CompareTo("White Rook") == 1) && (ProsorinoKommati.CompareTo("White Knight") == 1) && (ProsorinoKommati.CompareTo("White Bishop") == 1) && (ProsorinoKommati.CompareTo("White Pawn") == 1) && (DangerForMate == true) && ((StartingWhiteKingColumn - 1 + 1) <= 7))
  1885. {
  1886.  
  1887. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1888.  
  1889. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = "";
  1890. WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  1891. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  1892.  
  1893. if (WhiteKingCheck == false)
  1894. DangerForMate = false;
  1895.  
  1896. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1897. // σκοπούς του ελέγχου.
  1898.  
  1899. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  1900. WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1)] = ProsorinoKommati;
  1901.  
  1902. }
  1903.  
  1904. }
  1905.  
  1906.  
  1907. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1908. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο λευκός βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1909. // προς τα κάτω-δεξιά
  1910. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1911.  
  1912. if ((StartingWhiteKingColumn < 8) && (StartingWhiteKingRank > 1))
  1913. {
  1914.  
  1915. MovingPiece = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)];
  1916. ProsorinoKommati = WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1 - 1)];
  1917.  
  1918. if ((ProsorinoKommati.CompareTo("White Queen") == 1) && (ProsorinoKommati.CompareTo("White Rook") == 1) && (ProsorinoKommati.CompareTo("White Knight") == 1) && (ProsorinoKommati.CompareTo("White Bishop") == 1) && (ProsorinoKommati.CompareTo("White Pawn") == 1) && (DangerForMate == true) && ((StartingWhiteKingRank - 1 - 1) >= 0) && ((StartingWhiteKingColumn - 1 + 1) <= 7))
  1919. {
  1920.  
  1921. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1922.  
  1923. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = "";
  1924. WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1 - 1)] = MovingPiece;
  1925. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  1926.  
  1927. if (WhiteKingCheck == false)
  1928. DangerForMate = false;
  1929.  
  1930. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1931. // σκοπούς του ελέγχου.
  1932.  
  1933. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  1934. WMSkakiera[(StartingWhiteKingColumn - 1 + 1), (StartingWhiteKingRank - 1 - 1)] = ProsorinoKommati;
  1935.  
  1936. }
  1937.  
  1938. }
  1939.  
  1940.  
  1941. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1942. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο λευκός βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1943. // προς τα κάτω
  1944. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1945.  
  1946. if (StartingWhiteKingRank > 1)
  1947. {
  1948.  
  1949. MovingPiece = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)];
  1950. ProsorinoKommati = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1 - 1)];
  1951.  
  1952. if ((ProsorinoKommati.CompareTo("White Queen") == 1) && (ProsorinoKommati.CompareTo("White Rook") == 1) && (ProsorinoKommati.CompareTo("White Knight") == 1) && (ProsorinoKommati.CompareTo("White Bishop") == 1) && (ProsorinoKommati.CompareTo("White Pawn") == 1) && (DangerForMate == true) && ((StartingWhiteKingRank - 1 - 1) >= 0))
  1953. {
  1954.  
  1955. // (Προσωρινή) μετακίνηση του βασιλιά προς τα πάνω και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1956.  
  1957. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = "";
  1958. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1 - 1)] = MovingPiece;
  1959. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  1960.  
  1961. if (WhiteKingCheck == false)
  1962. DangerForMate = false;
  1963.  
  1964. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1965. // σκοπούς του ελέγχου.
  1966.  
  1967. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  1968. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1 - 1)] = ProsorinoKommati;
  1969.  
  1970. }
  1971.  
  1972. }
  1973.  
  1974.  
  1975. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1976. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο λευκός βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  1977. // προς τα κάτω-αριστερά
  1978. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  1979.  
  1980. if ((StartingWhiteKingColumn > 1) && (StartingWhiteKingRank > 1))
  1981. {
  1982.  
  1983. MovingPiece = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)];
  1984. ProsorinoKommati = WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1 - 1)];
  1985.  
  1986. if ((ProsorinoKommati.CompareTo("White Queen") == 1) && (ProsorinoKommati.CompareTo("White Rook") == 1) && (ProsorinoKommati.CompareTo("White Knight") == 1) && (ProsorinoKommati.CompareTo("White Bishop") == 1) && (ProsorinoKommati.CompareTo("White Pawn") == 1) && (DangerForMate == true) && ((StartingWhiteKingRank - 1 - 1) >= 0) && ((StartingWhiteKingColumn - 1 - 1) >= 0))
  1987. {
  1988.  
  1989. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  1990.  
  1991. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = "";
  1992. WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1 - 1)] = MovingPiece;
  1993. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  1994.  
  1995. if (WhiteKingCheck == false)
  1996. DangerForMate = false;
  1997.  
  1998. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  1999. // σκοπούς του ελέγχου.
  2000.  
  2001. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  2002. WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1 - 1)] = ProsorinoKommati;
  2003.  
  2004. }
  2005.  
  2006. }
  2007.  
  2008.  
  2009. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2010. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο λευκός βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  2011. // προς τα αριστερά
  2012. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2013.  
  2014. if (StartingWhiteKingColumn > 1)
  2015. {
  2016.  
  2017. MovingPiece = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)];
  2018. ProsorinoKommati = WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1)];
  2019.  
  2020. if ((ProsorinoKommati.CompareTo("White Queen") == 1) && (ProsorinoKommati.CompareTo("White Rook") == 1) && (ProsorinoKommati.CompareTo("White Knight") == 1) && (ProsorinoKommati.CompareTo("White Bishop") == 1) && (ProsorinoKommati.CompareTo("White Pawn") == 1) && (DangerForMate == true) && ((StartingWhiteKingColumn - 1 - 1) >= 0))
  2021. {
  2022.  
  2023. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  2024.  
  2025. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = "";
  2026. WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  2027. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  2028.  
  2029. if (WhiteKingCheck == false)
  2030. DangerForMate = false;
  2031.  
  2032. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  2033. // σκοπούς του ελέγχου.
  2034.  
  2035. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  2036. WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1)] = ProsorinoKommati;
  2037.  
  2038. }
  2039.  
  2040. }
  2041.  
  2042.  
  2043. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2044. // Έλεγχος του αν θα συνεχίσει να υπάρχει σαχ αν ο λευκός βασιλιάς προσπαθήσει να διαφύγει μετακινούμενος
  2045. // προς τα πάνω-αριστερά
  2046. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2047.  
  2048. if ((StartingWhiteKingColumn > 1) && (StartingWhiteKingRank < 8))
  2049. {
  2050.  
  2051. MovingPiece = WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)];
  2052. ProsorinoKommati = WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1 + 1)];
  2053.  
  2054. if ((ProsorinoKommati.CompareTo("White Queen") == 1) && (ProsorinoKommati.CompareTo("White Rook") == 1) && (ProsorinoKommati.CompareTo("White Knight") == 1) && (ProsorinoKommati.CompareTo("White Bishop") == 1) && (ProsorinoKommati.CompareTo("White Pawn") == 1) && (DangerForMate == true) && ((StartingWhiteKingRank - 1 + 1) <= 7) && ((StartingWhiteKingColumn - 1 - 1) >= 0))
  2055. {
  2056.  
  2057. // (Προσωρινή) μετακίνηση του βασιλιά και έλεγχος του αν συνεχίζει τότε να υπάρχει σαχ.
  2058.  
  2059. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = "";
  2060. WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1 + 1)] = MovingPiece;
  2061. WhiteKingCheck = CheckForWhiteCheck(WMSkakiera);
  2062.  
  2063. if (WhiteKingCheck == false)
  2064. DangerForMate = false;
  2065.  
  2066. // Επαναφορά της σκακιέρας στην κατάσταση στην οποία βρισκόταν πριν μετακινηθεί ο βασιλιάς για τους
  2067. // σκοπούς του ελέγχου.
  2068.  
  2069. WMSkakiera[(StartingWhiteKingColumn - 1), (StartingWhiteKingRank - 1)] = MovingPiece;
  2070. WMSkakiera[(StartingWhiteKingColumn - 1 - 1), (StartingWhiteKingRank - 1 + 1)] = ProsorinoKommati;
  2071.  
  2072. }
  2073.  
  2074. }
  2075.  
  2076. if (DangerForMate == true)
  2077. Mate = true;
  2078.  
  2079. }
  2080.  
  2081. return Mate;
  2082. }
  2083.  
  2084.  
  2085. // Changed in version 0.961!
  2086. public static void CheckMove(string[,] CMSkakiera)
  2087. {
  2088. #region WriteLog
  2089. //huo_sw1.WriteLine("");
  2090. //huo_sw1.WriteLine("ChMo -- Entered CheckMove");
  2091. //huo_sw1.WriteLine(string.Concat("ChMo -- Depth analyzed: ", Move_Analyzed.ToString()));
  2092. //huo_sw1.WriteLine(string.Concat("ChMo -- Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  2093. //huo_sw1.WriteLine(string.Concat("ChMo -- Move analyzed: ", m_StartingColumnNumber_HY.ToString(), m_StartingRank_HY.ToString(), " -> ", m_FinishingColumnNumber_HY.ToString(), m_FinishingRank_HY.ToString()));
  2094. //huo_sw1.WriteLine(string.Concat("ChMo -- Number of Nodes 0: ", NodeLevel_0_count.ToString()));
  2095. //huo_sw1.WriteLine(string.Concat("ChMo -- Number of Nodes 1: ", NodeLevel_1_count.ToString()));
  2096. //huo_sw1.WriteLine(string.Concat("ChMo -- Number of Nodes 2: ", NodeLevel_2_count.ToString()));
  2097. //huo_sw1.WriteLine(string.Concat("ChMo -- Number of Nodes 3: ", NodeLevel_3_count.ToString()));
  2098. //huo_sw1.WriteLine(string.Concat("ChMo -- Number of Nodes 4: ", NodeLevel_4_count.ToString()));
  2099. //huo_sw1.WriteLine(string.Concat("ChMo -- Number of Nodes 5: ", NodeLevel_5_count.ToString()));
  2100. //huo_sw1.WriteLine(string.Concat("ChMo -- Number of Nodes 6: ", NodeLevel_6_count.ToString()));
  2101. //huo_sw1.WriteLine("");
  2102. #endregion WriteLog
  2103.  
  2104. number_of_moves_analysed++;
  2105.  
  2106. m_WhoPlays = "Human";
  2107. m_WrongColumn = false;
  2108. MovingPiece = CMSkakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)];
  2109.  
  2110. // Check correctness of move
  2111. m_OrthotitaKinisis = ElegxosOrthotitas(CMSkakiera, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  2112. // if move is correct, then check the legality also
  2113. if (m_OrthotitaKinisis == true)
  2114. m_NomimotitaKinisis = ElegxosNomimotitas(CMSkakiera, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  2115.  
  2116. // restore the normal value of the m_WhoPlays
  2117. m_WhoPlays = "HY";
  2118.  
  2119. // CHECK FOR MATE
  2120. #region CheckForMate
  2121.  
  2122. if (((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true)) && (Move_Analyzed == 0))
  2123. {
  2124. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2125. // temporarily move the piece to see if the king will continue to be under check
  2126. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  2127.  
  2128. CMSkakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  2129. ProsorinoKommati = CMSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)]; // Προσωρινή αποθήκευση του
  2130. // κομματιού που βρίσκεται στο
  2131. // τετράγωνο προορισμού
  2132. // (βλ. μετά για τη χρησιμότητα
  2133. // του, εκεί που γίνεται έλεγ-
  2134. // χος για το αν συνεχίζει να
  2135. // υφίσταται σαχ).
  2136.  
  2137. CMSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  2138.  
  2139.  
  2140. //////////////////////////////////////////////////////////////////////////
  2141. // is the king still under check?
  2142. //////////////////////////////////////////////////////////////////////////
  2143.  
  2144. WhiteKingCheck = CheckForWhiteCheck(CMSkakiera);
  2145.  
  2146. if ((m_WhichColorPlays.CompareTo("White") == 0) && (WhiteKingCheck == true))
  2147. {
  2148. m_NomimotitaKinisis = false;
  2149. }
  2150.  
  2151.  
  2152. ///////////////////////////////////////////////////////////////////////////
  2153. // is the black king under check?
  2154. ///////////////////////////////////////////////////////////////////////////
  2155.  
  2156. BlackKingCheck = CheckForBlackCheck(CMSkakiera);
  2157.  
  2158. if ((m_WhichColorPlays.CompareTo("Black") == 0) && (BlackKingCheck == true))
  2159. {
  2160. m_NomimotitaKinisis = false;
  2161. }
  2162.  
  2163.  
  2164. // restore pieces to their initial positions
  2165. CMSkakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = MovingPiece;
  2166. CMSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = ProsorinoKommati;
  2167.  
  2168. }
  2169. #endregion CheckForMate
  2170.  
  2171. if (((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true)) && (Move_Analyzed == 0))
  2172. {
  2173. // Store the move to ***_HY variables (because after continuous calls of ComputerMove the initial move under analysis will be lost...)
  2174.  
  2175. MovingPiece_HY = MovingPiece;
  2176. m_StartingColumnNumber_HY = m_StartingColumnNumber;
  2177. m_FinishingColumnNumber_HY = m_FinishingColumnNumber;
  2178. m_StartingRank_HY = m_StartingRank;
  2179. m_FinishingRank_HY = m_FinishingRank;
  2180.  
  2181. // Store the initial move coordinates (at the node 0 level)
  2182. NodesAnalysis[NodeLevel_0_count, 21, 0] = m_StartingColumnNumber_HY;
  2183. NodesAnalysis[NodeLevel_0_count, 22, 0] = m_FinishingColumnNumber_HY;
  2184. NodesAnalysis[NodeLevel_0_count, 23, 0] = m_StartingRank_HY;
  2185. NodesAnalysis[NodeLevel_0_count, 24, 0] = m_FinishingRank_HY;
  2186.  
  2187. // Temporarily move the piece to see if the king will continue to be under check
  2188. #region CheckCheck
  2189.  
  2190. CMSkakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  2191. ProsorinoKommati = CMSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  2192. // Προσωρινή αποθήκευση του κομματιού που βρίσκεται στο τετράγωνο προορισμού
  2193. // (βλ. μετά για τη χρησιμότητα του, εκεί που γίνεται έλεγχος για το αν συνεχίζει να υφίσταται σαχ).
  2194.  
  2195. CMSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  2196.  
  2197.  
  2198. //////////////////////////////////////////////////////////////////////////
  2199. // is the king still under check?
  2200. //////////////////////////////////////////////////////////////////////////
  2201.  
  2202. WhiteKingCheck = CheckForWhiteCheck(CMSkakiera);
  2203.  
  2204. if ((m_WhichColorPlays.CompareTo("White") == 0) && (WhiteKingCheck == true))
  2205. {
  2206. m_NomimotitaKinisis = false;
  2207. }
  2208.  
  2209.  
  2210. ///////////////////////////////////////////////////////////////////////////
  2211. // is the black king under check?
  2212. ///////////////////////////////////////////////////////////////////////////
  2213.  
  2214. BlackKingCheck = CheckForBlackCheck(CMSkakiera);
  2215.  
  2216. if ((m_WhichColorPlays.CompareTo("Black") == 0) && (BlackKingCheck == true))
  2217. {
  2218. m_NomimotitaKinisis = false;
  2219. }
  2220.  
  2221.  
  2222. // restore pieces to their initial positions
  2223. CMSkakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = MovingPiece;
  2224. CMSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = ProsorinoKommati;
  2225. #endregion CheckCheck
  2226.  
  2227. // check is HY eats the opponents queen (so it is preferable to do so...)
  2228. if ((ProsorinoKommati.CompareTo("White Queen") == 0) || (ProsorinoKommati.CompareTo("Black Queen") == 0))
  2229. go_for_it = true;
  2230. // Not operational yet...
  2231. go_for_it = false;
  2232.  
  2233. // CHECK FOR DANGER PENALTY
  2234. #region DangerPenalty
  2235. int Existing_Danger_level = 0;
  2236. int Current_Danger_level = 0;
  2237. Danger_penalty = false;
  2238. Danger_for_piece = false;
  2239. int Piece_in_danger_rank = 0;
  2240. int Piece_in_danger_column = 0;
  2241.  
  2242. // Find value of piece in Skakiera(y,u)
  2243. // v0.96
  2244. int Value_of_piece_in_square = 0;
  2245. if ((Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Rook") == 0) || (Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Rook") == 0))
  2246. Value_of_piece_in_square = 5;
  2247. else if ((Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Bishop") == 0) || (Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Bishop") == 0))
  2248. Value_of_piece_in_square = 3;
  2249. else if ((Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Knight") == 0) || (Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Knight") == 0))
  2250. Value_of_piece_in_square = 3;
  2251. else if ((Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Queen") == 0) || (Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Queen") == 0))
  2252. Value_of_piece_in_square = 9;
  2253. else if ((Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Pawn") == 0) || (Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Pawn") == 0))
  2254. Value_of_piece_in_square = 1;
  2255.  
  2256. int Value_of_moving_piece = 0;
  2257. if ((MovingPiece.CompareTo("White Rook") == 0) || (MovingPiece.CompareTo("Black Rook") == 0))
  2258. Value_of_moving_piece = 5;
  2259. else if ((MovingPiece.CompareTo("White Bishop") == 0) || (MovingPiece.CompareTo("Black Bishop") == 0))
  2260. Value_of_moving_piece = 3;
  2261. else if ((MovingPiece.CompareTo("White Knight") == 0) || (MovingPiece.CompareTo("Black Knight") == 0))
  2262. Value_of_moving_piece = 3;
  2263. else if ((MovingPiece.CompareTo("White Queen") == 0) || (MovingPiece.CompareTo("Black Queen") == 0))
  2264. Value_of_moving_piece = 9;
  2265. else if ((MovingPiece.CompareTo("White Pawn") == 0) || (MovingPiece.CompareTo("Black Pawn") == 0))
  2266. Value_of_moving_piece = 1;
  2267.  
  2268. if ((Number_of_defenders[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] == Number_of_attackers[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)]) && ((Value_of_defenders[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)]) > Value_of_attackers[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)]))
  2269. {
  2270. Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = "Danger";
  2271. }
  2272.  
  2273. if (Number_of_defenders[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] < Number_of_attackers[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)])
  2274. {
  2275. Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = "Danger";
  2276. }
  2277.  
  2278. // Check danger for specific pieces
  2279. if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0) && (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Queen") == 0) && (m_PlayerColor.CompareTo("Black") == 0))
  2280. {
  2281. Current_Danger_level = 9;
  2282.  
  2283. if (Current_Danger_level > Existing_Danger_level)
  2284. {
  2285. //Console.WriteLine("Danger for White Queen!");
  2286. Danger_for_piece = true;
  2287. Piece_in_danger_rank = (m_FinishingRank - 1);
  2288. Piece_in_danger_column = (m_FinishingColumnNumber - 1);
  2289. Existing_Danger_level = Current_Danger_level;
  2290. }
  2291. }
  2292. else if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0) && (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Queen") == 0) && (m_PlayerColor.CompareTo("White") == 0))
  2293. {
  2294. Current_Danger_level = 9;
  2295.  
  2296. if (Current_Danger_level > Existing_Danger_level)
  2297. {
  2298. //Console.WriteLine("Danger for Black Queen!");
  2299. Danger_for_piece = true;
  2300. Piece_in_danger_rank = (m_FinishingRank - 1);
  2301. Piece_in_danger_column = (m_FinishingColumnNumber - 1);
  2302. Existing_Danger_level = Current_Danger_level;
  2303. }
  2304. }
  2305. else if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0) && (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Rook") == 0) && (m_PlayerColor.CompareTo("Black") == 0))
  2306. {
  2307. Current_Danger_level = 5;
  2308.  
  2309. if (Current_Danger_level > Existing_Danger_level)
  2310. {
  2311. //Console.WriteLine("Danger for White Rook!");
  2312. Danger_for_piece = true;
  2313. Piece_in_danger_rank = (m_FinishingRank - 1);
  2314. Piece_in_danger_column = (m_FinishingColumnNumber - 1);
  2315. Existing_Danger_level = Current_Danger_level;
  2316. }
  2317. }
  2318. else if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0) && (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Rook") == 0) && (m_PlayerColor.CompareTo("White") == 0))
  2319. {
  2320. Current_Danger_level = 5;
  2321.  
  2322. if (Current_Danger_level > Existing_Danger_level)
  2323. {
  2324. //Console.WriteLine("Danger for Black Rook!");
  2325. Danger_for_piece = true;
  2326. Piece_in_danger_rank = (m_FinishingRank - 1);
  2327. Piece_in_danger_column = (m_FinishingColumnNumber - 1);
  2328. Existing_Danger_level = Current_Danger_level;
  2329. }
  2330. }
  2331. else if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0) && (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Knight") == 0) && (m_PlayerColor.CompareTo("Black") == 0))
  2332. {
  2333. Current_Danger_level = 3;
  2334.  
  2335. if (Current_Danger_level > Existing_Danger_level)
  2336. {
  2337. //Console.WriteLine("Danger for White Knight!");
  2338. Danger_for_piece = true;
  2339. Piece_in_danger_rank = (m_FinishingRank - 1);
  2340. Piece_in_danger_column = (m_FinishingColumnNumber - 1);
  2341. Existing_Danger_level = Current_Danger_level;
  2342. }
  2343. }
  2344. else if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0) && (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Knight") == 0) && (m_PlayerColor.CompareTo("White") == 0))
  2345. {
  2346. Current_Danger_level = 3;
  2347.  
  2348. if (Current_Danger_level > Existing_Danger_level)
  2349. {
  2350. //Console.WriteLine("Danger for Black Knight!");
  2351. Danger_for_piece = true;
  2352. Piece_in_danger_rank = (m_FinishingRank - 1);
  2353. Piece_in_danger_column = (m_FinishingColumnNumber - 1);
  2354. Existing_Danger_level = Current_Danger_level;
  2355. }
  2356. }
  2357. else if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0) && (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("White Bishop") == 0) && (m_PlayerColor.CompareTo("Black") == 0))
  2358. {
  2359. Current_Danger_level = 3;
  2360.  
  2361. if (Current_Danger_level > Existing_Danger_level)
  2362. {
  2363. //Console.WriteLine("Danger for White Bishop!");
  2364. Danger_for_piece = true;
  2365. Piece_in_danger_rank = (m_FinishingRank - 1);
  2366. Piece_in_danger_column = (m_FinishingColumnNumber - 1);
  2367. Existing_Danger_level = Current_Danger_level;
  2368. }
  2369. }
  2370. else if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0) && (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Black Bishop") == 0) && (m_PlayerColor.CompareTo("White") == 0))
  2371. {
  2372. Current_Danger_level = 3;
  2373.  
  2374. if (Current_Danger_level > Existing_Danger_level)
  2375. {
  2376. //Console.WriteLine("Danger for Black Bishop!");
  2377. Danger_for_piece = true;
  2378. Piece_in_danger_rank = (m_FinishingRank - 1);
  2379. Piece_in_danger_column = (m_FinishingColumnNumber - 1);
  2380. Existing_Danger_level = Current_Danger_level;
  2381. }
  2382. }
  2383.  
  2384.  
  2385. if ((Skakiera_Dangerous_Squares[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("Danger") == 0))
  2386. {
  2387. Danger_penalty = true;
  2388. }
  2389.  
  2390. // If you do not move the threatened piece, then: Danger Penalty!
  2391. if (Danger_for_piece == true)
  2392. {
  2393. if (((m_StartingColumnNumber - 1) != Piece_in_danger_column) || ((m_StartingRank - 1) != Piece_in_danger_rank))
  2394. {
  2395. //Console.WriteLine("Didn't you save the queen?");
  2396. Danger_penalty = true;
  2397. }
  2398.  
  2399. // Check again if the move eats the piece which threatens the computer's piece
  2400. if ((((m_FinishingColumnNumber - 1) == Attackers_coordinates_column[(Piece_in_danger_column), (Piece_in_danger_rank)]) && ((m_FinishingRank - 1) == Attackers_coordinates_rank[(Piece_in_danger_column), (Piece_in_danger_rank)])))
  2401. {
  2402. //Console.WriteLine(string.Concat("The move ", m_StartingColumnNumber.ToString(), m_StartingRank.ToString(), "->", m_FinishingColumnNumber.ToString(), m_FinishingRank.ToString(), " saves the queen!"));
  2403. Danger_penalty = false;
  2404. }
  2405. }
  2406.  
  2407. // Penalty for moving the only piece that defends a square to that square (thus leavind the defender
  2408. // alone in the square he once defended, defenceless!)
  2409. if ((Exception_defender_column[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] == (m_StartingColumnNumber - 1)) && (Exception_defender_rank[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] == (m_StartingRank - 1)))
  2410. {
  2411. //MessageBox.Show("Debug message - Danger penalty checkpoint 1");
  2412. Danger_penalty = true;
  2413. }
  2414.  
  2415. //------------------- END OF DANGER PENALTY CHECK --------------------------
  2416. #endregion DangerPenalty
  2417. }
  2418.  
  2419. }
  2420.  
  2421. // Changed in version 0.961!
  2422. public static void ComputerMove(string[,] Skakiera_Thinking_init)
  2423. {
  2424. #region WriteLog
  2425. //huo_sw1.WriteLine("");
  2426. //huo_sw1.WriteLine("CoMo -- Entered ComputerMove");
  2427. //huo_sw1.WriteLine(string.Concat("CoMo -- Depth analyzed: ", Move_Analyzed.ToString()));
  2428. //huo_sw1.WriteLine(string.Concat("CoMo -- Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  2429. //huo_sw1.WriteLine(string.Concat("CoMo -- Move analyzed: ", m_StartingColumnNumber_HY.ToString(), m_StartingRank_HY.ToString(), " -> ", m_FinishingColumnNumber_HY.ToString(), m_FinishingRank_HY.ToString()));
  2430. //huo_sw1.WriteLine(string.Concat("CoMo -- Number of Nodes 0: ", NodeLevel_0_count.ToString()));
  2431. //huo_sw1.WriteLine(string.Concat("CoMo -- Number of Nodes 1: ", NodeLevel_1_count.ToString()));
  2432. //huo_sw1.WriteLine(string.Concat("CoMo -- Number of Nodes 2: ", NodeLevel_2_count.ToString()));
  2433. //huo_sw1.WriteLine(string.Concat("CoMo -- Number of Nodes 3: ", NodeLevel_3_count.ToString()));
  2434. //huo_sw1.WriteLine(string.Concat("CoMo -- Number of Nodes 4: ", NodeLevel_4_count.ToString()));
  2435. //huo_sw1.WriteLine(string.Concat("CoMo -- Number of Nodes 5: ", NodeLevel_5_count.ToString()));
  2436. //huo_sw1.WriteLine(string.Concat("CoMo -- Number of Nodes 6: ", NodeLevel_6_count.ToString()));
  2437. //huo_sw1.WriteLine("");
  2438. #endregion WriteLog
  2439.  
  2440. int iii;
  2441. int jjj;
  2442. String MovingPiece0;
  2443. String ProsorinoKommati0;
  2444. int m_StartingColumnNumber0;
  2445. int m_FinishingColumnNumber0;
  2446. int m_StartingRank0;
  2447. int m_FinishingRank0;
  2448.  
  2449. #region InitializeNodes
  2450. // START [MiniMax algorithm - skakos]
  2451. NodeLevel_0_count = 0;
  2452. NodeLevel_1_count = 0;
  2453. NodeLevel_2_count = 0;
  2454. NodeLevel_3_count = 0;
  2455. NodeLevel_4_count = 0;
  2456. NodeLevel_5_count = 0;
  2457. NodeLevel_6_count = 0;
  2458. NodeLevel_7_count = 0;
  2459. NodeLevel_8_count = 0;
  2460. NodeLevel_9_count = 0;
  2461. NodeLevel_10_count = 0;
  2462. NodeLevel_11_count = 0;
  2463. NodeLevel_12_count = 0;
  2464. NodeLevel_13_count = 0;
  2465. NodeLevel_14_count = 0;
  2466. NodeLevel_15_count = 0;
  2467. NodeLevel_16_count = 0;
  2468. NodeLevel_17_count = 0;
  2469. NodeLevel_18_count = 0;
  2470. NodeLevel_19_count = 0;
  2471. NodeLevel_20_count = 0;
  2472. Nodes_Total_count = 0;
  2473.  
  2474. for (int dimension1 = 0; dimension1 < 1000000; dimension1++)
  2475. {
  2476. for (int dimension2 = 0; dimension2 < 26; dimension2++)
  2477. {
  2478. for (int dimension3 = 0; dimension3 < 2; dimension3++)
  2479. {
  2480. NodesAnalysis[dimension1, dimension2, dimension3] = 0;
  2481. }
  2482. }
  2483. }
  2484. #endregion InitializeNodes
  2485.  
  2486. #region StoreInitialPosition
  2487. // Store the initial position in the chessboard
  2488. for (iii = 0; iii <= 7; iii++)
  2489. {
  2490. for (jjj = 0; jjj <= 7; jjj++)
  2491. {
  2492. Skakiera_Thinking[iii, jjj] = Skakiera_Thinking_init[(iii), (jjj)];
  2493. Skakiera_Move_0[(iii), (jjj)] = Skakiera_Thinking_init[(iii), (jjj)];
  2494. }
  2495. }
  2496. #endregion StoreInitialPosition
  2497.  
  2498. // CHECK IF POSITION IS IN THE OPENING BOOK
  2499. #region OpeningBookCheck
  2500. int op_iii;
  2501. int op_jjj;
  2502.  
  2503. int opening = 1;
  2504.  
  2505. bool exit_opening_loop = false;
  2506. // Μεταβλητή που καταδεικνύει το αν υπάρχει ταίριασμα της παρούσας θέσης με κάποια από τις θέσεις που υπάρχουν αποθηκευμένες στο βιβλίο ανοιγμάτων του ΗΥ
  2507. bool match_found;
  2508.  
  2509. String line_in_opening_book;
  2510.  
  2511. do
  2512. {
  2513. if (File.Exists(String.Concat("Huo Chess Opening Book\\", opening.ToString(), ".txt")))
  2514. {
  2515. // Άνοιγμα των αρχείων .txt που περιέχει η βάση δεδομένων του ΗΥ
  2516. StreamReader sr = new StreamReader(String.Concat("Huo Chess Opening Book\\", opening.ToString(), ".txt"));
  2517. match_found = true;
  2518.  
  2519. for (op_iii = 0; op_iii <= 7; op_iii++)
  2520. {
  2521. for (op_jjj = 0; op_jjj <= 7; op_jjj++)
  2522. {
  2523. line_in_opening_book = sr.ReadLine();
  2524. if (Skakiera_Thinking[op_iii, op_jjj].CompareTo(line_in_opening_book) != 0)
  2525. match_found = false;
  2526. }
  2527. }
  2528.  
  2529. // Αν βρέθηκε μια θέση που είναι αποθηκευμένη στο βιβλίο ανοιγμάτων,
  2530. // τότε διάβασε και τις επόμενες σειρές στο αρχείο text οι οποίες περιέχουν
  2531. // την κίνηση που πρέπει να κάνει ο ΗΥ στην παρούσα θέση.
  2532.  
  2533. if (match_found == true)
  2534. {
  2535. // Αφού βρέθηκε θέση, τότε δεν χρειάζεται περαιτέρω ανάλυση.
  2536. exit_opening_loop = true;
  2537.  
  2538. // Αφού βρέθηκε θέση, τότε ο ΗΥ δεν χρειάζεται να σκεφτεί για την κίνηση του, την έχει βρει έτοιμη!
  2539. Stop_Analyzing = true;
  2540.  
  2541. // Διάβασμα της κενής γραμμής που υπάρχει στο αρχείο.
  2542. line_in_opening_book = sr.ReadLine();
  2543.  
  2544. line_in_opening_book = sr.ReadLine();
  2545. Best_Move_StartingColumnNumber = Int32.Parse(line_in_opening_book);
  2546. line_in_opening_book = sr.ReadLine();
  2547. Best_Move_StartingRank = Int32.Parse(line_in_opening_book);
  2548.  
  2549. line_in_opening_book = sr.ReadLine();
  2550. Best_Move_FinishingColumnNumber = Int32.Parse(line_in_opening_book);
  2551. line_in_opening_book = sr.ReadLine();
  2552. Best_Move_FinishingRank = Int32.Parse(line_in_opening_book);
  2553. }
  2554. }
  2555. else
  2556. {
  2557. exit_opening_loop = true;
  2558. }
  2559.  
  2560. opening = opening + 1;
  2561. } while (exit_opening_loop == false);
  2562. #endregion OpeningBookCheck
  2563.  
  2564. // CHECK FOR DANGEROUS SQUARES
  2565. #region DangerousSquares
  2566. Danger_for_piece = false;
  2567.  
  2568. for (int o1 = 0; o1 <= 7; o1++)
  2569. {
  2570. for (int p1 = 0; p1 <= 7; p1++)
  2571. {
  2572. Skakiera_Dangerous_Squares[(o1), (p1)] = "";
  2573. }
  2574. }
  2575.  
  2576. FindAttackers(Skakiera_Thinking);
  2577. FindDefenders(Skakiera_Thinking);
  2578. #endregion DangerousSquares
  2579.  
  2580.  
  2581. //---------------------------------------
  2582. // CHECK ALL POSSIBLE MOVES!
  2583. //---------------------------------------
  2584.  
  2585. for (iii = 0; iii <= 7; iii++)
  2586. {
  2587. for (jjj = 0; jjj <= 7; jjj++)
  2588. {
  2589.  
  2590. if (((Who_Is_Analyzed.CompareTo("HY") == 0) && ((((Skakiera_Thinking[(iii), (jjj)].CompareTo("White King") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Queen") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Rook") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Knight") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Bishop") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)) || (((Skakiera_Thinking[(iii), (jjj)].CompareTo("Black King") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Queen") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Rook") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Knight") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Bishop") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)))) || ((Who_Is_Analyzed.CompareTo("Human") == 0) && ((((Skakiera_Thinking[(iii), (jjj)].CompareTo("White King") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Queen") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Rook") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Knight") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Bishop") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)) || (((Skakiera_Thinking[(iii), (jjj)].CompareTo("Black King") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Queen") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Rook") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Knight") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Bishop") == 0) || (Skakiera_Thinking[(iii), (jjj)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)))))
  2591. {
  2592.  
  2593. for (int w = 0; w <= 7; w++)
  2594. {
  2595. for (int r = 0; r <= 7; r++)
  2596. {
  2597. Danger_penalty = false;
  2598. //Attackers_penalty = false;
  2599. //Defenders_value_penalty = false;
  2600.  
  2601. MovingPiece = Skakiera_Thinking[(iii), (jjj)];
  2602. m_StartingColumnNumber = iii + 1;
  2603. m_FinishingColumnNumber = w + 1;
  2604. m_StartingRank = jjj + 1;
  2605. m_FinishingRank = r + 1;
  2606.  
  2607. // Store temporary move data in local variables, so as to use them in the Undo of the move
  2608. // at the end of this function (the MovingPiece, m_StartingColumnNumber, etc variables are
  2609. // changed by next functions as well, so using them leads to problems)
  2610. MovingPiece0 = MovingPiece;
  2611. m_StartingColumnNumber0 = m_StartingColumnNumber;
  2612. m_FinishingColumnNumber0 = m_FinishingColumnNumber;
  2613. m_StartingRank0 = m_StartingRank;
  2614. m_FinishingRank0 = m_FinishingRank;
  2615. ProsorinoKommati0 = Skakiera_Thinking[(m_FinishingColumnNumber0 - 1), (m_FinishingRank0 - 1)];
  2616.  
  2617. possibility_to_eat_back = false;
  2618. if ((m_FinishingColumnNumber == target_column) && (m_FinishingRank == target_row))
  2619. possibility_to_eat_back = true;
  2620.  
  2621. // Check for stupid moves in the start of the game
  2622. bool DoNotMakeStupidMove = false;
  2623. #region CheckStupidMove
  2624. if (Move < 5)
  2625. {
  2626. if ((MovingPiece.CompareTo("White Queen") == 0) || (MovingPiece.CompareTo("Black Queen") == 0) ||
  2627. (MovingPiece.CompareTo("White Rook") == 0) || (MovingPiece.CompareTo("Black Rook") == 0))
  2628. {
  2629. DoNotMakeStupidMove = true;
  2630. }
  2631. else if (((MovingPiece.CompareTo("White Knight") == 0) || (MovingPiece.CompareTo("Black Knight") == 0))
  2632. && (m_FinishingColumnNumber == 1))
  2633. {
  2634. DoNotMakeStupidMove = true;
  2635. }
  2636. else if (((MovingPiece.CompareTo("White Knight") == 0) || (MovingPiece.CompareTo("Black Knight") == 0))
  2637. && (m_FinishingColumnNumber == 8))
  2638. {
  2639. DoNotMakeStupidMove = true;
  2640. }
  2641. else if ((MovingPiece.CompareTo("White Knight") == 0) && (m_FinishingRank == 2) && (m_FinishingColumnNumber == 4)
  2642. && (Skakiera_Thinking[(2), (0)].CompareTo("White Bishop") == 0))
  2643. {
  2644. DoNotMakeStupidMove = true;
  2645. }
  2646. else if ((MovingPiece.CompareTo("White Knight") == 0) && (m_FinishingRank == 2) && (m_FinishingColumnNumber == 5)
  2647. && (Skakiera_Thinking[(5), (0)].CompareTo("White Bishop") == 0))
  2648. {
  2649. DoNotMakeStupidMove = true;
  2650. }
  2651. else if ((MovingPiece.CompareTo("Black Knight") == 0) && (m_FinishingRank == 7) && (m_FinishingColumnNumber == 4)
  2652. && (Skakiera_Thinking[(2), (7)].CompareTo("Black Bishop") == 0))
  2653. {
  2654. DoNotMakeStupidMove = true;
  2655. }
  2656. else if ((MovingPiece.CompareTo("Black Knight") == 0) && (m_FinishingRank == 7) && (m_FinishingColumnNumber == 5)
  2657. && (Skakiera_Thinking[(5), (7)].CompareTo("Black Bishop") == 0))
  2658. {
  2659. DoNotMakeStupidMove = true;
  2660. }
  2661. else if ((MovingPiece.CompareTo("White Pawn") == 0) && ((m_StartingColumnNumber == 1) || (m_StartingColumnNumber == 2)))
  2662. {
  2663. DoNotMakeStupidMove = true;
  2664. }
  2665. else if ((MovingPiece.CompareTo("White Pawn") == 0) && ((m_StartingColumnNumber == 7) || (m_StartingColumnNumber == 8)))
  2666. {
  2667. DoNotMakeStupidMove = true;
  2668. }
  2669. else if ((MovingPiece.CompareTo("Black Pawn") == 0) && ((m_StartingColumnNumber == 1) || (m_StartingColumnNumber == 2)))
  2670. {
  2671. DoNotMakeStupidMove = true;
  2672. }
  2673. else if ((MovingPiece.CompareTo("Black Pawn") == 0) && ((m_StartingColumnNumber == 7) || (m_StartingColumnNumber == 8)))
  2674. {
  2675. DoNotMakeStupidMove = true;
  2676. }
  2677. else if ((MovingPiece.CompareTo("White King") == 0) || (MovingPiece.CompareTo("Black King") == 0))
  2678. {
  2679. DoNotMakeStupidMove = true;
  2680. }
  2681. else if (((MovingPiece.CompareTo("White Bishop") == 0) || (MovingPiece.CompareTo("Black Bishop") == 0))
  2682. && ((m_FinishingRank == 3) || (m_FinishingRank == 5) || (m_FinishingRank == 6)))
  2683. {
  2684. DoNotMakeStupidMove = true;
  2685. }
  2686. }
  2687. #endregion CheckStupidMove
  2688.  
  2689. if (DoNotMakeStupidMove == false)
  2690. {
  2691. // THE HEART OF THE THINKING MECHANISM - Here the computer checks the moves
  2692.  
  2693. // Validity and legality of the move has been checked in CheckMove
  2694. // (plus some additional checks)
  2695. CheckMove(Skakiera_Thinking);
  2696.  
  2697. number_of_moves_analysed++;
  2698.  
  2699. // If all ok, then do the move and measure it
  2700. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  2701. {
  2702. // huo_sw1.WriteLine(string.Concat("Human move 1: Found a legal move!"));
  2703.  
  2704. // Do the move
  2705. ProsorinoKommati = Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  2706. Skakiera_Thinking[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  2707. Skakiera_Thinking[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  2708.  
  2709. // Check the score after the computer move.
  2710. if (Move_Analyzed == 0)
  2711. {
  2712. NodeLevel_0_count++;
  2713. Temp_Score_Move_0 = CountScore(Skakiera_Thinking, humanDangerParameter);
  2714. }
  2715. if (Move_Analyzed == 2)
  2716. {
  2717. NodeLevel_2_count++;
  2718. Temp_Score_Move_2 = CountScore(Skakiera_Thinking, humanDangerParameter);
  2719. }
  2720. if (Move_Analyzed == 4)
  2721. {
  2722. NodeLevel_4_count++;
  2723. Temp_Score_Move_4 = CountScore(Skakiera_Thinking, humanDangerParameter);
  2724. }
  2725. if (Move_Analyzed == 6)
  2726. {
  2727. NodeLevel_6_count++;
  2728. Temp_Score_Move_6 = CountScore(Skakiera_Thinking, humanDangerParameter);
  2729. }
  2730.  
  2731. if (Move_Analyzed < Thinking_Depth)
  2732. {
  2733. Move_Analyzed = Move_Analyzed + 1;
  2734.  
  2735. for (i = 0; i <= 7; i++)
  2736. {
  2737. for (j = 0; j <= 7; j++)
  2738. {
  2739. Skakiera_Move_After[(i), (j)] = Skakiera_Thinking[(i), (j)];
  2740. }
  2741. }
  2742.  
  2743. Who_Is_Analyzed = "Human";
  2744. First_Call_Human_Thought = true;
  2745.  
  2746. // Check human move (to find the best possible answer of the human
  2747. // to the move currently analyzed by the HY Thought process)
  2748. if (Move_Analyzed == 1)
  2749. Analyze_Move_1_HumanMove(Skakiera_Move_After);
  2750. else if (Move_Analyzed == 3)
  2751. Analyze_Move_3_HumanMove(Skakiera_Move_After);
  2752. else if (Move_Analyzed == 5)
  2753. Analyze_Move_5_HumanMove(Skakiera_Move_After);
  2754. }
  2755.  
  2756. if (Move_Analyzed == Thinking_Depth)
  2757. {
  2758. // [MiniMax algorithm - skakos]
  2759. // Record the node in the Nodes Analysis array (to use with MiniMax algorithm) skakos
  2760. NodesAnalysis[NodeLevel_0_count, 0, 0] = Temp_Score_Move_0;
  2761. NodesAnalysis[NodeLevel_1_count, 1, 0] = Temp_Score_Move_1_human;
  2762. NodesAnalysis[NodeLevel_2_count, 2, 0] = Temp_Score_Move_2;
  2763. NodesAnalysis[NodeLevel_3_count, 3, 0] = Temp_Score_Move_3_human;
  2764. NodesAnalysis[NodeLevel_4_count, 4, 0] = Temp_Score_Move_4;
  2765. NodesAnalysis[NodeLevel_5_count, 5, 0] = Temp_Score_Move_5_human;
  2766. NodesAnalysis[NodeLevel_6_count, 6, 0] = Temp_Score_Move_6;
  2767.  
  2768. // Store the parents (number of the node of the upper level)
  2769. NodesAnalysis[NodeLevel_0_count, 0, 1] = 0;
  2770. NodesAnalysis[NodeLevel_1_count, 1, 1] = NodeLevel_0_count;
  2771. NodesAnalysis[NodeLevel_2_count, 2, 1] = NodeLevel_1_count;
  2772. NodesAnalysis[NodeLevel_3_count, 3, 1] = NodeLevel_2_count;
  2773. NodesAnalysis[NodeLevel_4_count, 4, 1] = NodeLevel_3_count;
  2774. NodesAnalysis[NodeLevel_5_count, 5, 1] = NodeLevel_4_count;
  2775. NodesAnalysis[NodeLevel_6_count, 6, 1] = NodeLevel_5_count;
  2776.  
  2777. if (Danger_penalty == true)
  2778. {
  2779. //NodesAnalysis[NodeLevel_0_count, 0, 0] = NodesAnalysis[NodeLevel_0_count, 0, 0] - 2000000000;
  2780. //NodesAnalysis[NodeLevel_1_count, 1, 0] = NodesAnalysis[NodeLevel_1_count, 1, 0] + 2000000000;
  2781. }
  2782.  
  2783. if (go_for_it == true)
  2784. {
  2785. //NodesAnalysis[NodeLevel_0_count, 0, 0] = NodesAnalysis[NodeLevel_0_count, 0, 0] + 2000000000;
  2786. //NodesAnalysis[NodeLevel_1_count, 1, 0] = NodesAnalysis[NodeLevel_1_count, 1, 0] - 2000000000;
  2787. }
  2788.  
  2789. Nodes_Total_count++;
  2790.  
  2791. // Safety valve in case we reach the end of the table capacity
  2792. // This is a limit for the memory. Will have to do something about it!
  2793. if (Nodes_Total_count > 1000000)
  2794. {
  2795. Console.WriteLine("Limit of memory in NodesAnalysis array reached!");
  2796. Nodes_Total_count = 1000000;
  2797. }
  2798. }
  2799.  
  2800. // Undo the move
  2801. Skakiera_Thinking[(m_StartingColumnNumber0 - 1), (m_StartingRank0 - 1)] = MovingPiece0;
  2802. Skakiera_Thinking[(m_FinishingColumnNumber0 - 1), (m_FinishingRank0 - 1)] = ProsorinoKommati0;
  2803. }
  2804.  
  2805. }
  2806.  
  2807.  
  2808. }
  2809. }
  2810.  
  2811. }
  2812.  
  2813.  
  2814. }
  2815. }
  2816.  
  2817. // Find if there is mate
  2818. #region CheckIfMate
  2819. if ((Move_Analyzed == 0) && ((WhiteKingCheck == true) || (BlackKingCheck == true)))
  2820. {
  2821.  
  2822. // Αν ο υπολογιστής δεν κατόρθωσε να βρει καμία νόμιμη κίνηση να κάνει εξαιτίας του ότι είναι ματ
  2823.  
  2824. if (Best_Move_Found == false)
  2825. {
  2826. //Mate = true;
  2827.  
  2828. if (m_PlayerColor.CompareTo("White") == 0)
  2829. Console.WriteLine("Black is MATE!");
  2830. else if (m_PlayerColor.CompareTo("Black") == 0)
  2831. Console.WriteLine("White is MATE!");
  2832. }
  2833.  
  2834. }
  2835. #endregion CheckIfMate
  2836.  
  2837. // DO THE BEST MOVE FOUND
  2838.  
  2839. // [MiniMax algorithm - skakos]
  2840. // Find node 1 move with the best score" part to stop using the MiniMax algorithm.
  2841. int counter0, counter1, counter2, counter3, counter4, counter5, counter6, counter7, counter8, counter9, counter10;
  2842. int counter11, counter12, counter13, counter14, counter15, counter16, counter17, counter18, counter19;
  2843. int counter20;
  2844.  
  2845. // Write log of nodes BEFORE
  2846. #region NodesLogBEFORE
  2847.  
  2848. //StreamWriter huo_sw2 = new StreamWriter("NodesAnalysis_before.txt", true);
  2849.  
  2850. ////MessageBox.Show(string.Concat("Stoped thinking at: ", DateTime.Now.ToString("hh:mm:ss.fffffff")));
  2851. //huo_sw2.WriteLine(string.Concat("Stoped thinking at: ", DateTime.Now.ToString("hh:mm:ss.fffffff")));
  2852. ////MessageBox.Show(string.Concat("Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  2853. //huo_sw2.WriteLine(string.Concat("Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  2854. //huo_sw2.WriteLine("");
  2855.  
  2856. //for (counter20 = 1; counter20 <= NodeLevel_20_count; counter20++)
  2857. //{
  2858.  
  2859. // huo_sw2.WriteLine(string.Concat("20, ", counter20.ToString(), " , ", NodesAnalysis[counter20, 20, 0].ToString(), " , ", NodesAnalysis[counter20, 20, 1].ToString()));
  2860. //}
  2861.  
  2862. //huo_sw2.WriteLine("");
  2863. //huo_sw2.WriteLine(string.Concat("Node Level 19"));
  2864. //huo_sw2.WriteLine(string.Concat("****************************"));
  2865. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2866. //huo_sw2.WriteLine("");
  2867.  
  2868.  
  2869. //for (counter19 = 1; counter19 <= NodeLevel_19_count; counter19++)
  2870. //{
  2871.  
  2872. // huo_sw2.WriteLine(string.Concat("19, ", counter19.ToString(), " , ", NodesAnalysis[counter19, 19, 0].ToString(), " , ", NodesAnalysis[counter19, 19, 1].ToString()));
  2873.  
  2874. //}
  2875.  
  2876. //huo_sw2.WriteLine("");
  2877. //huo_sw2.WriteLine(string.Concat("Node Level 18"));
  2878. //huo_sw2.WriteLine(string.Concat("****************************"));
  2879. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2880. //huo_sw2.WriteLine("");
  2881.  
  2882.  
  2883. //for (counter18 = 1; counter18 <= NodeLevel_18_count; counter18++)
  2884. //{
  2885.  
  2886. // huo_sw2.WriteLine(string.Concat("18, ", counter18.ToString(), " , ", NodesAnalysis[counter18, 18, 0].ToString(), " , ", NodesAnalysis[counter18, 18, 1].ToString()));
  2887.  
  2888. //}
  2889.  
  2890. //huo_sw2.WriteLine("");
  2891. //huo_sw2.WriteLine(string.Concat("Node Level 17"));
  2892. //huo_sw2.WriteLine(string.Concat("****************************"));
  2893. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2894. //huo_sw2.WriteLine("");
  2895.  
  2896.  
  2897. //for (counter17 = 1; counter17 <= NodeLevel_17_count; counter17++)
  2898. //{
  2899.  
  2900. // huo_sw2.WriteLine(string.Concat("17, ", counter17.ToString(), " , ", NodesAnalysis[counter17, 17, 0].ToString(), " , ", NodesAnalysis[counter17, 17, 1].ToString()));
  2901.  
  2902. //}
  2903.  
  2904. //huo_sw2.WriteLine("");
  2905. //huo_sw2.WriteLine(string.Concat("Node Level 16"));
  2906. //huo_sw2.WriteLine(string.Concat("****************************"));
  2907. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2908. //huo_sw2.WriteLine("");
  2909.  
  2910.  
  2911. //for (counter16 = 1; counter16 <= NodeLevel_16_count; counter16++)
  2912. //{
  2913.  
  2914. // huo_sw2.WriteLine(string.Concat("16, ", counter16.ToString(), " , ", NodesAnalysis[counter16, 16, 0].ToString(), " , ", NodesAnalysis[counter16, 16, 1].ToString()));
  2915.  
  2916. //}
  2917.  
  2918. //huo_sw2.WriteLine("");
  2919. //huo_sw2.WriteLine(string.Concat("Node Level 15"));
  2920. //huo_sw2.WriteLine(string.Concat("****************************"));
  2921. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2922. //huo_sw2.WriteLine("");
  2923.  
  2924.  
  2925. //for (counter15 = 1; counter15 <= NodeLevel_15_count; counter15++)
  2926. //{
  2927.  
  2928. // huo_sw2.WriteLine(string.Concat("15, ", counter15.ToString(), " , ", NodesAnalysis[counter15, 15, 0].ToString(), " , ", NodesAnalysis[counter15, 15, 1].ToString()));
  2929.  
  2930. //}
  2931.  
  2932. //huo_sw2.WriteLine("");
  2933. //huo_sw2.WriteLine(string.Concat("Node Level 14"));
  2934. //huo_sw2.WriteLine(string.Concat("****************************"));
  2935. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2936. //huo_sw2.WriteLine("");
  2937.  
  2938.  
  2939. //for (counter14 = 1; counter14 <= NodeLevel_14_count; counter14++)
  2940. //{
  2941.  
  2942. // huo_sw2.WriteLine(string.Concat("14, ", counter14.ToString(), " , ", NodesAnalysis[counter14, 14, 0].ToString(), " , ", NodesAnalysis[counter14, 14, 1].ToString()));
  2943.  
  2944. //}
  2945.  
  2946. //huo_sw2.WriteLine("");
  2947. //huo_sw2.WriteLine(string.Concat("Node Level 13"));
  2948. //huo_sw2.WriteLine(string.Concat("****************************"));
  2949. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2950. //huo_sw2.WriteLine("");
  2951.  
  2952.  
  2953. //for (counter13 = 1; counter13 <= NodeLevel_13_count; counter13++)
  2954. //{
  2955.  
  2956. // huo_sw2.WriteLine(string.Concat("13, ", counter13.ToString(), " , ", NodesAnalysis[counter13, 13, 0].ToString(), " , ", NodesAnalysis[counter13, 13, 1].ToString()));
  2957.  
  2958. //}
  2959.  
  2960. //huo_sw2.WriteLine("");
  2961. //huo_sw2.WriteLine(string.Concat("Node Level 12"));
  2962. //huo_sw2.WriteLine(string.Concat("****************************"));
  2963. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2964. //huo_sw2.WriteLine("");
  2965.  
  2966.  
  2967. //for (counter12 = 1; counter12 <= NodeLevel_12_count; counter12++)
  2968. //{
  2969.  
  2970. // huo_sw2.WriteLine(string.Concat("12, ", counter12.ToString(), " , ", NodesAnalysis[counter12, 12, 0].ToString(), " , ", NodesAnalysis[counter12, 12, 1].ToString()));
  2971.  
  2972. //}
  2973.  
  2974. //huo_sw2.WriteLine("");
  2975. //huo_sw2.WriteLine(string.Concat("Node Level 11"));
  2976. //huo_sw2.WriteLine(string.Concat("****************************"));
  2977. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2978. //huo_sw2.WriteLine("");
  2979.  
  2980.  
  2981. //for (counter11 = 1; counter11 <= NodeLevel_11_count; counter11++)
  2982. //{
  2983.  
  2984. // huo_sw2.WriteLine(string.Concat("11, ", counter11.ToString(), " , ", NodesAnalysis[counter11, 11, 0].ToString(), " , ", NodesAnalysis[counter11, 11, 1].ToString()));
  2985.  
  2986. //}
  2987.  
  2988. //huo_sw2.WriteLine("");
  2989. //huo_sw2.WriteLine(string.Concat("Node Level 10"));
  2990. //huo_sw2.WriteLine(string.Concat("****************************"));
  2991. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  2992. //huo_sw2.WriteLine("");
  2993.  
  2994.  
  2995. //for (counter10 = 1; counter10 <= NodeLevel_10_count; counter10++)
  2996. //{
  2997.  
  2998. // huo_sw2.WriteLine(string.Concat("10, ", counter10.ToString(), " , ", NodesAnalysis[counter10, 10, 0].ToString(), " , ", NodesAnalysis[counter10, 10, 1].ToString()));
  2999.  
  3000. //}
  3001.  
  3002. //huo_sw2.WriteLine("");
  3003. //huo_sw2.WriteLine(string.Concat("Node Level 9"));
  3004. //huo_sw2.WriteLine(string.Concat("****************************"));
  3005. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3006. //huo_sw2.WriteLine("");
  3007.  
  3008.  
  3009. //for (counter9 = 1; counter9 <= NodeLevel_9_count; counter9++)
  3010. //{
  3011.  
  3012. // huo_sw2.WriteLine(string.Concat("9, ", counter9.ToString(), " , ", NodesAnalysis[counter9, 9, 0].ToString(), " , ", NodesAnalysis[counter9, 9, 1].ToString()));
  3013.  
  3014. //}
  3015.  
  3016. //huo_sw2.WriteLine("");
  3017. //huo_sw2.WriteLine(string.Concat("Node Level 8"));
  3018. //huo_sw2.WriteLine(string.Concat("****************************"));
  3019. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3020. //huo_sw2.WriteLine("");
  3021.  
  3022.  
  3023. //for (counter8 = 1; counter8 <= NodeLevel_8_count; counter8++)
  3024. //{
  3025.  
  3026. // huo_sw2.WriteLine(string.Concat("8, ", counter8.ToString(), " , ", NodesAnalysis[counter8, 8, 0].ToString(), " , ", NodesAnalysis[counter8, 8, 1].ToString()));
  3027.  
  3028. //}
  3029.  
  3030. //huo_sw2.WriteLine("");
  3031. //huo_sw2.WriteLine(string.Concat("Node Level 7"));
  3032. //huo_sw2.WriteLine(string.Concat("****************************"));
  3033. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3034. //huo_sw2.WriteLine("");
  3035.  
  3036. //for (counter7 = 1; counter7 <= NodeLevel_7_count; counter7++)
  3037. //{
  3038.  
  3039. // huo_sw2.WriteLine(string.Concat("7, ", counter7.ToString(), " , ", NodesAnalysis[counter7, 7, 0].ToString(), " , ", NodesAnalysis[counter7, 7, 1].ToString()));
  3040.  
  3041. //}
  3042.  
  3043. //huo_sw2.WriteLine("");
  3044. //huo_sw2.WriteLine(string.Concat("Node Level 6"));
  3045. //huo_sw2.WriteLine(string.Concat("****************************"));
  3046. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3047. //huo_sw2.WriteLine("");
  3048.  
  3049. //for (counter6 = 1; counter6 <= NodeLevel_6_count; counter6++)
  3050. //{
  3051.  
  3052. // huo_sw2.WriteLine(string.Concat("6, ", counter6.ToString(), " , ", NodesAnalysis[counter6, 6, 0].ToString(), " , ", NodesAnalysis[counter6, 6, 1].ToString()));
  3053.  
  3054. //}
  3055.  
  3056. //huo_sw2.WriteLine("");
  3057. //huo_sw2.WriteLine(string.Concat("Node Level 5"));
  3058. //huo_sw2.WriteLine(string.Concat("****************************"));
  3059. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3060. //huo_sw2.WriteLine("");
  3061.  
  3062. //for (counter5 = 1; counter5 <= NodeLevel_5_count; counter5++)
  3063. //{
  3064.  
  3065. // huo_sw2.WriteLine(string.Concat("5, ", counter5.ToString(), " , ", NodesAnalysis[counter5, 5, 0].ToString(), " , ", NodesAnalysis[counter5, 5, 1].ToString()));
  3066.  
  3067. //}
  3068.  
  3069. //huo_sw2.WriteLine("");
  3070. //huo_sw2.WriteLine(string.Concat("Node Level 4"));
  3071. //huo_sw2.WriteLine(string.Concat("****************************"));
  3072. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3073. //huo_sw2.WriteLine("");
  3074.  
  3075. //for (counter4 = 1; counter4 <= NodeLevel_4_count; counter4++)
  3076. //{
  3077.  
  3078. // huo_sw2.WriteLine(string.Concat("4, ", counter4.ToString(), " , ", NodesAnalysis[counter4, 4, 0].ToString(), " , ", NodesAnalysis[counter4, 4, 1].ToString()));
  3079.  
  3080. //}
  3081.  
  3082. //huo_sw2.WriteLine("");
  3083. //huo_sw2.WriteLine(string.Concat("Node Level 3"));
  3084. //huo_sw2.WriteLine(string.Concat("****************************"));
  3085. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3086. //huo_sw2.WriteLine("");
  3087.  
  3088. //for (counter3 = 1; counter3 <= NodeLevel_3_count; counter3++)
  3089. //{
  3090.  
  3091. // huo_sw2.WriteLine(string.Concat("3, ", counter3.ToString(), " , ", NodesAnalysis[counter3, 3, 0].ToString(), " , ", NodesAnalysis[counter3, 3, 1].ToString()));
  3092.  
  3093. //}
  3094.  
  3095. //huo_sw2.WriteLine("");
  3096. //huo_sw2.WriteLine(string.Concat("Node Level 2"));
  3097. //huo_sw2.WriteLine(string.Concat("****************************"));
  3098. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3099. //huo_sw2.WriteLine("");
  3100.  
  3101. //for (counter2 = 1; counter2 <= NodeLevel_2_count; counter2++)
  3102. //{
  3103.  
  3104. // huo_sw2.WriteLine(string.Concat("2, ", counter2.ToString(), " , ", NodesAnalysis[counter2, 2, 0].ToString(), " , ", NodesAnalysis[counter2, 2, 1].ToString()));
  3105.  
  3106. //}
  3107.  
  3108. //huo_sw2.WriteLine("");
  3109. //huo_sw2.WriteLine(string.Concat("Node Level 1"));
  3110. //huo_sw2.WriteLine(string.Concat("****************************"));
  3111. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3112. //huo_sw2.WriteLine("");
  3113.  
  3114. //for (counter1 = 1; counter1 <= NodeLevel_1_count; counter1++)
  3115. //{
  3116.  
  3117. // huo_sw2.WriteLine(string.Concat("1, ", counter1.ToString(), " , ", NodesAnalysis[counter1, 1, 0].ToString(), " , ", NodesAnalysis[counter1, 1, 1].ToString()));
  3118.  
  3119. //}
  3120.  
  3121. //huo_sw2.WriteLine("");
  3122. //huo_sw2.WriteLine(string.Concat("Node Level 0"));
  3123. //huo_sw2.WriteLine(string.Concat("****************************"));
  3124. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3125. //huo_sw2.WriteLine("");
  3126.  
  3127. //for (counter0 = 1; counter0 <= NodeLevel_0_count; counter0++)
  3128. //{
  3129. // huo_sw2.WriteLine(string.Concat("Move: ", NodesAnalysis[counter0, 21, 0].ToString(), NodesAnalysis[counter0, 23, 0].ToString(), " -> ", NodesAnalysis[counter0, 22, 0].ToString(), NodesAnalysis[counter0, 24, 0].ToString()));
  3130. // huo_sw2.WriteLine(string.Concat("0, ", counter0.ToString(), " , ", NodesAnalysis[counter0, 0, 0].ToString(), " , ", NodesAnalysis[counter0, 0, 1].ToString()));
  3131. // huo_sw2.WriteLine("");
  3132. //}
  3133.  
  3134. //huo_sw2.Close();
  3135.  
  3136. #endregion NodesLogBEFORE
  3137.  
  3138. // ------------------------------------------------------
  3139. // NodesAnalysis
  3140. // ------------------------------------------------------
  3141. // Nodes structure...
  3142. // [ccc, xxx, 0]: Score of node No. ccc at level xxx
  3143. // [ccc, xxx, 1]: Parent of node No. ccc at level xxx-1
  3144. // ------------------------------------------------------
  3145.  
  3146. int parentNodeAnalyzed = -999;
  3147.  
  3148. parentNodeAnalyzed = -999;
  3149.  
  3150. for (counter6 = 1; counter6 <= NodeLevel_6_count; counter6++)
  3151. {
  3152. if (Int32.Parse(NodesAnalysis[counter6, 6, 1].ToString()) != parentNodeAnalyzed)
  3153. {
  3154. //parentNodeAnalyzedchanged = true;
  3155. parentNodeAnalyzed = Int32.Parse(NodesAnalysis[counter6, 6, 1].ToString());
  3156. NodesAnalysis[Int32.Parse(NodesAnalysis[counter6, 6, 1].ToString()), 5, 0] = NodesAnalysis[counter6, 6, 0];
  3157. }
  3158.  
  3159. if (NodesAnalysis[counter6, 6, 0] >= NodesAnalysis[Int32.Parse(NodesAnalysis[counter6, 6, 1].ToString()), 5, 0])
  3160. NodesAnalysis[Int32.Parse(NodesAnalysis[counter6, 6, 1].ToString()), 5, 0] = NodesAnalysis[counter6, 6, 0];
  3161. }
  3162.  
  3163. parentNodeAnalyzed = -999;
  3164.  
  3165. for (counter5 = 1; counter5 <= NodeLevel_5_count; counter5++)
  3166. {
  3167. if (Int32.Parse(NodesAnalysis[counter5, 5, 1].ToString()) != parentNodeAnalyzed)
  3168. {
  3169. //parentNodeAnalyzedchanged = true;
  3170. parentNodeAnalyzed = Int32.Parse(NodesAnalysis[counter5, 5, 1].ToString());
  3171. NodesAnalysis[Int32.Parse(NodesAnalysis[counter5, 5, 1].ToString()), 4, 0] = NodesAnalysis[counter5, 5, 0];
  3172. }
  3173.  
  3174. if (NodesAnalysis[counter5, 5, 0] <= NodesAnalysis[Int32.Parse(NodesAnalysis[counter5, 5, 1].ToString()), 4, 0])
  3175. NodesAnalysis[Int32.Parse(NodesAnalysis[counter5, 5, 1].ToString()), 4, 0] = NodesAnalysis[counter5, 5, 0];
  3176. }
  3177.  
  3178. parentNodeAnalyzed = -999;
  3179.  
  3180. for (counter4 = 1; counter4 <= NodeLevel_4_count; counter4++)
  3181. {
  3182. if (Int32.Parse(NodesAnalysis[counter4, 4, 1].ToString()) != parentNodeAnalyzed)
  3183. {
  3184. //parentNodeAnalyzedchanged = true;
  3185. parentNodeAnalyzed = Int32.Parse(NodesAnalysis[counter4, 4, 1].ToString());
  3186. NodesAnalysis[Int32.Parse(NodesAnalysis[counter4, 4, 1].ToString()), 3, 0] = NodesAnalysis[counter4, 4, 0];
  3187. }
  3188.  
  3189. if (NodesAnalysis[counter4, 4, 0] >= NodesAnalysis[Int32.Parse(NodesAnalysis[counter4, 4, 1].ToString()), 3, 0])
  3190. NodesAnalysis[Int32.Parse(NodesAnalysis[counter4, 4, 1].ToString()), 3, 0] = NodesAnalysis[counter4, 4, 0];
  3191. }
  3192.  
  3193. parentNodeAnalyzed = -999;
  3194.  
  3195. for (counter3 = 1; counter3 <= NodeLevel_3_count; counter3++)
  3196. {
  3197. if (Int32.Parse(NodesAnalysis[counter3, 3, 1].ToString()) != parentNodeAnalyzed)
  3198. {
  3199. //parentNodeAnalyzedchanged = true;
  3200. parentNodeAnalyzed = Int32.Parse(NodesAnalysis[counter3, 3, 1].ToString());
  3201. NodesAnalysis[Int32.Parse(NodesAnalysis[counter3, 3, 1].ToString()), 2, 0] = NodesAnalysis[counter3, 3, 0];
  3202. }
  3203.  
  3204. if (NodesAnalysis[counter3, 3, 0] <= NodesAnalysis[Int32.Parse(NodesAnalysis[counter3, 3, 1].ToString()), 2, 0])
  3205. NodesAnalysis[Int32.Parse(NodesAnalysis[counter3, 3, 1].ToString()), 2, 0] = NodesAnalysis[counter3, 3, 0];
  3206. }
  3207.  
  3208. parentNodeAnalyzed = -999;
  3209.  
  3210. for (counter2 = 1; counter2 <= NodeLevel_2_count; counter2++)
  3211. {
  3212. if (Int32.Parse(NodesAnalysis[counter2, 2, 1].ToString()) != parentNodeAnalyzed)
  3213. {
  3214. //parentNodeAnalyzedchanged = true;
  3215. parentNodeAnalyzed = Int32.Parse(NodesAnalysis[counter2, 2, 1].ToString());
  3216. NodesAnalysis[Int32.Parse(NodesAnalysis[counter2, 2, 1].ToString()), 1, 0] = NodesAnalysis[counter2, 2, 0];
  3217. }
  3218.  
  3219. if (NodesAnalysis[counter2, 2, 0] >= NodesAnalysis[Int32.Parse(NodesAnalysis[counter2, 2, 1].ToString()), 1, 0])
  3220. NodesAnalysis[Int32.Parse(NodesAnalysis[counter2, 2, 1].ToString()), 1, 0] = NodesAnalysis[counter2, 2, 0];
  3221. }
  3222.  
  3223. // Now the node0 level is filled with the score data
  3224. // this is line 1 in the shape at http://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Minimax.svg/300px-Minimax.svg.png
  3225.  
  3226. parentNodeAnalyzed = -999;
  3227.  
  3228. for (counter1 = 1; counter1 <= NodeLevel_1_count; counter1++)
  3229. {
  3230. if (Int32.Parse(NodesAnalysis[counter1, 1, 1].ToString()) != parentNodeAnalyzed)
  3231. {
  3232. //parentNodeAnalyzedchanged = true;
  3233. parentNodeAnalyzed = Int32.Parse(NodesAnalysis[counter1, 1, 1].ToString());
  3234. NodesAnalysis[Int32.Parse(NodesAnalysis[counter1, 1, 1].ToString()), 0, 0] = NodesAnalysis[counter1, 1, 0];
  3235. }
  3236.  
  3237. if (NodesAnalysis[counter1, 1, 0] <= NodesAnalysis[Int32.Parse(NodesAnalysis[counter1, 1, 1].ToString()), 0, 0])
  3238. NodesAnalysis[Int32.Parse(NodesAnalysis[counter1, 1, 1].ToString()), 0, 0] = NodesAnalysis[counter1, 1, 0];
  3239. }
  3240.  
  3241. // Choose the biggest score at the Node0 level
  3242. // Check example at http://en.wikipedia.org/wiki/Minimax#Example_2
  3243. // This is line 0 at the shape at http://upload.wikimedia.org/wikipedia/commons/thumb/6/6f/Minimax.svg/300px-Minimax.svg.png
  3244.  
  3245. // Initialize the score with the first score and move found
  3246. double temp_score = NodesAnalysis[1, 0, 0];
  3247. Best_Move_StartingColumnNumber = Int32.Parse(NodesAnalysis[1, 21, 0].ToString());
  3248. Best_Move_StartingRank = Int32.Parse(NodesAnalysis[1, 23, 0].ToString());
  3249. Best_Move_FinishingColumnNumber = Int32.Parse(NodesAnalysis[1, 22, 0].ToString());
  3250. Best_Move_FinishingRank = Int32.Parse(NodesAnalysis[1, 24, 0].ToString());
  3251.  
  3252. for (counter0 = 1; counter0 <= NodeLevel_0_count; counter0++)
  3253. {
  3254. if (NodesAnalysis[counter0, 0, 0] > temp_score)
  3255. {
  3256. temp_score = NodesAnalysis[counter0, 0, 0];
  3257.  
  3258. Best_Move_StartingColumnNumber = Int32.Parse(NodesAnalysis[counter0, 21, 0].ToString());
  3259. Best_Move_StartingRank = Int32.Parse(NodesAnalysis[counter0, 23, 0].ToString());
  3260. Best_Move_FinishingColumnNumber = Int32.Parse(NodesAnalysis[counter0, 22, 0].ToString());
  3261. Best_Move_FinishingRank = Int32.Parse(NodesAnalysis[counter0, 24, 0].ToString());
  3262. }
  3263. }
  3264.  
  3265. // Limit of total nodes: 1000000
  3266. //MessageBox.Show(String.Concat("Total final positions analyzed: ", Nodes_Total_count.ToString()));
  3267. HuoChess_main.FinalPositions = Nodes_Total_count.ToString();
  3268.  
  3269. // Record log of nodes AFTER the MiniMax algorithm
  3270. #region NodesLogAFTER
  3271.  
  3272. //huo_sw2 = new StreamWriter("NodesAnalysis_after.txt", true);
  3273.  
  3274. ////MessageBox.Show(string.Concat("Stoped thinking at: ", DateTime.Now.ToString("hh:mm:ss.fffffff")));
  3275. //huo_sw2.WriteLine(string.Concat("Stoped thinking at: ", DateTime.Now.ToString("hh:mm:ss.fffffff")));
  3276. ////MessageBox.Show(string.Concat("Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  3277. //huo_sw2.WriteLine(string.Concat("Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  3278. //huo_sw2.WriteLine("");
  3279.  
  3280. //for (counter20 = 1; counter20 <= NodeLevel_20_count; counter20++)
  3281. //{
  3282.  
  3283. // huo_sw2.WriteLine(string.Concat("20, ", counter20.ToString(), " , ", NodesAnalysis[counter20, 20, 0].ToString(), " , ", NodesAnalysis[counter20, 20, 1].ToString()));
  3284. //}
  3285.  
  3286. //huo_sw2.WriteLine("");
  3287. //huo_sw2.WriteLine(string.Concat("Node Level 19"));
  3288. //huo_sw2.WriteLine(string.Concat("****************************"));
  3289. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3290. //huo_sw2.WriteLine("");
  3291.  
  3292.  
  3293. //for (counter19 = 1; counter19 <= NodeLevel_19_count; counter19++)
  3294. //{
  3295.  
  3296. // huo_sw2.WriteLine(string.Concat("19, ", counter19.ToString(), " , ", NodesAnalysis[counter19, 19, 0].ToString(), " , ", NodesAnalysis[counter19, 19, 1].ToString()));
  3297.  
  3298. //}
  3299.  
  3300. //huo_sw2.WriteLine("");
  3301. //huo_sw2.WriteLine(string.Concat("Node Level 18"));
  3302. //huo_sw2.WriteLine(string.Concat("****************************"));
  3303. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3304. //huo_sw2.WriteLine("");
  3305.  
  3306.  
  3307. //for (counter18 = 1; counter18 <= NodeLevel_18_count; counter18++)
  3308. //{
  3309.  
  3310. // huo_sw2.WriteLine(string.Concat("18, ", counter18.ToString(), " , ", NodesAnalysis[counter18, 18, 0].ToString(), " , ", NodesAnalysis[counter18, 18, 1].ToString()));
  3311.  
  3312. //}
  3313.  
  3314. //huo_sw2.WriteLine("");
  3315. //huo_sw2.WriteLine(string.Concat("Node Level 17"));
  3316. //huo_sw2.WriteLine(string.Concat("****************************"));
  3317. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3318. //huo_sw2.WriteLine("");
  3319.  
  3320.  
  3321. //for (counter17 = 1; counter17 <= NodeLevel_17_count; counter17++)
  3322. //{
  3323.  
  3324. // huo_sw2.WriteLine(string.Concat("17, ", counter17.ToString(), " , ", NodesAnalysis[counter17, 17, 0].ToString(), " , ", NodesAnalysis[counter17, 17, 1].ToString()));
  3325.  
  3326. //}
  3327.  
  3328. //huo_sw2.WriteLine("");
  3329. //huo_sw2.WriteLine(string.Concat("Node Level 16"));
  3330. //huo_sw2.WriteLine(string.Concat("****************************"));
  3331. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3332. //huo_sw2.WriteLine("");
  3333.  
  3334.  
  3335. //for (counter16 = 1; counter16 <= NodeLevel_16_count; counter16++)
  3336. //{
  3337.  
  3338. // huo_sw2.WriteLine(string.Concat("16, ", counter16.ToString(), " , ", NodesAnalysis[counter16, 16, 0].ToString(), " , ", NodesAnalysis[counter16, 16, 1].ToString()));
  3339.  
  3340. //}
  3341.  
  3342. //huo_sw2.WriteLine("");
  3343. //huo_sw2.WriteLine(string.Concat("Node Level 15"));
  3344. //huo_sw2.WriteLine(string.Concat("****************************"));
  3345. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3346. //huo_sw2.WriteLine("");
  3347.  
  3348.  
  3349. //for (counter15 = 1; counter15 <= NodeLevel_15_count; counter15++)
  3350. //{
  3351.  
  3352. // huo_sw2.WriteLine(string.Concat("15, ", counter15.ToString(), " , ", NodesAnalysis[counter15, 15, 0].ToString(), " , ", NodesAnalysis[counter15, 15, 1].ToString()));
  3353.  
  3354. //}
  3355.  
  3356. //huo_sw2.WriteLine("");
  3357. //huo_sw2.WriteLine(string.Concat("Node Level 14"));
  3358. //huo_sw2.WriteLine(string.Concat("****************************"));
  3359. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3360. //huo_sw2.WriteLine("");
  3361.  
  3362.  
  3363. //for (counter14 = 1; counter14 <= NodeLevel_14_count; counter14++)
  3364. //{
  3365.  
  3366. // huo_sw2.WriteLine(string.Concat("14, ", counter14.ToString(), " , ", NodesAnalysis[counter14, 14, 0].ToString(), " , ", NodesAnalysis[counter14, 14, 1].ToString()));
  3367.  
  3368. //}
  3369.  
  3370. //huo_sw2.WriteLine("");
  3371. //huo_sw2.WriteLine(string.Concat("Node Level 13"));
  3372. //huo_sw2.WriteLine(string.Concat("****************************"));
  3373. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3374. //huo_sw2.WriteLine("");
  3375.  
  3376.  
  3377. //for (counter13 = 1; counter13 <= NodeLevel_13_count; counter13++)
  3378. //{
  3379.  
  3380. // huo_sw2.WriteLine(string.Concat("13, ", counter13.ToString(), " , ", NodesAnalysis[counter13, 13, 0].ToString(), " , ", NodesAnalysis[counter13, 13, 1].ToString()));
  3381.  
  3382. //}
  3383.  
  3384. //huo_sw2.WriteLine("");
  3385. //huo_sw2.WriteLine(string.Concat("Node Level 12"));
  3386. //huo_sw2.WriteLine(string.Concat("****************************"));
  3387. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3388. //huo_sw2.WriteLine("");
  3389.  
  3390.  
  3391. //for (counter12 = 1; counter12 <= NodeLevel_12_count; counter12++)
  3392. //{
  3393.  
  3394. // huo_sw2.WriteLine(string.Concat("12, ", counter12.ToString(), " , ", NodesAnalysis[counter12, 12, 0].ToString(), " , ", NodesAnalysis[counter12, 12, 1].ToString()));
  3395.  
  3396. //}
  3397.  
  3398. //huo_sw2.WriteLine("");
  3399. //huo_sw2.WriteLine(string.Concat("Node Level 11"));
  3400. //huo_sw2.WriteLine(string.Concat("****************************"));
  3401. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3402. //huo_sw2.WriteLine("");
  3403.  
  3404.  
  3405. //for (counter11 = 1; counter11 <= NodeLevel_11_count; counter11++)
  3406. //{
  3407.  
  3408. // huo_sw2.WriteLine(string.Concat("11, ", counter11.ToString(), " , ", NodesAnalysis[counter11, 11, 0].ToString(), " , ", NodesAnalysis[counter11, 11, 1].ToString()));
  3409.  
  3410. //}
  3411.  
  3412. //huo_sw2.WriteLine("");
  3413. //huo_sw2.WriteLine(string.Concat("Node Level 10"));
  3414. //huo_sw2.WriteLine(string.Concat("****************************"));
  3415. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3416. //huo_sw2.WriteLine("");
  3417.  
  3418.  
  3419. //for (counter10 = 1; counter10 <= NodeLevel_10_count; counter10++)
  3420. //{
  3421.  
  3422. // huo_sw2.WriteLine(string.Concat("10, ", counter10.ToString(), " , ", NodesAnalysis[counter10, 10, 0].ToString(), " , ", NodesAnalysis[counter10, 10, 1].ToString()));
  3423.  
  3424. //}
  3425.  
  3426. //huo_sw2.WriteLine("");
  3427. //huo_sw2.WriteLine(string.Concat("Node Level 9"));
  3428. //huo_sw2.WriteLine(string.Concat("****************************"));
  3429. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3430. //huo_sw2.WriteLine("");
  3431.  
  3432.  
  3433. //for (counter9 = 1; counter9 <= NodeLevel_9_count; counter9++)
  3434. //{
  3435.  
  3436. // huo_sw2.WriteLine(string.Concat("9, ", counter9.ToString(), " , ", NodesAnalysis[counter9, 9, 0].ToString(), " , ", NodesAnalysis[counter9, 9, 1].ToString()));
  3437.  
  3438. //}
  3439.  
  3440. //huo_sw2.WriteLine("");
  3441. //huo_sw2.WriteLine(string.Concat("Node Level 8"));
  3442. //huo_sw2.WriteLine(string.Concat("****************************"));
  3443. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3444. //huo_sw2.WriteLine("");
  3445.  
  3446.  
  3447. //for (counter8 = 1; counter8 <= NodeLevel_8_count; counter8++)
  3448. //{
  3449.  
  3450. // huo_sw2.WriteLine(string.Concat("8, ", counter8.ToString(), " , ", NodesAnalysis[counter8, 8, 0].ToString(), " , ", NodesAnalysis[counter8, 8, 1].ToString()));
  3451.  
  3452. //}
  3453.  
  3454. //huo_sw2.WriteLine("");
  3455. //huo_sw2.WriteLine(string.Concat("Node Level 7"));
  3456. //huo_sw2.WriteLine(string.Concat("****************************"));
  3457. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3458. //huo_sw2.WriteLine("");
  3459.  
  3460. //for (counter7 = 1; counter7 <= NodeLevel_7_count; counter7++)
  3461. //{
  3462.  
  3463. // huo_sw2.WriteLine(string.Concat("7, ", counter7.ToString(), " , ", NodesAnalysis[counter7, 7, 0].ToString(), " , ", NodesAnalysis[counter7, 7, 1].ToString()));
  3464.  
  3465. //}
  3466.  
  3467. //huo_sw2.WriteLine("");
  3468. //huo_sw2.WriteLine(string.Concat("Node Level 6"));
  3469. //huo_sw2.WriteLine(string.Concat("****************************"));
  3470. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3471. //huo_sw2.WriteLine("");
  3472.  
  3473. //for (counter6 = 1; counter6 <= NodeLevel_6_count; counter6++)
  3474. //{
  3475.  
  3476. // huo_sw2.WriteLine(string.Concat("6, ", counter6.ToString(), " , ", NodesAnalysis[counter6, 6, 0].ToString(), " , ", NodesAnalysis[counter6, 6, 1].ToString()));
  3477.  
  3478. //}
  3479.  
  3480. //huo_sw2.WriteLine("");
  3481. //huo_sw2.WriteLine(string.Concat("Node Level 5"));
  3482. //huo_sw2.WriteLine(string.Concat("****************************"));
  3483. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3484. //huo_sw2.WriteLine("");
  3485.  
  3486. //for (counter5 = 1; counter5 <= NodeLevel_5_count; counter5++)
  3487. //{
  3488.  
  3489. // huo_sw2.WriteLine(string.Concat("5, ", counter5.ToString(), " , ", NodesAnalysis[counter5, 5, 0].ToString(), " , ", NodesAnalysis[counter5, 5, 1].ToString()));
  3490.  
  3491. //}
  3492.  
  3493. //huo_sw2.WriteLine("");
  3494. //huo_sw2.WriteLine(string.Concat("Node Level 4"));
  3495. //huo_sw2.WriteLine(string.Concat("****************************"));
  3496. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3497. //huo_sw2.WriteLine("");
  3498.  
  3499. //for (counter4 = 1; counter4 <= NodeLevel_4_count; counter4++)
  3500. //{
  3501.  
  3502. // huo_sw2.WriteLine(string.Concat("4, ", counter4.ToString(), " , ", NodesAnalysis[counter4, 4, 0].ToString(), " , ", NodesAnalysis[counter4, 4, 1].ToString()));
  3503.  
  3504. //}
  3505.  
  3506. //huo_sw2.WriteLine("");
  3507. //huo_sw2.WriteLine(string.Concat("Node Level 3"));
  3508. //huo_sw2.WriteLine(string.Concat("****************************"));
  3509. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3510. //huo_sw2.WriteLine("");
  3511.  
  3512. //for (counter3 = 1; counter3 <= NodeLevel_3_count; counter3++)
  3513. //{
  3514.  
  3515. // huo_sw2.WriteLine(string.Concat("3, ", counter3.ToString(), " , ", NodesAnalysis[counter3, 3, 0].ToString(), " , ", NodesAnalysis[counter3, 3, 1].ToString()));
  3516.  
  3517. //}
  3518.  
  3519. //huo_sw2.WriteLine("");
  3520. //huo_sw2.WriteLine(string.Concat("Node Level 2"));
  3521. //huo_sw2.WriteLine(string.Concat("****************************"));
  3522. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3523. //huo_sw2.WriteLine("");
  3524.  
  3525. //for (counter2 = 1; counter2 <= NodeLevel_2_count; counter2++)
  3526. //{
  3527.  
  3528. // huo_sw2.WriteLine(string.Concat("2, ", counter2.ToString(), " , ", NodesAnalysis[counter2, 2, 0].ToString(), " , ", NodesAnalysis[counter2, 2, 1].ToString()));
  3529.  
  3530. //}
  3531.  
  3532. //huo_sw2.WriteLine("");
  3533. //huo_sw2.WriteLine(string.Concat("Node Level 1"));
  3534. //huo_sw2.WriteLine(string.Concat("****************************"));
  3535. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3536. //huo_sw2.WriteLine("");
  3537.  
  3538. //for (counter1 = 1; counter1 <= NodeLevel_1_count; counter1++)
  3539. //{
  3540.  
  3541. // huo_sw2.WriteLine(string.Concat("1, ", counter1.ToString(), " , ", NodesAnalysis[counter1, 1, 0].ToString(), " , ", NodesAnalysis[counter1, 1, 1].ToString()));
  3542.  
  3543. //}
  3544.  
  3545. //huo_sw2.WriteLine("");
  3546. //huo_sw2.WriteLine(string.Concat("Node Level 0"));
  3547. //huo_sw2.WriteLine(string.Concat("****************************"));
  3548. //huo_sw2.WriteLine(string.Concat("Level, Count, Score, Parent"));
  3549. //huo_sw2.WriteLine("");
  3550.  
  3551. //for (counter0 = 1; counter0 <= NodeLevel_0_count; counter0++)
  3552. //{
  3553. // huo_sw2.WriteLine(string.Concat("Move: ", NodesAnalysis[counter0, 21, 0].ToString(), NodesAnalysis[counter0, 23, 0].ToString(), " -> ", NodesAnalysis[counter0, 22, 0].ToString(), NodesAnalysis[counter0, 24, 0].ToString()));
  3554. // huo_sw2.WriteLine(string.Concat("0, ", counter0.ToString(), " , ", NodesAnalysis[counter0, 0, 0].ToString(), " , ", NodesAnalysis[counter0, 0, 1].ToString()));
  3555. // huo_sw2.WriteLine("");
  3556. //}
  3557.  
  3558. //huo_sw2.Close();
  3559.  
  3560. #endregion NodesLogAFTER
  3561.  
  3562.  
  3563. /////////////////////////////////////////////////////////////////////////////////////////////////
  3564. // REDRAW THE CHESSBOARD
  3565. /////////////////////////////////////////////////////////////////////////////////////////////////
  3566.  
  3567. // Erase the initial square
  3568.  
  3569. for (iii = 0; iii <= 7; iii++)
  3570. {
  3571. for (jjj = 0; jjj <= 7; jjj++)
  3572. {
  3573. Skakiera[(iii), (jjj)] = Skakiera_Move_0[(iii), (jjj)];
  3574. }
  3575. }
  3576.  
  3577. MovingPiece = Skakiera[(Best_Move_StartingColumnNumber - 1), (Best_Move_StartingRank - 1)];
  3578. Skakiera[(Best_Move_StartingColumnNumber - 1), (Best_Move_StartingRank - 1)] = "";
  3579.  
  3580. if (Best_Move_StartingColumnNumber == 1)
  3581. HY_Starting_Column_Text = "a";
  3582. else if (Best_Move_StartingColumnNumber == 2)
  3583. HY_Starting_Column_Text = "b";
  3584. else if (Best_Move_StartingColumnNumber == 3)
  3585. HY_Starting_Column_Text = "c";
  3586. else if (Best_Move_StartingColumnNumber == 4)
  3587. HY_Starting_Column_Text = "d";
  3588. else if (Best_Move_StartingColumnNumber == 5)
  3589. HY_Starting_Column_Text = "e";
  3590. else if (Best_Move_StartingColumnNumber == 6)
  3591. HY_Starting_Column_Text = "f";
  3592. else if (Best_Move_StartingColumnNumber == 7)
  3593. HY_Starting_Column_Text = "g";
  3594. else if (Best_Move_StartingColumnNumber == 8)
  3595. HY_Starting_Column_Text = "h";
  3596.  
  3597. // position piece to the square of destination
  3598.  
  3599. Skakiera[(Best_Move_FinishingColumnNumber - 1), (Best_Move_FinishingRank - 1)] = MovingPiece;
  3600.  
  3601. if (Best_Move_FinishingColumnNumber == 1)
  3602. HY_Finishing_Column_Text = "a";
  3603. else if (Best_Move_FinishingColumnNumber == 2)
  3604. HY_Finishing_Column_Text = "b";
  3605. else if (Best_Move_FinishingColumnNumber == 3)
  3606. HY_Finishing_Column_Text = "c";
  3607. else if (Best_Move_FinishingColumnNumber == 4)
  3608. HY_Finishing_Column_Text = "d";
  3609. else if (Best_Move_FinishingColumnNumber == 5)
  3610. HY_Finishing_Column_Text = "e";
  3611. else if (Best_Move_FinishingColumnNumber == 6)
  3612. HY_Finishing_Column_Text = "f";
  3613. else if (Best_Move_FinishingColumnNumber == 7)
  3614. HY_Finishing_Column_Text = "g";
  3615. else if (Best_Move_FinishingColumnNumber == 8)
  3616. HY_Finishing_Column_Text = "h";
  3617.  
  3618. // if king is moved, no castling can occur
  3619. if (MovingPiece.CompareTo("White King") == 0)
  3620. White_King_Moved = true;
  3621. else if (MovingPiece.CompareTo("Black King") == 0)
  3622. Black_King_Moved = false;
  3623. else if (MovingPiece.CompareTo("White Rook") == 0)
  3624. {
  3625. if ((Best_Move_StartingColumnNumber == 1) && (Best_Move_StartingRank == 1))
  3626. White_Rook_a1_Moved = false;
  3627. else if ((Best_Move_StartingColumnNumber == 8) && (Best_Move_StartingRank == 1))
  3628. White_Rook_h1_Moved = false;
  3629. }
  3630. else if (MovingPiece.CompareTo("Black Rook") == 0)
  3631. {
  3632. if ((Best_Move_StartingColumnNumber == 1) && (Best_Move_StartingRank == 8))
  3633. Black_Rook_a8_Moved = false;
  3634. else if ((Best_Move_StartingColumnNumber == 8) && (Best_Move_StartingRank == 8))
  3635. Black_Rook_h8_Moved = false;
  3636. }
  3637.  
  3638. // is there a pawn to promote?
  3639. if (((MovingPiece.CompareTo("White Pawn") == 0) || (MovingPiece.CompareTo("Black Pawn") == 0)) && (m_WhoPlays.CompareTo("HY") == 0))
  3640. {
  3641.  
  3642. if (Best_Move_FinishingRank == 8)
  3643. {
  3644. Skakiera[(Best_Move_FinishingColumnNumber - 1), (Best_Move_FinishingRank - 1)] = "White Queen";
  3645. Console.WriteLine("Κάνω βασίλισσα!");
  3646. }
  3647. else if (Best_Move_FinishingRank == 1)
  3648. {
  3649. Skakiera[(Best_Move_FinishingColumnNumber - 1), (Best_Move_FinishingRank - 1)] = "Black Queen";
  3650. Console.WriteLine("Κάνω βασίλισσα!");
  3651. }
  3652.  
  3653. }
  3654.  
  3655.  
  3656. //////////////////////////////////////////////////////////////////////
  3657. // show HY move
  3658. //////////////////////////////////////////////////////////////////////
  3659. // COMPARISON CODE
  3660. // UNCOMMENT TO SHOW THINKING TIME!
  3661. // Uncomment to have the program record the start and stop time to a log .txt file
  3662. //StreamWriter huo_sw2 = new StreamWriter("game.txt", true);
  3663. //MessageBox.Show(string.Concat("Stoped thinking at: ", DateTime.Now.ToString("hh:mm:ss.fffffff")));
  3664. //huo_sw2.WriteLine(string.Concat("Stoped thinking at: ", DateTime.Now.ToString("hh:mm:ss.fffffff")));
  3665. //MessageBox.Show(string.Concat("Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  3666. //huo_sw2.WriteLine(string.Concat("Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  3667.  
  3668. NextLine = String.Concat(HY_Starting_Column_Text, Best_Move_StartingRank.ToString(), " -> ", HY_Finishing_Column_Text, Best_Move_FinishingRank.ToString());
  3669. Console.WriteLine(String.Concat("My move is: ", NextLine));
  3670. //MessageBox.Show(number_of_moves_analysed.ToString());
  3671.  
  3672. number_of_moves_analysed = 0;
  3673.  
  3674. // Αν ο υπολογιστής παίζει με τα λευκά, τότε αυξάνεται τώρα το νούμερο της κίνησης.
  3675. // If the computer plays with White, now is the time to increase the number of moves in the game.
  3676. if (m_PlayerColor.CompareTo("Black") == 0)
  3677. Move = Move + 1;
  3678.  
  3679. // now it is the other color's turn to play
  3680. if (m_PlayerColor.CompareTo("Black") == 0)
  3681. m_WhichColorPlays = "Black";
  3682. else if (m_PlayerColor.CompareTo("White") == 0)
  3683. m_WhichColorPlays = "White";
  3684.  
  3685. // now it is the human's turn to play
  3686. m_WhoPlays = "Human";
  3687.  
  3688. //}
  3689. //else
  3690. //{
  3691. // Move_Analyzed = Move_Analyzed - 2;
  3692. // Who_Is_Analyzed = "HY";
  3693. // for (i = 0; i <= 7; i++)
  3694. // {
  3695. // for (j = 0; j <= 7; j++)
  3696. // {
  3697. // Skakiera_Thinking[i, j] = Skakiera_Move_0[i, j];
  3698. // }
  3699. // }
  3700. //}
  3701. }
  3702.  
  3703.  
  3704. //v0.95
  3705. public static double CountScore(string[,] CSSkakiera, int DangerWeight)
  3706. {
  3707. // white pieces: positive score
  3708. // black pieces: negative score
  3709.  
  3710. Current_Move_Score = 0;
  3711. int addValueWhite = 0;
  3712. int addValueBlack = 0;
  3713. double Multiplier_White = 1;
  3714. double Multiplier_Black = 1;
  3715.  
  3716. // v0.96
  3717. DangerWeight = 0;
  3718.  
  3719. //if (m_PlayerColor.CompareTo("White") == 0)
  3720. //{
  3721. // DangerWeight = 1;
  3722. //}
  3723. //else if (m_PlayerColor.CompareTo("Black") == 0)
  3724. //{
  3725. // DangerWeight = 1;
  3726. //}
  3727. //if(Who_Is_Analyzed.CompareTo("HY")==0)
  3728. //{
  3729. // DangerWeight = 1;
  3730. //}
  3731.  
  3732. //if (Destination_Piece_Value >= Moving_Piece_Value)
  3733. //{
  3734. // if (m_PlayerColor.CompareTo("White") == 0)
  3735. // Current_Move_Score = Current_Move_Score - 500; // * (Destination_Piece_Value - Moving_Piece_Value);
  3736. // else if (m_PlayerColor.CompareTo("Black") == 0)
  3737. // Current_Move_Score = Current_Move_Score + 500; // * (Destination_Piece_Value - Moving_Piece_Value);
  3738. //}
  3739.  
  3740. // Make the computer care more for losing a piece
  3741. if (m_PlayerColor.CompareTo("White") == 0)
  3742. {
  3743. addValueWhite = 0;
  3744. addValueBlack = 0;
  3745. Multiplier_White = 1;
  3746. Multiplier_Black = 1;
  3747. }
  3748. else if (m_PlayerColor.CompareTo("Black") == 0)
  3749. {
  3750. addValueWhite = 0;
  3751. addValueBlack = 0;
  3752. Multiplier_White = 1;
  3753. Multiplier_Black = 1;
  3754. }
  3755.  
  3756. if (possibility_to_eat_back == true)
  3757. {
  3758. //MessageBox.Show("Enter possibility to eat back");
  3759. if (m_PlayerColor.CompareTo("White") == 0)
  3760. Current_Move_Score = Current_Move_Score - 1000 * DangerWeight;
  3761. else if (m_PlayerColor.CompareTo("Black") == 0)
  3762. Current_Move_Score = Current_Move_Score + 1000 * DangerWeight;
  3763. }
  3764.  
  3765. if (Danger_penalty == true)
  3766. {
  3767. if (m_PlayerColor.CompareTo("White") == 0)
  3768. Current_Move_Score = Current_Move_Score + 2000 * DangerWeight;
  3769. else if (m_PlayerColor.CompareTo("Black") == 0)
  3770. Current_Move_Score = Current_Move_Score - 2000 * DangerWeight;
  3771. }
  3772.  
  3773. for (i = 0; i <= 7; i++)
  3774. {
  3775. for (j = 0; j <= 7; j++)
  3776. {
  3777. if (CSSkakiera[(i), (j)].CompareTo("White Pawn") == 0)
  3778. Current_Move_Score = Current_Move_Score + 1 * Multiplier_White + (10 * addValueWhite);
  3779. else if (CSSkakiera[(i), (j)].CompareTo("White Rook") == 0)
  3780. {
  3781. Current_Move_Score = Current_Move_Score + 5 * Multiplier_White + (10 * addValueWhite);
  3782. // Decrease score based on the danger in which the piece is in
  3783. Current_Move_Score = Current_Move_Score - DangerWeight * CheckDanger_White(CSSkakiera, i, j);
  3784. }
  3785. else if (CSSkakiera[(i), (j)].CompareTo("White Knight") == 0)
  3786. {
  3787. Current_Move_Score = Current_Move_Score + 3 * Multiplier_White + (10 * addValueWhite);
  3788. // Decrease score based on the danger in which the piece is in
  3789. Current_Move_Score = Current_Move_Score - DangerWeight * CheckDanger_White(CSSkakiera, i, j);
  3790. }
  3791. else if (CSSkakiera[(i), (j)].CompareTo("White Bishop") == 0)
  3792. {
  3793. Current_Move_Score = Current_Move_Score + 3 * Multiplier_White + (10 * addValueWhite);
  3794. // Decrease score based on the danger in which the piece is in
  3795. Current_Move_Score = Current_Move_Score - DangerWeight * CheckDanger_White(CSSkakiera, i, j);
  3796. }
  3797. else if (CSSkakiera[(i), (j)].CompareTo("White Queen") == 0)
  3798. {
  3799. Current_Move_Score = Current_Move_Score + 9 * Multiplier_White + (10 * addValueWhite);
  3800. // Decrease score based on the danger in which the piece is in
  3801. Current_Move_Score = Current_Move_Score - DangerWeight * CheckDanger_White(CSSkakiera, i, j);
  3802. }
  3803. else if (CSSkakiera[(i), (j)].CompareTo("White King") == 0)
  3804. Current_Move_Score = Current_Move_Score + 15 * Multiplier_White + (10 * addValueWhite);
  3805. else if (CSSkakiera[(i), (j)].CompareTo("Black Pawn") == 0)
  3806. Current_Move_Score = Current_Move_Score - 1 * Multiplier_Black + (10 * addValueBlack);
  3807. else if (CSSkakiera[(i), (j)].CompareTo("Black Rook") == 0)
  3808. {
  3809. Current_Move_Score = Current_Move_Score - 5 * Multiplier_Black + (10 * addValueBlack);
  3810. // Decrease score based on the danger in which the piece is in
  3811. Current_Move_Score = Current_Move_Score + DangerWeight * CheckDanger_Black(CSSkakiera, i, j);
  3812. }
  3813. else if (CSSkakiera[(i), (j)].CompareTo("Black Knight") == 0)
  3814. {
  3815. Current_Move_Score = Current_Move_Score - 3 * Multiplier_Black + (10 * addValueBlack);
  3816. // Decrease score based on the danger in which the piece is in
  3817. Current_Move_Score = Current_Move_Score + DangerWeight * CheckDanger_Black(CSSkakiera, i, j);
  3818. }
  3819. else if (CSSkakiera[(i), (j)].CompareTo("Black Bishop") == 0)
  3820. {
  3821. Current_Move_Score = Current_Move_Score - 3 * Multiplier_Black + (10 * addValueBlack);
  3822. // Decrease score based on the danger in which the piece is in
  3823. Current_Move_Score = Current_Move_Score + DangerWeight * CheckDanger_Black(CSSkakiera, i, j);
  3824. }
  3825. else if (CSSkakiera[(i), (j)].CompareTo("Black Queen") == 0)
  3826. {
  3827. Current_Move_Score = Current_Move_Score - 9 * Multiplier_Black + (10 * addValueBlack);
  3828. // Decrease score based on the danger in which the piece is in
  3829. Current_Move_Score = Current_Move_Score + DangerWeight * CheckDanger_Black(CSSkakiera, i, j);
  3830. }
  3831. else if (CSSkakiera[(i), (j)].CompareTo("Black King") == 0)
  3832. Current_Move_Score = Current_Move_Score + 15 * Multiplier_Black + (10 * addValueBlack);
  3833.  
  3834. }
  3835. }
  3836.  
  3837. return Current_Move_Score;
  3838. }
  3839.  
  3840.  
  3841. public static double CheckDanger_White(string[,] CDSkakiera, int i, int j)
  3842. {
  3843. // i = Column
  3844. // j = Line
  3845.  
  3846. bool stopCheck = false;
  3847. int addValue = 1;
  3848. double decreaseScore = 0;
  3849.  
  3850. // Danger from up-right
  3851. do
  3852. {
  3853. if ((i + addValue < 8) && (j + addValue < 8))
  3854. {
  3855. if ((CDSkakiera[(i + addValue), (j + addValue)].CompareTo("Black Bishop") == 0)
  3856. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("Black Queen") == 0))
  3857. {
  3858. decreaseScore = decreaseScore + 0.05;
  3859. stopCheck = true;
  3860. }
  3861. else if ((CDSkakiera[(i + addValue), (j + addValue)].CompareTo("White Rook") == 0)
  3862. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("White Knight") == 0)
  3863. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("White Bishop") == 0)
  3864. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("White Queen") == 0)
  3865. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("White King") == 0)
  3866. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("White Pawn") == 0))
  3867. {
  3868. stopCheck = true;
  3869. }
  3870. }
  3871. else
  3872. {
  3873. stopCheck = true;
  3874. }
  3875.  
  3876. addValue++;
  3877. } while (stopCheck == false);
  3878.  
  3879. stopCheck = false;
  3880.  
  3881. // Danger from down-right
  3882. do
  3883. {
  3884. if ((i + addValue < 8) && (j - addValue > 0))
  3885. {
  3886. if ((CDSkakiera[(i + addValue), (j - addValue)].CompareTo("Black Bishop") == 0)
  3887. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("Black Queen") == 0))
  3888. {
  3889. decreaseScore = decreaseScore + 0.05;
  3890. stopCheck = true;
  3891. }
  3892. else if ((CDSkakiera[(i + addValue), (j - addValue)].CompareTo("White Rook") == 0)
  3893. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("White Knight") == 0)
  3894. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("White Bishop") == 0)
  3895. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("White Queen") == 0)
  3896. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("White King") == 0)
  3897. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("White Pawn") == 0))
  3898. {
  3899. stopCheck = true;
  3900. }
  3901. }
  3902. else
  3903. {
  3904. stopCheck = true;
  3905. }
  3906.  
  3907. addValue++;
  3908. } while (stopCheck == false);
  3909.  
  3910. stopCheck = false;
  3911.  
  3912. // Danger from down-left
  3913. do
  3914. {
  3915. if ((i - addValue > 0) && (j - addValue > 0))
  3916. {
  3917. if ((CDSkakiera[(i - addValue), (j - addValue)].CompareTo("Black Bishop") == 0)
  3918. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("Black Queen") == 0))
  3919. {
  3920. decreaseScore = decreaseScore + 0.05;
  3921. stopCheck = true;
  3922. }
  3923. else if ((CDSkakiera[(i - addValue), (j - addValue)].CompareTo("White Rook") == 0)
  3924. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("White Knight") == 0)
  3925. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("White Bishop") == 0)
  3926. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("White Queen") == 0)
  3927. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("White King") == 0)
  3928. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("White Pawn") == 0))
  3929. {
  3930. stopCheck = true;
  3931. }
  3932. }
  3933. else
  3934. {
  3935. stopCheck = true;
  3936. }
  3937.  
  3938. addValue++;
  3939. } while (stopCheck == false);
  3940.  
  3941. stopCheck = false;
  3942.  
  3943. // Danger from up-left
  3944. do
  3945. {
  3946. if ((i - addValue > 0) && (j + addValue < 8))
  3947. {
  3948. if ((CDSkakiera[(i - addValue), (j + addValue)].CompareTo("Black Bishop") == 0)
  3949. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("Black Queen") == 0))
  3950. {
  3951. decreaseScore = decreaseScore + 0.05;
  3952. stopCheck = true;
  3953. }
  3954. else if ((CDSkakiera[(i - addValue), (j + addValue)].CompareTo("White Rook") == 0)
  3955. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("White Knight") == 0)
  3956. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("White Bishop") == 0)
  3957. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("White Queen") == 0)
  3958. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("White King") == 0)
  3959. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("White Pawn") == 0))
  3960. {
  3961. stopCheck = true;
  3962. }
  3963. }
  3964. else
  3965. {
  3966. stopCheck = true;
  3967. }
  3968.  
  3969. addValue++;
  3970. } while (stopCheck == false);
  3971.  
  3972. stopCheck = false;
  3973.  
  3974. // Danger from right
  3975. do
  3976. {
  3977. if (i + addValue < 8)
  3978. {
  3979. if ((CDSkakiera[(i + addValue), (j - 0)].CompareTo("Black Rook") == 0)
  3980. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("Black Queen") == 0))
  3981. {
  3982. decreaseScore = decreaseScore + 0.05;
  3983. stopCheck = true;
  3984. }
  3985. else if ((CDSkakiera[(i + addValue), (j - 0)].CompareTo("White Rook") == 0)
  3986. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("White Knight") == 0)
  3987. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("White Bishop") == 0)
  3988. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("White Queen") == 0)
  3989. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("White King") == 0)
  3990. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("White Pawn") == 0))
  3991. {
  3992. stopCheck = true;
  3993. }
  3994. }
  3995. else
  3996. {
  3997. stopCheck = true;
  3998. }
  3999.  
  4000. addValue++;
  4001. } while (stopCheck == false);
  4002.  
  4003. stopCheck = false;
  4004.  
  4005. // Danger from left
  4006. do
  4007. {
  4008. if (i - addValue > 0)
  4009. {
  4010. if ((CDSkakiera[(i - addValue), (j - 0)].CompareTo("Black Rook") == 0)
  4011. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("Black Queen") == 0))
  4012. {
  4013. decreaseScore = decreaseScore + 0.05;
  4014. stopCheck = true;
  4015. }
  4016. else if ((CDSkakiera[(i - addValue), (j - 0)].CompareTo("White Rook") == 0)
  4017. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("White Knight") == 0)
  4018. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("White Bishop") == 0)
  4019. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("White Queen") == 0)
  4020. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("White King") == 0)
  4021. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("White Pawn") == 0))
  4022. {
  4023. stopCheck = true;
  4024. }
  4025. }
  4026. else
  4027. {
  4028. stopCheck = true;
  4029. }
  4030.  
  4031. addValue++;
  4032. } while (stopCheck == false);
  4033.  
  4034. stopCheck = false;
  4035.  
  4036. // Danger from up
  4037. do
  4038. {
  4039. if (j + addValue < 8)
  4040. {
  4041. if ((CDSkakiera[(i + 0), (j + addValue)].CompareTo("Black Rook") == 0)
  4042. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("Black Queen") == 0))
  4043. {
  4044. decreaseScore = decreaseScore + 0.05;
  4045. stopCheck = true;
  4046. }
  4047. else if ((CDSkakiera[(i + 0), (j + addValue)].CompareTo("White Rook") == 0)
  4048. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("White Knight") == 0)
  4049. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("White Bishop") == 0)
  4050. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("White Queen") == 0)
  4051. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("White King") == 0)
  4052. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("White Pawn") == 0))
  4053. {
  4054. stopCheck = true;
  4055. }
  4056. }
  4057. else
  4058. {
  4059. stopCheck = true;
  4060. }
  4061.  
  4062. addValue++;
  4063. } while (stopCheck == false);
  4064.  
  4065. stopCheck = false;
  4066.  
  4067. // Danger from down
  4068. do
  4069. {
  4070. if (j - addValue > 0)
  4071. {
  4072. if ((CDSkakiera[(i + 0), (j - addValue)].CompareTo("Black Rook") == 0)
  4073. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("Black Queen") == 0))
  4074. {
  4075. decreaseScore = decreaseScore + 0.05;
  4076. stopCheck = true;
  4077. }
  4078. else if ((CDSkakiera[(i + 0), (j - addValue)].CompareTo("White Rook") == 0)
  4079. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("White Knight") == 0)
  4080. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("White Bishop") == 0)
  4081. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("White Queen") == 0)
  4082. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("White King") == 0)
  4083. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("White Pawn") == 0))
  4084. {
  4085. stopCheck = true;
  4086. }
  4087. }
  4088. else
  4089. {
  4090. stopCheck = true;
  4091. }
  4092.  
  4093. addValue++;
  4094. } while (stopCheck == false);
  4095.  
  4096. stopCheck = false;
  4097.  
  4098. // Danger from pawn
  4099. if ((i - 1 > 0) && (j + 1 < 8))
  4100. {
  4101. if ((CDSkakiera[(i - 1), (j + 1)].CompareTo("Black Pawn") == 0))
  4102. {
  4103. decreaseScore = decreaseScore + 0.05;
  4104. }
  4105. }
  4106. if ((i + 1 < 8) && (j + 1 < 8))
  4107. {
  4108. if ((CDSkakiera[(i + 1), (j + 1)].CompareTo("Black Pawn") == 0))
  4109. {
  4110. decreaseScore = decreaseScore + 0.05;
  4111. }
  4112. }
  4113.  
  4114. ////////////////////////////////////////
  4115. // Danger from Horse
  4116. ////////////////////////////////////////
  4117. if ((i + 2 < 8) && (j - 1 > 0))
  4118. {
  4119. if ((CDSkakiera[(i + 2), (j - 1)].CompareTo("Black Knight") == 0))
  4120. {
  4121. decreaseScore = decreaseScore + 0.05;
  4122. }
  4123. }
  4124. if ((i + 2 < 8) && (j + 1 < 8))
  4125. {
  4126. if ((CDSkakiera[(i + 2), (j + 1)].CompareTo("Black Knight") == 0))
  4127. {
  4128. decreaseScore = decreaseScore + 0.05;
  4129. }
  4130. }
  4131. if ((i + 1 < 8) && (j + 2 < 8))
  4132. {
  4133. if ((CDSkakiera[(i + 1), (j + 2)].CompareTo("Black Knight") == 0))
  4134. {
  4135. decreaseScore = decreaseScore + 0.05;
  4136. }
  4137. }
  4138. if ((i - 1 > 0) && (j + 2 < 8))
  4139. {
  4140. if ((CDSkakiera[(i - 1), (j + 2)].CompareTo("Black Knight") == 0))
  4141. {
  4142. decreaseScore = decreaseScore + 0.05;
  4143. }
  4144. }
  4145. if ((i - 2 > 0) && (j + 1 < 8))
  4146. {
  4147. if ((CDSkakiera[(i - 2), (j + 1)].CompareTo("Black Knight") == 0))
  4148. {
  4149. decreaseScore = decreaseScore + 0.05;
  4150. }
  4151. }
  4152. if ((i - 2 > 0) && (j - 1 > 0))
  4153. {
  4154. if ((CDSkakiera[(i - 2), (j - 1)].CompareTo("Black Knight") == 0))
  4155. {
  4156. decreaseScore = decreaseScore + 0.05;
  4157. }
  4158. }
  4159. if ((i - 1 > 0) && (j - 2 > 0))
  4160. {
  4161. if ((CDSkakiera[(i - 1), (j - 2)].CompareTo("Black Knight") == 0))
  4162. {
  4163. decreaseScore = decreaseScore + 0.05;
  4164. }
  4165. }
  4166. if ((i + 1 < 8) && (j - 2 > 0))
  4167. {
  4168. if ((CDSkakiera[(i + 1), (j - 2)].CompareTo("Black Knight") == 0))
  4169. {
  4170. decreaseScore = decreaseScore + 0.05;
  4171. }
  4172. }
  4173.  
  4174.  
  4175. return decreaseScore;
  4176. }
  4177.  
  4178.  
  4179. public static double CheckDanger_Black(string[,] CDSkakiera, int i, int j)
  4180. {
  4181. // i = Column
  4182. // j = Line
  4183.  
  4184. bool stopCheck = false;
  4185. int addValue = 1;
  4186. double decreaseScore = 0;
  4187.  
  4188. // Danger from up-right
  4189. do
  4190. {
  4191. if ((i + addValue < 8) && (j + addValue < 8))
  4192. {
  4193. if ((CDSkakiera[(i + addValue), (j + addValue)].CompareTo("White Bishop") == 0)
  4194. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("White Queen") == 0))
  4195. {
  4196. decreaseScore = decreaseScore + 0.05;
  4197. stopCheck = true;
  4198. }
  4199. else if ((CDSkakiera[(i + addValue), (j + addValue)].CompareTo("Black Rook") == 0)
  4200. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("Black Knight") == 0)
  4201. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("Black Bishop") == 0)
  4202. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("Black Queen") == 0)
  4203. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("Black King") == 0)
  4204. || (CDSkakiera[(i + addValue), (j + addValue)].CompareTo("Black Pawn") == 0))
  4205. {
  4206. stopCheck = true;
  4207. }
  4208. }
  4209. else
  4210. {
  4211. stopCheck = true;
  4212. }
  4213.  
  4214. addValue++;
  4215. } while (stopCheck == false);
  4216.  
  4217. stopCheck = false;
  4218.  
  4219. // Danger from down-right
  4220. do
  4221. {
  4222. if ((i + addValue < 8) && (j - addValue > 0))
  4223. {
  4224. if ((CDSkakiera[(i + addValue), (j - addValue)].CompareTo("White Bishop") == 0)
  4225. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("White Queen") == 0))
  4226. {
  4227. decreaseScore = decreaseScore + 0.05;
  4228. stopCheck = true;
  4229. }
  4230. else if ((CDSkakiera[(i + addValue), (j - addValue)].CompareTo("Black Rook") == 0)
  4231. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("Black Knight") == 0)
  4232. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("Black Bishop") == 0)
  4233. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("Black Queen") == 0)
  4234. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("Black King") == 0)
  4235. || (CDSkakiera[(i + addValue), (j - addValue)].CompareTo("Black Pawn") == 0))
  4236. {
  4237. stopCheck = true;
  4238. }
  4239. }
  4240. else
  4241. {
  4242. stopCheck = true;
  4243. }
  4244.  
  4245. addValue++;
  4246. } while (stopCheck == false);
  4247.  
  4248. stopCheck = false;
  4249.  
  4250. // Danger from down-left
  4251. do
  4252. {
  4253. if ((i - addValue > 0) && (j - addValue > 0))
  4254. {
  4255. if ((CDSkakiera[(i - addValue), (j - addValue)].CompareTo("White Bishop") == 0)
  4256. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("White Queen") == 0))
  4257. {
  4258. decreaseScore = decreaseScore + 0.05;
  4259. stopCheck = true;
  4260. }
  4261. else if ((CDSkakiera[(i - addValue), (j - addValue)].CompareTo("Black Rook") == 0)
  4262. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("Black Knight") == 0)
  4263. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("Black Bishop") == 0)
  4264. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("Black Queen") == 0)
  4265. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("Black King") == 0)
  4266. || (CDSkakiera[(i - addValue), (j - addValue)].CompareTo("Black Pawn") == 0))
  4267. {
  4268. stopCheck = true;
  4269. }
  4270. }
  4271. else
  4272. {
  4273. stopCheck = true;
  4274. }
  4275.  
  4276. addValue++;
  4277. } while (stopCheck == false);
  4278.  
  4279. stopCheck = false;
  4280.  
  4281. // Danger from up-left
  4282. do
  4283. {
  4284. if ((i - addValue > 0) && (j + addValue < 8))
  4285. {
  4286. if ((CDSkakiera[(i - addValue), (j + addValue)].CompareTo("White Bishop") == 0)
  4287. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("White Queen") == 0))
  4288. {
  4289. decreaseScore = decreaseScore + 0.05;
  4290. stopCheck = true;
  4291. }
  4292. else if ((CDSkakiera[(i - addValue), (j + addValue)].CompareTo("Black Rook") == 0)
  4293. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("Black Knight") == 0)
  4294. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("Black Bishop") == 0)
  4295. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("Black Queen") == 0)
  4296. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("Black King") == 0)
  4297. || (CDSkakiera[(i - addValue), (j + addValue)].CompareTo("Black Pawn") == 0))
  4298. {
  4299. stopCheck = true;
  4300. }
  4301. }
  4302. else
  4303. {
  4304. stopCheck = true;
  4305. }
  4306.  
  4307. addValue++;
  4308. } while (stopCheck == false);
  4309.  
  4310. stopCheck = false;
  4311.  
  4312. // Danger from right
  4313. do
  4314. {
  4315. if (i + addValue < 8)
  4316. {
  4317. if ((CDSkakiera[(i + addValue), (j - 0)].CompareTo("White Rook") == 0)
  4318. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("White Queen") == 0))
  4319. {
  4320. decreaseScore = decreaseScore + 0.05;
  4321. stopCheck = true;
  4322. }
  4323. else if ((CDSkakiera[(i + addValue), (j - 0)].CompareTo("Black Rook") == 0)
  4324. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("Black Knight") == 0)
  4325. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("Black Bishop") == 0)
  4326. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("Black Queen") == 0)
  4327. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("Black King") == 0)
  4328. || (CDSkakiera[(i + addValue), (j - 0)].CompareTo("Black Pawn") == 0))
  4329. {
  4330. stopCheck = true;
  4331. }
  4332. }
  4333. else
  4334. {
  4335. stopCheck = true;
  4336. }
  4337.  
  4338. addValue++;
  4339. } while (stopCheck == false);
  4340.  
  4341. stopCheck = false;
  4342.  
  4343. // Danger from left
  4344. do
  4345. {
  4346. if (i - addValue > 0)
  4347. {
  4348. if ((CDSkakiera[(i - addValue), (j - 0)].CompareTo("White Rook") == 0)
  4349. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("White Queen") == 0))
  4350. {
  4351. decreaseScore = decreaseScore + 0.05;
  4352. stopCheck = true;
  4353. }
  4354. else if ((CDSkakiera[(i - addValue), (j - 0)].CompareTo("Black Rook") == 0)
  4355. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("Black Knight") == 0)
  4356. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("Black Bishop") == 0)
  4357. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("Black Queen") == 0)
  4358. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("Black King") == 0)
  4359. || (CDSkakiera[(i - addValue), (j - 0)].CompareTo("Black Pawn") == 0))
  4360. {
  4361. stopCheck = true;
  4362. }
  4363. }
  4364. else
  4365. {
  4366. stopCheck = true;
  4367. }
  4368.  
  4369. addValue++;
  4370. } while (stopCheck == false);
  4371.  
  4372. stopCheck = false;
  4373.  
  4374. // Danger from up
  4375. do
  4376. {
  4377. if (j + addValue < 8)
  4378. {
  4379. if ((CDSkakiera[(i + 0), (j + addValue)].CompareTo("White Rook") == 0)
  4380. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("White Queen") == 0))
  4381. {
  4382. decreaseScore = decreaseScore + 0.05;
  4383. stopCheck = true;
  4384. }
  4385. else if ((CDSkakiera[(i + 0), (j + addValue)].CompareTo("Black Rook") == 0)
  4386. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("Black Knight") == 0)
  4387. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("Black Bishop") == 0)
  4388. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("Black Queen") == 0)
  4389. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("Black King") == 0)
  4390. || (CDSkakiera[(i + 0), (j + addValue)].CompareTo("Black Pawn") == 0))
  4391. {
  4392. stopCheck = true;
  4393. }
  4394. }
  4395. else
  4396. {
  4397. stopCheck = true;
  4398. }
  4399.  
  4400. addValue++;
  4401. } while (stopCheck == false);
  4402.  
  4403. stopCheck = false;
  4404.  
  4405. // Danger from down
  4406. do
  4407. {
  4408. if (j - addValue > 0)
  4409. {
  4410. if ((CDSkakiera[(i + 0), (j - addValue)].CompareTo("White Rook") == 0)
  4411. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("White Queen") == 0))
  4412. {
  4413. decreaseScore = decreaseScore + 0.05;
  4414. stopCheck = true;
  4415. }
  4416. else if ((CDSkakiera[(i + 0), (j - addValue)].CompareTo("Black Rook") == 0)
  4417. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("Black Knight") == 0)
  4418. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("Black Bishop") == 0)
  4419. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("Black Queen") == 0)
  4420. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("Black King") == 0)
  4421. || (CDSkakiera[(i + 0), (j - addValue)].CompareTo("Black Pawn") == 0))
  4422. {
  4423. stopCheck = true;
  4424. }
  4425. }
  4426. else
  4427. {
  4428. stopCheck = true;
  4429. }
  4430.  
  4431. addValue++;
  4432. } while (stopCheck == false);
  4433.  
  4434. stopCheck = false;
  4435.  
  4436. // Danger from pawn
  4437. if ((i - 1 > 0) && (j - 1 > 0))
  4438. {
  4439. if ((CDSkakiera[(i - 1), (j - 1)].CompareTo("White Pawn") == 0))
  4440. {
  4441. decreaseScore = decreaseScore + 0.05;
  4442. }
  4443. }
  4444. if ((i + 1 < 8) && (j - 1 > 0))
  4445. {
  4446. if ((CDSkakiera[(i + 1), (j - 1)].CompareTo("White Pawn") == 0))
  4447. {
  4448. decreaseScore = decreaseScore + 0.05;
  4449. }
  4450. }
  4451.  
  4452. ////////////////////////////////////////
  4453. // Danger from Horse
  4454. ////////////////////////////////////////
  4455. if ((i + 2 < 8) && (j - 1 > 0))
  4456. {
  4457. if ((CDSkakiera[(i + 2), (j - 1)].CompareTo("White Knight") == 0))
  4458. {
  4459. decreaseScore = decreaseScore + 0.05;
  4460. }
  4461. }
  4462. if ((i + 2 < 8) && (j + 1 < 8))
  4463. {
  4464. if ((CDSkakiera[(i + 2), (j + 1)].CompareTo("White Knight") == 0))
  4465. {
  4466. decreaseScore = decreaseScore + 0.05;
  4467. }
  4468. }
  4469. if ((i + 1 < 8) && (j + 2 < 8))
  4470. {
  4471. if ((CDSkakiera[(i + 1), (j + 2)].CompareTo("White Knight") == 0))
  4472. {
  4473. decreaseScore = decreaseScore + 0.05;
  4474. }
  4475. }
  4476. if ((i - 1 > 0) && (j + 2 < 8))
  4477. {
  4478. if ((CDSkakiera[(i - 1), (j + 2)].CompareTo("White Knight") == 0))
  4479. {
  4480. decreaseScore = decreaseScore + 0.05;
  4481. }
  4482. }
  4483. if ((i - 2 > 0) && (j + 1 < 8))
  4484. {
  4485. if ((CDSkakiera[(i - 2), (j + 1)].CompareTo("White Knight") == 0))
  4486. {
  4487. decreaseScore = decreaseScore + 0.05;
  4488. }
  4489. }
  4490. if ((i - 2 > 0) && (j - 1 > 0))
  4491. {
  4492. if ((CDSkakiera[(i - 2), (j - 1)].CompareTo("White Knight") == 0))
  4493. {
  4494. decreaseScore = decreaseScore + 0.05;
  4495. }
  4496. }
  4497. if ((i - 1 > 0) && (j - 2 > 0))
  4498. {
  4499. if ((CDSkakiera[(i - 1), (j - 2)].CompareTo("White Knight") == 0))
  4500. {
  4501. decreaseScore = decreaseScore + 0.05;
  4502. }
  4503. }
  4504. if ((i + 1 < 8) && (j - 2 > 0))
  4505. {
  4506. if ((CDSkakiera[(i + 1), (j - 2)].CompareTo("White Knight") == 0))
  4507. {
  4508. decreaseScore = decreaseScore + 0.05;
  4509. }
  4510. }
  4511.  
  4512.  
  4513. return decreaseScore;
  4514. }
  4515.  
  4516.  
  4517.  
  4518.  
  4519. // 2011: This function has changed
  4520. public static void Enter_move()
  4521. {
  4522. // TODO: Add your control notification handler code here
  4523.  
  4524. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4525. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4526. // show the move entered by the human player
  4527. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4528. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4529.  
  4530. if (m_StartingColumn.CompareTo("A") == 0)
  4531. m_StartingColumnNumber = 1;
  4532. else if (m_StartingColumn.CompareTo("B") == 0)
  4533. m_StartingColumnNumber = 2;
  4534. else if (m_StartingColumn.CompareTo("C") == 0)
  4535. m_StartingColumnNumber = 3;
  4536. else if (m_StartingColumn.CompareTo("D") == 0)
  4537. m_StartingColumnNumber = 4;
  4538. else if (m_StartingColumn.CompareTo("E") == 0)
  4539. m_StartingColumnNumber = 5;
  4540. else if (m_StartingColumn.CompareTo("F") == 0)
  4541. m_StartingColumnNumber = 6;
  4542. else if (m_StartingColumn.CompareTo("G") == 0)
  4543. m_StartingColumnNumber = 7;
  4544. else if (m_StartingColumn.CompareTo("H") == 0)
  4545. m_StartingColumnNumber = 8;
  4546.  
  4547.  
  4548. if (m_FinishingColumn.CompareTo("A") == 0)
  4549. m_FinishingColumnNumber = 1;
  4550. else if (m_FinishingColumn.CompareTo("B") == 0)
  4551. m_FinishingColumnNumber = 2;
  4552. else if (m_FinishingColumn.CompareTo("C") == 0)
  4553. m_FinishingColumnNumber = 3;
  4554. else if (m_FinishingColumn.CompareTo("D") == 0)
  4555. m_FinishingColumnNumber = 4;
  4556. else if (m_FinishingColumn.CompareTo("E") == 0)
  4557. m_FinishingColumnNumber = 5;
  4558. else if (m_FinishingColumn.CompareTo("F") == 0)
  4559. m_FinishingColumnNumber = 6;
  4560. else if (m_FinishingColumn.CompareTo("G") == 0)
  4561. m_FinishingColumnNumber = 7;
  4562. else if (m_FinishingColumn.CompareTo("H") == 0)
  4563. m_FinishingColumnNumber = 8;
  4564.  
  4565.  
  4566. /////////////////////////////////////////////////////////////////////////////////////////////////
  4567. /////////////////////////////////////////////////////////////////////////////////////////////////
  4568. // record which piece is moving
  4569. /////////////////////////////////////////////////////////////////////////////////////////////////
  4570. /////////////////////////////////////////////////////////////////////////////////////////////////
  4571.  
  4572. if (m_WhoPlays.CompareTo("HY") == 0) // Αν είναι η σειρά του υπολογιστή να παίξει (και όχι του χρήστη), τότε άκυρο!!
  4573. MessageBox.Show("It's not your turn.");
  4574.  
  4575. // Αν χρήστης έχει εισάγει μία έγκυρη στήλη (π.χ. "ε" ή "ζ") και πάει να κινήσει ένα κομμάτι του σωστού
  4576. // χρώματος (π.χ. έναν λευκό ίππο και είναι πράγματι η σειρά των λευκών να παίξουν) τότε να προχωρήσει το
  4577. // πρόγραμμα σε ό,τι κάνει.
  4578. // Δεν είναι απαραίτητο να γίνει και έλεγχος του αν ο χρήστης έχει γράψει σωστή γραμμή (ήτοι ένα
  4579. // νούμερο από το 1 έως το 8), διότι αυτό απαγορεύεται από τη δήλωση των μεταβλητών m_StartingRank και
  4580. // m_FinishingRank (οι οποίες έχουν δηλωθεί σαν ακέραιοι που παίρνουν τιμές από 1 έως 8).
  4581.  
  4582. else if (((m_WhoPlays.CompareTo("Human") == 0) || (m_PlayerColor.CompareTo("Self") == 0)) && (((m_WhichColorPlays.CompareTo("White") == 0) && ((Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("White Pawn") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("White Rook") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("White Knight") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("White Bishop") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("White Queen") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("White King") == 0))) || ((m_WhichColorPlays.CompareTo("Black") == 0) && ((Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("Black Pawn") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("Black Rook") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("Black Knight") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("Black Bishop") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("Black Queen") == 0) || (Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("Black King") == 0)))))
  4583. {
  4584.  
  4585. m_WrongColumn = false;
  4586. MovingPiece = "";
  4587.  
  4588. // is the king under check?
  4589. if (m_PlayerColor.CompareTo("White") == 0)
  4590. WhiteKingCheck = CheckForWhiteCheck(Skakiera);
  4591. else if (m_PlayerColor.CompareTo("Black") == 0)
  4592. BlackKingCheck = CheckForBlackCheck(Skakiera);
  4593.  
  4594. MovingPiece = Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)];
  4595.  
  4596. // if he chooses to move a piece of different colour...
  4597. if (((m_PlayerColor.CompareTo("White") == 0) || (m_PlayerColor.CompareTo("Self") == 0) && ((Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("White Rook") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("White Knight") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("White Bishop") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("White Queen") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("White King") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("White Pawn") == 0))) || (((m_PlayerColor.CompareTo("Black") == 0) || (m_PlayerColor.CompareTo("Self") == 0)) && ((Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("Black Rook") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("Black Knight") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("Black Bishop") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("Black Queen") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("Black King") == 0) || (Skakiera[(m_StartingColumnNumber - 1), ((m_StartingRank - 1))].CompareTo("Black Pawn") == 0))))
  4598. {
  4599. Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  4600. }
  4601.  
  4602. }
  4603. else
  4604. {
  4605. if (m_WhichColorPlays.CompareTo("White") == 0)
  4606. MessageBox.Show("White plays.");
  4607. else if (m_WhichColorPlays.CompareTo("Black") == 0)
  4608. MessageBox.Show("Black plays.");
  4609.  
  4610. m_WrongColumn = true; // Η μεταβλητή αυτή τίθεται true για να βγει "μη ορθή" η κίνηση από
  4611. // τη συνάρτηση που ακολουθεί ακριβώς από κάτω και ελέγχει την "ορθότητα"
  4612. // της κίνησης.
  4613. }
  4614.  
  4615. // Check correctness of move entered
  4616. m_OrthotitaKinisis = ElegxosOrthotitas(Skakiera, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  4617.  
  4618. // check legality of move entered
  4619. // (only if it is correct - so as to save time!)
  4620. if (m_OrthotitaKinisis == true)
  4621. m_NomimotitaKinisis = ElegxosNomimotitas(Skakiera, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  4622. else
  4623. m_NomimotitaKinisis = false;
  4624.  
  4625. // check if the human's king is in check even after his move!
  4626. // temporarily move the piece the user wants to move
  4627. Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  4628. ProsorinoKommati = Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  4629. Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  4630.  
  4631. // check if king is still under check
  4632. WhiteKingCheck = CheckForWhiteCheck(Skakiera);
  4633.  
  4634. if ((m_WhichColorPlays.CompareTo("White") == 0) && (WhiteKingCheck == true))
  4635. m_NomimotitaKinisis = false;
  4636.  
  4637.  
  4638. // check if black king is still under check
  4639. BlackKingCheck = CheckForBlackCheck(Skakiera);
  4640.  
  4641. if ((m_WhichColorPlays.CompareTo("Black") == 0) && (BlackKingCheck == true))
  4642. m_NomimotitaKinisis = false;
  4643.  
  4644. // restore all pieces to the initial state
  4645. Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = MovingPiece;
  4646. Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = ProsorinoKommati;
  4647.  
  4648. ///////////////////////////////////////////////////////////////////
  4649. // CHECK IF THE HUMAN HAS ENTERED A CASTLING MOVE
  4650. ///////////////////////////////////////////////////////////////////
  4651.  
  4652. ///////////////////////////
  4653. // WHITE CASTLING
  4654. ///////////////////////////
  4655.  
  4656. // small castling
  4657.  
  4658. if ((m_PlayerColor.CompareTo("White") == 0) && (m_StartingColumnNumber == 5) && (m_FinishingColumnNumber == 7) && (m_StartingRank == 1) && (m_FinishingRank == 1))
  4659. {
  4660. if ((Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("White King") == 0) && (Skakiera[(7), (0)].CompareTo("White Rook") == 0) && (Skakiera[(5), (0)].CompareTo("") == 0) && (Skakiera[(6), (0)].CompareTo("") == 0))
  4661. {
  4662. m_OrthotitaKinisis = true;
  4663. m_NomimotitaKinisis = true;
  4664. Castling_Occured = true;
  4665. }
  4666. }
  4667.  
  4668. // big castling
  4669.  
  4670. if ((m_PlayerColor.CompareTo("White") == 0) && (m_StartingColumnNumber == 5) && (m_FinishingColumnNumber == 3) && (m_StartingRank == 1) && (m_FinishingRank == 1))
  4671. {
  4672. if ((Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("White King") == 0) && (Skakiera[(0), (0)].CompareTo("White Rook") == 0) && (Skakiera[(1), (0)].CompareTo("") == 0) && (Skakiera[(2), (0)].CompareTo("") == 0) && (Skakiera[(3), (0)].CompareTo("") == 0))
  4673. {
  4674. m_OrthotitaKinisis = true;
  4675. m_NomimotitaKinisis = true;
  4676. Castling_Occured = true;
  4677. }
  4678. }
  4679.  
  4680.  
  4681. ///////////////////////////
  4682. // black castling
  4683. ///////////////////////////
  4684.  
  4685. // small castling
  4686.  
  4687. if ((m_PlayerColor.CompareTo("Black") == 0) && (m_StartingColumnNumber == 5) && (m_FinishingColumnNumber == 7) && (m_StartingRank == 8) && (m_FinishingRank == 8))
  4688. {
  4689. if ((Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("Black King") == 0) && (Skakiera[(7), (7)].CompareTo("Black Rook") == 0) && (Skakiera[(5), (7)].CompareTo("") == 0) && (Skakiera[(6), (7)].CompareTo("") == 0))
  4690. {
  4691. m_OrthotitaKinisis = true;
  4692. m_NomimotitaKinisis = true;
  4693. Castling_Occured = true;
  4694. }
  4695. }
  4696.  
  4697. // big castling
  4698.  
  4699. if ((m_PlayerColor.CompareTo("Black") == 0) && (m_StartingColumnNumber == 5) && (m_FinishingColumnNumber == 3) && (m_StartingRank == 8) && (m_FinishingRank == 8))
  4700. {
  4701. if ((Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)].CompareTo("Black King") == 0) && (Skakiera[(0), (7)].CompareTo("Black Rook") == 0) && (Skakiera[(1), (7)].CompareTo("") == 0) && (Skakiera[(2), (7)].CompareTo("") == 0) && (Skakiera[(3), (7)].CompareTo("") == 0))
  4702. {
  4703. m_OrthotitaKinisis = true;
  4704. m_NomimotitaKinisis = true;
  4705. Castling_Occured = true;
  4706. }
  4707. }
  4708.  
  4709. // redraw the chessboard
  4710. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  4711. {
  4712.  
  4713. // game moves on by 1 move (this happens only when the player plays,
  4714. // so as to avoid increasing the game moves every half-move!)
  4715. if (m_PlayerColor.CompareTo("White") == 0)
  4716. Move = Move + 1;
  4717.  
  4718. // erase initial square
  4719. Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  4720.  
  4721. //2011
  4722. //if (Thinking_Depth == 3)
  4723. // Thinking_Depth = Thinking_Depth_temp;
  4724.  
  4725. ////2011
  4726. //if (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("") == 1)
  4727. //{
  4728. // Thinking_Depth_temp = Thinking_Depth;
  4729. // Thinking_Depth = 3;
  4730. //}
  4731.  
  4732. // 2011 START
  4733. target_column = -1;
  4734. target_row = -1;
  4735. if (Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)].CompareTo("") == 1)
  4736. {
  4737. target_column = m_FinishingColumnNumber;
  4738. target_row = m_FinishingRank;
  4739. //MessageBox.Show("target column: ");
  4740. //MessageBox.Show(target_column.ToString());
  4741. //MessageBox.Show("target rank: ");
  4742. //MessageBox.Show(target_row.ToString());
  4743. }
  4744. // 2011 END
  4745.  
  4746. // go to destination square
  4747. Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  4748.  
  4749. //////////////////////////////////////////////////////////
  4750. // check for en passant
  4751. //////////////////////////////////////////////////////////
  4752. if (enpassant_occured == true)
  4753. {
  4754. if (m_PlayerColor.CompareTo("White") == 0)
  4755. Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1 - 1)] = "";
  4756. else if (m_PlayerColor.CompareTo("Black") == 0)
  4757. Skakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1 + 1)] = "";
  4758. }
  4759.  
  4760.  
  4761. ////////////////////////////////////////////////////////////////////
  4762. // record possible sqaure when the next one playing will
  4763. // be able to perform en passant
  4764. ////////////////////////////////////////////////////////////////////
  4765. if ((m_StartingRank == 2) && (m_FinishingRank == 4))
  4766. {
  4767. enpassant_possible_target_rank = m_FinishingRank - 1;
  4768. enpassant_possible_target_column = m_FinishingColumnNumber;
  4769. }
  4770. else if ((m_StartingRank == 7) && (m_FinishingRank == 5))
  4771. {
  4772. enpassant_possible_target_rank = m_FinishingRank + 1;
  4773. enpassant_possible_target_column = m_FinishingColumnNumber;
  4774. }
  4775. else
  4776. {
  4777. // invalid value for enpassant move (= enpassant not possible in the next move)
  4778. enpassant_possible_target_rank = -9;
  4779. enpassant_possible_target_column = -9;
  4780. }
  4781.  
  4782. // check if castling occured (so as to move the rook next to the
  4783. // moving king)
  4784. if (Castling_Occured == true)
  4785. {
  4786.  
  4787. if (m_PlayerColor.CompareTo("White") == 0)
  4788. {
  4789. if (Skakiera[(6), (0)].CompareTo("White King") == 0)
  4790. {
  4791. Skakiera[(5), (0)] = "White Rook";
  4792. Skakiera[(7), (0)] = "";
  4793. //MessageBox.Show( "Ο λευκός κάνει μικρό ροκε." ); // Changed in version 0.5
  4794. }
  4795. else if (Skakiera[(2), (0)].CompareTo("White King") == 0)
  4796. {
  4797. Skakiera[(3), (0)] = "White Rook";
  4798. Skakiera[(0), (0)] = "";
  4799. //MessageBox.Show( "Ο λευκός κάνει μεγάλο ροκε." ); // Changed in version 0.5
  4800. }
  4801. }
  4802. else if (m_PlayerColor.CompareTo("Black") == 0)
  4803. {
  4804. if (Skakiera[(6), (7)].CompareTo("Black King") == 0)
  4805. {
  4806. Skakiera[(5), (7)] = "Black Rook";
  4807. Skakiera[(7), (7)] = "";
  4808. //MessageBox.Show( "Ο μαύρος κάνει μικρό ροκε." ); // Changed in version 0.5
  4809. }
  4810. else if (Skakiera[(2), (7)].CompareTo("Black King") == 0)
  4811. {
  4812. Skakiera[(3), (7)] = "Black Rook";
  4813. Skakiera[(0), (7)] = "";
  4814. //MessageBox.Show( "Ο μαύρος κάνει μεγάλο ροκε." ); // Changed in version 0.5
  4815. }
  4816. }
  4817.  
  4818. // restore the Castling_Occured variable to false, so as to avoid false castlings in the future!
  4819. Castling_Occured = false;
  4820.  
  4821. }
  4822.  
  4823.  
  4824. //////////////////////////////////////////////////////////
  4825. // does a pawn needs promotion?
  4826. //////////////////////////////////////////////////////////
  4827.  
  4828. PawnPromotion();
  4829.  
  4830. if ((m_PlayerColor.CompareTo("White") == 0) || (m_PlayerColor.CompareTo("Black") == 0))
  4831. m_WhoPlays = "HY";
  4832.  
  4833. // it is the other color's turn to play
  4834. if (m_WhichColorPlays.CompareTo("White") == 0)
  4835. m_WhichColorPlays = "Black";
  4836. else if (m_WhichColorPlays.CompareTo("Black") == 0)
  4837. m_WhichColorPlays = "White";
  4838.  
  4839. // restore variable values to initial values
  4840. m_StartingColumn = "";
  4841. m_FinishingColumn = "";
  4842. m_StartingRank = 1;
  4843. m_FinishingRank = 1;
  4844.  
  4845.  
  4846.  
  4847.  
  4848. /////////////////////////////////////////////
  4849. // CHECK MESSAGE
  4850. /////////////////////////////////////////////
  4851.  
  4852. WhiteKingCheck = CheckForWhiteCheck(Skakiera);
  4853. BlackKingCheck = CheckForBlackCheck(Skakiera);
  4854.  
  4855. if ((WhiteKingCheck == true) || (BlackKingCheck == true))
  4856. {
  4857. MessageBox.Show("CHECK!");
  4858. }
  4859.  
  4860.  
  4861. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4862. // if it is the turn of the HY to play, then call the respective
  4863. // HY Thought function
  4864. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4865.  
  4866. if (m_WhoPlays.CompareTo("HY") == 0)
  4867. {
  4868. Move_Analyzed = 0;
  4869. Stop_Analyzing = false;
  4870. First_Call = true;
  4871. Best_Move_Found = false;
  4872. Who_Is_Analyzed = "HY";
  4873. //2012: ComputerMove(Skakiera);
  4874. }
  4875.  
  4876. }
  4877.  
  4878. else
  4879. {
  4880. MessageBox.Show("INVALID MOVE!");
  4881. Skakiera[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = MovingPiece;
  4882. MovingPiece = "";
  4883. m_WhoPlays = "Human";
  4884. }
  4885.  
  4886.  
  4887. }
  4888.  
  4889.  
  4890. public static void PawnPromotion()
  4891. {
  4892. for (i = 0; i <= 7; i++)
  4893. {
  4894.  
  4895. if (Skakiera[(i), (0)].CompareTo("Black Pawn") == 0)
  4896. {
  4897.  
  4898. if (m_WhoPlays.CompareTo("Human") == 0)
  4899. {
  4900. ///////////////////////////
  4901. // promote pawn
  4902. ///////////////////////////
  4903.  
  4904. MessageBox.Show("");
  4905.  
  4906. MessageBox.Show("Promote your pawn to: 1. Queen, 2. Rook, 3. Knight, 4. Bishop");
  4907. Console.Write("CHOOSE (1-4): ");
  4908. choise_of_user = Int32.Parse(Console.ReadLine());
  4909.  
  4910. switch (choise_of_user)
  4911. {
  4912. case 1:
  4913. Skakiera[(i), (0)] = "Black Queen";
  4914. break;
  4915.  
  4916. case 2:
  4917. Skakiera[(i), (0)] = "Black Rook";
  4918. break;
  4919.  
  4920. case 3:
  4921. Skakiera[(i), (0)] = "Black Knight";
  4922. break;
  4923.  
  4924. case 4:
  4925. Skakiera[(i), (0)] = "Black Bishop";
  4926. break;
  4927. };
  4928. }
  4929.  
  4930. }
  4931.  
  4932. if (Skakiera[(i), (7)].CompareTo("White Pawn") == 0)
  4933. {
  4934. if (m_WhoPlays.CompareTo("Human") == 0)
  4935. {
  4936. ///////////////////////////
  4937. // promote pawn
  4938. ///////////////////////////
  4939.  
  4940. MessageBox.Show("");
  4941.  
  4942. MessageBox.Show("Promote your pawn to: 1. Queen, 2. Rook, 3. Knight, 4. Bishop");
  4943. Console.Write("CHOOSE (1-4): ");
  4944. choise_of_user = Int32.Parse(Console.ReadLine());
  4945.  
  4946. switch (choise_of_user)
  4947. {
  4948. case 1:
  4949. Skakiera[(i), (0)] = "White Queen";
  4950. break;
  4951.  
  4952. case 2:
  4953. Skakiera[(i), (0)] = "White Rook";
  4954. break;
  4955.  
  4956. case 3:
  4957. Skakiera[(i), (0)] = "White Knight";
  4958. break;
  4959.  
  4960. case 4:
  4961. Skakiera[(i), (0)] = "White Bishop";
  4962. break;
  4963. };
  4964. }
  4965.  
  4966. }
  4967.  
  4968. }
  4969. }
  4970.  
  4971.  
  4972. // FUNCTION TO CHECK THE LEGALITY (='Nomimotita' in Greek) OF A MOVE
  4973. // (i.e. if between the initial and the destination square lies another
  4974. // piece, then the move is not legal).
  4975. // The ElegxosNomimotitas "checkForDanger" function differs from the normal function in that it does not make all the validations
  4976. // (since it is used to check for "Dangerous" squares in the chessboard and not to actually judge the correctness of an actual move)
  4977. // Changed in version 0.961!
  4978. public static bool ElegxosNomimotitas(string[,] ENSkakiera, int checkForDanger, int startRank, int startColumn, int finishRank, int finishColumn, String MovingPiece_2)
  4979. {
  4980. // TODO: Add your control notification handler code here
  4981.  
  4982. bool Nomimotita;
  4983. //Console.WriteLine("into Elegxos Nomimotitas");
  4984.  
  4985. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4986. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4987. // Έλεγχος της "ΝΟΜΙΜΟΤΗΤΑΣ" της κίνησης. Αν π.χ. ο χρήστης έχει επιλέξει να κινήσει έναν πύργο από
  4988. // το α2 στο α5, αλλά στο α4 υπάρχει κάποιο πιόνι του, τότε η Nomimotita έχει τιμή false.
  4989. // Η συνάρτηση "επιστρέφει" τη boolean μεταβλητή Nomimotita.
  4990. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4991. ////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4992.  
  4993. Nomimotita = true;
  4994.  
  4995. if (((finishRank - 1) > 7) || ((finishRank - 1) < 0) || ((finishColumn - 1) > 7) || ((finishColumn - 1) < 0))
  4996. Nomimotita = false;
  4997.  
  4998. // if a piece of the same colout is in the destination square...
  4999. if (checkForDanger == 0)
  5000. {
  5001. if ((MovingPiece_2.CompareTo("White King") == 0) || (MovingPiece_2.CompareTo("White Queen") == 0) || (MovingPiece_2.CompareTo("White Rook") == 0) || (MovingPiece_2.CompareTo("White Knight") == 0) || (MovingPiece_2.CompareTo("White Bishop") == 0) || (MovingPiece_2.CompareTo("White Pawn") == 0))
  5002. {
  5003. if ((ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("White King") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("White Queen") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("White Rook") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("White Knight") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("White Bishop") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("White Pawn") == 0))
  5004. {
  5005. Nomimotita = false;
  5006. }
  5007. }
  5008. else if ((MovingPiece_2.CompareTo("Black King") == 0) || (MovingPiece_2.CompareTo("Black Queen") == 0) || (MovingPiece_2.CompareTo("Black Rook") == 0) || (MovingPiece_2.CompareTo("Black Knight") == 0) || (MovingPiece_2.CompareTo("Black Bishop") == 0) || (MovingPiece_2.CompareTo("Black Pawn") == 0))
  5009. {
  5010. if ((ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("Black King") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("Black Queen") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("Black Rook") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("Black Knight") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("Black Bishop") == 0) || (ENSkakiera[((finishColumn - 1)), ((finishRank - 1))].CompareTo("Black Pawn") == 0))
  5011. Nomimotita = false;
  5012. }
  5013. }
  5014.  
  5015. if (MovingPiece_2.CompareTo("White King") == 0)
  5016. {
  5017. if (checkForDanger == 0)
  5018. {
  5019. /////////////////////////
  5020. // white king
  5021. /////////////////////////
  5022. // is the king threatened in the destination square?
  5023. // temporarily move king
  5024. ENSkakiera[(startColumn - 1), (startRank - 1)] = "";
  5025. ProsorinoKommati_KingCheck = ENSkakiera[(finishColumn - 1), (finishRank - 1)];
  5026. ENSkakiera[(finishColumn - 1), (finishRank - 1)] = "White King";
  5027.  
  5028. WhiteKingCheck = CheckForWhiteCheck(ENSkakiera);
  5029.  
  5030. if (WhiteKingCheck == true)
  5031. Nomimotita = false;
  5032.  
  5033. // restore pieces
  5034. ENSkakiera[(startColumn - 1), (startRank - 1)] = "White King";
  5035. ENSkakiera[(finishColumn - 1), (finishRank - 1)] = ProsorinoKommati_KingCheck;
  5036. }
  5037. }
  5038. else if (MovingPiece_2.CompareTo("Black King") == 0)
  5039. {
  5040. if (checkForDanger == 0)
  5041. {
  5042. ///////////////////////////
  5043. // black king
  5044. ///////////////////////////
  5045. // is the black king threatened in the destination square?
  5046. // temporarily move king
  5047. ENSkakiera[(startColumn - 1), (startRank - 1)] = "";
  5048. ProsorinoKommati_KingCheck = ENSkakiera[(finishColumn - 1), (finishRank - 1)];
  5049. ENSkakiera[(finishColumn - 1), (finishRank - 1)] = "Black King";
  5050.  
  5051. BlackKingCheck = CheckForBlackCheck(ENSkakiera);
  5052.  
  5053. if (BlackKingCheck == true)
  5054. Nomimotita = false;
  5055.  
  5056. // restore pieces
  5057. ENSkakiera[(startColumn - 1), (startRank - 1)] = "Black King";
  5058. ENSkakiera[(finishColumn - 1), (finishRank - 1)] = ProsorinoKommati_KingCheck;
  5059. }
  5060. }
  5061. else if (MovingPiece_2.CompareTo("White Pawn") == 0)
  5062. {
  5063. if (checkForDanger == 0)
  5064. {
  5065. //Console.WriteLine("checking white pawn");
  5066.  
  5067. /////////////////////
  5068. // white pawn
  5069. /////////////////////
  5070.  
  5071. // move forward
  5072.  
  5073. if ((finishRank == (startRank + 1)) && (finishColumn == startColumn))
  5074. {
  5075. if (ENSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("") == 1)
  5076. {
  5077. //Console.WriteLine("pawn Nomimotita false");
  5078. Nomimotita = false;
  5079. }
  5080. }
  5081.  
  5082. // move forward for 2 squares
  5083. else if ((finishRank == (startRank + 2)) && (finishColumn == startColumn))
  5084. {
  5085. if (startRank == 2)
  5086. {
  5087. if ((ENSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("") == 1) || (ENSkakiera[(finishColumn - 1), (finishRank - 1 - 1)].CompareTo("") == 1))
  5088. Nomimotita = false;
  5089. }
  5090. }
  5091.  
  5092. // eat forward to the right
  5093.  
  5094. else if ((finishRank == (startRank + 1)) && (finishColumn == startColumn + 1))
  5095. {
  5096. if (enpassant_occured == false)
  5097. {
  5098. if (ENSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("") == 0)
  5099. Nomimotita = false;
  5100. }
  5101. }
  5102.  
  5103. // eat forward to the left
  5104.  
  5105. else if ((finishRank == (startRank + 1)) && (finishColumn == startColumn - 1))
  5106. {
  5107. if (enpassant_occured == false)
  5108. {
  5109. if (ENSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("") == 0)
  5110. Nomimotita = false;
  5111. }
  5112. }
  5113. }
  5114. }
  5115. else if (MovingPiece_2.CompareTo("Black Pawn") == 0)
  5116. {
  5117. if (checkForDanger == 0)
  5118. {
  5119. /////////////////////
  5120. // black pawn
  5121. /////////////////////
  5122.  
  5123. // move forward
  5124.  
  5125. if ((finishRank == (startRank - 1)) && (finishColumn == startColumn))
  5126. {
  5127. if (ENSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("") == 1)
  5128. Nomimotita = false;
  5129. }
  5130.  
  5131. // move forward for 2 squares
  5132. else if ((finishRank == (startRank - 2)) && (finishColumn == startColumn))
  5133. {
  5134. if (startRank == 7)
  5135. {
  5136. if ((ENSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("") == 1) || (ENSkakiera[(finishColumn - 1), (finishRank + 1 - 1)].CompareTo("") == 1))
  5137. Nomimotita = false;
  5138. }
  5139. }
  5140.  
  5141. // eat forward to the right
  5142.  
  5143. else if ((finishRank == (startRank - 1)) && (finishColumn == startColumn + 1))
  5144. {
  5145. if (enpassant_occured == false)
  5146. {
  5147. if (ENSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("") == 0)
  5148. Nomimotita = false;
  5149. }
  5150. }
  5151.  
  5152. // eat forward to the left
  5153.  
  5154. else if ((finishRank == (startRank - 1)) && (finishColumn == startColumn - 1))
  5155. {
  5156. if (enpassant_occured == false)
  5157. {
  5158. if (ENSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("") == 0)
  5159. Nomimotita = false;
  5160. }
  5161. }
  5162. }
  5163. }
  5164. else if ((MovingPiece_2.CompareTo("White Rook") == 0) || (MovingPiece_2.CompareTo("White Queen") == 0) || (MovingPiece_2.CompareTo("White Bishop") == 0) || (MovingPiece_2.CompareTo("Black Rook") == 0) || (MovingPiece_2.CompareTo("Black Queen") == 0) || (MovingPiece_2.CompareTo("Black Bishop") == 0))
  5165. {
  5166. h = 0;
  5167. p = 0;
  5168. //hhh = 0;
  5169. how_to_move_Rank = 0;
  5170. how_to_move_Column = 0;
  5171.  
  5172. if (((finishRank - 1) > (startRank - 1)) || ((finishRank - 1) < (startRank - 1)))
  5173. how_to_move_Rank = ((finishRank - 1) - (startRank - 1)) / System.Math.Abs((finishRank - 1) - (startRank - 1));
  5174.  
  5175. if (((finishColumn - 1) > (startColumn - 1)) || ((finishColumn - 1) < (startColumn - 1)))
  5176. how_to_move_Column = ((finishColumn - 1) - (startColumn - 1)) / System.Math.Abs((finishColumn - 1) - (startColumn - 1));
  5177.  
  5178. exit_elegxos_nomimothtas = false;
  5179.  
  5180. do
  5181. {
  5182. h = h + how_to_move_Rank;
  5183. p = p + how_to_move_Column;
  5184.  
  5185. if ((((startRank - 1) + h) == (finishRank - 1)) && ((((startColumn - 1) + p)) == (finishColumn - 1)))
  5186. exit_elegxos_nomimothtas = true;
  5187.  
  5188. if ((startColumn - 1 + p) < 0)
  5189. exit_elegxos_nomimothtas = true;
  5190. else if ((startRank - 1 + h) < 0)
  5191. exit_elegxos_nomimothtas = true;
  5192. else if ((startColumn - 1 + p) > 7)
  5193. exit_elegxos_nomimothtas = true;
  5194. else if ((startRank - 1 + h) > 7)
  5195. exit_elegxos_nomimothtas = true;
  5196.  
  5197. // if a piece exists between the initial and the destination square,
  5198. // then the move is illegal!
  5199. if (exit_elegxos_nomimothtas == false)
  5200. {
  5201. if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("White Rook") == 0)
  5202. {
  5203. Nomimotita = false;
  5204. exit_elegxos_nomimothtas = true;
  5205. }
  5206. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("White Knight") == 0)
  5207. {
  5208. Nomimotita = false;
  5209. exit_elegxos_nomimothtas = true;
  5210. }
  5211. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("White Bishop") == 0)
  5212. {
  5213. Nomimotita = false;
  5214. exit_elegxos_nomimothtas = true;
  5215. }
  5216. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("White Queen") == 0)
  5217. {
  5218. Nomimotita = false;
  5219. exit_elegxos_nomimothtas = true;
  5220. }
  5221. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("White King") == 0)
  5222. {
  5223. Nomimotita = false;
  5224. exit_elegxos_nomimothtas = true;
  5225. }
  5226. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("White Pawn") == 0)
  5227. {
  5228. Nomimotita = false;
  5229. exit_elegxos_nomimothtas = true;
  5230. }
  5231.  
  5232. if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("Black Rook") == 0)
  5233. {
  5234. Nomimotita = false;
  5235. exit_elegxos_nomimothtas = true;
  5236. }
  5237. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("Black Knight") == 0)
  5238. {
  5239. Nomimotita = false;
  5240. exit_elegxos_nomimothtas = true;
  5241. }
  5242. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("Black Bishop") == 0)
  5243. {
  5244. Nomimotita = false;
  5245. exit_elegxos_nomimothtas = true;
  5246. }
  5247. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("Black Queen") == 0)
  5248. {
  5249. Nomimotita = false;
  5250. exit_elegxos_nomimothtas = true;
  5251. }
  5252. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("Black King") == 0)
  5253. {
  5254. Nomimotita = false;
  5255. exit_elegxos_nomimothtas = true;
  5256. }
  5257. else if (ENSkakiera[(startColumn - 1 + p), (startRank - 1 + h)].CompareTo("Black Pawn") == 0)
  5258. {
  5259. Nomimotita = false;
  5260. exit_elegxos_nomimothtas = true;
  5261. }
  5262. }
  5263. } while (exit_elegxos_nomimothtas == false);
  5264. }
  5265.  
  5266. // Check if HY moves the king next to the king of the opponent
  5267. // (this case is not controlled in the lines above)
  5268. #region CheckKindNextToKing
  5269. if (MovingPiece_2.CompareTo("White King") == 0)
  5270. {
  5271. if (((m_FinishingColumnNumber - 1 + 1) >= 0) && ((m_FinishingColumnNumber - 1 + 1) <= 7) && ((m_FinishingRank - 1 + 1) >= 0) && ((m_FinishingRank - 1 + 1) <= 7))
  5272. {
  5273. if (ENSkakiera[(m_FinishingColumnNumber - 1 + 1), (m_FinishingRank - 1 + 1)].CompareTo("Black King") == 0)
  5274. m_NomimotitaKinisis = false;
  5275. }
  5276.  
  5277. if (((m_FinishingColumnNumber - 1) >= 0) && ((m_FinishingColumnNumber - 1) <= 7) && ((m_FinishingRank - 1 + 1) >= 0) && ((m_FinishingRank - 1 + 1) <= 7))
  5278. {
  5279. if (ENSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1 + 1)].CompareTo("Black King") == 0)
  5280. m_NomimotitaKinisis = false;
  5281. }
  5282.  
  5283. if (((m_FinishingColumnNumber - 1 - 1) >= 0) && ((m_FinishingColumnNumber - 1 - 1) <= 7) && ((m_FinishingRank - 1 + 1) >= 0) && ((m_FinishingRank - 1 + 1) <= 7))
  5284. {
  5285. if (ENSkakiera[(m_FinishingColumnNumber - 1 - 1), (m_FinishingRank - 1 + 1)].CompareTo("Black King") == 0)
  5286. m_NomimotitaKinisis = false;
  5287. }
  5288.  
  5289. if (((m_FinishingColumnNumber - 1 - 1) >= 0) && ((m_FinishingColumnNumber - 1 - 1) <= 7) && ((m_FinishingRank - 1) >= 0) && ((m_FinishingRank - 1) <= 7))
  5290. {
  5291. if (ENSkakiera[(m_FinishingColumnNumber - 1 - 1), (m_FinishingRank - 1)].CompareTo("Black King") == 0)
  5292. m_NomimotitaKinisis = false;
  5293. }
  5294.  
  5295. if (((m_FinishingColumnNumber - 1 - 1) >= 0) && ((m_FinishingColumnNumber - 1 - 1) <= 7) && ((m_FinishingRank - 1 - 1) >= 0) && ((m_FinishingRank - 1 - 1) <= 7))
  5296. {
  5297. if (ENSkakiera[(m_FinishingColumnNumber - 1 - 1), (m_FinishingRank - 1 - 1)].CompareTo("Black King") == 0)
  5298. m_NomimotitaKinisis = false;
  5299. }
  5300.  
  5301. if (((m_FinishingColumnNumber - 1) >= 0) && ((m_FinishingColumnNumber - 1) <= 7) && ((m_FinishingRank - 1 - 1) >= 0) && ((m_FinishingRank - 1 - 1) <= 7))
  5302. {
  5303. if (ENSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1 - 1)].CompareTo("Black King") == 0)
  5304. m_NomimotitaKinisis = false;
  5305. }
  5306.  
  5307. if (((m_FinishingColumnNumber - 1 + 1) >= 0) && ((m_FinishingColumnNumber - 1 + 1) <= 7) && ((m_FinishingRank - 1 - 1) >= 0) && ((m_FinishingRank - 1 - 1) <= 7))
  5308. {
  5309. if (ENSkakiera[(m_FinishingColumnNumber - 1 + 1), (m_FinishingRank - 1 - 1)].CompareTo("Black King") == 0)
  5310. m_NomimotitaKinisis = false;
  5311. }
  5312.  
  5313. if (((m_FinishingColumnNumber - 1 + 1) >= 0) && ((m_FinishingColumnNumber - 1 + 1) <= 7) && ((m_FinishingRank - 1) >= 0) && ((m_FinishingRank - 1) <= 7))
  5314. {
  5315. if (ENSkakiera[(m_FinishingColumnNumber - 1 + 1), (m_FinishingRank - 1)].CompareTo("Black King") == 0)
  5316. m_NomimotitaKinisis = false;
  5317. }
  5318. }
  5319.  
  5320.  
  5321. if (MovingPiece_2.CompareTo("Black King") == 0)
  5322. {
  5323. if (((m_FinishingColumnNumber - 1 + 1) >= 0) && ((m_FinishingColumnNumber - 1 + 1) <= 7) && ((m_FinishingRank - 1 + 1) >= 0) && ((m_FinishingRank - 1 + 1) <= 7))
  5324. {
  5325. if (ENSkakiera[(m_FinishingColumnNumber - 1 + 1), (m_FinishingRank - 1 + 1)].CompareTo("White King") == 0)
  5326. m_NomimotitaKinisis = false;
  5327. }
  5328.  
  5329. if (((m_FinishingColumnNumber - 1) >= 0) && ((m_FinishingColumnNumber - 1) <= 7) && ((m_FinishingRank - 1 + 1) >= 0) && ((m_FinishingRank - 1 + 1) <= 7))
  5330. {
  5331. if (ENSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1 + 1)].CompareTo("White King") == 0)
  5332. m_NomimotitaKinisis = false;
  5333. }
  5334.  
  5335. if (((m_FinishingColumnNumber - 1 - 1) >= 0) && ((m_FinishingColumnNumber - 1 - 1) <= 7) && ((m_FinishingRank - 1 + 1) >= 0) && ((m_FinishingRank - 1 + 1) <= 7))
  5336. {
  5337. if (ENSkakiera[(m_FinishingColumnNumber - 1 - 1), (m_FinishingRank - 1 + 1)].CompareTo("White King") == 0)
  5338. m_NomimotitaKinisis = false;
  5339. }
  5340.  
  5341. if (((m_FinishingColumnNumber - 1 - 1) >= 0) && ((m_FinishingColumnNumber - 1 - 1) <= 7) && ((m_FinishingRank - 1) >= 0) && ((m_FinishingRank - 1) <= 7))
  5342. {
  5343. if (ENSkakiera[(m_FinishingColumnNumber - 1 - 1), (m_FinishingRank - 1)].CompareTo("White King") == 0)
  5344. m_NomimotitaKinisis = false;
  5345. }
  5346.  
  5347. if (((m_FinishingColumnNumber - 1 - 1) >= 0) && ((m_FinishingColumnNumber - 1 - 1) <= 7) && ((m_FinishingRank - 1 - 1) >= 0) && ((m_FinishingRank - 1 - 1) <= 7))
  5348. {
  5349. if (ENSkakiera[(m_FinishingColumnNumber - 1 - 1), (m_FinishingRank - 1 - 1)].CompareTo("White King") == 0)
  5350. m_NomimotitaKinisis = false;
  5351. }
  5352.  
  5353. if (((m_FinishingColumnNumber - 1) >= 0) && ((m_FinishingColumnNumber - 1) <= 7) && ((m_FinishingRank - 1 - 1) >= 0) && ((m_FinishingRank - 1 - 1) <= 7))
  5354. {
  5355. if (ENSkakiera[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1 - 1)].CompareTo("White King") == 0)
  5356. m_NomimotitaKinisis = false;
  5357. }
  5358.  
  5359. if (((m_FinishingColumnNumber - 1 + 1) >= 0) && ((m_FinishingColumnNumber - 1 + 1) <= 7) && ((m_FinishingRank - 1 - 1) >= 0) && ((m_FinishingRank - 1 - 1) <= 7))
  5360. {
  5361. if (ENSkakiera[(m_FinishingColumnNumber - 1 + 1), (m_FinishingRank - 1 - 1)].CompareTo("White King") == 0)
  5362. m_NomimotitaKinisis = false;
  5363. }
  5364.  
  5365. if (((m_FinishingColumnNumber - 1 + 1) >= 0) && ((m_FinishingColumnNumber - 1 + 1) <= 7) && ((m_FinishingRank - 1) >= 0) && ((m_FinishingRank - 1) <= 7))
  5366. {
  5367. if (ENSkakiera[(m_FinishingColumnNumber - 1 + 1), (m_FinishingRank - 1)].CompareTo("White King") == 0)
  5368. m_NomimotitaKinisis = false;
  5369. }
  5370. }
  5371. #endregion CheckKindNextToKing
  5372.  
  5373. return Nomimotita;
  5374. }
  5375.  
  5376.  
  5377. // FUNCTION TO CHECK THE CORRECTNESS (='Orthotita' in Greek) OF THE MOVE
  5378. // (i.e. a Bishop can only move in diagonals, rooks in lines and columns etc)
  5379. // The ElegxosOrthotitas "checkForDanger" mode differs from the ElegxosOrthotitas normal mode in that it does not make all the validations
  5380. // (since it is used to check for "Dangerous" squares in the chessboard and not to actually judge the correctness of an actual move)
  5381. public static bool ElegxosOrthotitas(string[,] EOSkakiera, int checkForDanger, int startRank, int startColumn, int finishRank, int finishColumn, String MovingPiece_2)
  5382. {
  5383. // TODO: Add your control notification handler code here
  5384.  
  5385. // If called for checking dangerous squares, put a virtual piece in the destination square so as to pass the validation checks
  5386. // if (checkForDanger == 1)
  5387. // Don't care about checking for the existence of a piece in the destination square
  5388.  
  5389.  
  5390. bool Orthotita;
  5391. Orthotita = false;
  5392. enpassant_occured = false;
  5393.  
  5394. //Console.WriteLine("ElegxosOrthotitas");
  5395. //Console.WriteLine(MovingPiece_2);
  5396.  
  5397. if ((m_WhoPlays.CompareTo("Human") == 0) && (m_WrongColumn == false) && (MovingPiece_2.CompareTo("") == 1)) // Αν ο χρήστης έχει γράψει μία έγκυρη στήλη και έχει
  5398. { // επιλέξει να κινήσει ένα κομμάτι (και δεν έχει επι-
  5399. // λέξει να κινήσει ένα "κενό" τετράγωνο) και είναι η σειρά του να παίξει, τότε να γί-
  5400. // νει έλεγχος της ορθότητας της κίνησης.
  5401.  
  5402. //Console.WriteLine("1");
  5403.  
  5404. // ROOK
  5405.  
  5406. if ((MovingPiece_2.CompareTo("White Rook") == 0) || (MovingPiece_2.CompareTo("Black Rook") == 0))
  5407. {
  5408. if ((finishColumn != startColumn) && (finishRank == startRank)) // Κίνηση σε στήλη
  5409. Orthotita = true;
  5410. else if ((finishRank != startRank) && (finishColumn == startColumn)) // Κίνηση σε γραμμή
  5411. Orthotita = true;
  5412. }
  5413.  
  5414. // horse (with knight...)
  5415.  
  5416. if ((MovingPiece_2.CompareTo("White Knight") == 0) || (MovingPiece_2.CompareTo("Black Knight") == 0))
  5417. {
  5418. if ((finishColumn == (startColumn + 1)) && (finishRank == (startRank + 2)))
  5419. Orthotita = true;
  5420. else if ((finishColumn == (startColumn + 2)) && (finishRank == (startRank - 1)))
  5421. Orthotita = true;
  5422. else if ((finishColumn == (startColumn + 1)) && (finishRank == (startRank - 2)))
  5423. Orthotita = true;
  5424. else if ((finishColumn == (startColumn - 1)) && (finishRank == (startRank - 2)))
  5425. Orthotita = true;
  5426. else if ((finishColumn == (startColumn - 2)) && (finishRank == (startRank - 1)))
  5427. Orthotita = true;
  5428. else if ((finishColumn == (startColumn - 2)) && (finishRank == (startRank + 1)))
  5429. Orthotita = true;
  5430. else if ((finishColumn == (startColumn - 1)) && (finishRank == (startRank + 2)))
  5431. Orthotita = true;
  5432. else if ((finishColumn == (startColumn + 2)) && (finishRank == (startRank + 1)))
  5433. Orthotita = true;
  5434. }
  5435.  
  5436. // bishop
  5437.  
  5438. if ((MovingPiece_2.CompareTo("White Bishop") == 0) || (MovingPiece_2.CompareTo("Black Bishop") == 0))
  5439. {
  5440. ////////////////////
  5441. // 2009 v4 change
  5442. ////////////////////
  5443. //if ((Math.Abs(finishColumn - startColumn)) == (Math.Abs(finishRank - startRank)))
  5444. // Orthotita = true;
  5445. if (((Math.Abs(finishColumn - startColumn)) == (Math.Abs(finishRank - startRank))) && (finishColumn != startColumn) && (finishRank != startRank))
  5446. Orthotita = true;
  5447. ////////////////////
  5448. // 2009 v4 change
  5449. ////////////////////
  5450. }
  5451.  
  5452. // queen
  5453.  
  5454. if ((MovingPiece_2.CompareTo("White Queen") == 0) || (MovingPiece_2.CompareTo("Black Queen") == 0))
  5455. {
  5456. if ((finishColumn != startColumn) && (finishRank == startRank)) // Κίνηση σε στήλη
  5457. Orthotita = true;
  5458. else if ((finishRank != startRank) && (finishColumn == startColumn)) // Κίνηση σε γραμμή
  5459. Orthotita = true;
  5460.  
  5461. ////////////////////
  5462. // 2009 v4 change
  5463. ////////////////////
  5464. // move in diagonals
  5465. //if ((Math.Abs(finishColumn - startColumn)) == (Math.Abs(finishRank - startRank)))
  5466. // Orthotita = true;
  5467. if (((Math.Abs(finishColumn - startColumn)) == (Math.Abs(finishRank - startRank))) && (finishColumn != startColumn) && (finishRank != startRank))
  5468. Orthotita = true;
  5469. ////////////////////
  5470. // 2009 v4 change
  5471. ////////////////////
  5472. }
  5473.  
  5474. // king
  5475.  
  5476. if ((MovingPiece_2.CompareTo("White King") == 0) || (MovingPiece_2.CompareTo("Black King") == 0))
  5477. {
  5478. // move in rows and columns
  5479.  
  5480. if ((finishColumn == (startColumn + 1)) && (finishRank == startRank))
  5481. Orthotita = true;
  5482. else if ((finishColumn == (startColumn - 1)) && (finishRank == startRank))
  5483. Orthotita = true;
  5484. else if ((finishRank == (startRank + 1)) && (finishColumn == startColumn))
  5485. Orthotita = true;
  5486. else if ((finishRank == (startRank - 1)) && (finishColumn == startColumn))
  5487. Orthotita = true;
  5488.  
  5489. // move in diagonals
  5490.  
  5491. else if ((finishColumn == (startColumn + 1)) && (finishRank == (startRank + 1)))
  5492. Orthotita = true;
  5493. else if ((finishColumn == (startColumn + 1)) && (finishRank == (startRank - 1)))
  5494. Orthotita = true;
  5495. else if ((finishColumn == (startColumn - 1)) && (finishRank == (startRank - 1)))
  5496. Orthotita = true;
  5497. else if ((finishColumn == (startColumn - 1)) && (finishRank == (startRank + 1)))
  5498. Orthotita = true;
  5499.  
  5500. }
  5501.  
  5502. // white pawn
  5503.  
  5504. if (MovingPiece_2.CompareTo("White Pawn") == 0)
  5505. {
  5506. // move forward
  5507. //Console.WriteLine("2");
  5508.  
  5509. if ((finishRank == (startRank + 1)) && (finishColumn == startColumn))
  5510. Orthotita = true;
  5511.  
  5512. // move forward for 2 squares
  5513. else if ((finishRank == (startRank + 2)) && (finishColumn == startColumn) && (startRank == 2))
  5514. Orthotita = true;
  5515.  
  5516. else if ((finishRank == (startRank + 1)) && ((finishColumn == (startColumn - 1)) || (finishColumn == (startColumn + 1))))
  5517. {
  5518. if (checkForDanger == 0)
  5519. {
  5520. // eat forward to the left
  5521. if ((finishRank == (startRank + 1)) && (finishColumn == (startColumn - 1)) && ((EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Pawn") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Rook") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Knight") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Bishop") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Queen") == 0)))
  5522. Orthotita = true;
  5523.  
  5524. // eat forward to the right
  5525. if ((finishRank == (startRank + 1)) && (finishColumn == (startColumn + 1)) && ((EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Pawn") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Rook") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Knight") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Bishop") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("Black Queen") == 0)))
  5526. Orthotita = true;
  5527. }
  5528. else if (checkForDanger == 1)
  5529. {
  5530. Orthotita = true;
  5531. }
  5532. }
  5533.  
  5534. // En Passant eat forward to the left
  5535. else if ((finishRank == (startRank + 1)) && (finishColumn == (startColumn - 1)))
  5536. {
  5537. if (checkForDanger == 0)
  5538. {
  5539. //Console.WriteLine(finishRank.ToString());
  5540. //Console.WriteLine(finishColumn.ToString());
  5541. //Console.WriteLine("checking En passant...");
  5542. if ((finishRank == 6) && (EOSkakiera[(finishColumn - 1), (4)].CompareTo("Black Pawn") == 0))
  5543. {
  5544. Orthotita = true;
  5545. enpassant_occured = true;
  5546. EOSkakiera[(finishColumn - 1), (finishRank - 1 - 1)] = "";
  5547. //Console.WriteLine("En passant true");
  5548. }
  5549. else
  5550. {
  5551. Orthotita = false;
  5552. enpassant_occured = false;
  5553. }
  5554. }
  5555. }
  5556.  
  5557. // En Passant eat forward to the right
  5558. else if ((finishRank == (startRank + 1)) && (finishColumn == (startColumn + 1)))
  5559. {
  5560. if (checkForDanger == 0)
  5561. {
  5562. if ((finishRank == 6) && (EOSkakiera[(finishColumn - 1), (4)].CompareTo("Black Pawn") == 0))
  5563. {
  5564. Orthotita = true;
  5565. enpassant_occured = true;
  5566. EOSkakiera[(finishColumn - 1), (finishRank - 1 - 1)] = "";
  5567. }
  5568. else
  5569. {
  5570. Orthotita = false;
  5571. enpassant_occured = false;
  5572. }
  5573. }
  5574. }
  5575.  
  5576. }
  5577.  
  5578.  
  5579. // black pawn
  5580.  
  5581. if (MovingPiece_2.CompareTo("Black Pawn") == 0)
  5582. {
  5583. // move forward
  5584.  
  5585. if ((finishRank == (startRank - 1)) && (finishColumn == startColumn))
  5586. Orthotita = true;
  5587.  
  5588. // move forward for 2 squares
  5589. else if ((finishRank == (startRank - 2)) && (finishColumn == startColumn) && (startRank == 7))
  5590. Orthotita = true;
  5591.  
  5592. else if ((finishRank == (startRank - 1)) && ((finishColumn == (startColumn + 1)) || (finishColumn == (startColumn - 1))))
  5593. {
  5594. if (checkForDanger == 0)
  5595. {
  5596. // eat forward to the left
  5597. if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn + 1)) && ((EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Pawn") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Rook") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Knight") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Bishop") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Queen") == 0)))
  5598. Orthotita = true;
  5599.  
  5600. // eat forward to the right
  5601. if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn - 1)) && ((EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Pawn") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Rook") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Knight") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Bishop") == 0) || (EOSkakiera[(finishColumn - 1), (finishRank - 1)].CompareTo("White Queen") == 0)))
  5602. Orthotita = true;
  5603. }
  5604. else if (checkForDanger == 1)
  5605. {
  5606. // eat forward to the left
  5607. if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn + 1)))
  5608. Orthotita = true;
  5609.  
  5610. // eat forward to the right
  5611. if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn - 1)))
  5612. Orthotita = true;
  5613. }
  5614. }
  5615.  
  5616. // En Passant eat forward to the left
  5617. else if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn + 1)))
  5618. {
  5619. if (checkForDanger == 0)
  5620. {
  5621. if ((finishRank == 3) && (EOSkakiera[(finishColumn - 1), (3)].CompareTo("White Pawn") == 0))
  5622. {
  5623. Orthotita = true;
  5624. enpassant_occured = true;
  5625. EOSkakiera[(finishColumn - 1), (finishRank + 1 - 1)] = "";
  5626. }
  5627. else
  5628. {
  5629. Orthotita = false;
  5630. enpassant_occured = false;
  5631. }
  5632. }
  5633. }
  5634.  
  5635. // En Passant eat forward to the right
  5636. else if ((finishRank == (startRank - 1)) && (finishColumn == (startColumn - 1)))
  5637. {
  5638. if (checkForDanger == 0)
  5639. {
  5640. if ((finishRank == 3) && (EOSkakiera[(finishColumn - 1), (3)].CompareTo("White Pawn") == 0))
  5641. {
  5642. Orthotita = true;
  5643. enpassant_occured = true;
  5644. EOSkakiera[(finishColumn - 1), (finishRank + 1 - 1)] = "";
  5645. }
  5646. else
  5647. {
  5648. Orthotita = false;
  5649. enpassant_occured = false;
  5650. }
  5651. }
  5652. }
  5653.  
  5654. }
  5655.  
  5656. }
  5657.  
  5658. //Console.WriteLine(Orthotita.ToString());
  5659. return Orthotita;
  5660. }
  5661.  
  5662.  
  5663.  
  5664. public static void Starting_position()
  5665. {
  5666. // TODO: Add your control notification handler code here
  5667.  
  5668. for (int a = 0; a <= 7; a++)
  5669. {
  5670. for (int b = 0; b <= 7; b++)
  5671. {
  5672. Skakiera[(a), (b)] = "";
  5673. }
  5674. }
  5675.  
  5676. Skakiera[(0), (0)] = "White Rook";
  5677. Skakiera[(0), (1)] = "White Pawn";
  5678. Skakiera[(0), (6)] = "Black Pawn";
  5679. Skakiera[(0), (7)] = "Black Rook";
  5680. Skakiera[(1), (0)] = "White Knight";
  5681. Skakiera[(1), (1)] = "White Pawn";
  5682. Skakiera[(1), (6)] = "Black Pawn";
  5683. Skakiera[(1), (7)] = "Black Knight";
  5684. Skakiera[(2), (0)] = "White Bishop";
  5685. Skakiera[(2), (1)] = "White Pawn";
  5686. Skakiera[(2), (6)] = "Black Pawn";
  5687. Skakiera[(2), (7)] = "Black Bishop";
  5688. Skakiera[(3), (0)] = "White Queen";
  5689. Skakiera[(3), (1)] = "White Pawn";
  5690. Skakiera[(3), (6)] = "Black Pawn";
  5691. Skakiera[(3), (7)] = "Black Queen";
  5692. Skakiera[(4), (0)] = "White King";
  5693. Skakiera[(4), (1)] = "White Pawn";
  5694. Skakiera[(4), (6)] = "Black Pawn";
  5695. Skakiera[(4), (7)] = "Black King";
  5696. Skakiera[(5), (0)] = "White Bishop";
  5697. Skakiera[(5), (1)] = "White Pawn";
  5698. Skakiera[(5), (6)] = "Black Pawn";
  5699. Skakiera[(5), (7)] = "Black Bishop";
  5700. Skakiera[(6), (0)] = "White Knight";
  5701. Skakiera[(6), (1)] = "White Pawn";
  5702. Skakiera[(6), (6)] = "Black Pawn";
  5703. Skakiera[(6), (7)] = "Black Knight";
  5704. Skakiera[(7), (0)] = "White Rook";
  5705. Skakiera[(7), (1)] = "White Pawn";
  5706. Skakiera[(7), (6)] = "Black Pawn";
  5707. Skakiera[(7), (7)] = "Black Rook";
  5708.  
  5709. m_WhichColorPlays = "White";
  5710. }
  5711.  
  5712. public static void Analyze_Move_1_HumanMove(string[,] Skakiera_Human_Thinking_2)
  5713. {
  5714. #region WriteLog
  5715. //huo_sw1.WriteLine("");
  5716. //huo_sw1.WriteLine("HMT2 -- Entered HumanMove_template 2");
  5717. //huo_sw1.WriteLine(string.Concat("HMT2 -- Depth analyzed: ", Move_Analyzed.ToString()));
  5718. //huo_sw1.WriteLine(string.Concat("HMT2 -- Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  5719. //huo_sw1.WriteLine(string.Concat("HMT2 -- Move analyzed: ", m_StartingColumnNumber_HY.ToString(), m_StartingRank_HY.ToString(), " -> ", m_FinishingColumnNumber_HY.ToString(), m_FinishingRank_HY.ToString()));
  5720. //huo_sw1.WriteLine(string.Concat("HMT2 -- Number of Nodes 0: ", NodeLevel_0_count.ToString()));
  5721. //huo_sw1.WriteLine(string.Concat("HMT2 -- Number of Nodes 1: ", NodeLevel_1_count.ToString()));
  5722. //huo_sw1.WriteLine(string.Concat("HMT2 -- Number of Nodes 2: ", NodeLevel_2_count.ToString()));
  5723. //huo_sw1.WriteLine(string.Concat("HMT2 -- Number of Nodes 3: ", NodeLevel_3_count.ToString()));
  5724. //huo_sw1.WriteLine(string.Concat("HMT2 -- Number of Nodes 4: ", NodeLevel_4_count.ToString()));
  5725. //huo_sw1.WriteLine(string.Concat("HMT2 -- Number of Nodes 5: ", NodeLevel_5_count.ToString()));
  5726. //huo_sw1.WriteLine(string.Concat("HMT2 -- Number of Nodes 6: ", NodeLevel_6_count.ToString()));
  5727. //huo_sw1.WriteLine("");
  5728. #endregion WriteLog
  5729.  
  5730. // Scan chessboard . Find a piece of the human player . Move to all possible squares.
  5731. // Check corr1ectness and legality of move . If all OK then measure the move's score.
  5732. // Do the best move and handle over to the ComputerMove function to continue analysis in the next move (deeper depth...)
  5733. int skakos1;
  5734. int trelos5;
  5735. String MovingPiece1;
  5736. String ProsorinoKommati1;
  5737. int m_StartingColumnNumber1;
  5738. int m_FinishingColumnNumber1;
  5739. int m_StartingRank1;
  5740. int m_FinishingRank1;
  5741.  
  5742. // Checl all possible moves
  5743. for (skakos1 = 0; skakos1 <= 7; skakos1++)
  5744. {
  5745. for (trelos5 = 0; trelos5 <= 7; trelos5++)
  5746. {
  5747.  
  5748. if (((Who_Is_Analyzed.CompareTo("Human") == 0) && ((((Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("Black King") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("Black Queen") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("Black Rook") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("Black Knight") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("Black Bishop") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)) || (((Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("White King") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("White Queen") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("White Rook") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("White Knight") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("White Bishop") == 0) || (Skakiera_Human_Thinking_2[(skakos1), (trelos5)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)))))
  5749. {
  5750. for (int w = 0; w <= 7; w++)
  5751. {
  5752. for (int r = 0; r <= 7; r++)
  5753. {
  5754. MovingPiece = Skakiera_Human_Thinking_2[(skakos1), (trelos5)];
  5755. m_StartingColumnNumber = skakos1 + 1;
  5756. m_FinishingColumnNumber = w + 1;
  5757. m_StartingRank = trelos5 + 1;
  5758. m_FinishingRank = r + 1;
  5759.  
  5760. // Store temporary move data in local variables, so as to use them in the Undo of the move
  5761. // at the end of this function (the MovingPiece, m_StartingColumnNumber, etc variables are
  5762. // changed by next functions as well, so using them leads to problems)
  5763. MovingPiece1 = MovingPiece;
  5764. m_StartingColumnNumber1 = m_StartingColumnNumber;
  5765. m_FinishingColumnNumber1 = m_FinishingColumnNumber;
  5766. m_StartingRank1 = m_StartingRank;
  5767. m_FinishingRank1 = m_FinishingRank;
  5768. ProsorinoKommati1 = Skakiera_Human_Thinking_2[(m_FinishingColumnNumber1 - 1), (m_FinishingRank1 - 1)];
  5769.  
  5770. // Check the move
  5771. number_of_moves_analysed++;
  5772.  
  5773. // Necessary values for variables for the ElegxosOrthotitas (check move corr1ectness) and
  5774. // ElegxosNomimotitas (check move legality) function to...function properly.
  5775. m_WhoPlays = "Human";
  5776. m_WrongColumn = false;
  5777. MovingPiece = Skakiera_Human_Thinking_2[(m_StartingColumnNumber - 1), (m_StartingRank - 1)];
  5778. m_OrthotitaKinisis = ElegxosOrthotitas(Skakiera_Human_Thinking_2, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  5779. m_NomimotitaKinisis = ElegxosNomimotitas(Skakiera_Human_Thinking_2, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  5780. // Restore normal value of m_WhoPlays
  5781. m_WhoPlays = "HY";
  5782.  
  5783. // If all ok, then do the move and measure it
  5784. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  5785. {
  5786. // Do the move
  5787. ProsorinoKommati = Skakiera_Human_Thinking_2[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  5788. Skakiera_Human_Thinking_2[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  5789. Skakiera_Human_Thinking_2[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  5790.  
  5791. // Measure score AFTER the move
  5792. if (Move_Analyzed == 1)
  5793. {
  5794. NodeLevel_1_count++;
  5795. Temp_Score_Move_1_human = CountScore(Skakiera_Human_Thinking_2, humanDangerParameter);
  5796. }
  5797. if (Move_Analyzed == 3)
  5798. {
  5799. NodeLevel_3_count++;
  5800. Temp_Score_Move_3_human = CountScore(Skakiera_Human_Thinking_2, humanDangerParameter);
  5801. }
  5802. if (Move_Analyzed == 5)
  5803. {
  5804. NodeLevel_5_count++;
  5805. Temp_Score_Move_5_human = CountScore(Skakiera_Human_Thinking_2, humanDangerParameter);
  5806. }
  5807.  
  5808. if (Move_Analyzed < Thinking_Depth)
  5809. {
  5810. // Call ComputerMove for the HY throught process to continue
  5811. Move_Analyzed = Move_Analyzed + 1;
  5812.  
  5813. Who_Is_Analyzed = "HY";
  5814.  
  5815. for (i = 0; i <= 7; i++)
  5816. {
  5817. for (j = 0; j <= 7; j++)
  5818. {
  5819. Skakiera_Move_After[(i), (j)] = Skakiera_Human_Thinking_2[(i), (j)];
  5820. }
  5821. }
  5822.  
  5823. if (Move_Analyzed == 2)
  5824. Analyze_Move_2_ComputerMove(Skakiera_Move_After);
  5825. else if (Move_Analyzed == 4)
  5826. Analyze_Move_4_ComputerMove(Skakiera_Move_After);
  5827. else if (Move_Analyzed == 6)
  5828. Analyze_Move_6_ComputerMove(Skakiera_Move_After);
  5829. }
  5830.  
  5831. // Undo the move
  5832. Skakiera_Human_Thinking_2[(m_StartingColumnNumber1 - 1), (m_StartingRank1 - 1)] = MovingPiece1;
  5833. Skakiera_Human_Thinking_2[(m_FinishingColumnNumber1 - 1), (m_FinishingRank1 - 1)] = ProsorinoKommati1;
  5834. }
  5835.  
  5836. } // For 4
  5837. } // For 3
  5838.  
  5839. }// IF
  5840.  
  5841. } // For 2
  5842. } // For 1
  5843.  
  5844. Move_Analyzed = Move_Analyzed - 1;
  5845. Who_Is_Analyzed = "HY";
  5846. }
  5847.  
  5848. public static void Analyze_Move_3_HumanMove(string[,] Skakiera_Human_Thinking_4)
  5849. {
  5850. //huo_sw1.WriteLine("");
  5851. //huo_sw1.WriteLine("HMT4 -- Entered HumanMove_template 4");
  5852. //huo_sw1.WriteLine(string.Concat("HMT4 -- Depth analyzed: ", Move_Analyzed.ToString()));
  5853. //huo_sw1.WriteLine(string.Concat("HMT4 -- Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  5854. //huo_sw1.WriteLine(string.Concat("HMT4 -- Move analyzed: ", m_StartingColumnNumber_HY.ToString(), m_StartingRank_HY.ToString(), " -> ", m_FinishingColumnNumber_HY.ToString(), m_FinishingRank_HY.ToString()));
  5855. //huo_sw1.WriteLine(string.Concat("HMT4 -- Number of Nodes 0: ", NodeLevel_0_count.ToString()));
  5856. //huo_sw1.WriteLine(string.Concat("HMT4 -- Number of Nodes 1: ", NodeLevel_1_count.ToString()));
  5857. //huo_sw1.WriteLine(string.Concat("HMT4 -- Number of Nodes 2: ", NodeLevel_2_count.ToString()));
  5858. //huo_sw1.WriteLine(string.Concat("HMT4 -- Number of Nodes 3: ", NodeLevel_3_count.ToString()));
  5859. //huo_sw1.WriteLine(string.Concat("HMT4 -- Number of Nodes 4: ", NodeLevel_4_count.ToString()));
  5860. //huo_sw1.WriteLine(string.Concat("HMT4 -- Number of Nodes 5: ", NodeLevel_5_count.ToString()));
  5861. //huo_sw1.WriteLine(string.Concat("HMT4 -- Number of Nodes 6: ", NodeLevel_6_count.ToString()));
  5862. //huo_sw1.WriteLine("");
  5863.  
  5864. // scan chessboard . find a piece of the human player . move to all
  5865. // possible squares . check correctness and legality of move . if
  5866. // all ok then measure the move's score . do the best move and handle
  5867. // over to the ComputerMove function to continue analysis in the next
  5868. // move (deeper depth...)
  5869. int ww2;
  5870. int rr2;
  5871. int www2;
  5872. int rrr2;
  5873. String MovingPiece3;
  5874. String ProsorinoKommati3;
  5875. int m_StartingColumnNumber3;
  5876. int m_FinishingColumnNumber3;
  5877. int m_StartingRank3;
  5878. int m_FinishingRank3;
  5879.  
  5880. // Check all possible moves
  5881. for (www2 = 0; www2 <= 7; www2++)
  5882. {
  5883. for (rrr2 = 0; rrr2 <= 7; rrr2++)
  5884. {
  5885.  
  5886. if (((Who_Is_Analyzed.CompareTo("Human") == 0) && ((((Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("Black King") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("Black Queen") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("Black Rook") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("Black Knight") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("Black Bishop") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)) || (((Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("White King") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("White Queen") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("White Rook") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("White Knight") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("White Bishop") == 0) || (Skakiera_Human_Thinking_4[(www2), (rrr2)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)))))
  5887. {
  5888. for (ww2 = 0; ww2 <= 7; ww2++)
  5889. {
  5890. for (rr2 = 0; rr2 <= 7; rr2++)
  5891. {
  5892. MovingPiece = Skakiera_Human_Thinking_4[(www2), (rrr2)];
  5893. m_StartingColumnNumber = www2 + 1;
  5894. m_FinishingColumnNumber = ww2 + 1;
  5895. m_StartingRank = rrr2 + 1;
  5896. m_FinishingRank = rr2 + 1;
  5897.  
  5898. // Store temporary move data in local variables, so as to use them in the Undo of the move
  5899. // at the end of this function (the MovingPiece, m_StartingColumnNumber, etc variables are
  5900. // changed by next functions as well, so using them leads to problems)
  5901. MovingPiece3 = MovingPiece;
  5902. m_StartingColumnNumber3 = m_StartingColumnNumber;
  5903. m_FinishingColumnNumber3 = m_FinishingColumnNumber;
  5904. m_StartingRank3 = m_StartingRank;
  5905. m_FinishingRank3 = m_FinishingRank;
  5906. ProsorinoKommati3 = Skakiera_Human_Thinking_4[(m_FinishingColumnNumber3 - 1), (m_FinishingRank3 - 1)];
  5907.  
  5908. // Check the move
  5909. number_of_moves_analysed++;
  5910.  
  5911. // Necessary values for variables for the ElegxosOrthotitas (check move correctness) and
  5912. // ElegxosNomimotitas (check move legality) function to...function properly.
  5913. m_WhoPlays = "Human";
  5914. m_WrongColumn = false;
  5915. MovingPiece = Skakiera_Human_Thinking_4[(m_StartingColumnNumber - 1), (m_StartingRank - 1)];
  5916.  
  5917. m_OrthotitaKinisis = ElegxosOrthotitas(Skakiera_Human_Thinking_4, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  5918. m_NomimotitaKinisis = ElegxosNomimotitas(Skakiera_Human_Thinking_4, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  5919.  
  5920. // restore normal value of m_WhoPlays
  5921. m_WhoPlays = "HY";
  5922.  
  5923. // if all ok, then do the move and measure it
  5924. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  5925. {
  5926. // do the move
  5927. ProsorinoKommati = Skakiera_Human_Thinking_4[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  5928. Skakiera_Human_Thinking_4[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  5929. Skakiera_Human_Thinking_4[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  5930.  
  5931. // Measure score AFTER the move
  5932. //Temp_Score_Human_before_0 = CountScore(Skakiera_Human_Thinking_4);
  5933. if (Move_Analyzed == 1)
  5934. {
  5935. NodeLevel_1_count++;
  5936. Temp_Score_Move_1_human = CountScore(Skakiera_Human_Thinking_4, humanDangerParameter);
  5937. }
  5938. if (Move_Analyzed == 3)
  5939. {
  5940. NodeLevel_3_count++;
  5941. Temp_Score_Move_3_human = CountScore(Skakiera_Human_Thinking_4, humanDangerParameter);
  5942. }
  5943. if (Move_Analyzed == 5)
  5944. {
  5945. NodeLevel_5_count++;
  5946. Temp_Score_Move_5_human = CountScore(Skakiera_Human_Thinking_4, humanDangerParameter);
  5947. }
  5948.  
  5949. ///////////////////////////////////////////////////////////////////
  5950. // Is the king still under check? If yes, then we have mate!
  5951. ///////////////////////////////////////////////////////////////////
  5952. Possible_mate = false;
  5953.  
  5954. if (Human_is_in_check == true)
  5955. {
  5956. WhiteKingCheck = CheckForWhiteCheck(Skakiera_Human_Thinking_4);
  5957. if ((m_PlayerColor.CompareTo("White") == 0) && (WhiteKingCheck == true))
  5958. Possible_mate = true;
  5959.  
  5960. BlackKingCheck = CheckForBlackCheck(Skakiera_Human_Thinking_4);
  5961. if ((m_PlayerColor.CompareTo("Black") == 0) && (BlackKingCheck == true))
  5962. Possible_mate = true;
  5963. }
  5964.  
  5965. if (Move_Analyzed < Thinking_Depth)
  5966. {
  5967. // Call ComputerMove for the HY throught process to continue
  5968. Move_Analyzed = Move_Analyzed + 1;
  5969.  
  5970. Who_Is_Analyzed = "HY";
  5971.  
  5972. for (i = 0; i <= 7; i++)
  5973. {
  5974. for (j = 0; j <= 7; j++)
  5975. {
  5976. Skakiera_Move_After[(i), (j)] = Skakiera_Human_Thinking_4[(i), (j)];
  5977. }
  5978. }
  5979.  
  5980. if (Move_Analyzed == 2)
  5981. Analyze_Move_2_ComputerMove(Skakiera_Move_After);
  5982. else if (Move_Analyzed == 4)
  5983. Analyze_Move_4_ComputerMove(Skakiera_Move_After);
  5984. else if (Move_Analyzed == 6)
  5985. Analyze_Move_6_ComputerMove(Skakiera_Move_After);
  5986. }
  5987.  
  5988. // Undo the move
  5989. Skakiera_Human_Thinking_4[(m_StartingColumnNumber3 - 1), (m_StartingRank3 - 1)] = MovingPiece3;
  5990. Skakiera_Human_Thinking_4[(m_FinishingColumnNumber3 - 1), (m_FinishingRank3 - 1)] = ProsorinoKommati3;
  5991. }
  5992. }
  5993. }
  5994. }
  5995.  
  5996. }
  5997. }
  5998.  
  5999. Move_Analyzed = Move_Analyzed - 1;
  6000. Who_Is_Analyzed = "HY";
  6001. }
  6002.  
  6003. public static void Analyze_Move_5_HumanMove(string[,] Skakiera_Human_Thinking_6)
  6004. {
  6005. //huo_sw1.WriteLine("");
  6006. //huo_sw1.WriteLine("HMT6 -- Entered HumanMove_template 6");
  6007. //huo_sw1.WriteLine(string.Concat("HMT6 -- Depth analyzed: ", Move_Analyzed.ToString()));
  6008. //huo_sw1.WriteLine(string.Concat("HMT6 -- Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  6009. //huo_sw1.WriteLine(string.Concat("HMT6 -- Move analyzed: ", m_StartingColumnNumber_HY.ToString(), m_StartingRank_HY.ToString(), " -> ", m_FinishingColumnNumber_HY.ToString(), m_FinishingRank_HY.ToString()));
  6010. //huo_sw1.WriteLine(string.Concat("HMT6 -- Number of Nodes 0: ", NodeLevel_0_count.ToString()));
  6011. //huo_sw1.WriteLine(string.Concat("HMT6 -- Number of Nodes 1: ", NodeLevel_1_count.ToString()));
  6012. //huo_sw1.WriteLine(string.Concat("HMT6 -- Number of Nodes 2: ", NodeLevel_2_count.ToString()));
  6013. //huo_sw1.WriteLine(string.Concat("HMT6 -- Number of Nodes 3: ", NodeLevel_3_count.ToString()));
  6014. //huo_sw1.WriteLine(string.Concat("HMT6 -- Number of Nodes 4: ", NodeLevel_4_count.ToString()));
  6015. //huo_sw1.WriteLine(string.Concat("HMT6 -- Number of Nodes 5: ", NodeLevel_5_count.ToString()));
  6016. //huo_sw1.WriteLine(string.Concat("HMT6 -- Number of Nodes 6: ", NodeLevel_6_count.ToString()));
  6017. //huo_sw1.WriteLine("");
  6018.  
  6019. // scan chessboard . find a piece of the human player . move to all
  6020. // possible squares . check correctness and legality of move . if
  6021. // all ok then measure the move's score . do the best move and handle
  6022. // over to the ComputerMove function to continue analysis in the next
  6023. // move (deeper depth...)
  6024. int ww5;
  6025. int rr5;
  6026. int www5;
  6027. int rrr5;
  6028. String MovingPiece5;
  6029. String ProsorinoKommati5;
  6030. int m_StartingColumnNumber5;
  6031. int m_FinishingColumnNumber5;
  6032. int m_StartingRank5;
  6033. int m_FinishingRank5;
  6034.  
  6035. // Check all possible moves
  6036. for (www5 = 0; www5 <= 7; www5++)
  6037. {
  6038. for (rrr5 = 0; rrr5 <= 7; rrr5++)
  6039. {
  6040.  
  6041. if (((Who_Is_Analyzed.CompareTo("Human") == 0) && ((((Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("Black King") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("Black Queen") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("Black Rook") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("Black Knight") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("Black Bishop") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)) || (((Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("White King") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("White Queen") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("White Rook") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("White Knight") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("White Bishop") == 0) || (Skakiera_Human_Thinking_6[(www5), (rrr5)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)))))
  6042. {
  6043. for (ww5 = 0; ww5 <= 7; ww5++)
  6044. {
  6045. for (rr5 = 0; rr5 <= 7; rr5++)
  6046. {
  6047. MovingPiece = Skakiera_Human_Thinking_6[(www5), (rrr5)];
  6048. m_StartingColumnNumber = www5 + 1;
  6049. m_FinishingColumnNumber = ww5 + 1;
  6050. m_StartingRank = rrr5 + 1;
  6051. m_FinishingRank = rr5 + 1;
  6052.  
  6053. // Store temporary move data in local variables, so as to use them in the Undo of the move
  6054. // at the end of this function (the MovingPiece, m_StartingColumnNumber, etc variables are
  6055. // changed by next functions as well, so using them leads to problems)
  6056. MovingPiece5 = MovingPiece;
  6057. m_StartingColumnNumber5 = m_StartingColumnNumber;
  6058. m_FinishingColumnNumber5 = m_FinishingColumnNumber;
  6059. m_StartingRank5 = m_StartingRank;
  6060. m_FinishingRank5 = m_FinishingRank;
  6061. ProsorinoKommati5 = Skakiera_Human_Thinking_6[(m_FinishingColumnNumber5 - 1), (m_FinishingRank5 - 1)];
  6062.  
  6063. // Check the move
  6064. number_of_moves_analysed++;
  6065.  
  6066. // Necessary values for variables for the ElegxosOrthotitas (check move correctness) and
  6067. // ElegxosNomimotitas (check move legality) function to...function properly.
  6068. m_WhoPlays = "Human";
  6069. m_WrongColumn = false;
  6070. MovingPiece = Skakiera_Human_Thinking_6[(m_StartingColumnNumber - 1), (m_StartingRank - 1)];
  6071.  
  6072. m_OrthotitaKinisis = ElegxosOrthotitas(Skakiera_Human_Thinking_6, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  6073. m_NomimotitaKinisis = ElegxosNomimotitas(Skakiera_Human_Thinking_6, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  6074.  
  6075. // restore normal value of m_WhoPlays
  6076. m_WhoPlays = "HY";
  6077.  
  6078. // If all ok, then do the move and measure it
  6079. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  6080. {
  6081. // Do the move
  6082. ProsorinoKommati = Skakiera_Human_Thinking_6[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  6083. Skakiera_Human_Thinking_6[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  6084. Skakiera_Human_Thinking_6[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  6085.  
  6086.  
  6087. // Measure score AFTER the move
  6088. if (Move_Analyzed == 1)
  6089. {
  6090. NodeLevel_1_count++;
  6091. //Human_Stupid_Move_2_penalty = false;
  6092. // Chessboard score before the human plays (i.e. before depth 2 computer move)
  6093. Temp_Score_Move_1_human = CountScore(Skakiera_Human_Thinking_6, humanDangerParameter);
  6094. //Temp_Score_Move_1_human = CountScore(Skakiera_Human_Thinking_6);
  6095. }
  6096. if (Move_Analyzed == 3)
  6097. {
  6098. NodeLevel_3_count++;
  6099. //Human_Stupid_Move_4_penalty = false;
  6100. Temp_Score_Move_3_human = CountScore(Skakiera_Human_Thinking_6, humanDangerParameter);
  6101. //Temp_Score_Move_3_human = CountScore(Skakiera_Human_Thinking_6);
  6102. }
  6103. if (Move_Analyzed == 5)
  6104. {
  6105. NodeLevel_5_count++;
  6106. //Human_Stupid_Move_6_penalty = false;
  6107. Temp_Score_Move_5_human = CountScore(Skakiera_Human_Thinking_6, humanDangerParameter);
  6108. //Temp_Score_Move_5_human = CountScore(Skakiera_Human_Thinking_6);
  6109. }
  6110.  
  6111.  
  6112. ///////////////////////////////////////////////////////////////////
  6113. // is the king still under check? if yes, then we have mate!
  6114. ///////////////////////////////////////////////////////////////////
  6115. Possible_mate = false;
  6116.  
  6117. if (Human_is_in_check == true)
  6118. {
  6119. WhiteKingCheck = CheckForWhiteCheck(Skakiera_Human_Thinking_6);
  6120. if ((m_PlayerColor.CompareTo("White") == 0) && (WhiteKingCheck == true))
  6121. Possible_mate = true;
  6122.  
  6123. BlackKingCheck = CheckForBlackCheck(Skakiera_Human_Thinking_6);
  6124. if ((m_PlayerColor.CompareTo("Black") == 0) && (BlackKingCheck == true))
  6125. Possible_mate = true;
  6126. }
  6127.  
  6128. if (Move_Analyzed < Thinking_Depth)
  6129. {
  6130. // Call ComputerMove for the HY throught process to continue
  6131. Move_Analyzed = Move_Analyzed + 1;
  6132.  
  6133. Who_Is_Analyzed = "HY";
  6134.  
  6135. for (i = 0; i <= 7; i++)
  6136. {
  6137. for (j = 0; j <= 7; j++)
  6138. {
  6139. Skakiera_Move_After[(i), (j)] = Skakiera_Human_Thinking_6[(i), (j)];
  6140. }
  6141. }
  6142.  
  6143. if (Move_Analyzed == 2)
  6144. Analyze_Move_2_ComputerMove(Skakiera_Move_After);
  6145. else if (Move_Analyzed == 4)
  6146. Analyze_Move_4_ComputerMove(Skakiera_Move_After);
  6147. else if (Move_Analyzed == 6)
  6148. Analyze_Move_6_ComputerMove(Skakiera_Move_After);
  6149. }
  6150.  
  6151. // Undo the move
  6152. Skakiera_Human_Thinking_6[(m_StartingColumnNumber5 - 1), (m_StartingRank5 - 1)] = MovingPiece5;
  6153. Skakiera_Human_Thinking_6[(m_FinishingColumnNumber5 - 1), (m_FinishingRank5 - 1)] = ProsorinoKommati5;
  6154. }
  6155. }
  6156. }
  6157. }
  6158.  
  6159. }
  6160. }
  6161.  
  6162. Move_Analyzed = Move_Analyzed - 1;
  6163. Who_Is_Analyzed = "HY";
  6164. }
  6165.  
  6166. // HY Thought Process:
  6167. // Depth 0 (Move_Analyzed = 0): First half move analyzed - First HY half move analyzed
  6168. // Depth 1 (Move_Analyzed = 1): Second half move analyzed - First human half move analyzed
  6169. // Depth 2 (Move_Analyzed = 2): Thirf half move analyzed - Second HY half move analyzed
  6170. // et cetera...
  6171.  
  6172. // Functions for analyzing the HY Thought in depth...
  6173. // ...of the 3rd half move (Analyze_Move_2_ComputerMove)
  6174. // ...of the 5th half move (Analyze_Move_4_ComputerMove)
  6175. // ...of the 7th half move (Analyze_Move_6_ComputerMove)
  6176.  
  6177. public static void Analyze_Move_2_ComputerMove(string[,] Skakiera_Thinking_HY_2)
  6178. {
  6179. #region WriteLog
  6180. //huo_sw1.WriteLine("");
  6181. //huo_sw1.WriteLine("CMT2 -- Entered ComputerMove_template 2");
  6182. //huo_sw1.WriteLine(string.Concat("CMT2 -- Depth analyzed: ", Move_Analyzed.ToString()));
  6183. //huo_sw1.WriteLine(string.Concat("CMT2 -- Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  6184. //huo_sw1.WriteLine(string.Concat("CMT2 -- Move analyzed: ", m_StartingColumnNumber_HY.ToString(), m_StartingRank_HY.ToString(), " -> ", m_FinishingColumnNumber_HY.ToString(), m_FinishingRank_HY.ToString()));
  6185. //huo_sw1.WriteLine(string.Concat("CMT2 -- Number of Nodes 0: ", NodeLevel_0_count.ToString()));
  6186. //huo_sw1.WriteLine(string.Concat("CMT2 -- Number of Nodes 1: ", NodeLevel_1_count.ToString()));
  6187. //huo_sw1.WriteLine(string.Concat("CMT2 -- Number of Nodes 2: ", NodeLevel_2_count.ToString()));
  6188. //huo_sw1.WriteLine(string.Concat("CMT2 -- Number of Nodes 3: ", NodeLevel_3_count.ToString()));
  6189. //huo_sw1.WriteLine(string.Concat("CMT2 -- Number of Nodes 4: ", NodeLevel_4_count.ToString()));
  6190. //huo_sw1.WriteLine(string.Concat("CMT2 -- Number of Nodes 5: ", NodeLevel_5_count.ToString()));
  6191. //huo_sw1.WriteLine(string.Concat("CMT2 -- Number of Nodes 6: ", NodeLevel_6_count.ToString()));
  6192. //huo_sw1.WriteLine("");
  6193. #endregion WriteLog
  6194.  
  6195. // Δήλωση μεταβλητών που χρησιμοποιούνται στο βρόγχο "for" (δεν μπορεί να χρησιμοποιηθούν οι μεταβλητές i και j διότι αυτές οι
  6196. // μεταβλητές είναι καθολικές και δημιουργείται πρόβλημα κατά την επιστροφή στην ComputerMove από την CheckMove)
  6197.  
  6198. int iii2;
  6199. int jjj2;
  6200. String MovingPiece2;
  6201. String ProsorinoKommati2;
  6202. int m_StartingColumnNumber2;
  6203. int m_FinishingColumnNumber2;
  6204. int m_StartingRank2;
  6205. int m_FinishingRank2;
  6206.  
  6207. // Σκανάρισμα της σκακιέρας: Όταν εντοπίζεται κάποιο κομμάτι του υπολογιστή,
  6208. // θα υπολογίζονται ΟΛΕΣ οι πιθανές κινήσεις του προς κάθε κατεύθυνση, ακόμα
  6209. // και αυτές που δεν μπορεί να κάνει το κομμάτι. Στη συνέχεια, με τη βοήθεια
  6210. // των συναρτήσεων ElegxosNomimotitas και ElegxosOrthotitas θα ελέγχεται το
  6211. // αν η κίνηση είναι ορθή και νόμιμη. Αν είναι, η εν λόγω κίνηση θα γίνεται
  6212. // προσωρινά στη σκακιέρα και θα καταγράφεται το σκορ της νέας θέσης που
  6213. // προέκυψε
  6214.  
  6215. // ΣΗΜΕΙΩΣΗ: Σε όλες τις στήλες και τις οριζόντιους προστίθεται η μονάδα (+1)
  6216. // διότι πρέπει να μετατραπούν από το "σύστημα" μέτρησης "0-7" (που χρησιμο-
  6217. // ποιείται στο παρακάτω "for i…next" αλλά και στο συμβολισμό του πίνακα
  6218. // Skakiera) στο σύστημα μέτρησης "1-8" το οποίο χρησιμοποιείται στις
  6219. // μεταβλητές Starting/Finishing_Column/Rank σε όλο το υπόλοιπο πρόγραμμα.
  6220.  
  6221. for (iii2 = 0; iii2 <= 7; iii2++)
  6222. {
  6223. for (jjj2 = 0; jjj2 <= 7; jjj2++)
  6224. {
  6225.  
  6226. if (((Who_Is_Analyzed.CompareTo("HY") == 0) && ((((Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("White King") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("White Queen") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("White Rook") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("White Knight") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("White Bishop") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)) || (((Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("Black King") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("Black Queen") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("Black Rook") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("Black Knight") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("Black Bishop") == 0) || (Skakiera_Thinking_HY_2[(iii2), (jjj2)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)))))
  6227. {
  6228.  
  6229.  
  6230. for (int w = 0; w <= 7; w++)
  6231. {
  6232. for (int r = 0; r <= 7; r++)
  6233. {
  6234. MovingPiece = Skakiera_Thinking_HY_2[(iii2), (jjj2)];
  6235. m_StartingColumnNumber = iii2 + 1;
  6236. m_FinishingColumnNumber = w + 1;
  6237. m_StartingRank = jjj2 + 1;
  6238. m_FinishingRank = r + 1;
  6239.  
  6240. // Store temporary move data in local variables, so as to use them in the Undo of the move
  6241. // at the end of this function (the MovingPiece, m_StartingColumnNumber, etc variables are
  6242. // changed by next functions as well, so using them leads to problems)
  6243. MovingPiece2 = MovingPiece;
  6244. m_StartingColumnNumber2 = m_StartingColumnNumber;
  6245. m_FinishingColumnNumber2 = m_FinishingColumnNumber;
  6246. m_StartingRank2 = m_StartingRank;
  6247. m_FinishingRank2 = m_FinishingRank;
  6248. ProsorinoKommati2 = Skakiera_Thinking_HY_2[(m_FinishingColumnNumber2 - 1), (m_FinishingRank2 - 1)];
  6249.  
  6250. // Έλεγχος της κίνησης
  6251.  
  6252. // Validity and legality of the move has been checked in CheckMove
  6253. // CheckMove(Skakiera_Thinking_HY_2);
  6254.  
  6255. // Check validity and legality
  6256. // Necessary values for variables for the ElegxosOrthotitas (check move corr1ectness) and
  6257. // ElegxosNomimotitas (check move legality) function to...function properly.
  6258. m_WhoPlays = "Human";
  6259. m_WrongColumn = false;
  6260. m_OrthotitaKinisis = ElegxosOrthotitas(Skakiera_Thinking_HY_2, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  6261. m_NomimotitaKinisis = ElegxosNomimotitas(Skakiera_Thinking_HY_2, 0, m_StartingRank, m_StartingColumnNumber, m_FinishingRank, m_FinishingColumnNumber, MovingPiece);
  6262. // restore normal value of m_WhoPlays
  6263. m_WhoPlays = "HY";
  6264.  
  6265. number_of_moves_analysed++;
  6266.  
  6267. // If all ok, then do the move and measure it
  6268. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  6269. {
  6270. // huo_sw1.WriteLine(string.Concat("Human move 1: Found a legal move!"));
  6271.  
  6272. // Do the move
  6273. ProsorinoKommati = Skakiera_Thinking_HY_2[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  6274. Skakiera_Thinking_HY_2[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  6275. Skakiera_Thinking_HY_2[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  6276.  
  6277. // Check the score after the computer move.
  6278. if (Move_Analyzed == 0)
  6279. {
  6280. NodeLevel_0_count++;
  6281. Temp_Score_Move_0 = CountScore(Skakiera_Thinking_HY_2, humanDangerParameter);
  6282. }
  6283. if (Move_Analyzed == 2)
  6284. {
  6285. NodeLevel_2_count++;
  6286. Temp_Score_Move_2 = CountScore(Skakiera_Thinking_HY_2, humanDangerParameter);
  6287. }
  6288. if (Move_Analyzed == 4)
  6289. {
  6290. NodeLevel_4_count++;
  6291. Temp_Score_Move_4 = CountScore(Skakiera_Thinking_HY_2, humanDangerParameter);
  6292. }
  6293. if (Move_Analyzed == 6)
  6294. {
  6295. NodeLevel_6_count++;
  6296. Temp_Score_Move_6 = CountScore(Skakiera_Thinking_HY_2, humanDangerParameter);
  6297. }
  6298.  
  6299. if (Move_Analyzed < Thinking_Depth)
  6300. {
  6301. Move_Analyzed = Move_Analyzed + 1;
  6302.  
  6303. for (i = 0; i <= 7; i++)
  6304. {
  6305. for (j = 0; j <= 7; j++)
  6306. {
  6307. Skakiera_Move_After[(i), (j)] = Skakiera_Thinking[(i), (j)];
  6308. }
  6309. }
  6310.  
  6311. Who_Is_Analyzed = "Human";
  6312. First_Call_Human_Thought = true;
  6313.  
  6314. // Check human move
  6315. if (Move_Analyzed == 1)
  6316. Analyze_Move_1_HumanMove(Skakiera_Move_After);
  6317. else if (Move_Analyzed == 3)
  6318. Analyze_Move_3_HumanMove(Skakiera_Move_After);
  6319. else if (Move_Analyzed == 5)
  6320. Analyze_Move_5_HumanMove(Skakiera_Move_After);
  6321. }
  6322.  
  6323.  
  6324. if (Move_Analyzed == Thinking_Depth)
  6325. {
  6326. // [MiniMax algorithm - skakos]
  6327. // Record the node in the Nodes Analysis array (to use with MiniMax algorithm) skakos
  6328.  
  6329. NodesAnalysis[NodeLevel_0_count, 0, 0] = Temp_Score_Move_0;
  6330. NodesAnalysis[NodeLevel_1_count, 1, 0] = Temp_Score_Move_1_human;
  6331. NodesAnalysis[NodeLevel_2_count, 2, 0] = Temp_Score_Move_2;
  6332. NodesAnalysis[NodeLevel_3_count, 3, 0] = Temp_Score_Move_3_human;
  6333. NodesAnalysis[NodeLevel_4_count, 4, 0] = Temp_Score_Move_4;
  6334. NodesAnalysis[NodeLevel_5_count, 5, 0] = Temp_Score_Move_5_human;
  6335. NodesAnalysis[NodeLevel_6_count, 6, 0] = Temp_Score_Move_6;
  6336.  
  6337. // Store the parents (number of the node of the upper level)
  6338. NodesAnalysis[NodeLevel_0_count, 0, 1] = 0;
  6339. NodesAnalysis[NodeLevel_1_count, 1, 1] = NodeLevel_0_count;
  6340. NodesAnalysis[NodeLevel_2_count, 2, 1] = NodeLevel_1_count;
  6341. NodesAnalysis[NodeLevel_3_count, 3, 1] = NodeLevel_2_count;
  6342. NodesAnalysis[NodeLevel_4_count, 4, 1] = NodeLevel_3_count;
  6343. NodesAnalysis[NodeLevel_5_count, 5, 1] = NodeLevel_4_count;
  6344. NodesAnalysis[NodeLevel_6_count, 6, 1] = NodeLevel_5_count;
  6345.  
  6346. if (Danger_penalty == true)
  6347. {
  6348. //NodesAnalysis[NodeLevel_0_count, 0, 0] = NodesAnalysis[NodeLevel_0_count, 0, 0] - 2000000000;
  6349. //NodesAnalysis[NodeLevel_1_count, 1, 0] = NodesAnalysis[NodeLevel_1_count, 1, 0] + 2000000000;
  6350. }
  6351.  
  6352. if (go_for_it == true)
  6353. {
  6354. //NodesAnalysis[NodeLevel_0_count, 0, 0] = NodesAnalysis[NodeLevel_0_count, 0, 0] + 2000000000;
  6355. //NodesAnalysis[NodeLevel_1_count, 1, 0] = NodesAnalysis[NodeLevel_1_count, 1, 0] - 2000000000;
  6356. }
  6357.  
  6358. Nodes_Total_count++;
  6359.  
  6360. // Safety valve in case we reach the end of the table capacity
  6361. // This is a limit for the memory. Will have to do something about it!
  6362. if (Nodes_Total_count > 1000000)
  6363. {
  6364. Console.WriteLine("Limit of memory in NodesAnalysis array reached!");
  6365. Nodes_Total_count = 1000000;
  6366. }
  6367. }
  6368.  
  6369. // Undo the move
  6370. Skakiera_Thinking_HY_2[(m_StartingColumnNumber2 - 1), (m_StartingRank2 - 1)] = MovingPiece2;
  6371. Skakiera_Thinking_HY_2[(m_FinishingColumnNumber2 - 1), (m_FinishingRank2 - 1)] = ProsorinoKommati2;
  6372. }
  6373.  
  6374. }
  6375. }
  6376.  
  6377. }
  6378.  
  6379.  
  6380. }
  6381. }
  6382.  
  6383. Move_Analyzed = Move_Analyzed - 1;
  6384. Who_Is_Analyzed = "Human";
  6385. }
  6386.  
  6387. public static void Analyze_Move_4_ComputerMove(string[,] Skakiera_Thinking_HY_4)
  6388. {
  6389. //huo_sw1.WriteLine("");
  6390. //huo_sw1.WriteLine("CMT4 -- Entered ComputerMove_template 4");
  6391. //huo_sw1.WriteLine(string.Concat("CMT4 -- Depth analyzed: ", Move_Analyzed.ToString()));
  6392. //huo_sw1.WriteLine(string.Concat("CMT4 -- Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  6393. //huo_sw1.WriteLine(string.Concat("CMT4 -- Move analyzed: ", m_StartingColumnNumber_HY.ToString(), m_StartingRank_HY.ToString(), " -> ", m_FinishingColumnNumber_HY.ToString(), m_FinishingRank_HY.ToString()));
  6394. //huo_sw1.WriteLine(string.Concat("CMT4 -- Number of Nodes 0: ", NodeLevel_0_count.ToString()));
  6395. //huo_sw1.WriteLine(string.Concat("CMT4 -- Number of Nodes 1: ", NodeLevel_1_count.ToString()));
  6396. //huo_sw1.WriteLine(string.Concat("CMT4 -- Number of Nodes 2: ", NodeLevel_2_count.ToString()));
  6397. //huo_sw1.WriteLine(string.Concat("CMT4 -- Number of Nodes 3: ", NodeLevel_3_count.ToString()));
  6398. //huo_sw1.WriteLine(string.Concat("CMT4 -- Number of Nodes 4: ", NodeLevel_4_count.ToString()));
  6399. //huo_sw1.WriteLine(string.Concat("CMT4 -- Number of Nodes 5: ", NodeLevel_5_count.ToString()));
  6400. //huo_sw1.WriteLine(string.Concat("CMT4 -- Number of Nodes 6: ", NodeLevel_6_count.ToString()));
  6401. //huo_sw1.WriteLine("");
  6402.  
  6403. // Δήλωση μεταβλητών που χρησιμοποιούνται στο βρόγχο "for"
  6404. // (δεν μπορεί να χρησιμοποιηθούν οι μεταβλητές i και j διότι αυτές οι
  6405. // μεταβλητές είναι καθολικές και δημιουργείται πρόβλημα κατά την
  6406. // επιστροφή στην ComputerMove από την CheckMove
  6407.  
  6408. int iii4;
  6409. int jjj4;
  6410. String MovingPiece4;
  6411. String ProsorinoKommati4;
  6412. int m_StartingColumnNumber4;
  6413. int m_FinishingColumnNumber4;
  6414. int m_StartingRank4;
  6415. int m_FinishingRank4;
  6416.  
  6417. // Σκανάρισμα της σκακιέρας: Όταν εντοπίζεται κάποιο κομμάτι του υπολογιστή,
  6418. // θα υπολογίζονται ΟΛΕΣ οι πιθανές κινήσεις του προς κάθε κατεύθυνση, ακόμα
  6419. // και αυτές που δεν μπορεί να κάνει το κομμάτι. Στη συνέχεια, με τη βοήθεια
  6420. // των συναρτήσεων ElegxosNomimotitas και ElegxosOrthotitas θα ελέγχεται το
  6421. // αν η κίνηση είναι ορθή και νόμιμη. Αν είναι, η εν λόγω κίνηση θα γίνεται
  6422. // προσωρινά στη σκακιέρα και θα καταγράφεται το σκορ της νέας θέσης που
  6423. // προέκυψε
  6424.  
  6425. // ΣΗΜΕΙΩΣΗ: Σε όλες τις στήλες και τις οριζόντιους προστίθεται η μονάδα (+1)
  6426. // διότι πρέπει να μετατραπούν από το "σύστημα" μέτρησης "0-7" (που χρησιμο-
  6427. // ποιείται στο παρακάτω "for i…next" αλλά και στο συμβολισμό του πίνακα
  6428. // Skakiera) στο σύστημα μέτρησης "1-8" το οποίο χρησιμοποιείται στις
  6429. // μεταβλητές Starting/Finishing_Column/Rank σε όλο το υπόλοιπο πρόγραμμα.
  6430.  
  6431. for (iii4 = 0; iii4 <= 7; iii4++)
  6432. {
  6433. for (jjj4 = 0; jjj4 <= 7; jjj4++)
  6434. {
  6435.  
  6436. if (((Who_Is_Analyzed.CompareTo("HY") == 0) && ((((Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("White King") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("White Queen") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("White Rook") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("White Knight") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("White Bishop") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)) || (((Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("Black King") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("Black Queen") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("Black Rook") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("Black Knight") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("Black Bishop") == 0) || (Skakiera_Thinking_HY_4[(iii4), (jjj4)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)))))
  6437. {
  6438.  
  6439.  
  6440. for (int w = 0; w <= 7; w++)
  6441. {
  6442. for (int r = 0; r <= 7; r++)
  6443. {
  6444. MovingPiece = Skakiera_Thinking_HY_4[(iii4), (jjj4)];
  6445. m_StartingColumnNumber = iii4 + 1;
  6446. m_FinishingColumnNumber = w + 1;
  6447. m_StartingRank = jjj4 + 1;
  6448. m_FinishingRank = r + 1;
  6449.  
  6450. // Store temporary move data in local variables, so as to use them in the Undo of the move
  6451. // at the end of this function (the MovingPiece, m_StartingColumnNumber, etc variables are
  6452. // changed by next functions as well, so using them leads to problems)
  6453. MovingPiece4 = MovingPiece;
  6454. m_StartingColumnNumber4 = m_StartingColumnNumber;
  6455. m_FinishingColumnNumber4 = m_FinishingColumnNumber;
  6456. m_StartingRank4 = m_StartingRank;
  6457. m_FinishingRank4 = m_FinishingRank;
  6458. ProsorinoKommati4 = Skakiera_Thinking_HY_4[(m_FinishingColumnNumber4 - 1), (m_FinishingRank4 - 1)];
  6459.  
  6460. // Έλεγχος της κίνησης
  6461. // Validity and legality of the move has been checked in CheckMove
  6462. CheckMove(Skakiera_Thinking_HY_4);
  6463.  
  6464. number_of_moves_analysed++;
  6465.  
  6466. // If all ok, then do the move and measure it
  6467. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  6468. {
  6469. // huo_sw1.WriteLine(string.Concat("Human move 1: Found a legal move!"));
  6470.  
  6471. // Do the move
  6472. ProsorinoKommati = Skakiera_Thinking_HY_4[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  6473. Skakiera_Thinking_HY_4[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  6474. Skakiera_Thinking_HY_4[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  6475.  
  6476. // Check the score after the computer move.
  6477. if (Move_Analyzed == 0)
  6478. {
  6479. NodeLevel_0_count++;
  6480. Temp_Score_Move_0 = CountScore(Skakiera_Thinking_HY_4, humanDangerParameter);
  6481. }
  6482. if (Move_Analyzed == 2)
  6483. {
  6484. NodeLevel_2_count++;
  6485. Temp_Score_Move_2 = CountScore(Skakiera_Thinking_HY_4, humanDangerParameter);
  6486. }
  6487. if (Move_Analyzed == 4)
  6488. {
  6489. NodeLevel_4_count++;
  6490. Temp_Score_Move_4 = CountScore(Skakiera_Thinking_HY_4, humanDangerParameter);
  6491. }
  6492. if (Move_Analyzed == 6)
  6493. {
  6494. NodeLevel_6_count++;
  6495. Temp_Score_Move_6 = CountScore(Skakiera_Thinking_HY_4, humanDangerParameter);
  6496. }
  6497.  
  6498. // Change 2014-08 - Start
  6499. if (Move_Analyzed < Thinking_Depth)
  6500. // Change 2014-08 - End
  6501. {
  6502. Move_Analyzed = Move_Analyzed + 1;
  6503.  
  6504. for (i = 0; i <= 7; i++)
  6505. {
  6506. for (j = 0; j <= 7; j++)
  6507. {
  6508. Skakiera_Move_After[(i), (j)] = Skakiera_Thinking[(i), (j)];
  6509. }
  6510. }
  6511.  
  6512. Who_Is_Analyzed = "Human";
  6513. First_Call_Human_Thought = true;
  6514.  
  6515. // Check human move (to find the best possible answer of the human
  6516. // to the move currently analyzed by the HY Thought process)
  6517. if (Move_Analyzed == 1)
  6518. Analyze_Move_1_HumanMove(Skakiera_Move_After);
  6519. else if (Move_Analyzed == 3)
  6520. Analyze_Move_3_HumanMove(Skakiera_Move_After);
  6521. else if (Move_Analyzed == 5)
  6522. Analyze_Move_5_HumanMove(Skakiera_Move_After);
  6523. }
  6524.  
  6525. if (Move_Analyzed == Thinking_Depth)
  6526. {
  6527. // [MiniMax algorithm - skakos]
  6528. // Record the node in the Nodes Analysis array (to use with MiniMax algorithm) skakos
  6529. NodesAnalysis[NodeLevel_0_count, 0, 0] = Temp_Score_Move_0;
  6530. NodesAnalysis[NodeLevel_1_count, 1, 0] = Temp_Score_Move_1_human;
  6531. NodesAnalysis[NodeLevel_2_count, 2, 0] = Temp_Score_Move_2;
  6532. NodesAnalysis[NodeLevel_3_count, 3, 0] = Temp_Score_Move_3_human;
  6533. NodesAnalysis[NodeLevel_4_count, 4, 0] = Temp_Score_Move_4;
  6534. NodesAnalysis[NodeLevel_5_count, 5, 0] = Temp_Score_Move_5_human;
  6535. NodesAnalysis[NodeLevel_6_count, 6, 0] = Temp_Score_Move_6;
  6536.  
  6537. // Store the parents (number of the node of the upper level)
  6538. NodesAnalysis[NodeLevel_0_count, 0, 1] = 0;
  6539. NodesAnalysis[NodeLevel_1_count, 1, 1] = NodeLevel_0_count;
  6540. NodesAnalysis[NodeLevel_2_count, 2, 1] = NodeLevel_1_count;
  6541. NodesAnalysis[NodeLevel_3_count, 3, 1] = NodeLevel_2_count;
  6542. NodesAnalysis[NodeLevel_4_count, 4, 1] = NodeLevel_3_count;
  6543. NodesAnalysis[NodeLevel_5_count, 5, 1] = NodeLevel_4_count;
  6544. NodesAnalysis[NodeLevel_6_count, 6, 1] = NodeLevel_5_count;
  6545.  
  6546. if (Danger_penalty == true)
  6547. {
  6548. //NodesAnalysis[NodeLevel_0_count, 0, 0] = NodesAnalysis[NodeLevel_0_count, 0, 0] - 2000000000;
  6549. //NodesAnalysis[NodeLevel_1_count, 1, 0] = NodesAnalysis[NodeLevel_1_count, 1, 0] + 2000000000;
  6550. }
  6551.  
  6552. if (go_for_it == true)
  6553. {
  6554. //NodesAnalysis[NodeLevel_0_count, 0, 0] = NodesAnalysis[NodeLevel_0_count, 0, 0] + 2000000000;
  6555. //NodesAnalysis[NodeLevel_1_count, 1, 0] = NodesAnalysis[NodeLevel_1_count, 1, 0] - 2000000000;
  6556. }
  6557.  
  6558. Nodes_Total_count++;
  6559.  
  6560. // Safety valve in case we reach the end of the table capacity
  6561. // This is a limit for the memory. Will have to do something about it!
  6562. if (Nodes_Total_count > 1000000)
  6563. {
  6564. Console.WriteLine("Limit of memory in NodesAnalysis array reached!");
  6565. Nodes_Total_count = 1000000;
  6566. }
  6567. }
  6568.  
  6569. // Undo the move
  6570. Skakiera_Thinking_HY_4[(m_StartingColumnNumber4 - 1), (m_StartingRank4 - 1)] = MovingPiece4;
  6571. Skakiera_Thinking_HY_4[(m_FinishingColumnNumber4 - 1), (m_FinishingRank4 - 1)] = ProsorinoKommati4;
  6572. }
  6573.  
  6574. }
  6575. }
  6576.  
  6577. }
  6578.  
  6579.  
  6580. }
  6581. }
  6582.  
  6583. Move_Analyzed = Move_Analyzed - 1;
  6584. Who_Is_Analyzed = "Human";
  6585. }
  6586.  
  6587. public static void Analyze_Move_6_ComputerMove(string[,] Skakiera_Thinking_HY_6)
  6588. {
  6589. //huo_sw1.WriteLine("");
  6590. //huo_sw1.WriteLine("CMT6 -- Entered ComputerMove_template 6");
  6591. //huo_sw1.WriteLine(string.Concat("CMT6 -- Depth analyzed: ", Move_Analyzed.ToString()));
  6592. //huo_sw1.WriteLine(string.Concat("CMT6 -- Number of moves analyzed: ", number_of_moves_analysed.ToString()));
  6593. //huo_sw1.WriteLine(string.Concat("CMT6 -- Move analyzed: ", m_StartingColumnNumber_HY.ToString(), m_StartingRank_HY.ToString(), " -> ", m_FinishingColumnNumber_HY.ToString(), m_FinishingRank_HY.ToString()));
  6594. //huo_sw1.WriteLine(string.Concat("CMT6 -- Number of Nodes 0: ", NodeLevel_0_count.ToString()));
  6595. //huo_sw1.WriteLine(string.Concat("CMT6 -- Number of Nodes 1: ", NodeLevel_1_count.ToString()));
  6596. //huo_sw1.WriteLine(string.Concat("CMT6 -- Number of Nodes 2: ", NodeLevel_2_count.ToString()));
  6597. //huo_sw1.WriteLine(string.Concat("CMT6 -- Number of Nodes 3: ", NodeLevel_3_count.ToString()));
  6598. //huo_sw1.WriteLine(string.Concat("CMT6 -- Number of Nodes 4: ", NodeLevel_4_count.ToString()));
  6599. //huo_sw1.WriteLine(string.Concat("CMT6 -- Number of Nodes 5: ", NodeLevel_5_count.ToString()));
  6600. //huo_sw1.WriteLine(string.Concat("CMT6 -- Number of Nodes 6: ", NodeLevel_6_count.ToString()));
  6601. //huo_sw1.WriteLine("");
  6602.  
  6603. // Δήλωση μεταβλητών που χρησιμοποιούνται στο βρόγχο "for"
  6604. // (δεν μπορεί να χρησιμοποιηθούν οι μεταβλητές i και j διότι αυτές οι
  6605. // μεταβλητές είναι καθολικές και δημιουργείται πρόβλημα κατά την
  6606. // επιστροφή στην ComputerMove από την CheckMove
  6607.  
  6608. int iii6;
  6609. int jjj6;
  6610. String MovingPiece6;
  6611. String ProsorinoKommati6;
  6612. int m_StartingColumnNumber6;
  6613. int m_FinishingColumnNumber6;
  6614. int m_StartingRank6;
  6615. int m_FinishingRank6;
  6616.  
  6617. // Σκανάρισμα της σκακιέρας: Όταν εντοπίζεται κάποιο κομμάτι του υπολογιστή,
  6618. // θα υπολογίζονται ΟΛΕΣ οι πιθανές κινήσεις του προς κάθε κατεύθυνση, ακόμα
  6619. // και αυτές που δεν μπορεί να κάνει το κομμάτι. Στη συνέχεια, με τη βοήθεια
  6620. // των συναρτήσεων ElegxosNomimotitas και ElegxosOrthotitas θα ελέγχεται το
  6621. // αν η κίνηση είναι ορθή και νόμιμη. Αν είναι, η εν λόγω κίνηση θα γίνεται
  6622. // προσωρινά στη σκακιέρα και θα καταγράφεται το σκορ της νέας θέσης που
  6623. // προέκυψε
  6624.  
  6625. // ΣΗΜΕΙΩΣΗ: Σε όλες τις στήλες και τις οριζόντιους προστίθεται η μονάδα (+1)
  6626. // διότι πρέπει να μετατραπούν από το "σύστημα" μέτρησης "0-7" (που χρησιμο-
  6627. // ποιείται στο παρακάτω "for i…next" αλλά και στο συμβολισμό του πίνακα
  6628. // Skakiera) στο σύστημα μέτρησης "1-8" το οποίο χρησιμοποιείται στις
  6629. // μεταβλητές Starting/Finishing_Column/Rank σε όλο το υπόλοιπο πρόγραμμα.
  6630.  
  6631. for (iii6 = 0; iii6 <= 7; iii6++)
  6632. {
  6633. for (jjj6 = 0; jjj6 <= 7; jjj6++)
  6634. {
  6635.  
  6636. if (((Who_Is_Analyzed.CompareTo("HY") == 0) && ((((Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("White King") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("White Queen") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("White Rook") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("White Knight") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("White Bishop") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)) || (((Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("Black King") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("Black Queen") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("Black Rook") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("Black Knight") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("Black Bishop") == 0) || (Skakiera_Thinking_HY_6[(iii6), (jjj6)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)))))
  6637. {
  6638.  
  6639.  
  6640. for (int w = 0; w <= 7; w++)
  6641. {
  6642. for (int r = 0; r <= 7; r++)
  6643. {
  6644. MovingPiece = Skakiera_Thinking_HY_6[(iii6), (jjj6)];
  6645. m_StartingColumnNumber = iii6 + 1;
  6646. m_FinishingColumnNumber = w + 1;
  6647. m_StartingRank = jjj6 + 1;
  6648. m_FinishingRank = r + 1;
  6649.  
  6650. // Store temporary move data in local variables, so as to use them in the Undo of the move
  6651. // at the end of this function (the MovingPiece, m_StartingColumnNumber, etc variables are
  6652. // changed by next functions as well, so using them leads to problems)
  6653. MovingPiece6 = MovingPiece;
  6654. m_StartingColumnNumber6 = m_StartingColumnNumber;
  6655. m_FinishingColumnNumber6 = m_FinishingColumnNumber;
  6656. m_StartingRank6 = m_StartingRank;
  6657. m_FinishingRank6 = m_FinishingRank;
  6658. ProsorinoKommati6 = Skakiera_Thinking_HY_6[(m_FinishingColumnNumber6 - 1), (m_FinishingRank6 - 1)];
  6659.  
  6660. // Έλεγχος της κίνησης
  6661. // Validity and legality of the move has been checked in CheckMove
  6662. CheckMove(Skakiera_Thinking_HY_6);
  6663.  
  6664. number_of_moves_analysed++;
  6665.  
  6666. // If all ok, then do the move and measure it
  6667. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  6668. {
  6669. // huo_sw1.WriteLine(string.Concat("Human move 1: Found a legal move!"));
  6670.  
  6671. // Do the move
  6672. ProsorinoKommati = Skakiera_Thinking_HY_6[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)];
  6673. Skakiera_Thinking_HY_6[(m_StartingColumnNumber - 1), (m_StartingRank - 1)] = "";
  6674. Skakiera_Thinking_HY_6[(m_FinishingColumnNumber - 1), (m_FinishingRank - 1)] = MovingPiece;
  6675.  
  6676. // Check the score after the computer move.
  6677. if (Move_Analyzed == 0)
  6678. {
  6679. NodeLevel_0_count++;
  6680. Temp_Score_Move_0 = CountScore(Skakiera_Thinking_HY_6, humanDangerParameter);
  6681. }
  6682. if (Move_Analyzed == 2)
  6683. {
  6684. NodeLevel_2_count++;
  6685. Temp_Score_Move_2 = CountScore(Skakiera_Thinking_HY_6, humanDangerParameter);
  6686. }
  6687. if (Move_Analyzed == 4)
  6688. {
  6689. NodeLevel_4_count++;
  6690. Temp_Score_Move_4 = CountScore(Skakiera_Thinking_HY_6, humanDangerParameter);
  6691. }
  6692. if (Move_Analyzed == 6)
  6693. {
  6694. NodeLevel_6_count++;
  6695. Temp_Score_Move_6 = CountScore(Skakiera_Thinking_HY_6, humanDangerParameter);
  6696. }
  6697.  
  6698. if (Move_Analyzed < Thinking_Depth)
  6699. {
  6700. Move_Analyzed = Move_Analyzed + 1;
  6701.  
  6702. for (i = 0; i <= 7; i++)
  6703. {
  6704. for (j = 0; j <= 7; j++)
  6705. {
  6706. Skakiera_Move_After[(i), (j)] = Skakiera_Thinking[(i), (j)];
  6707. }
  6708. }
  6709.  
  6710. Who_Is_Analyzed = "Human";
  6711. First_Call_Human_Thought = true;
  6712.  
  6713. // Check human move
  6714. if (Move_Analyzed == 1)
  6715. Analyze_Move_1_HumanMove(Skakiera_Move_After);
  6716. else if (Move_Analyzed == 3)
  6717. Analyze_Move_3_HumanMove(Skakiera_Move_After);
  6718. else if (Move_Analyzed == 5)
  6719. Analyze_Move_5_HumanMove(Skakiera_Move_After);
  6720. }
  6721.  
  6722. if (Move_Analyzed == Thinking_Depth)
  6723. {
  6724. // [MiniMax algorithm - skakos]
  6725. // Record the node in the Nodes Analysis array (to use with MiniMax algorithm) skakos
  6726. NodesAnalysis[NodeLevel_0_count, 0, 0] = Temp_Score_Move_0;
  6727. NodesAnalysis[NodeLevel_1_count, 1, 0] = Temp_Score_Move_1_human;
  6728. NodesAnalysis[NodeLevel_2_count, 2, 0] = Temp_Score_Move_2;
  6729. NodesAnalysis[NodeLevel_3_count, 3, 0] = Temp_Score_Move_3_human;
  6730. NodesAnalysis[NodeLevel_4_count, 4, 0] = Temp_Score_Move_4;
  6731. NodesAnalysis[NodeLevel_5_count, 5, 0] = Temp_Score_Move_5_human;
  6732. NodesAnalysis[NodeLevel_6_count, 6, 0] = Temp_Score_Move_6;
  6733.  
  6734. // Store the parents (number of the node of the upper level)
  6735. NodesAnalysis[NodeLevel_0_count, 0, 1] = 0;
  6736. NodesAnalysis[NodeLevel_1_count, 1, 1] = NodeLevel_0_count;
  6737. NodesAnalysis[NodeLevel_2_count, 2, 1] = NodeLevel_1_count;
  6738. NodesAnalysis[NodeLevel_3_count, 3, 1] = NodeLevel_2_count;
  6739. NodesAnalysis[NodeLevel_4_count, 4, 1] = NodeLevel_3_count;
  6740. NodesAnalysis[NodeLevel_5_count, 5, 1] = NodeLevel_4_count;
  6741. NodesAnalysis[NodeLevel_6_count, 6, 1] = NodeLevel_5_count;
  6742.  
  6743. if (Danger_penalty == true)
  6744. {
  6745. //NodesAnalysis[NodeLevel_0_count, 0, 0] = NodesAnalysis[NodeLevel_0_count, 0, 0] - 2000000000;
  6746. //NodesAnalysis[NodeLevel_1_count, 1, 0] = NodesAnalysis[NodeLevel_1_count, 1, 0] + 2000000000;
  6747. }
  6748.  
  6749. if (go_for_it == true)
  6750. {
  6751. //NodesAnalysis[NodeLevel_0_count, 0, 0] = NodesAnalysis[NodeLevel_0_count, 0, 0] + 2000000000;
  6752. //NodesAnalysis[NodeLevel_1_count, 1, 0] = NodesAnalysis[NodeLevel_1_count, 1, 0] - 2000000000;
  6753. }
  6754.  
  6755. Nodes_Total_count++;
  6756.  
  6757. // Safety valve in case we reach the end of the table capacity
  6758. // This is a limit for the memory. Will have to do something about it!
  6759. if (Nodes_Total_count > 1000000)
  6760. {
  6761. Console.WriteLine("Limit of memory in NodesAnalysis array reached!");
  6762. Nodes_Total_count = 1000000;
  6763. }
  6764. }
  6765.  
  6766. // Undo the move
  6767. Skakiera_Thinking_HY_6[(m_StartingColumnNumber6 - 1), (m_StartingRank6 - 1)] = MovingPiece6;
  6768. Skakiera_Thinking_HY_6[(m_FinishingColumnNumber6 - 1), (m_FinishingRank6 - 1)] = ProsorinoKommati6;
  6769. }
  6770.  
  6771. }
  6772. }
  6773.  
  6774. }
  6775.  
  6776.  
  6777. }
  6778. }
  6779.  
  6780. Move_Analyzed = Move_Analyzed - 1;
  6781. Who_Is_Analyzed = "Human";
  6782. }
  6783.  
  6784. public static void FindAttackers(string[,] SkakieraAttackers)
  6785. {
  6786. String MovingPiece_Attack;
  6787. int m_StartingRank_Attack;
  6788. int m_StartingColumnNumber_Attack;
  6789. int m_FinishingRank_Attack;
  6790. int m_FinishingColumnNumber_Attack;
  6791.  
  6792. // Scan the chessboard . if a piece of HY is found . check all
  6793. // possible destinations in the chessboard . check correctness of
  6794. // the move analyzed . check legality of the move analyzed . if
  6795. // correct and legal, then do the move.
  6796. // NOTE: In all column and rank numbers I add +1, because I must transform
  6797. // them from the 0...7 'measure system' of the chessboard (='Skakiera' in Greek) table
  6798. // to the 1...8 'measure system' of the chessboard.
  6799.  
  6800. for (int iii2 = 0; iii2 <= 7; iii2++)
  6801. {
  6802. for (int jjj2 = 0; jjj2 <= 7; jjj2++)
  6803. {
  6804. if ((((SkakieraAttackers[(iii2), (jjj2)].CompareTo("White King") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("White Queen") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("White Rook") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("White Knight") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("White Bishop") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)) || (((SkakieraAttackers[(iii2), (jjj2)].CompareTo("Black King") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("Black Queen") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("Black Rook") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("Black Knight") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("Black Bishop") == 0) || (SkakieraAttackers[(iii2), (jjj2)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)))
  6805. {
  6806.  
  6807. MovingPiece_Attack = SkakieraAttackers[(iii2), (jjj2)];
  6808. m_StartingColumnNumber_Attack = iii2 + 1;
  6809. m_StartingRank_Attack = jjj2 + 1;
  6810.  
  6811. // find squares where the human opponent can hit
  6812. for (int w2 = 0; w2 <= 7; w2++)
  6813. {
  6814. for (int r2 = 0; r2 <= 7; r2++)
  6815. {
  6816. m_FinishingColumnNumber_Attack = w2 + 1;
  6817. m_FinishingRank_Attack = r2 + 1;
  6818.  
  6819. // check the move
  6820. m_WhoPlays = "Human";
  6821. m_WrongColumn = false;
  6822. m_OrthotitaKinisis = ElegxosOrthotitas(Skakiera, 1, m_StartingRank_Attack, m_StartingColumnNumber_Attack, m_FinishingRank_Attack, m_FinishingColumnNumber_Attack, MovingPiece_Attack);
  6823. if (m_OrthotitaKinisis == true)
  6824. {
  6825. m_NomimotitaKinisis = ElegxosNomimotitas(Skakiera, 1, m_StartingRank_Attack, m_StartingColumnNumber_Attack, m_FinishingRank_Attack, m_FinishingColumnNumber_Attack, MovingPiece_Attack);
  6826. }
  6827. // restore normal value of m_whoplays
  6828. m_WhoPlays = "HY";
  6829. // 2012: If a pawn is moving, then take into account only moves of eating other pieces!
  6830. // and not moves of moving forward
  6831. if ((MovingPiece_Attack.CompareTo("White Pawn") == 0) || (MovingPiece_Attack.CompareTo("Black Pawn") == 0))
  6832. {
  6833. if (m_FinishingColumnNumber_Attack == m_StartingColumnNumber_Attack)
  6834. {
  6835. m_OrthotitaKinisis = false;
  6836. }
  6837. }
  6838.  
  6839. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  6840. {
  6841. // Another attacker on that square found!
  6842. Number_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Number_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 1;
  6843. // v0.96
  6844. //Skakiera_Dangerous_Squares[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = "Danger";
  6845.  
  6846. //2012 new
  6847. Attackers_coordinates_column[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = m_StartingColumnNumber_Attack - 1;
  6848. Attackers_coordinates_rank[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = m_StartingRank_Attack - 1;
  6849.  
  6850. // Calculate the value (total value) of the attackers
  6851. //MessageBox.Show(string.Concat("Added something to the value of attackers: ", MovingPiece_Attack.ToString()));
  6852.  
  6853. if ((MovingPiece_Attack.CompareTo("White Rook") == 0) || (MovingPiece_Attack.CompareTo("Black Rook") == 0))
  6854. Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 5;
  6855. else if ((MovingPiece_Attack.CompareTo("White Bishop") == 0) || (MovingPiece_Attack.CompareTo("Black Bishop") == 0))
  6856. Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 3;
  6857. else if ((MovingPiece_Attack.CompareTo("White Knight") == 0) || (MovingPiece_Attack.CompareTo("Black Knight") == 0))
  6858. Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 3;
  6859. else if ((MovingPiece_Attack.CompareTo("White Queen") == 0) || (MovingPiece_Attack.CompareTo("Black Queen") == 0))
  6860. Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 9;
  6861. else if ((MovingPiece_Attack.CompareTo("White Pawn") == 0) || (MovingPiece_Attack.CompareTo("Black Pawn") == 0))
  6862. Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 1;
  6863. //v0.95
  6864. //else if ((MovingPiece_Attack.CompareTo("White King") == 0) || (MovingPiece_Attack.CompareTo("Black King") == 0))
  6865. // Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_attackers[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 15;
  6866. }
  6867. }
  6868. }
  6869. }
  6870. }
  6871. }
  6872.  
  6873.  
  6874. }
  6875.  
  6876. public static void FindDefenders(string[,] SkakieraDefenders)
  6877. {
  6878. String MovingPiece_Attack;
  6879. int m_StartingRank_Attack;
  6880. int m_StartingColumnNumber_Attack;
  6881. int m_FinishingRank_Attack;
  6882. int m_FinishingColumnNumber_Attack;
  6883.  
  6884. // Find squares that are also 'protected' by a piece of the HY.
  6885. // If protected, then the square is not really dangerous
  6886.  
  6887. // Changed in version 0.5
  6888. // Initialize all variables used to find exceptions in the non-dangerous squares.
  6889. // Exceptions definition: If human can hit a square and the computer defends it with its pieces, then the
  6890. // square is not dangerous. However, if the computer has only one (1) piece to defend that square, then
  6891. // it cannot move that specific piece to that square (because then the square would have no defenders and
  6892. // would become again a dangerous square!).
  6893.  
  6894. for (int iii3 = 0; iii3 <= 7; iii3++)
  6895. {
  6896. for (int jjj3 = 0; jjj3 <= 7; jjj3++)
  6897. {
  6898. if ((((SkakieraDefenders[(iii3), (jjj3)].CompareTo("White King") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("White Queen") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("White Rook") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("White Knight") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("White Bishop") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("White Pawn") == 0)) && (m_PlayerColor.CompareTo("Black") == 0)) || (((SkakieraDefenders[(iii3), (jjj3)].CompareTo("Black King") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("Black Queen") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("Black Rook") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("Black Knight") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("Black Bishop") == 0) || (SkakieraDefenders[(iii3), (jjj3)].CompareTo("Black Pawn") == 0)) && (m_PlayerColor.CompareTo("White") == 0)))
  6899. {
  6900. MovingPiece_Attack = SkakieraDefenders[(iii3), (jjj3)];
  6901. m_StartingColumnNumber_Attack = iii3 + 1;
  6902. m_StartingRank_Attack = jjj3 + 1;
  6903.  
  6904. for (int w1 = 0; w1 <= 7; w1++)
  6905. {
  6906. for (int r1 = 0; r1 <= 7; r1++)
  6907. {
  6908.  
  6909. m_FinishingColumnNumber_Attack = w1 + 1;
  6910. m_FinishingRank_Attack = r1 + 1;
  6911.  
  6912. // Έλεγχος της κίνησης
  6913. // Απόδοση τιμών στις μεταβλητές m_WhoPlays και m_WrongColumn, οι οποίες είναι απαραίτητες για να λειτουργήσει σωστά οι συναρτήσεις ElegxosNomimotitas και ElegxosOrthotitas
  6914. m_WhoPlays = "Human";
  6915. m_WrongColumn = false;
  6916. m_OrthotitaKinisis = ElegxosOrthotitas(SkakieraDefenders, 1, m_StartingRank_Attack, m_StartingColumnNumber_Attack, m_FinishingRank_Attack, m_FinishingColumnNumber_Attack, MovingPiece_Attack);
  6917. if (m_OrthotitaKinisis == true)
  6918. {
  6919. m_NomimotitaKinisis = ElegxosNomimotitas(SkakieraDefenders, 1, m_StartingRank_Attack, m_StartingColumnNumber_Attack, m_FinishingRank_Attack, m_FinishingColumnNumber_Attack, MovingPiece_Attack);
  6920. }
  6921. // Επαναφορά της κανονικής τιμής της m_WhoPlays
  6922. m_WhoPlays = "HY";
  6923.  
  6924. // NEW
  6925. // You can count for all moves that "defend" a square,
  6926. // except the move of a pawn forward! :)
  6927. if ((MovingPiece_Attack.CompareTo("White Pawn") == 0) || (MovingPiece_Attack.CompareTo("Black Pawn") == 0))
  6928. {
  6929. if (m_FinishingColumnNumber_Attack == m_StartingColumnNumber_Attack)
  6930. {
  6931. m_OrthotitaKinisis = false;
  6932. }
  6933. }
  6934.  
  6935. m_WhoPlays = "HY";
  6936. if ((m_OrthotitaKinisis == true) && (m_NomimotitaKinisis == true))
  6937. {
  6938. // A new defender for that square is found!
  6939. Number_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Number_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 1;
  6940.  
  6941. // Calculate the value (total value) of the defenders
  6942. //MessageBox.Show(string.Concat("Added something to the value of defenders for (", (m_FinishingColumnNumber_Attack).ToString(), ",", (m_FinishingRank_Attack).ToString(), "): ", MovingPiece_Attack.ToString()));
  6943.  
  6944. if ((MovingPiece_Attack.CompareTo("White Rook") == 0) || (MovingPiece_Attack.CompareTo("Black Rook") == 0))
  6945. Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 5;
  6946. else if ((MovingPiece_Attack.CompareTo("White Bishop") == 0) || (MovingPiece_Attack.CompareTo("Black Bishop") == 0))
  6947. Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 3;
  6948. else if ((MovingPiece_Attack.CompareTo("White Knight") == 0) || (MovingPiece_Attack.CompareTo("Black Knight") == 0))
  6949. Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 3;
  6950. else if ((MovingPiece_Attack.CompareTo("White Queen") == 0) || (MovingPiece_Attack.CompareTo("Black Queen") == 0))
  6951. Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 9;
  6952. else if ((MovingPiece_Attack.CompareTo("White Pawn") == 0) || (MovingPiece_Attack.CompareTo("Black Pawn") == 0))
  6953. Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 1;
  6954. else if ((MovingPiece_Attack.CompareTo("White King") == 0) || (MovingPiece_Attack.CompareTo("Black King") == 0))
  6955. Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = Value_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] + 15;
  6956.  
  6957. // Record the coordinates of the defender.
  6958. // If the defender found is the only one, then that defender cannot move to that square,
  6959. // since then the square would be again dangerous (since its only defender would have moved into it!)
  6960. // If more than one defenders is found, then no exceptions exist.
  6961. if (Number_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] == 1)
  6962. {
  6963. Exception_defender_column[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = (m_StartingColumnNumber_Attack - 1);
  6964. Exception_defender_rank[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = (m_StartingRank_Attack - 1);
  6965.  
  6966. // DEBUGGING
  6967. //if (((m_FinishingColumnNumber_Attack - 1) == 2) && ((m_FinishingRank_Attack - 1) == 4))
  6968. //{
  6969. // MessageBox.Show("hOU");
  6970. // MessageBox.Show(String.Concat("Move found: ", m_StartingColumnNumber_Attack.ToString(), m_StartingRank_Attack.ToString(), "->", m_FinishingColumnNumber_Attack.ToString(), m_FinishingRank_Attack.ToString()));
  6971. // MessageBox.Show(String.Concat("Exception column: ",Exception_defender_column[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)]));
  6972. // MessageBox.Show(String.Concat("Exception rank: ",Exception_defender_rank[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)]));
  6973. // MessageBox.Show(String.Concat("Exception column: ",(iii3).ToString()));
  6974. // MessageBox.Show(String.Concat("Exception rank: ",(jjj3).ToString() ));
  6975. //}
  6976. // PLAYING
  6977. }
  6978. if (Number_of_defenders[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] > 1)
  6979. {
  6980. Exception_defender_column[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = -99;
  6981. Exception_defender_rank[(m_FinishingColumnNumber_Attack - 1), (m_FinishingRank_Attack - 1)] = -99;
  6982. }
  6983.  
  6984. }
  6985. }
  6986. }
  6987. }
  6988. }
  6989. }
  6990. }
  6991.  
  6992. };
  6993.  
  6994.  
  6995.  
  6996. private void button_Play_Click(object sender, EventArgs e)
  6997. {
  6998. Form1.HuoChess_main.Starting_position();
  6999. RedrawTheSkakiera(Form1.HuoChess_main.Skakiera);
  7000.  
  7001. if (Form1.HuoChess_main.m_WhoPlays.CompareTo("HY") == 0)
  7002. {
  7003. label2.Text = "Thinking...";
  7004. label3.Text = "";
  7005. }
  7006.  
  7007. Form1.HuoChess_main.Main_Console();
  7008. RedrawTheSkakiera(Form1.HuoChess_main.Skakiera);
  7009. label2.Text = "I played! Now it is your turn!";
  7010. Application.DoEvents();
  7011. }
  7012.  
  7013. private void radioButton_White_Click(object sender, EventArgs e)
  7014. {
  7015. Form1.HuoChess_main.m_PlayerColor = "White";
  7016. Form1.HuoChess_main.m_WhoPlays = "Human";
  7017. }
  7018.  
  7019. private void radioButton_Black_Click(object sender, EventArgs e)
  7020. {
  7021. Form1.HuoChess_main.m_PlayerColor = "Black";
  7022. Form1.HuoChess_main.m_WhoPlays = "HY";
  7023. }
  7024.  
  7025. private void Form1_Click(object sender, EventArgs e)
  7026. {
  7027. // For test purposes
  7028. //HuoChess_main.m_StartingColumn = "D";
  7029. //HuoChess_main.m_StartingRank = 2;
  7030. //HuoChess_main.m_FinishingColumn = "D";
  7031. //HuoChess_main.m_FinishingRank = 4;
  7032. //playerClicks++;
  7033. //HuoChess_main.Enter_move();
  7034. //call_AI();
  7035. }
  7036.  
  7037. private void ManageGameSequence()
  7038. {
  7039. // If this is the first click, then it is the starting square
  7040. if (playerClicks == 0)
  7041. {
  7042. HuoChess_main.m_StartingColumn = columnClicked;
  7043. HuoChess_main.m_StartingRank = rankClicked;
  7044. playerClicks++;
  7045. }
  7046. // If this is the second click, then it is the finishing square
  7047. else if (playerClicks == 1)
  7048. {
  7049. HuoChess_main.m_FinishingColumn = columnClicked;
  7050. HuoChess_main.m_FinishingRank = rankClicked;
  7051. playerClicks++;
  7052. HuoChess_main.Enter_move();
  7053. call_AI();
  7054. }
  7055. }
  7056.  
  7057. private void call_AI()
  7058. {
  7059. playerClicks = 0;
  7060. RedrawTheSkakiera(Form1.HuoChess_main.Skakiera);
  7061. label2.Text = "Thinking...";
  7062. label3.Text = "";
  7063. Application.DoEvents();
  7064. HuoChess_main.ComputerMove(Form1.HuoChess_main.Skakiera);
  7065. RedrawTheSkakiera(Form1.HuoChess_main.Skakiera);
  7066. label2.Text = string.Concat("Huo Chess move: ", HuoChess_main.NextLine);
  7067. label3.Text = string.Concat("Final positions analyzed: ", HuoChess_main.FinalPositions);
  7068. }
  7069.  
  7070.  
  7071.  
  7072. private void pictureBoxD2_Click(object sender, EventArgs e)
  7073. {
  7074. rankClicked = 2;
  7075. columnClicked = "D";
  7076. ManageGameSequence();
  7077. }
  7078.  
  7079. private void pictureBoxD4_Click(object sender, EventArgs e)
  7080. {
  7081. rankClicked = 4;
  7082. columnClicked = "D";
  7083. ManageGameSequence();
  7084.  
  7085. //string path = Directory.GetCurrentDirectory();
  7086. //MessageBox.Show("before changing 21 from INSIDE");
  7087. //string whole_path = string.Concat(path, "\\Resources\\WKing.gif");
  7088. //pictureBox21.Load(whole_path);
  7089. //pictureBox21.Show();
  7090. //MessageBox.Show("is it drawn?");
  7091. //Application.DoEvents();
  7092. //pictureBox21.Show();
  7093. //Invalidate();
  7094. }
  7095.  
  7096. private void pictureBoxA1_Click(object sender, EventArgs e)
  7097. {
  7098. rankClicked = 1;
  7099. columnClicked = "A";
  7100. ManageGameSequence();
  7101. }
  7102.  
  7103. private void pictureBoxA2_Click(object sender, EventArgs e)
  7104. {
  7105. rankClicked = 2;
  7106. columnClicked = "A";
  7107. ManageGameSequence();
  7108. }
  7109.  
  7110. private void pictureBoxA3_Click(object sender, EventArgs e)
  7111. {
  7112. rankClicked = 3;
  7113. columnClicked = "A";
  7114. ManageGameSequence();
  7115. }
  7116.  
  7117. private void pictureBoxA4_Click(object sender, EventArgs e)
  7118. {
  7119. rankClicked = 4;
  7120. columnClicked = "A";
  7121. ManageGameSequence();
  7122. }
  7123.  
  7124. private void pictureBoxA5_Click(object sender, EventArgs e)
  7125. {
  7126. rankClicked = 5;
  7127. columnClicked = "A";
  7128. ManageGameSequence();
  7129. }
  7130.  
  7131. private void pictureBoxA6_Click(object sender, EventArgs e)
  7132. {
  7133. rankClicked = 6;
  7134. columnClicked = "A";
  7135. ManageGameSequence();
  7136. }
  7137.  
  7138. private void pictureBoxA7_Click(object sender, EventArgs e)
  7139. {
  7140. rankClicked = 7;
  7141. columnClicked = "A";
  7142. ManageGameSequence();
  7143. }
  7144.  
  7145. private void pictureBoxA8_Click(object sender, EventArgs e)
  7146. {
  7147. rankClicked = 8;
  7148. columnClicked = "A";
  7149. ManageGameSequence();
  7150. }
  7151.  
  7152. private void pictureBoxB1_Click(object sender, EventArgs e)
  7153. {
  7154. rankClicked = 1;
  7155. columnClicked = "B";
  7156. ManageGameSequence();
  7157. }
  7158.  
  7159. private void pictureBoxB2_Click(object sender, EventArgs e)
  7160. {
  7161. rankClicked = 2;
  7162. columnClicked = "B";
  7163. ManageGameSequence();
  7164. }
  7165.  
  7166. private void pictureBoxB3_Click(object sender, EventArgs e)
  7167. {
  7168. rankClicked = 3;
  7169. columnClicked = "B";
  7170. ManageGameSequence();
  7171. }
  7172.  
  7173. private void pictureBoxB4_Click(object sender, EventArgs e)
  7174. {
  7175. rankClicked = 4;
  7176. columnClicked = "B";
  7177. ManageGameSequence();
  7178. }
  7179.  
  7180. private void pictureBoxB5_Click(object sender, EventArgs e)
  7181. {
  7182. rankClicked = 5;
  7183. columnClicked = "B";
  7184. ManageGameSequence();
  7185. }
  7186.  
  7187. private void pictureBoxB6_Click(object sender, EventArgs e)
  7188. {
  7189. rankClicked = 6;
  7190. columnClicked = "B";
  7191. ManageGameSequence();
  7192. }
  7193.  
  7194. private void pictureBoxB7_Click(object sender, EventArgs e)
  7195. {
  7196. rankClicked = 7;
  7197. columnClicked = "B";
  7198. ManageGameSequence();
  7199. }
  7200.  
  7201. private void pictureBoxB8_Click(object sender, EventArgs e)
  7202. {
  7203. rankClicked = 8;
  7204. columnClicked = "B";
  7205. ManageGameSequence();
  7206. }
  7207.  
  7208. private void pictureBoxC1_Click(object sender, EventArgs e)
  7209. {
  7210. rankClicked = 1;
  7211. columnClicked = "C";
  7212. ManageGameSequence();
  7213. }
  7214.  
  7215. private void pictureBoxC2_Click(object sender, EventArgs e)
  7216. {
  7217. columnClicked = "C";
  7218. rankClicked = 2;
  7219. ManageGameSequence();
  7220. }
  7221.  
  7222. private void pictureBoxC3_Click(object sender, EventArgs e)
  7223. {
  7224. columnClicked = "C";
  7225. rankClicked = 3;
  7226. ManageGameSequence();
  7227. }
  7228.  
  7229. private void pictureBoxC4_Click(object sender, EventArgs e)
  7230. {
  7231. columnClicked = "C";
  7232. rankClicked = 4;
  7233. ManageGameSequence();
  7234. }
  7235.  
  7236. private void pictureBoxC5_Click(object sender, EventArgs e)
  7237. {
  7238. columnClicked = "C";
  7239. rankClicked = 5;
  7240. ManageGameSequence();
  7241. }
  7242.  
  7243. private void pictureBoxC6_Click(object sender, EventArgs e)
  7244. {
  7245. columnClicked = "C";
  7246. rankClicked = 6;
  7247. ManageGameSequence();
  7248. }
  7249.  
  7250. private void pictureBoxC7_Click(object sender, EventArgs e)
  7251. {
  7252. columnClicked = "C";
  7253. rankClicked = 7;
  7254. ManageGameSequence();
  7255. }
  7256.  
  7257. private void pictureBoxC8_Click(object sender, EventArgs e)
  7258. {
  7259. columnClicked = "C";
  7260. rankClicked = 8;
  7261. ManageGameSequence();
  7262. }
  7263.  
  7264. private void pictureBoxD1_Click(object sender, EventArgs e)
  7265. {
  7266. columnClicked = "D";
  7267. rankClicked = 1;
  7268. ManageGameSequence();
  7269. }
  7270.  
  7271. private void pictureBoxD3_Click(object sender, EventArgs e)
  7272. {
  7273. columnClicked = "D";
  7274. rankClicked = 3;
  7275. ManageGameSequence();
  7276. }
  7277.  
  7278. private void pictureBoxD5_Click(object sender, EventArgs e)
  7279. {
  7280. columnClicked = "D";
  7281. rankClicked = 5;
  7282. ManageGameSequence();
  7283. }
  7284.  
  7285. private void pictureBoxD6_Click(object sender, EventArgs e)
  7286. {
  7287. columnClicked = "D";
  7288. rankClicked = 6;
  7289. ManageGameSequence();
  7290. }
  7291.  
  7292. private void pictureBoxD7_Click(object sender, EventArgs e)
  7293. {
  7294. columnClicked = "D";
  7295. rankClicked = 7;
  7296. ManageGameSequence();
  7297. }
  7298.  
  7299. private void pictureBoxD8_Click(object sender, EventArgs e)
  7300. {
  7301. columnClicked = "D";
  7302. rankClicked = 8;
  7303. ManageGameSequence();
  7304. }
  7305.  
  7306. private void pictureBoxE1_Click(object sender, EventArgs e)
  7307. {
  7308. columnClicked = "E";
  7309. rankClicked = 1;
  7310. ManageGameSequence();
  7311. }
  7312.  
  7313. private void pictureBoxE2_Click(object sender, EventArgs e)
  7314. {
  7315. columnClicked = "E";
  7316. rankClicked = 2;
  7317. ManageGameSequence();
  7318. }
  7319.  
  7320. private void pictureBoxE3_Click(object sender, EventArgs e)
  7321. {
  7322. columnClicked = "E";
  7323. rankClicked = 3;
  7324. ManageGameSequence();
  7325. }
  7326.  
  7327. private void pictureBoxE4_Click(object sender, EventArgs e)
  7328. {
  7329. columnClicked = "E";
  7330. rankClicked = 4;
  7331. ManageGameSequence();
  7332. }
  7333.  
  7334. private void pictureBoxE5_Click(object sender, EventArgs e)
  7335. {
  7336. columnClicked = "E";
  7337. rankClicked = 5;
  7338. ManageGameSequence();
  7339. }
  7340.  
  7341. private void pictureBoxE6_Click(object sender, EventArgs e)
  7342. {
  7343. columnClicked = "E";
  7344. rankClicked = 6;
  7345. ManageGameSequence();
  7346. }
  7347.  
  7348. private void pictureBoxE7_Click(object sender, EventArgs e)
  7349. {
  7350. columnClicked = "E";
  7351. rankClicked = 7;
  7352. ManageGameSequence();
  7353. }
  7354.  
  7355. private void pictureBoxE8_Click(object sender, EventArgs e)
  7356. {
  7357. columnClicked = "E";
  7358. rankClicked = 8;
  7359. ManageGameSequence();
  7360. }
  7361.  
  7362. private void pictureBoxF1_Click(object sender, EventArgs e)
  7363. {
  7364. columnClicked = "F";
  7365. rankClicked = 1;
  7366. ManageGameSequence();
  7367. }
  7368.  
  7369. private void pictureBoxF2_Click(object sender, EventArgs e)
  7370. {
  7371. columnClicked = "F";
  7372. rankClicked = 2;
  7373. ManageGameSequence();
  7374. }
  7375.  
  7376. private void pictureBoxF3_Click(object sender, EventArgs e)
  7377. {
  7378. columnClicked = "F";
  7379. rankClicked = 3;
  7380. ManageGameSequence();
  7381. }
  7382.  
  7383. private void pictureBoxF4_Click(object sender, EventArgs e)
  7384. {
  7385. columnClicked = "F";
  7386. rankClicked = 4;
  7387. ManageGameSequence();
  7388. }
  7389.  
  7390. private void pictureBoxF5_Click(object sender, EventArgs e)
  7391. {
  7392. columnClicked = "F";
  7393. rankClicked = 5;
  7394. ManageGameSequence();
  7395. }
  7396.  
  7397. private void pictureBoxF6_Click(object sender, EventArgs e)
  7398. {
  7399. columnClicked = "F";
  7400. rankClicked = 6;
  7401. ManageGameSequence();
  7402. }
  7403.  
  7404. private void pictureBoxF7_Click(object sender, EventArgs e)
  7405. {
  7406. columnClicked = "F";
  7407. rankClicked = 7;
  7408. ManageGameSequence();
  7409. }
  7410.  
  7411. private void pictureBoxF8_Click(object sender, EventArgs e)
  7412. {
  7413. columnClicked = "F";
  7414. rankClicked = 8;
  7415. ManageGameSequence();
  7416. }
  7417.  
  7418. private void pictureBoxG1_Click(object sender, EventArgs e)
  7419. {
  7420. columnClicked = "G";
  7421. rankClicked = 1;
  7422. ManageGameSequence();
  7423. }
  7424.  
  7425. private void pictureBoxG2_Click(object sender, EventArgs e)
  7426. {
  7427. columnClicked = "G";
  7428. rankClicked = 2;
  7429. ManageGameSequence();
  7430. }
  7431.  
  7432. private void pictureBoxG3_Click(object sender, EventArgs e)
  7433. {
  7434. columnClicked = "G";
  7435. rankClicked = 3;
  7436. ManageGameSequence();
  7437. }
  7438.  
  7439. private void pictureBoxG4_Click(object sender, EventArgs e)
  7440. {
  7441. columnClicked = "G";
  7442. rankClicked = 4;
  7443. ManageGameSequence();
  7444. }
  7445.  
  7446. private void pictureBoxG5_Click(object sender, EventArgs e)
  7447. {
  7448. columnClicked = "G";
  7449. rankClicked = 5;
  7450. ManageGameSequence();
  7451. }
  7452.  
  7453. private void pictureBoxG6_Click(object sender, EventArgs e)
  7454. {
  7455. columnClicked = "G";
  7456. rankClicked = 6;
  7457. ManageGameSequence();
  7458. }
  7459.  
  7460. private void pictureBoxG7_Click(object sender, EventArgs e)
  7461. {
  7462. columnClicked = "G";
  7463. rankClicked = 7;
  7464. ManageGameSequence();
  7465. }
  7466.  
  7467. private void pictureBoxG8_Click(object sender, EventArgs e)
  7468. {
  7469. columnClicked = "G";
  7470. rankClicked = 8;
  7471. ManageGameSequence();
  7472. }
  7473.  
  7474. private void pictureBoxH1_Click(object sender, EventArgs e)
  7475. {
  7476. columnClicked = "H";
  7477. rankClicked = 1;
  7478. ManageGameSequence();
  7479. }
  7480.  
  7481. private void pictureBoxH2_Click(object sender, EventArgs e)
  7482. {
  7483. columnClicked = "H";
  7484. rankClicked = 2;
  7485. ManageGameSequence();
  7486. }
  7487.  
  7488. private void pictureBoxH3_Click(object sender, EventArgs e)
  7489. {
  7490. columnClicked = "H";
  7491. rankClicked = 3;
  7492. ManageGameSequence();
  7493. }
  7494.  
  7495. private void pictureBoxH4_Click(object sender, EventArgs e)
  7496. {
  7497. columnClicked = "H";
  7498. rankClicked = 4;
  7499. ManageGameSequence();
  7500. }
  7501.  
  7502. private void pictureBoxH5_Click(object sender, EventArgs e)
  7503. {
  7504. columnClicked = "H";
  7505. rankClicked = 5;
  7506. ManageGameSequence();
  7507. }
  7508.  
  7509. private void pictureBoxH6_Click(object sender, EventArgs e)
  7510. {
  7511. columnClicked = "H";
  7512. rankClicked = 6;
  7513. ManageGameSequence();
  7514. }
  7515.  
  7516. private void pictureBoxH7_Click(object sender, EventArgs e)
  7517. {
  7518. columnClicked = "H";
  7519. rankClicked = 7;
  7520. ManageGameSequence();
  7521. }
  7522.  
  7523. private void pictureBoxH8_Click(object sender, EventArgs e)
  7524. {
  7525. columnClicked = "H";
  7526. rankClicked = 8;
  7527. ManageGameSequence();
  7528. }
  7529.  
  7530.  
  7531. }
  7532. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement