ychess is a chess implementation written in nim.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1227 lines
44 KiB

  1. import einheit
  2. import algorithm
  3. import ./chess
  4. testSuite GameTest of TestSuite:
  5. var
  6. game: Game
  7. method setup() =
  8. self.game = initGame()
  9. ## Tests for isInCheck()
  10. method testIsInCheckFalse() =
  11. self.setup()
  12. self.game.checkedMove(notationToMove("e2e4", Color.White))
  13. self.game.checkedMove(notationToMove("e7e5", Color.Black))
  14. self.game.checkedMove(notationToMove("d2d3", Color.White))
  15. self.game.checkedMove(notationToMove("d8h4", Color.Black))
  16. self.check(not self.game.isInCheck(Color.White))
  17. self.check(not self.game.isInCheck(Color.White))
  18. method testIsInCheckTrueWhite() =
  19. self.setup()
  20. self.game.checkedMove(notationToMove("f2f4", Color.White))
  21. self.game.checkedMove(notationToMove("e7e5", Color.Black))
  22. self.game.checkedMove(notationToMove("e2e3", Color.White))
  23. self.game.checkedMove(notationToMove("d8h4", Color.Black))
  24. self.check(self.game.isInCheck(Color.White))
  25. method testIsInCheckTrueBlack() =
  26. self.setup()
  27. self.game.checkedMove(notationToMove("e2e4", Color.White))
  28. self.game.checkedMove(notationToMove("f7f6", Color.Black))
  29. self.game.checkedMove(notationToMove("d2d4", Color.White))
  30. self.game.checkedMove(notationToMove("g7g5", Color.Black))
  31. self.game.checkedMove(notationToMove("d1h5", Color.White))
  32. self.check(self.game.isInCheck(Color.Black))
  33. ## Tests for isCheckmate()
  34. method testIsCheckmateFalseWhite() =
  35. self.setup()
  36. self.game.checkedMove(notationToMove("f2f4", Color.White))
  37. self.game.checkedMove(notationToMove("e7e5", Color.Black))
  38. self.game.checkedMove(notationToMove("e2e3", Color.White))
  39. self.game.checkedMove(notationToMove("d8h4", Color.Black))
  40. self.check(not self.game.isCheckmate(Color.White))
  41. method testIsCheckmateFalseBlack() =
  42. self.setup()
  43. self.game.checkedMove(notationToMove("f2f4", Color.White))
  44. self.game.checkedMove(notationToMove("e7e5", Color.Black))
  45. self.game.checkedMove(notationToMove("e2e3", Color.White))
  46. self.game.checkedMove(notationToMove("d8h4", Color.Black))
  47. self.check(not self.game.isCheckmate(Color.Black))
  48. method testIsCheckmateTrueWhite() =
  49. self.setup()
  50. self.game.checkedMove(notationToMove("f2f3", Color.White))
  51. self.game.checkedMove(notationToMove("e7e6", Color.Black))
  52. self.game.checkedMove(notationToMove("g2g4", Color.White))
  53. self.game.checkedMove(notationToMove("d8h4", Color.Black))
  54. self.check(self.game.isCheckmate(Color.White))
  55. method testIsCheckmateTrueBlack() =
  56. self.setup()
  57. self.game.checkedMove(notationToMove("e2e4", Color.White))
  58. self.game.checkedMove(notationToMove("g7g5", Color.Black))
  59. self.game.checkedMove(notationToMove("d2d4", Color.White))
  60. self.game.checkedMove(notationToMove("f7f6", Color.Black))
  61. self.game.checkedMove(notationToMove("d1h5", Color.White))
  62. self.check(self.game.isCheckmate(Color.Black))
  63. ## Tests for isStalemate()
  64. method testIsStalemateFalse() =
  65. self.setup()
  66. self.game.checkedMove(notationToMove("f2f3", Color.White))
  67. self.game.checkedMove(notationToMove("e7e6", Color.Black))
  68. self.game.checkedMove(notationToMove("g2g4", Color.White))
  69. self.game.checkedMove(notationToMove("d8h4", Color.Black))
  70. self.check(not self.game.isStalemate(Color.White))
  71. self.check(not self.game.isStalemate(Color.Black))
  72. method testIsStalemateTrueWhite() =
  73. self.game = initGame([
  74. 0, 0, 0, 0, BRook, BQueen, BRook, BKnight,
  75. 0, BPawn, 0, 0, BPawn, BPawn, BBishop, WKing,
  76. 0, BPawn, 0, BPawn, 0, BPawn, 0, BKnight,
  77. 0, 0, 0, 0, 0, 0, BPawn, 0,
  78. 0, 0, BBishop, 0, 0, 0, 0, 0,
  79. 0, 0, 0, 0, 0, 0, 0, 0,
  80. 0, BPawn, BKing, 0, 0, 0, 0, 0,
  81. 0, 0, 0, 0, 0, 0, 0, 0
  82. ], Color.White)
  83. self.check(self.game.isStalemate(Color.White))
  84. method testIsStalemateTrueBlack() =
  85. self.game = initGame([
  86. 0, 0, 0, 0, WRook, WQueen, WRook, WKnight,
  87. 0, WPawn, 0, 0, WPawn, WPawn, WBishop, BKing,
  88. 0, WPawn, 0, WPawn, 0, WPawn, 0, WKnight,
  89. 0, 0, 0, 0, 0, 0, WPawn, 0,
  90. 0, 0, WBishop, 0, 0, 0, 0, 0,
  91. 0, 0, 0, 0, 0, 0, 0, 0,
  92. 0, WPawn, WKing, 0, 0, 0, 0, 0,
  93. 0, 0, 0, 0, 0, 0, 0, 0
  94. ], Color.Black)
  95. self.check(self.game.isStalemate(Color.Black))
  96. method testIsStalemateInsufficientMaterialTrue() =
  97. self.game = initGame([
  98. 0, 0, 0, 0, 0, 0, 0, 0,
  99. 0, 0, 0, WKing, 0, 0, 0, 0,
  100. 0, 0, 0, 0, 0, 0, 0, 0,
  101. 0, 0, 0, 0, 0, 0, 0, 0,
  102. 0, 0, 0, 0, 0, 0, 0, 0,
  103. 0, 0, 0, 0, 0, 0, 0, 0,
  104. 0, 0, 0, 0, 0, BKing, 0, 0,
  105. 0, 0, 0, 0, 0, 0, 0, 0
  106. ], Color.Black)
  107. self.check(self.game.isStalemate(Color.Black))
  108. self.check(self.game.isStalemate(Color.White))
  109. self.game = initGame([
  110. 0, 0, 0, 0, 0, 0, 0, 0,
  111. 0, 0, 0, WKing, 0, 0, 0, 0,
  112. 0, 0, 0, 0, 0, 0, 0, 0,
  113. 0, 0, 0, 0, 0, 0, 0, WKnight,
  114. 0, 0, WKnight, 0, 0, 0, 0, 0,
  115. 0, 0, 0, 0, 0, 0, 0, 0,
  116. 0, 0, 0, 0, 0, BKing, 0, 0,
  117. 0, 0, 0, 0, 0, 0, 0, 0
  118. ], Color.Black)
  119. self.check(self.game.isStalemate(Color.Black))
  120. self.check(self.game.isStalemate(Color.White))
  121. self.game = initGame([
  122. 0, 0, 0, 0, 0, 0, 0, 0,
  123. 0, 0, 0, WKing, 0, 0, 0, 0,
  124. 0, 0, 0, 0, 0, 0, 0, 0,
  125. 0, 0, 0, 0, 0, 0, 0, BKnight,
  126. 0, 0, BKnight, 0, 0, 0, 0, 0,
  127. 0, 0, 0, 0, 0, 0, 0, 0,
  128. 0, 0, 0, 0, 0, BKing, 0, 0,
  129. 0, 0, 0, 0, 0, 0, 0, 0
  130. ], Color.Black)
  131. self.check(self.game.isStalemate(Color.Black))
  132. self.check(self.game.isStalemate(Color.White))
  133. self.game = initGame([
  134. 0, 0, 0, 0, 0, 0, 0, 0,
  135. 0, 0, 0, WKing, 0, 0, 0, 0,
  136. 0, 0, 0, 0, 0, 0, 0, 0,
  137. 0, 0, 0, 0, 0, 0, 0, BKnight,
  138. 0, 0, 0, 0, 0, 0, 0, 0,
  139. 0, 0, 0, 0, 0, 0, 0, 0,
  140. 0, 0, 0, 0, 0, BKing, 0, 0,
  141. 0, 0, 0, 0, 0, 0, 0, 0
  142. ], Color.Black)
  143. self.check(self.game.isStalemate(Color.Black))
  144. self.check(self.game.isStalemate(Color.White))
  145. self.game = initGame([
  146. 0, 0, 0, 0, 0, 0, 0, 0,
  147. 0, 0, 0, WKing, 0, 0, 0, 0,
  148. 0, 0, 0, 0, 0, 0, 0, 0,
  149. 0, 0, 0, 0, 0, 0, 0, WKnight,
  150. 0, 0, 0, 0, 0, 0, 0, 0,
  151. 0, 0, 0, 0, 0, 0, 0, 0,
  152. 0, 0, 0, 0, 0, BKing, 0, 0,
  153. 0, 0, 0, 0, 0, 0, 0, 0
  154. ], Color.Black)
  155. self.check(self.game.isStalemate(Color.Black))
  156. self.check(self.game.isStalemate(Color.White))
  157. self.game = initGame([
  158. 0, 0, 0, 0, 0, 0, 0, 0,
  159. 0, 0, 0, WKing, 0, 0, 0, 0,
  160. 0, 0, 0, 0, 0, 0, 0, 0,
  161. 0, 0, 0, 0, 0, 0, 0, BBishop,
  162. 0, 0, 0, 0, 0, 0, 0, 0,
  163. 0, 0, 0, 0, 0, 0, 0, 0,
  164. 0, 0, 0, 0, 0, BKing, 0, 0,
  165. 0, 0, 0, 0, 0, 0, 0, 0
  166. ], Color.Black)
  167. self.check(self.game.isStalemate(Color.Black))
  168. self.check(self.game.isStalemate(Color.White))
  169. self.game = initGame([
  170. 0, 0, 0, 0, 0, 0, 0, 0,
  171. 0, 0, 0, WKing, 0, 0, 0, 0,
  172. 0, 0, 0, 0, 0, 0, 0, 0,
  173. 0, 0, 0, 0, 0, 0, 0, WBishop,
  174. 0, 0, 0, 0, 0, 0, 0, 0,
  175. 0, 0, 0, 0, 0, 0, 0, 0,
  176. 0, 0, 0, 0, 0, BKing, 0, 0,
  177. 0, 0, 0, 0, 0, 0, 0, 0
  178. ], Color.Black)
  179. self.check(self.game.isStalemate(Color.Black))
  180. self.check(self.game.isStalemate(Color.White))
  181. method testIsStalemateInsufficientMaterialFalse() =
  182. self.game = initGame([
  183. 0, 0, 0, 0, 0, 0, 0, 0,
  184. 0, 0, 0, WKing, 0, 0, 0, 0,
  185. 0, 0, 0, 0, 0, 0, 0, 0,
  186. 0, 0, 0, 0, 0, 0, 0, BPawn,
  187. 0, 0, 0, 0, 0, 0, 0, 0,
  188. 0, 0, 0, 0, 0, 0, 0, 0,
  189. 0, 0, 0, 0, 0, BKing, 0, 0,
  190. 0, 0, 0, 0, 0, 0, 0, 0
  191. ], Color.Black)
  192. self.check(not self.game.isStalemate(Color.Black))
  193. self.check(not self.game.isStalemate(Color.White))
  194. self.game = initGame([
  195. 0, 0, 0, 0, 0, 0, 0, 0,
  196. 0, 0, 0, WKing, 0, 0, 0, 0,
  197. 0, 0, 0, 0, 0, 0, 0, 0,
  198. 0, 0, 0, 0, 0, 0, 0, WPawn,
  199. 0, 0, 0, 0, 0, 0, 0, 0,
  200. 0, 0, 0, 0, 0, 0, 0, 0,
  201. 0, 0, 0, 0, 0, BKing, 0, 0,
  202. 0, 0, 0, 0, 0, 0, 0, 0
  203. ], Color.Black)
  204. self.check(not self.game.isStalemate(Color.Black))
  205. self.check(not self.game.isStalemate(Color.White))
  206. self.game = initGame([
  207. 0, 0, 0, 0, 0, 0, 0, 0,
  208. 0, 0, 0, WKing, 0, 0, 0, 0,
  209. 0, 0, 0, 0, 0, 0, 0, 0,
  210. 0, 0, 0, 0, 0, 0, 0, BRook,
  211. 0, 0, 0, 0, 0, 0, 0, 0,
  212. 0, 0, 0, 0, 0, 0, 0, 0,
  213. 0, 0, 0, 0, 0, BKing, 0, 0,
  214. 0, 0, 0, 0, 0, 0, 0, 0
  215. ], Color.Black)
  216. self.check(not self.game.isStalemate(Color.Black))
  217. self.check(not self.game.isStalemate(Color.White))
  218. self.game = initGame([
  219. 0, 0, 0, 0, 0, 0, 0, 0,
  220. 0, 0, 0, WKing, 0, 0, 0, 0,
  221. 0, 0, 0, 0, 0, 0, 0, 0,
  222. 0, 0, 0, 0, 0, 0, 0, WRook,
  223. 0, 0, 0, 0, 0, 0, 0, 0,
  224. 0, 0, 0, 0, 0, 0, 0, 0,
  225. 0, 0, 0, 0, 0, BKing, 0, 0,
  226. 0, 0, 0, 0, 0, 0, 0, 0
  227. ], Color.Black)
  228. self.check(not self.game.isStalemate(Color.Black))
  229. self.check(not self.game.isStalemate(Color.White))
  230. self.game = initGame([
  231. 0, 0, 0, 0, 0, 0, 0, 0,
  232. 0, 0, 0, WKing, 0, 0, 0, 0,
  233. 0, 0, 0, 0, 0, 0, 0, 0,
  234. 0, WBishop, 0, 0, 0, 0, 0, BPawn,
  235. 0, 0, 0, 0, 0, 0, 0, 0,
  236. 0, 0, 0, 0, 0, 0, 0, 0,
  237. 0, 0, 0, 0, 0, BKing, 0, 0,
  238. 0, 0, 0, 0, 0, 0, 0, 0
  239. ], Color.Black)
  240. self.check(not self.game.isStalemate(Color.Black))
  241. self.check(not self.game.isStalemate(Color.White))
  242. self.game = initGame([
  243. 0, 0, 0, 0, 0, 0, 0, 0,
  244. 0, 0, 0, WKing, 0, 0, 0, 0,
  245. 0, 0, 0, 0, 0, 0, 0, 0,
  246. 0, 0, BBishop, 0, 0, 0, 0, WPawn,
  247. 0, 0, 0, 0, 0, 0, 0, 0,
  248. 0, 0, 0, 0, 0, 0, 0, 0,
  249. 0, 0, 0, 0, 0, BKing, 0, 0,
  250. 0, 0, 0, 0, 0, 0, 0, 0
  251. ], Color.Black)
  252. self.check(not self.game.isStalemate(Color.Black))
  253. self.check(not self.game.isStalemate(Color.White))
  254. ## Tests for Pawn moves
  255. method testCheckedMovePawnSingleTrue() =
  256. self.setup()
  257. var test: bool
  258. for file in "abcdefgh":
  259. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  260. self.check(test)
  261. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  262. self.check(test)
  263. test = self.game.checkedMove(notationToMove($file & "3" & $file & "4", Color.White))
  264. self.check(test)
  265. test = self.game.checkedMove(notationToMove($file & "6" & $file & "5", Color.Black))
  266. self.check(test)
  267. method testCheckedMovePawnSingleFalseIntoEnemyPiece() =
  268. var test: bool
  269. let pos = initGame([
  270. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  271. 0, 0, 0, 0, 0, 0, 0, 0,
  272. 0, 0, 0, 0, 0, 0, 0, 0,
  273. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  274. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  275. 0, 0, 0, 0, 0, 0, 0, 0,
  276. 0, 0, 0, 0, 0, 0, 0, 0,
  277. BRook, 0, 0, BKing, 0, 0, 0, BRook
  278. ], Color.White)
  279. self.game = pos
  280. for file in "abcdefgh":
  281. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  282. self.check(not test)
  283. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  284. self.check(not test)
  285. method testCheckedMovePawnSingleFalseIntoOwnPiece() =
  286. var test: bool
  287. let pos = initGame([
  288. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  289. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  290. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  291. 0, 0, 0, 0, 0, 0, 0, 0,
  292. 0, 0, 0, 0, 0, 0, 0, 0,
  293. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  294. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  295. BRook, 0, 0, BKing, 0, 0, 0, BRook
  296. ], Color.White)
  297. self.game = pos
  298. for file in "abcdefgh":
  299. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  300. self.check(not test)
  301. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  302. self.check(not test)
  303. method testCheckedMovePawnDoubleTrue() =
  304. self.setup()
  305. var test: bool
  306. for file in "abcdefgh":
  307. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  308. self.check(test)
  309. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  310. self.check(test)
  311. method testCheckedMovePawnDoubleFalseAlreadyMoved() =
  312. var test: bool
  313. let pos = initGame([
  314. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  315. 0, 0, 0, 0, 0, 0, 0, 0,
  316. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  317. 0, 0, 0, 0, 0, 0, 0, 0,
  318. 0, 0, 0, 0, 0, 0, 0, 0,
  319. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  320. 0, 0, 0, 0, 0, 0, 0, 0,
  321. BRook, 0, 0, BKing, 0, 0, 0, BRook
  322. ], Color.White)
  323. self.game = pos
  324. for file in "abcdefgh":
  325. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  326. self.check(not test)
  327. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  328. self.check(not test)
  329. method testCheckedMovePawnDoubleFalseThroughEnemyPiece() =
  330. var test: bool
  331. let pos = initGame([
  332. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  333. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  334. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  335. 0, 0, 0, 0, 0, 0, 0, 0,
  336. 0, 0, 0, 0, 0, 0, 0, 0,
  337. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  338. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  339. BRook, 0, 0, BKing, 0, 0, 0, BRook
  340. ], Color.White)
  341. self.game = pos
  342. for file in "abcdefgh":
  343. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  344. self.check(not test)
  345. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  346. self.check(not test)
  347. method testCheckedMovePawnDoubleFalseThroughOwnPiece() =
  348. var test: bool
  349. let pos = initGame([
  350. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  351. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  352. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  353. 0, 0, 0, 0, 0, 0, 0, 0,
  354. 0, 0, 0, 0, 0, 0, 0, 0,
  355. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  356. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  357. BRook, 0, 0, BKing, 0, 0, 0, BRook
  358. ], Color.White)
  359. self.game = pos
  360. for file in "abcdefgh":
  361. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  362. self.check(not test)
  363. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  364. self.check(not test)
  365. method testCheckedMovePawnDoubleFalseIntoEnemyPiece() =
  366. var test: bool
  367. let pos = initGame([
  368. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  369. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  370. 0, 0, 0, 0, 0, 0, 0, 0,
  371. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  372. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  373. 0, 0, 0, 0, 0, 0, 0, 0,
  374. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  375. BRook, 0, 0, BKing, 0, 0, 0, BRook
  376. ], Color.White)
  377. self.game = pos
  378. for file in "abcdefgh":
  379. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  380. self.check(not test)
  381. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  382. self.check(not test)
  383. method testCheckedMovePawnDoubleFalseIntoOwnPiece() =
  384. var test: bool
  385. let pos = initGame([
  386. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  387. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  388. 0, 0, 0, 0, 0, 0, 0, 0,
  389. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  390. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  391. 0, 0, 0, 0, 0, 0, 0, 0,
  392. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  393. BRook, 0, 0, BKing, 0, 0, 0, BRook
  394. ], Color.White)
  395. self.game = pos
  396. for file in "abcdefgh":
  397. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  398. self.check(not test)
  399. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  400. self.check(not test)
  401. method testCheckedMovePawnCaptureTrueWhite() =
  402. var test: bool
  403. let pos = initGame([
  404. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  405. 0, 0, 0, 0, 0, 0, 0, 0,
  406. 0, 0, 0, 0, 0, 0, 0, 0,
  407. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  408. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  409. 0, 0, 0, 0, 0, 0, 0, 0,
  410. 0, 0, 0, 0, 0, 0, 0, 0,
  411. BRook, 0, 0, BKing, 0, 0, 0, BRook
  412. ], Color.White)
  413. var str: string
  414. str = "abcdefgh"
  415. for ind, file in str:
  416. if ind < len(str)-1:
  417. self.game = pos
  418. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  419. "5", Color.White))
  420. self.check(test)
  421. str.reverse()
  422. for ind, file in str:
  423. if ind < len(str)-1:
  424. self.game = pos
  425. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  426. "5", Color.White))
  427. self.check(test)
  428. method testCheckedMovePawnCaptureTrueBlack() =
  429. var test: bool
  430. let pos = initGame([
  431. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  432. 0, 0, 0, 0, 0, 0, 0, 0,
  433. 0, 0, 0, 0, 0, 0, 0, 0,
  434. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  435. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  436. 0, 0, 0, 0, 0, 0, 0, 0,
  437. 0, 0, 0, 0, 0, 0, 0, 0,
  438. BRook, 0, 0, BKing, 0, 0, 0, BRook
  439. ], Color.Black)
  440. var str: string
  441. str = "abcdefgh"
  442. for ind, file in str:
  443. if ind < len(str)-1:
  444. self.game = pos
  445. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  446. "4", Color.Black))
  447. self.check(test)
  448. str.reverse()
  449. for ind, file in str:
  450. if ind < len(str)-1:
  451. self.game = pos
  452. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  453. "4", Color.Black))
  454. self.check(test)
  455. method testCheckedMovePawnCaptureFalseWhite() =
  456. var test: bool
  457. let pos = initGame([
  458. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  459. 0, 0, 0, 0, 0, 0, 0, 0,
  460. 0, 0, 0, 0, 0, 0, 0, 0,
  461. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  462. 0, 0, 0, 0, 0, 0, 0, 0,
  463. 0, 0, 0, 0, 0, 0, 0, 0,
  464. 0, 0, 0, 0, 0, 0, 0, 0,
  465. BRook, 0, 0, BKing, 0, 0, 0, BRook
  466. ], Color.White)
  467. var str: string
  468. str = "abcdefgh"
  469. for ind, file in str:
  470. if ind < len(str)-1:
  471. self.game = pos
  472. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  473. "5", Color.White))
  474. self.check(not test)
  475. str.reverse()
  476. for ind, file in str:
  477. if ind < len(str)-1:
  478. self.game = pos
  479. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  480. "5", Color.White))
  481. self.check(not test)
  482. method testCheckedMovePawnCaptureFalseBlack() =
  483. var test: bool
  484. let pos = initGame([
  485. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  486. 0, 0, 0, 0, 0, 0, 0, 0,
  487. 0, 0, 0, 0, 0, 0, 0, 0,
  488. 0, 0, 0, 0, 0, 0, 0, 0,
  489. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  490. 0, 0, 0, 0, 0, 0, 0, 0,
  491. 0, 0, 0, 0, 0, 0, 0, 0,
  492. BRook, 0, 0, BKing, 0, 0, 0, BRook
  493. ], Color.Black)
  494. var str: string
  495. str = "abcdefgh"
  496. for ind, file in str:
  497. if ind < len(str)-1:
  498. self.game = pos
  499. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  500. "4", Color.Black))
  501. self.check(not test)
  502. str.reverse()
  503. for ind, file in str:
  504. if ind < len(str)-1:
  505. self.game = pos
  506. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  507. "4", Color.Black))
  508. self.check(not test)
  509. method testCheckedMovePawnEnPassantTrueWhite() =
  510. var test: bool
  511. let pos = initGame([
  512. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  513. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  514. 0, 0, 0, 0, 0, 0, 0, 0,
  515. 0, 0, 0, 0, 0, 0, 0, 0,
  516. 0, 0, 0, 0, 0, 0, 0, 0,
  517. 0, 0, 0, 0, 0, 0, 0, 0,
  518. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  519. BRook, 0, 0, BKing, 0, 0, 0, BRook
  520. ], Color.White)
  521. var str: string
  522. str = "abcdefgh"
  523. for ind, file in str:
  524. if ind < len(str)-1:
  525. self.game = pos
  526. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  527. self.check(test)
  528. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  529. self.check(test)
  530. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  531. self.check(test)
  532. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  533. ind+1] & "5", Color.Black))
  534. self.check(test)
  535. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  536. "6", Color.White))
  537. self.check(test)
  538. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "5")))
  539. self.check(test)
  540. str.reverse()
  541. for ind, file in str:
  542. if ind < len(str)-1:
  543. self.game = pos
  544. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  545. self.check(test)
  546. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  547. self.check(test)
  548. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  549. self.check(test)
  550. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  551. ind+1] & "5", Color.Black))
  552. self.check(test)
  553. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  554. "6", Color.White))
  555. self.check(test)
  556. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "5")))
  557. self.check(test)
  558. method testCheckedMovePawnEnPassantTrueBlack() =
  559. var test: bool
  560. let pos = initGame([
  561. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  562. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  563. 0, 0, 0, 0, 0, 0, 0, 0,
  564. 0, 0, 0, 0, 0, 0, 0, 0,
  565. 0, 0, 0, 0, 0, 0, 0, 0,
  566. 0, 0, 0, 0, 0, 0, 0, 0,
  567. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  568. BRook, 0, 0, BKing, 0, 0, 0, BRook
  569. ], Color.Black)
  570. var str: string
  571. str = "abcdefgh"
  572. for ind, file in str:
  573. if ind < len(str)-1:
  574. self.game = pos
  575. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  576. self.check(test)
  577. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  578. self.check(test)
  579. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  580. self.check(test)
  581. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  582. ind+1] & "4", Color.White))
  583. self.check(test)
  584. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  585. "3", Color.Black))
  586. self.check(test)
  587. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "4")))
  588. self.check(test)
  589. str.reverse()
  590. for ind, file in str:
  591. if ind < len(str)-1:
  592. self.game = pos
  593. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  594. self.check(test)
  595. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  596. self.check(test)
  597. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  598. self.check(test)
  599. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  600. ind+1] & "4", Color.White))
  601. self.check(test)
  602. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  603. "3", Color.Black))
  604. self.check(test)
  605. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "4")))
  606. self.check(test)
  607. method testCheckedMovePawnEnPassantFalseWhite() =
  608. var test: bool
  609. let pos = initGame([
  610. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  611. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  612. 0, 0, 0, 0, 0, 0, 0, 0,
  613. 0, 0, 0, 0, 0, 0, 0, 0,
  614. 0, 0, 0, 0, 0, 0, 0, 0,
  615. 0, 0, 0, 0, 0, 0, 0, 0,
  616. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  617. BRook, 0, 0, BKing, 0, 0, 0, BRook
  618. ], Color.White)
  619. var str: string
  620. str = "abcdefgh"
  621. for ind, file in str:
  622. if ind < len(str)-1:
  623. self.game = pos
  624. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  625. self.check(test)
  626. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  627. ind+1] & "5", Color.Black))
  628. self.check(test)
  629. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  630. self.check(test)
  631. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  632. self.check(test)
  633. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  634. "6", Color.White))
  635. self.check(not test)
  636. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "5")))
  637. self.check(not test)
  638. str.reverse()
  639. for ind, file in str:
  640. if ind < len(str)-1:
  641. self.game = pos
  642. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  643. self.check(test)
  644. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  645. ind+1] & "5", Color.Black))
  646. self.check(test)
  647. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  648. self.check(test)
  649. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  650. self.check(test)
  651. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  652. "6", Color.White))
  653. self.check(not test)
  654. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "5")))
  655. self.check(not test)
  656. method testCheckedMovePawnEnPassantFalseBlack() =
  657. var test: bool
  658. let pos = initGame([
  659. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  660. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  661. 0, 0, 0, 0, 0, 0, 0, 0,
  662. 0, 0, 0, 0, 0, 0, 0, 0,
  663. 0, 0, 0, 0, 0, 0, 0, 0,
  664. 0, 0, 0, 0, 0, 0, 0, 0,
  665. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  666. BRook, 0, 0, BKing, 0, 0, 0, BRook
  667. ], Color.Black)
  668. var str: string
  669. str = "abcdefgh"
  670. for ind, file in str:
  671. if ind < len(str)-1:
  672. self.game = pos
  673. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  674. self.check(test)
  675. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  676. ind+1] & "4", Color.White))
  677. self.check(test)
  678. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  679. self.check(test)
  680. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  681. self.check(test)
  682. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  683. "3", Color.Black))
  684. self.check(not test)
  685. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "4")))
  686. self.check(not test)
  687. str.reverse()
  688. for ind, file in str:
  689. if ind < len(str)-1:
  690. self.game = pos
  691. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  692. self.check(test)
  693. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  694. ind+1] & "4", Color.White))
  695. self.check(test)
  696. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  697. self.check(test)
  698. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  699. self.check(test)
  700. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  701. "3", Color.Black))
  702. self.check(not test)
  703. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "4")))
  704. self.check(not test)
  705. ## Tests for King moves
  706. method testCheckedMoveKingCastleTrueWhite() =
  707. var test: bool
  708. let pos = initGame([
  709. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  710. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  711. 0, 0, 0, 0, 0, 0, 0, 0,
  712. 0, 0, 0, 0, 0, 0, 0, 0,
  713. 0, 0, 0, 0, 0, 0, 0, 0,
  714. 0, 0, 0, 0, 0, 0, 0, 0,
  715. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  716. BRook, 0, 0, BKing, 0, 0, 0, BRook
  717. ], Color.White)
  718. self.game = pos
  719. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  720. self.check(test)
  721. self.game = pos
  722. self.game.checkedMove(notationToMove("e1g1", Color.White))
  723. self.check(test)
  724. method testCheckedMoveKingCastleTrueBlack() =
  725. var test: bool
  726. let pos = initGame([
  727. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  728. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  729. 0, 0, 0, 0, 0, 0, 0, 0,
  730. 0, 0, 0, 0, 0, 0, 0, 0,
  731. 0, 0, 0, 0, 0, 0, 0, 0,
  732. 0, 0, 0, 0, 0, 0, 0, 0,
  733. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  734. BRook, 0, 0, BKing, 0, 0, 0, BRook
  735. ], Color.Black)
  736. self.game = pos
  737. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  738. self.check(test)
  739. self.game = pos
  740. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  741. self.check(test)
  742. method testCheckedMoveKingCastleFalseAlreadyMovedKing() =
  743. var test: bool
  744. let pos = initGame([
  745. WRook, 0, 0, 0, WKing, 0, 0, WRook,
  746. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  747. 0, 0, 0, 0, 0, 0, 0, 0,
  748. 0, 0, 0, 0, 0, 0, 0, 0,
  749. 0, 0, 0, 0, 0, 0, 0, 0,
  750. 0, 0, 0, 0, 0, 0, 0, 0,
  751. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  752. BRook, 0, 0, 0, BKing, 0, 0, BRook
  753. ], Color.White)
  754. self.game.checkedMove(notationToMove("d1e1", Color.White))
  755. self.game.checkedMove(notationToMove("d8e8", Color.White))
  756. self.game = pos
  757. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  758. self.check(not test)
  759. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  760. self.check(not test)
  761. self.game.checkedMove(notationToMove("e1g1", Color.White))
  762. self.check(not test)
  763. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  764. self.check(not test)
  765. method testCheckedMoveKingCastleFalseAlreadyMovedRook() =
  766. var test: bool
  767. let pos = initGame([
  768. 0, WRook, 0, WKing, 0, 0, WRook, 0,
  769. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  770. 0, 0, 0, 0, 0, 0, 0, 0,
  771. 0, 0, 0, 0, 0, 0, 0, 0,
  772. 0, 0, 0, 0, 0, 0, 0, 0,
  773. 0, 0, 0, 0, 0, 0, 0, 0,
  774. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  775. 0, BRook, 0, BKing, 0, 0, BRook, 0
  776. ], Color.White)
  777. self.game = pos
  778. self.game.checkedMove(notationToMove("b1a1", Color.White))
  779. self.game.checkedMove(notationToMove("b8a8", Color.Black))
  780. self.game.checkedMove(notationToMove("g1h1", Color.White))
  781. self.game.checkedMove(notationToMove("g8h8", Color.Black))
  782. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  783. self.check(not test)
  784. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  785. self.check(not test)
  786. self.game.checkedMove(notationToMove("e1g1", Color.White))
  787. self.check(not test)
  788. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  789. self.check(not test)
  790. method testCheckedMoveKingCastleFalseThroughCheck() =
  791. var test: bool
  792. let pos = initGame([
  793. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  794. WPawn, WPawn, BRook, WPawn, BRook, WPawn, WPawn, WPawn,
  795. 0, 0, 0, 0, 0, 0, 0, 0,
  796. 0, 0, 0, 0, 0, 0, 0, 0,
  797. 0, 0, 0, 0, 0, 0, 0, 0,
  798. 0, 0, 0, 0, 0, 0, 0, 0,
  799. BPawn, BPawn, WRook, BPawn, WRook, BPawn, BPawn, BPawn,
  800. BRook, 0, 0, BKing, 0, 0, 0, BRook
  801. ], Color.White)
  802. self.game = pos
  803. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  804. self.check(not test)
  805. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  806. self.check(not test)
  807. self.game.checkedMove(notationToMove("e1g1", Color.White))
  808. self.check(not test)
  809. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  810. self.check(not test)
  811. method testCheckedMoveKingCastleFalseIntoCheck() =
  812. var test: bool
  813. let pos = initGame([
  814. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  815. WPawn, BRook, WPawn, WPawn, WPawn, BRook, WPawn, WPawn,
  816. 0, 0, 0, 0, 0, 0, 0, 0,
  817. 0, 0, 0, 0, 0, 0, 0, 0,
  818. 0, 0, 0, 0, 0, 0, 0, 0,
  819. 0, 0, 0, 0, 0, 0, 0, 0,
  820. BPawn, WRook, BPawn, BPawn, BPawn, WRook, BPawn, BPawn,
  821. BRook, 0, 0, BKing, 0, 0, 0, BRook
  822. ], Color.White)
  823. self.game = pos
  824. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  825. self.check(not test)
  826. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  827. self.check(not test)
  828. self.game.checkedMove(notationToMove("e1g1", Color.White))
  829. self.check(not test)
  830. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  831. self.check(not test)
  832. method testCheckedMoveKingCastleFalseThroughOwnPiece() =
  833. var test: bool
  834. let pos = initGame([
  835. WRook, 0, WBishop, WKing, WBishop, 0, 0, WRook,
  836. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  837. 0, 0, 0, 0, 0, 0, 0, 0,
  838. 0, 0, 0, 0, 0, 0, 0, 0,
  839. 0, 0, 0, 0, 0, 0, 0, 0,
  840. 0, 0, 0, 0, 0, 0, 0, 0,
  841. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  842. BRook, 0, BBishop, BKing, BBishop, 0, 0, BRook
  843. ], Color.White)
  844. self.game = pos
  845. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  846. self.check(not test)
  847. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  848. self.check(not test)
  849. self.game.checkedMove(notationToMove("e1g1", Color.White))
  850. self.check(not test)
  851. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  852. self.check(not test)
  853. method testCheckedMoveKingCastleFalseThroughEnemyPiece() =
  854. var test: bool
  855. let pos = initGame([
  856. WRook, 0, BBishop, WKing, BBishop, 0, 0, WRook,
  857. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  858. 0, 0, 0, 0, 0, 0, 0, 0,
  859. 0, 0, 0, 0, 0, 0, 0, 0,
  860. 0, 0, 0, 0, 0, 0, 0, 0,
  861. 0, 0, 0, 0, 0, 0, 0, 0,
  862. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  863. BRook, 0, WBishop, BKing, WBishop, 0, 0, BRook
  864. ], Color.White)
  865. self.game = pos
  866. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  867. self.check(not test)
  868. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  869. self.check(not test)
  870. self.game.checkedMove(notationToMove("e1g1", Color.White))
  871. self.check(not test)
  872. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  873. self.check(not test)
  874. method testCheckedMoveKingCastleFalseIntoOwnPiece() =
  875. var test: bool
  876. let pos = initGame([
  877. WRook, WBishop, 0, WKing, 0, WBishop, 0, WRook,
  878. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  879. 0, 0, 0, 0, 0, 0, 0, 0,
  880. 0, 0, 0, 0, 0, 0, 0, 0,
  881. 0, 0, 0, 0, 0, 0, 0, 0,
  882. 0, 0, 0, 0, 0, 0, 0, 0,
  883. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  884. BRook, BBishop, 0, BKing, 0, BBishop, 0, BRook
  885. ], Color.White)
  886. self.game = pos
  887. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  888. self.check(not test)
  889. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  890. self.check(not test)
  891. self.game.checkedMove(notationToMove("e1g1", Color.White))
  892. self.check(not test)
  893. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  894. self.check(not test)
  895. method testCheckedMoveKingCastleFalseIntoEnemyPiece() =
  896. var test: bool
  897. let pos = initGame([
  898. WRook, BBishop, 0, WKing, 0, BBishop, 0, WRook,
  899. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  900. 0, 0, 0, 0, 0, 0, 0, 0,
  901. 0, 0, 0, 0, 0, 0, 0, 0,
  902. 0, 0, 0, 0, 0, 0, 0, 0,
  903. 0, 0, 0, 0, 0, 0, 0, 0,
  904. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  905. BRook, WBishop, 0, BKing, 0, WBishop, 0, BRook
  906. ], Color.White)
  907. self.game = pos
  908. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  909. self.check(not test)
  910. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  911. self.check(not test)
  912. self.game.checkedMove(notationToMove("e1g1", Color.White))
  913. self.check(not test)
  914. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  915. self.check(not test)
  916. method testCheckedMoveKingWhite() =
  917. var test: bool
  918. let pos = initGame([
  919. 0, 0, 0, 0, 0, 0, 0, 0,
  920. 0, 0, 0, 0, 0, 0, 0, 0,
  921. 0, 0, 0, 0, 0, 0, 0, 0,
  922. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  923. 0, 0, BPawn, WKing, WPawn, 0, 0, 0,
  924. 0, 0, BEnPassant, 0, 0, 0, 0, 0,
  925. 0, 0, 0, 0, 0, 0, 0, 0,
  926. 0, 0, 0, 0, 0, 0, 0, 0,
  927. ], Color.White)
  928. let start = "e5"
  929. let legalMoves = ["f4", "d4", "f5", "f6", "e6", "d6"]
  930. let str = "abcdefgh"
  931. var move: string
  932. for cha in str:
  933. for num in 1..8:
  934. self.game = pos
  935. move = $cha & $num
  936. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  937. if move in legalMoves:
  938. self.check(test)
  939. else:
  940. self.check(not test)
  941. method testCheckedMoveKingBlack() =
  942. var test: bool
  943. let pos = initGame([
  944. 0, 0, 0, 0, 0, 0, 0, 0,
  945. 0, 0, 0, 0, 0, 0, 0, 0,
  946. 0, 0, 0, 0, 0, 0, 0, 0,
  947. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  948. 0, 0, WPawn, BKing, BPawn, 0, 0, 0,
  949. 0, 0, WEnPassant, 0, 0, 0, 0, 0,
  950. 0, 0, 0, 0, 0, 0, 0, 0,
  951. 0, 0, 0, 0, 0, 0, 0, 0,
  952. ], Color.Black)
  953. let start = "e5"
  954. let legalMoves = ["f4", "d4", "f5", "f6", "e4", "d6"]
  955. let str = "abcdefgh"
  956. var move: string
  957. for cha in str:
  958. for num in 1..8:
  959. self.game = pos
  960. move = $cha & $num
  961. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  962. if move in legalMoves:
  963. self.check(test)
  964. else:
  965. self.check(not test)
  966. ## Tests for Bishop moves
  967. method testCheckedMoveBishopWhite() =
  968. var test: bool
  969. let pos = initGame([
  970. 0, 0, 0, 0, 0, 0, 0, 0,
  971. 0, 0, 0, 0, 0, 0, 0, 0,
  972. 0, 0, 0, 0, 0, 0, 0, 0,
  973. 0, 0, 0, BEnPassant, 0, WPawn, 0, 0,
  974. 0, 0, 0, 0, WBishop, 0, 0, 0,
  975. 0, 0, 0, BPawn, 0, WEnPassant, 0, 0,
  976. 0, 0, 0, 0, 0, 0, 0, 0,
  977. 0, 0, 0, 0, 0, 0, 0, 0,
  978. ], Color.White)
  979. let start = "d5"
  980. let legalMoves = ["e4", "f3", "g2", "h1", "c6", "b7", "a8", "e6"]
  981. let str = "abcdefgh"
  982. var move: string
  983. for cha in str:
  984. for num in 1..8:
  985. self.game = pos
  986. move = $cha & $num
  987. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  988. if move in legalMoves:
  989. self.check(test)
  990. else:
  991. self.check(not test)
  992. method testCheckedMoveBishopBlack() =
  993. var test: bool
  994. let pos = initGame([
  995. 0, 0, 0, 0, 0, 0, 0, 0,
  996. 0, 0, 0, 0, 0, 0, 0, 0,
  997. 0, 0, 0, 0, 0, 0, 0, 0,
  998. 0, 0, 0, WEnPassant, 0, BPawn, 0, 0,
  999. 0, 0, 0, 0, BBishop, 0, 0, 0,
  1000. 0, 0, 0, WPawn, 0, BEnPassant, 0, 0,
  1001. 0, 0, 0, 0, 0, 0, 0, 0,
  1002. 0, 0, 0, 0, 0, 0, 0, 0,
  1003. ], Color.Black)
  1004. let start = "d5"
  1005. let legalMoves = ["e4", "f3", "g2", "h1", "c6", "b7", "a8", "e6"]
  1006. let str = "abcdefgh"
  1007. var move: string
  1008. for cha in str:
  1009. for num in 1..8:
  1010. self.game = pos
  1011. move = $cha & $num
  1012. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1013. if move in legalMoves:
  1014. self.check(test)
  1015. else:
  1016. self.check(not test)
  1017. ## Tests for Knight moves
  1018. method testCheckedMoveKnightWhite() =
  1019. var test: bool
  1020. let pos = initGame([
  1021. 0, 0, 0, 0, 0, 0, 0, 0,
  1022. 0, 0, 0, 0, 0, 0, 0, 0,
  1023. 0, 0, 0, WEnPassant, 0, WPawn, 0, 0,
  1024. 0, 0, BEnPassant, 0, 0, 0, 0, 0,
  1025. 0, 0, 0, 0, WKnight, 0, 0, 0,
  1026. 0, 0, BPawn, 0, 0, 0, 0, 0,
  1027. 0, 0, 0, 0, 0, 0, 0, 0,
  1028. 0, 0, 0, 0, 0, 0, 0, 0,
  1029. ], Color.White)
  1030. let start = "d5"
  1031. let legalMoves = ["f6", "f4", "e3", "b4", "b6", "c7", "e7"]
  1032. let str = "abcdefgh"
  1033. var move: string
  1034. for cha in str:
  1035. for num in 1..8:
  1036. self.game = pos
  1037. move = $cha & $num
  1038. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  1039. if move in legalMoves:
  1040. self.check(test)
  1041. else:
  1042. self.check(not test)
  1043. method testCheckedMoveKnightBlack() =
  1044. var test: bool
  1045. let pos = initGame([
  1046. 0, 0, 0, 0, 0, 0, 0, 0,
  1047. 0, 0, 0, 0, 0, 0, 0, 0,
  1048. 0, 0, 0, BEnPassant, 0, BPawn, 0, 0,
  1049. 0, 0, WEnPassant, 0, 0, 0, 0, 0,
  1050. 0, 0, 0, 0, BKnight, 0, 0, 0,
  1051. 0, 0, WPawn, 0, 0, 0, 0, 0,
  1052. 0, 0, 0, 0, 0, 0, 0, 0,
  1053. 0, 0, 0, 0, 0, 0, 0, 0,
  1054. ], Color.Black)
  1055. let start = "d5"
  1056. let legalMoves = ["f6", "f4", "e3", "b4", "b6", "c7", "e7"]
  1057. let str = "abcdefgh"
  1058. var move: string
  1059. for cha in str:
  1060. for num in 1..8:
  1061. self.game = pos
  1062. move = $cha & $num
  1063. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1064. if move in legalMoves:
  1065. self.check(test)
  1066. else:
  1067. self.check(not test)
  1068. ## Tests for Rook moves
  1069. method testCheckedMoveRookWhite() =
  1070. var test: bool
  1071. let pos = initGame([
  1072. 0, 0, 0, 0, 0, 0, 0, 0,
  1073. 0, 0, 0, 0, 0, 0, 0, 0,
  1074. 0, 0, 0, 0, 0, 0, 0, 0,
  1075. 0, 0, 0, 0, WPawn, 0, 0, 0,
  1076. 0, 0, 0, BPawn, WRook, WEnPassant, 0, 0,
  1077. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  1078. 0, 0, 0, 0, 0, 0, 0, 0,
  1079. 0, 0, 0, 0, 0, 0, 0, 0,
  1080. ], Color.White)
  1081. let start = "d5"
  1082. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5"]
  1083. let str = "abcdefgh"
  1084. var move: string
  1085. for cha in str:
  1086. for num in 1..8:
  1087. self.game = pos
  1088. move = $cha & $num
  1089. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  1090. if move in legalMoves:
  1091. self.check(test)
  1092. else:
  1093. self.check(not test)
  1094. method testCheckedMoveRookBlack() =
  1095. var test: bool
  1096. let pos = initGame([
  1097. 0, 0, 0, 0, 0, 0, 0, 0,
  1098. 0, 0, 0, 0, 0, 0, 0, 0,
  1099. 0, 0, 0, 0, 0, 0, 0, 0,
  1100. 0, 0, 0, 0, BPawn, 0, 0, 0,
  1101. 0, 0, 0, WPawn, BRook, BEnPassant, 0, 0,
  1102. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  1103. 0, 0, 0, 0, 0, 0, 0, 0,
  1104. 0, 0, 0, 0, 0, 0, 0, 0,
  1105. ], Color.Black)
  1106. let start = "d5"
  1107. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5"]
  1108. let str = "abcdefgh"
  1109. var move: string
  1110. for cha in str:
  1111. for num in 1..8:
  1112. self.game = pos
  1113. move = $cha & $num
  1114. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1115. if move in legalMoves:
  1116. self.check(test)
  1117. else:
  1118. self.check(not test)
  1119. ## Tests for Queen moves
  1120. method testCheckedMoveQueenWhite() =
  1121. var test: bool
  1122. let pos = initGame([
  1123. 0, 0, 0, 0, 0, 0, 0, 0,
  1124. 0, 0, 0, 0, 0, 0, 0, 0,
  1125. 0, 0, 0, 0, 0, 0, 0, 0,
  1126. 0, 0, 0, 0, WPawn, 0, 0, 0,
  1127. 0, 0, 0, BPawn, WQueen, WEnPassant, 0, 0,
  1128. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  1129. 0, 0, 0, 0, 0, 0, 0, 0,
  1130. 0, 0, 0, 0, 0, 0, 0, 0,
  1131. ], Color.White)
  1132. let start = "d5"
  1133. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5", "h1", "g2",
  1134. "f3", "e4", "c4", "b3", "a2", "g8", "f7", "e6", "c6", "b7", "a8"]
  1135. let str = "abcdefgh"
  1136. var move: string
  1137. for cha in str:
  1138. for num in 1..8:
  1139. self.game = pos
  1140. move = $cha & $num
  1141. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  1142. if move in legalMoves:
  1143. self.check(test)
  1144. else:
  1145. self.check(not test)
  1146. method testCheckedMoveQueenBlack() =
  1147. var test: bool
  1148. let pos = initGame([
  1149. 0, 0, 0, 0, 0, 0, 0, 0,
  1150. 0, 0, 0, 0, 0, 0, 0, 0,
  1151. 0, 0, 0, 0, 0, 0, 0, 0,
  1152. 0, 0, 0, 0, BPawn, 0, 0, 0,
  1153. 0, 0, 0, WPawn, BQueen, BEnPassant, 0, 0,
  1154. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  1155. 0, 0, 0, 0, 0, 0, 0, 0,
  1156. 0, 0, 0, 0, 0, 0, 0, 0,
  1157. ], Color.Black)
  1158. let start = "d5"
  1159. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5", "h1", "g2",
  1160. "f3", "e4", "c4", "b3", "a2", "g8", "f7", "e6", "c6", "b7", "a8"]
  1161. let str = "abcdefgh"
  1162. var move: string
  1163. for cha in str:
  1164. for num in 1..8:
  1165. self.game = pos
  1166. move = $cha & $num
  1167. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1168. if move in legalMoves:
  1169. self.check(test)
  1170. else:
  1171. self.check(not test)
  1172. when isMainModule:
  1173. einheit.runTests()