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.

1252 lines
45 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. method testIsDrawClaimableThreeFoldRepTrue() =
  255. self.setup()
  256. self.game.checkedMove(notationToMove("g1f3", Color.White))
  257. self.game.checkedMove(notationToMove("g8f6", Color.Black))
  258. self.game.checkedMove(notationToMove("f3g1", Color.White))
  259. self.game.checkedMove(notationToMove("f6g8", Color.Black))
  260. self.game.checkedMove(notationToMove("g1f3", Color.White))
  261. self.game.checkedMove(notationToMove("g8f6", Color.Black))
  262. self.game.checkedMove(notationToMove("f3g1", Color.White))
  263. self.game.checkedMove(notationToMove("f6g8", Color.Black))
  264. self.game.checkedMove(notationToMove("g1f3", Color.White))
  265. self.check(self.game.isDrawClaimable())
  266. method testIsDrawClaimableThreeFoldRepFalse() =
  267. self.setup()
  268. self.game.checkedMove(notationToMove("g1f3", Color.White))
  269. self.game.checkedMove(notationToMove("g8f6", Color.Black))
  270. self.game.checkedMove(notationToMove("f3g1", Color.White))
  271. self.game.checkedMove(notationToMove("f6g8", Color.Black))
  272. self.game.checkedMove(notationToMove("g1f3", Color.White))
  273. self.game.checkedMove(notationToMove("g8f6", Color.Black))
  274. self.game.checkedMove(notationToMove("f3g1", Color.White))
  275. self.game.checkedMove(notationToMove("f6g8", Color.Black))
  276. self.check(not self.game.isDrawClaimable())
  277. ## Tests for Pawn moves
  278. method testCheckedMovePawnSingleTrue() =
  279. self.setup()
  280. var test: bool
  281. for file in "abcdefgh":
  282. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  283. self.check(test)
  284. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  285. self.check(test)
  286. test = self.game.checkedMove(notationToMove($file & "3" & $file & "4", Color.White))
  287. self.check(test)
  288. test = self.game.checkedMove(notationToMove($file & "6" & $file & "5", Color.Black))
  289. self.check(test)
  290. method testCheckedMovePawnSingleFalseIntoEnemyPiece() =
  291. var test: bool
  292. let pos = initGame([
  293. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  294. 0, 0, 0, 0, 0, 0, 0, 0,
  295. 0, 0, 0, 0, 0, 0, 0, 0,
  296. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  297. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  298. 0, 0, 0, 0, 0, 0, 0, 0,
  299. 0, 0, 0, 0, 0, 0, 0, 0,
  300. BRook, 0, 0, BKing, 0, 0, 0, BRook
  301. ], Color.White)
  302. self.game = pos
  303. for file in "abcdefgh":
  304. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  305. self.check(not test)
  306. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  307. self.check(not test)
  308. method testCheckedMovePawnSingleFalseIntoOwnPiece() =
  309. var test: bool
  310. let pos = initGame([
  311. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  312. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  313. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  314. 0, 0, 0, 0, 0, 0, 0, 0,
  315. 0, 0, 0, 0, 0, 0, 0, 0,
  316. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  317. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  318. BRook, 0, 0, BKing, 0, 0, 0, BRook
  319. ], Color.White)
  320. self.game = pos
  321. for file in "abcdefgh":
  322. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  323. self.check(not test)
  324. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  325. self.check(not test)
  326. method testCheckedMovePawnDoubleTrue() =
  327. self.setup()
  328. var test: bool
  329. for file in "abcdefgh":
  330. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  331. self.check(test)
  332. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  333. self.check(test)
  334. method testCheckedMovePawnDoubleFalseAlreadyMoved() =
  335. var test: bool
  336. let pos = initGame([
  337. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  338. 0, 0, 0, 0, 0, 0, 0, 0,
  339. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  340. 0, 0, 0, 0, 0, 0, 0, 0,
  341. 0, 0, 0, 0, 0, 0, 0, 0,
  342. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  343. 0, 0, 0, 0, 0, 0, 0, 0,
  344. BRook, 0, 0, BKing, 0, 0, 0, BRook
  345. ], Color.White)
  346. self.game = pos
  347. for file in "abcdefgh":
  348. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  349. self.check(not test)
  350. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  351. self.check(not test)
  352. method testCheckedMovePawnDoubleFalseThroughEnemyPiece() =
  353. var test: bool
  354. let pos = initGame([
  355. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  356. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  357. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  358. 0, 0, 0, 0, 0, 0, 0, 0,
  359. 0, 0, 0, 0, 0, 0, 0, 0,
  360. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  361. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  362. BRook, 0, 0, BKing, 0, 0, 0, BRook
  363. ], Color.White)
  364. self.game = pos
  365. for file in "abcdefgh":
  366. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  367. self.check(not test)
  368. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  369. self.check(not test)
  370. method testCheckedMovePawnDoubleFalseThroughOwnPiece() =
  371. var test: bool
  372. let pos = initGame([
  373. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  374. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  375. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  376. 0, 0, 0, 0, 0, 0, 0, 0,
  377. 0, 0, 0, 0, 0, 0, 0, 0,
  378. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  379. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  380. BRook, 0, 0, BKing, 0, 0, 0, BRook
  381. ], Color.White)
  382. self.game = pos
  383. for file in "abcdefgh":
  384. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  385. self.check(not test)
  386. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  387. self.check(not test)
  388. method testCheckedMovePawnDoubleFalseIntoEnemyPiece() =
  389. var test: bool
  390. let pos = initGame([
  391. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  392. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  393. 0, 0, 0, 0, 0, 0, 0, 0,
  394. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  395. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  396. 0, 0, 0, 0, 0, 0, 0, 0,
  397. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  398. BRook, 0, 0, BKing, 0, 0, 0, BRook
  399. ], Color.White)
  400. self.game = pos
  401. for file in "abcdefgh":
  402. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  403. self.check(not test)
  404. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  405. self.check(not test)
  406. method testCheckedMovePawnDoubleFalseIntoOwnPiece() =
  407. var test: bool
  408. let pos = initGame([
  409. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  410. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  411. 0, 0, 0, 0, 0, 0, 0, 0,
  412. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  413. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  414. 0, 0, 0, 0, 0, 0, 0, 0,
  415. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  416. BRook, 0, 0, BKing, 0, 0, 0, BRook
  417. ], Color.White)
  418. self.game = pos
  419. for file in "abcdefgh":
  420. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  421. self.check(not test)
  422. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  423. self.check(not test)
  424. method testCheckedMovePawnCaptureTrueWhite() =
  425. var test: bool
  426. let pos = initGame([
  427. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  428. 0, 0, 0, 0, 0, 0, 0, 0,
  429. 0, 0, 0, 0, 0, 0, 0, 0,
  430. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  431. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  432. 0, 0, 0, 0, 0, 0, 0, 0,
  433. 0, 0, 0, 0, 0, 0, 0, 0,
  434. BRook, 0, 0, BKing, 0, 0, 0, BRook
  435. ], Color.White)
  436. var str: string
  437. str = "abcdefgh"
  438. for ind, file in str:
  439. if ind < len(str)-1:
  440. self.game = pos
  441. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  442. "5", Color.White))
  443. self.check(test)
  444. str.reverse()
  445. for ind, file in str:
  446. if ind < len(str)-1:
  447. self.game = pos
  448. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  449. "5", Color.White))
  450. self.check(test)
  451. method testCheckedMovePawnCaptureTrueBlack() =
  452. var test: bool
  453. let pos = initGame([
  454. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  455. 0, 0, 0, 0, 0, 0, 0, 0,
  456. 0, 0, 0, 0, 0, 0, 0, 0,
  457. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  458. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  459. 0, 0, 0, 0, 0, 0, 0, 0,
  460. 0, 0, 0, 0, 0, 0, 0, 0,
  461. BRook, 0, 0, BKing, 0, 0, 0, BRook
  462. ], Color.Black)
  463. var str: string
  464. str = "abcdefgh"
  465. for ind, file in str:
  466. if ind < len(str)-1:
  467. self.game = pos
  468. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  469. "4", Color.Black))
  470. self.check(test)
  471. str.reverse()
  472. for ind, file in str:
  473. if ind < len(str)-1:
  474. self.game = pos
  475. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  476. "4", Color.Black))
  477. self.check(test)
  478. method testCheckedMovePawnCaptureFalseWhite() =
  479. var test: bool
  480. let pos = initGame([
  481. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  482. 0, 0, 0, 0, 0, 0, 0, 0,
  483. 0, 0, 0, 0, 0, 0, 0, 0,
  484. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  485. 0, 0, 0, 0, 0, 0, 0, 0,
  486. 0, 0, 0, 0, 0, 0, 0, 0,
  487. 0, 0, 0, 0, 0, 0, 0, 0,
  488. BRook, 0, 0, BKing, 0, 0, 0, BRook
  489. ], Color.White)
  490. var str: string
  491. str = "abcdefgh"
  492. for ind, file in str:
  493. if ind < len(str)-1:
  494. self.game = pos
  495. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  496. "5", Color.White))
  497. self.check(not test)
  498. str.reverse()
  499. for ind, file in str:
  500. if ind < len(str)-1:
  501. self.game = pos
  502. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  503. "5", Color.White))
  504. self.check(not test)
  505. method testCheckedMovePawnCaptureFalseBlack() =
  506. var test: bool
  507. let pos = initGame([
  508. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  509. 0, 0, 0, 0, 0, 0, 0, 0,
  510. 0, 0, 0, 0, 0, 0, 0, 0,
  511. 0, 0, 0, 0, 0, 0, 0, 0,
  512. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  513. 0, 0, 0, 0, 0, 0, 0, 0,
  514. 0, 0, 0, 0, 0, 0, 0, 0,
  515. BRook, 0, 0, BKing, 0, 0, 0, BRook
  516. ], Color.Black)
  517. var str: string
  518. str = "abcdefgh"
  519. for ind, file in str:
  520. if ind < len(str)-1:
  521. self.game = pos
  522. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  523. "4", Color.Black))
  524. self.check(not test)
  525. str.reverse()
  526. for ind, file in str:
  527. if ind < len(str)-1:
  528. self.game = pos
  529. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  530. "4", Color.Black))
  531. self.check(not test)
  532. method testCheckedMovePawnEnPassantTrueWhite() =
  533. var test: bool
  534. let pos = initGame([
  535. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  536. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  537. 0, 0, 0, 0, 0, 0, 0, 0,
  538. 0, 0, 0, 0, 0, 0, 0, 0,
  539. 0, 0, 0, 0, 0, 0, 0, 0,
  540. 0, 0, 0, 0, 0, 0, 0, 0,
  541. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  542. BRook, 0, 0, BKing, 0, 0, 0, BRook
  543. ], Color.White)
  544. var str: string
  545. str = "abcdefgh"
  546. for ind, file in str:
  547. if ind < len(str)-1:
  548. self.game = pos
  549. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  550. self.check(test)
  551. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  552. self.check(test)
  553. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  554. self.check(test)
  555. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  556. ind+1] & "5", Color.Black))
  557. self.check(test)
  558. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  559. "6", Color.White))
  560. self.check(test)
  561. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "5")))
  562. self.check(test)
  563. str.reverse()
  564. for ind, file in str:
  565. if ind < len(str)-1:
  566. self.game = pos
  567. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  568. self.check(test)
  569. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  570. self.check(test)
  571. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  572. self.check(test)
  573. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  574. ind+1] & "5", Color.Black))
  575. self.check(test)
  576. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  577. "6", Color.White))
  578. self.check(test)
  579. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "5")))
  580. self.check(test)
  581. method testCheckedMovePawnEnPassantTrueBlack() =
  582. var test: bool
  583. let pos = initGame([
  584. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  585. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  586. 0, 0, 0, 0, 0, 0, 0, 0,
  587. 0, 0, 0, 0, 0, 0, 0, 0,
  588. 0, 0, 0, 0, 0, 0, 0, 0,
  589. 0, 0, 0, 0, 0, 0, 0, 0,
  590. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  591. BRook, 0, 0, BKing, 0, 0, 0, BRook
  592. ], Color.Black)
  593. var str: string
  594. str = "abcdefgh"
  595. for ind, file in str:
  596. if ind < len(str)-1:
  597. self.game = pos
  598. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  599. self.check(test)
  600. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  601. self.check(test)
  602. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  603. self.check(test)
  604. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  605. ind+1] & "4", Color.White))
  606. self.check(test)
  607. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  608. "3", Color.Black))
  609. self.check(test)
  610. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "4")))
  611. self.check(test)
  612. str.reverse()
  613. for ind, file in str:
  614. if ind < len(str)-1:
  615. self.game = pos
  616. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  617. self.check(test)
  618. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  619. self.check(test)
  620. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  621. self.check(test)
  622. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  623. ind+1] & "4", Color.White))
  624. self.check(test)
  625. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  626. "3", Color.Black))
  627. self.check(test)
  628. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "4")))
  629. self.check(test)
  630. method testCheckedMovePawnEnPassantFalseWhite() =
  631. var test: bool
  632. let pos = initGame([
  633. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  634. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  635. 0, 0, 0, 0, 0, 0, 0, 0,
  636. 0, 0, 0, 0, 0, 0, 0, 0,
  637. 0, 0, 0, 0, 0, 0, 0, 0,
  638. 0, 0, 0, 0, 0, 0, 0, 0,
  639. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  640. BRook, 0, 0, BKing, 0, 0, 0, BRook
  641. ], Color.White)
  642. var str: string
  643. str = "abcdefgh"
  644. for ind, file in str:
  645. if ind < len(str)-1:
  646. self.game = pos
  647. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  648. self.check(test)
  649. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  650. ind+1] & "5", Color.Black))
  651. self.check(test)
  652. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  653. self.check(test)
  654. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  655. self.check(test)
  656. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  657. "6", Color.White))
  658. self.check(not test)
  659. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "5")))
  660. self.check(not test)
  661. str.reverse()
  662. for ind, file in str:
  663. if ind < len(str)-1:
  664. self.game = pos
  665. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  666. self.check(test)
  667. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  668. ind+1] & "5", Color.Black))
  669. self.check(test)
  670. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  671. self.check(test)
  672. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  673. self.check(test)
  674. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  675. "6", Color.White))
  676. self.check(not test)
  677. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "5")))
  678. self.check(not test)
  679. method testCheckedMovePawnEnPassantFalseBlack() =
  680. var test: bool
  681. let pos = initGame([
  682. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  683. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  684. 0, 0, 0, 0, 0, 0, 0, 0,
  685. 0, 0, 0, 0, 0, 0, 0, 0,
  686. 0, 0, 0, 0, 0, 0, 0, 0,
  687. 0, 0, 0, 0, 0, 0, 0, 0,
  688. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  689. BRook, 0, 0, BKing, 0, 0, 0, BRook
  690. ], Color.Black)
  691. var str: string
  692. str = "abcdefgh"
  693. for ind, file in str:
  694. if ind < len(str)-1:
  695. self.game = pos
  696. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  697. self.check(test)
  698. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  699. ind+1] & "4", Color.White))
  700. self.check(test)
  701. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  702. self.check(test)
  703. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  704. self.check(test)
  705. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  706. "3", Color.Black))
  707. self.check(not test)
  708. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "4")))
  709. self.check(not test)
  710. str.reverse()
  711. for ind, file in str:
  712. if ind < len(str)-1:
  713. self.game = pos
  714. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  715. self.check(test)
  716. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  717. ind+1] & "4", Color.White))
  718. self.check(test)
  719. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  720. self.check(test)
  721. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  722. self.check(test)
  723. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  724. "3", Color.Black))
  725. self.check(not test)
  726. test = (0 == self.game.board.getField(fieldToInd($str[ind+1] & "4")))
  727. self.check(not test)
  728. ## Tests for King moves
  729. method testCheckedMoveKingCastleTrueWhite() =
  730. var test: bool
  731. let pos = initGame([
  732. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  733. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  734. 0, 0, 0, 0, 0, 0, 0, 0,
  735. 0, 0, 0, 0, 0, 0, 0, 0,
  736. 0, 0, 0, 0, 0, 0, 0, 0,
  737. 0, 0, 0, 0, 0, 0, 0, 0,
  738. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  739. BRook, 0, 0, BKing, 0, 0, 0, BRook
  740. ], Color.White)
  741. self.game = pos
  742. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  743. self.check(test)
  744. self.game = pos
  745. self.game.checkedMove(notationToMove("e1g1", Color.White))
  746. self.check(test)
  747. method testCheckedMoveKingCastleTrueBlack() =
  748. var test: bool
  749. let pos = initGame([
  750. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  751. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  752. 0, 0, 0, 0, 0, 0, 0, 0,
  753. 0, 0, 0, 0, 0, 0, 0, 0,
  754. 0, 0, 0, 0, 0, 0, 0, 0,
  755. 0, 0, 0, 0, 0, 0, 0, 0,
  756. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  757. BRook, 0, 0, BKing, 0, 0, 0, BRook
  758. ], Color.Black)
  759. self.game = pos
  760. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  761. self.check(test)
  762. self.game = pos
  763. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  764. self.check(test)
  765. method testCheckedMoveKingCastleFalseAlreadyMovedKing() =
  766. var test: bool
  767. let pos = initGame([
  768. WRook, 0, 0, 0, WKing, 0, 0, WRook,
  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. BRook, 0, 0, 0, BKing, 0, 0, BRook
  776. ], Color.White)
  777. self.game.checkedMove(notationToMove("d1e1", Color.White))
  778. self.game.checkedMove(notationToMove("d8e8", Color.White))
  779. self.game = pos
  780. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  781. self.check(not test)
  782. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  783. self.check(not test)
  784. self.game.checkedMove(notationToMove("e1g1", Color.White))
  785. self.check(not test)
  786. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  787. self.check(not test)
  788. method testCheckedMoveKingCastleFalseAlreadyMovedRook() =
  789. var test: bool
  790. let pos = initGame([
  791. 0, WRook, 0, WKing, 0, 0, WRook, 0,
  792. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  793. 0, 0, 0, 0, 0, 0, 0, 0,
  794. 0, 0, 0, 0, 0, 0, 0, 0,
  795. 0, 0, 0, 0, 0, 0, 0, 0,
  796. 0, 0, 0, 0, 0, 0, 0, 0,
  797. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  798. 0, BRook, 0, BKing, 0, 0, BRook, 0
  799. ], Color.White)
  800. self.game = pos
  801. self.game.checkedMove(notationToMove("b1a1", Color.White))
  802. self.game.checkedMove(notationToMove("b8a8", Color.Black))
  803. self.game.checkedMove(notationToMove("g1h1", Color.White))
  804. self.game.checkedMove(notationToMove("g8h8", Color.Black))
  805. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  806. self.check(not test)
  807. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  808. self.check(not test)
  809. self.game.checkedMove(notationToMove("e1g1", Color.White))
  810. self.check(not test)
  811. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  812. self.check(not test)
  813. method testCheckedMoveKingCastleFalseThroughCheck() =
  814. var test: bool
  815. let pos = initGame([
  816. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  817. WPawn, WPawn, BRook, WPawn, BRook, WPawn, WPawn, WPawn,
  818. 0, 0, 0, 0, 0, 0, 0, 0,
  819. 0, 0, 0, 0, 0, 0, 0, 0,
  820. 0, 0, 0, 0, 0, 0, 0, 0,
  821. 0, 0, 0, 0, 0, 0, 0, 0,
  822. BPawn, BPawn, WRook, BPawn, WRook, BPawn, BPawn, BPawn,
  823. BRook, 0, 0, BKing, 0, 0, 0, BRook
  824. ], Color.White)
  825. self.game = pos
  826. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  827. self.check(not test)
  828. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  829. self.check(not test)
  830. self.game.checkedMove(notationToMove("e1g1", Color.White))
  831. self.check(not test)
  832. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  833. self.check(not test)
  834. method testCheckedMoveKingCastleFalseIntoCheck() =
  835. var test: bool
  836. let pos = initGame([
  837. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  838. WPawn, BRook, WPawn, WPawn, WPawn, BRook, WPawn, WPawn,
  839. 0, 0, 0, 0, 0, 0, 0, 0,
  840. 0, 0, 0, 0, 0, 0, 0, 0,
  841. 0, 0, 0, 0, 0, 0, 0, 0,
  842. 0, 0, 0, 0, 0, 0, 0, 0,
  843. BPawn, WRook, BPawn, BPawn, BPawn, WRook, BPawn, BPawn,
  844. BRook, 0, 0, BKing, 0, 0, 0, BRook
  845. ], Color.White)
  846. self.game = pos
  847. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  848. self.check(not test)
  849. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  850. self.check(not test)
  851. self.game.checkedMove(notationToMove("e1g1", Color.White))
  852. self.check(not test)
  853. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  854. self.check(not test)
  855. method testCheckedMoveKingCastleFalseThroughOwnPiece() =
  856. var test: bool
  857. let pos = initGame([
  858. WRook, 0, WBishop, WKing, WBishop, 0, 0, WRook,
  859. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  860. 0, 0, 0, 0, 0, 0, 0, 0,
  861. 0, 0, 0, 0, 0, 0, 0, 0,
  862. 0, 0, 0, 0, 0, 0, 0, 0,
  863. 0, 0, 0, 0, 0, 0, 0, 0,
  864. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  865. BRook, 0, BBishop, BKing, BBishop, 0, 0, BRook
  866. ], Color.White)
  867. self.game = pos
  868. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  869. self.check(not test)
  870. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  871. self.check(not test)
  872. self.game.checkedMove(notationToMove("e1g1", Color.White))
  873. self.check(not test)
  874. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  875. self.check(not test)
  876. method testCheckedMoveKingCastleFalseThroughEnemyPiece() =
  877. var test: bool
  878. let pos = initGame([
  879. WRook, 0, BBishop, WKing, BBishop, 0, 0, WRook,
  880. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  881. 0, 0, 0, 0, 0, 0, 0, 0,
  882. 0, 0, 0, 0, 0, 0, 0, 0,
  883. 0, 0, 0, 0, 0, 0, 0, 0,
  884. 0, 0, 0, 0, 0, 0, 0, 0,
  885. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  886. BRook, 0, WBishop, BKing, WBishop, 0, 0, BRook
  887. ], Color.White)
  888. self.game = pos
  889. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  890. self.check(not test)
  891. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  892. self.check(not test)
  893. self.game.checkedMove(notationToMove("e1g1", Color.White))
  894. self.check(not test)
  895. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  896. self.check(not test)
  897. method testCheckedMoveKingCastleFalseIntoOwnPiece() =
  898. var test: bool
  899. let pos = initGame([
  900. WRook, WBishop, 0, WKing, 0, WBishop, 0, WRook,
  901. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  902. 0, 0, 0, 0, 0, 0, 0, 0,
  903. 0, 0, 0, 0, 0, 0, 0, 0,
  904. 0, 0, 0, 0, 0, 0, 0, 0,
  905. 0, 0, 0, 0, 0, 0, 0, 0,
  906. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  907. BRook, BBishop, 0, BKing, 0, BBishop, 0, BRook
  908. ], Color.White)
  909. self.game = pos
  910. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  911. self.check(not test)
  912. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  913. self.check(not test)
  914. self.game.checkedMove(notationToMove("e1g1", Color.White))
  915. self.check(not test)
  916. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  917. self.check(not test)
  918. method testCheckedMoveKingCastleFalseIntoEnemyPiece() =
  919. var test: bool
  920. let pos = initGame([
  921. WRook, BBishop, 0, WKing, 0, BBishop, 0, WRook,
  922. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  923. 0, 0, 0, 0, 0, 0, 0, 0,
  924. 0, 0, 0, 0, 0, 0, 0, 0,
  925. 0, 0, 0, 0, 0, 0, 0, 0,
  926. 0, 0, 0, 0, 0, 0, 0, 0,
  927. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  928. BRook, WBishop, 0, BKing, 0, WBishop, 0, BRook
  929. ], Color.White)
  930. self.game = pos
  931. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  932. self.check(not test)
  933. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  934. self.check(not test)
  935. self.game.checkedMove(notationToMove("e1g1", Color.White))
  936. self.check(not test)
  937. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  938. self.check(not test)
  939. method testCheckedMoveKingWhite() =
  940. var test: bool
  941. let pos = initGame([
  942. 0, 0, 0, 0, 0, 0, 0, 0,
  943. 0, 0, 0, 0, 0, 0, 0, 0,
  944. 0, 0, 0, 0, 0, 0, 0, 0,
  945. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  946. 0, 0, BPawn, WKing, WPawn, 0, 0, 0,
  947. 0, 0, BEnPassant, 0, 0, 0, 0, 0,
  948. 0, 0, 0, 0, 0, 0, 0, 0,
  949. 0, 0, 0, 0, 0, 0, 0, 0,
  950. ], Color.White)
  951. let start = "e5"
  952. let legalMoves = ["f4", "d4", "f5", "f6", "e6", "d6"]
  953. let str = "abcdefgh"
  954. var move: string
  955. for cha in str:
  956. for num in 1..8:
  957. self.game = pos
  958. move = $cha & $num
  959. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  960. if move in legalMoves:
  961. self.check(test)
  962. else:
  963. self.check(not test)
  964. method testCheckedMoveKingBlack() =
  965. var test: bool
  966. let pos = initGame([
  967. 0, 0, 0, 0, 0, 0, 0, 0,
  968. 0, 0, 0, 0, 0, 0, 0, 0,
  969. 0, 0, 0, 0, 0, 0, 0, 0,
  970. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  971. 0, 0, WPawn, BKing, BPawn, 0, 0, 0,
  972. 0, 0, WEnPassant, 0, 0, 0, 0, 0,
  973. 0, 0, 0, 0, 0, 0, 0, 0,
  974. 0, 0, 0, 0, 0, 0, 0, 0,
  975. ], Color.Black)
  976. let start = "e5"
  977. let legalMoves = ["f4", "d4", "f5", "f6", "e4", "d6"]
  978. let str = "abcdefgh"
  979. var move: string
  980. for cha in str:
  981. for num in 1..8:
  982. self.game = pos
  983. move = $cha & $num
  984. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  985. if move in legalMoves:
  986. self.check(test)
  987. else:
  988. self.check(not test)
  989. ## Tests for Bishop moves
  990. method testCheckedMoveBishopWhite() =
  991. var test: bool
  992. let pos = initGame([
  993. 0, 0, 0, 0, 0, 0, 0, 0,
  994. 0, 0, 0, 0, 0, 0, 0, 0,
  995. 0, 0, 0, 0, 0, 0, 0, 0,
  996. 0, 0, 0, BEnPassant, 0, WPawn, 0, 0,
  997. 0, 0, 0, 0, WBishop, 0, 0, 0,
  998. 0, 0, 0, BPawn, 0, WEnPassant, 0, 0,
  999. 0, 0, 0, 0, 0, 0, 0, 0,
  1000. 0, 0, 0, 0, 0, 0, 0, 0,
  1001. ], Color.White)
  1002. let start = "d5"
  1003. let legalMoves = ["e4", "f3", "g2", "h1", "c6", "b7", "a8", "e6"]
  1004. let str = "abcdefgh"
  1005. var move: string
  1006. for cha in str:
  1007. for num in 1..8:
  1008. self.game = pos
  1009. move = $cha & $num
  1010. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  1011. if move in legalMoves:
  1012. self.check(test)
  1013. else:
  1014. self.check(not test)
  1015. method testCheckedMoveBishopBlack() =
  1016. var test: bool
  1017. let pos = initGame([
  1018. 0, 0, 0, 0, 0, 0, 0, 0,
  1019. 0, 0, 0, 0, 0, 0, 0, 0,
  1020. 0, 0, 0, 0, 0, 0, 0, 0,
  1021. 0, 0, 0, WEnPassant, 0, BPawn, 0, 0,
  1022. 0, 0, 0, 0, BBishop, 0, 0, 0,
  1023. 0, 0, 0, WPawn, 0, BEnPassant, 0, 0,
  1024. 0, 0, 0, 0, 0, 0, 0, 0,
  1025. 0, 0, 0, 0, 0, 0, 0, 0,
  1026. ], Color.Black)
  1027. let start = "d5"
  1028. let legalMoves = ["e4", "f3", "g2", "h1", "c6", "b7", "a8", "e6"]
  1029. let str = "abcdefgh"
  1030. var move: string
  1031. for cha in str:
  1032. for num in 1..8:
  1033. self.game = pos
  1034. move = $cha & $num
  1035. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1036. if move in legalMoves:
  1037. self.check(test)
  1038. else:
  1039. self.check(not test)
  1040. ## Tests for Knight moves
  1041. method testCheckedMoveKnightWhite() =
  1042. var test: bool
  1043. let pos = initGame([
  1044. 0, 0, 0, 0, 0, 0, 0, 0,
  1045. 0, 0, 0, 0, 0, 0, 0, 0,
  1046. 0, 0, 0, WEnPassant, 0, WPawn, 0, 0,
  1047. 0, 0, BEnPassant, 0, 0, 0, 0, 0,
  1048. 0, 0, 0, 0, WKnight, 0, 0, 0,
  1049. 0, 0, BPawn, 0, 0, 0, 0, 0,
  1050. 0, 0, 0, 0, 0, 0, 0, 0,
  1051. 0, 0, 0, 0, 0, 0, 0, 0,
  1052. ], Color.White)
  1053. let start = "d5"
  1054. let legalMoves = ["f6", "f4", "e3", "b4", "b6", "c7", "e7"]
  1055. let str = "abcdefgh"
  1056. var move: string
  1057. for cha in str:
  1058. for num in 1..8:
  1059. self.game = pos
  1060. move = $cha & $num
  1061. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  1062. if move in legalMoves:
  1063. self.check(test)
  1064. else:
  1065. self.check(not test)
  1066. method testCheckedMoveKnightBlack() =
  1067. var test: bool
  1068. let pos = initGame([
  1069. 0, 0, 0, 0, 0, 0, 0, 0,
  1070. 0, 0, 0, 0, 0, 0, 0, 0,
  1071. 0, 0, 0, BEnPassant, 0, BPawn, 0, 0,
  1072. 0, 0, WEnPassant, 0, 0, 0, 0, 0,
  1073. 0, 0, 0, 0, BKnight, 0, 0, 0,
  1074. 0, 0, WPawn, 0, 0, 0, 0, 0,
  1075. 0, 0, 0, 0, 0, 0, 0, 0,
  1076. 0, 0, 0, 0, 0, 0, 0, 0,
  1077. ], Color.Black)
  1078. let start = "d5"
  1079. let legalMoves = ["f6", "f4", "e3", "b4", "b6", "c7", "e7"]
  1080. let str = "abcdefgh"
  1081. var move: string
  1082. for cha in str:
  1083. for num in 1..8:
  1084. self.game = pos
  1085. move = $cha & $num
  1086. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1087. if move in legalMoves:
  1088. self.check(test)
  1089. else:
  1090. self.check(not test)
  1091. ## Tests for Rook moves
  1092. method testCheckedMoveRookWhite() =
  1093. var test: bool
  1094. let pos = initGame([
  1095. 0, 0, 0, 0, 0, 0, 0, 0,
  1096. 0, 0, 0, 0, 0, 0, 0, 0,
  1097. 0, 0, 0, 0, 0, 0, 0, 0,
  1098. 0, 0, 0, 0, WPawn, 0, 0, 0,
  1099. 0, 0, 0, BPawn, WRook, WEnPassant, 0, 0,
  1100. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  1101. 0, 0, 0, 0, 0, 0, 0, 0,
  1102. 0, 0, 0, 0, 0, 0, 0, 0,
  1103. ], Color.White)
  1104. let start = "d5"
  1105. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5"]
  1106. let str = "abcdefgh"
  1107. var move: string
  1108. for cha in str:
  1109. for num in 1..8:
  1110. self.game = pos
  1111. move = $cha & $num
  1112. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  1113. if move in legalMoves:
  1114. self.check(test)
  1115. else:
  1116. self.check(not test)
  1117. method testCheckedMoveRookBlack() =
  1118. var test: bool
  1119. let pos = initGame([
  1120. 0, 0, 0, 0, 0, 0, 0, 0,
  1121. 0, 0, 0, 0, 0, 0, 0, 0,
  1122. 0, 0, 0, 0, 0, 0, 0, 0,
  1123. 0, 0, 0, 0, BPawn, 0, 0, 0,
  1124. 0, 0, 0, WPawn, BRook, BEnPassant, 0, 0,
  1125. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  1126. 0, 0, 0, 0, 0, 0, 0, 0,
  1127. 0, 0, 0, 0, 0, 0, 0, 0,
  1128. ], Color.Black)
  1129. let start = "d5"
  1130. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5"]
  1131. let str = "abcdefgh"
  1132. var move: string
  1133. for cha in str:
  1134. for num in 1..8:
  1135. self.game = pos
  1136. move = $cha & $num
  1137. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1138. if move in legalMoves:
  1139. self.check(test)
  1140. else:
  1141. self.check(not test)
  1142. ## Tests for Queen moves
  1143. method testCheckedMoveQueenWhite() =
  1144. var test: bool
  1145. let pos = initGame([
  1146. 0, 0, 0, 0, 0, 0, 0, 0,
  1147. 0, 0, 0, 0, 0, 0, 0, 0,
  1148. 0, 0, 0, 0, 0, 0, 0, 0,
  1149. 0, 0, 0, 0, WPawn, 0, 0, 0,
  1150. 0, 0, 0, BPawn, WQueen, WEnPassant, 0, 0,
  1151. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  1152. 0, 0, 0, 0, 0, 0, 0, 0,
  1153. 0, 0, 0, 0, 0, 0, 0, 0,
  1154. ], Color.White)
  1155. let start = "d5"
  1156. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5", "h1", "g2",
  1157. "f3", "e4", "c4", "b3", "a2", "g8", "f7", "e6", "c6", "b7", "a8"]
  1158. let str = "abcdefgh"
  1159. var move: string
  1160. for cha in str:
  1161. for num in 1..8:
  1162. self.game = pos
  1163. move = $cha & $num
  1164. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  1165. if move in legalMoves:
  1166. self.check(test)
  1167. else:
  1168. self.check(not test)
  1169. method testCheckedMoveQueenBlack() =
  1170. var test: bool
  1171. let pos = initGame([
  1172. 0, 0, 0, 0, 0, 0, 0, 0,
  1173. 0, 0, 0, 0, 0, 0, 0, 0,
  1174. 0, 0, 0, 0, 0, 0, 0, 0,
  1175. 0, 0, 0, 0, BPawn, 0, 0, 0,
  1176. 0, 0, 0, WPawn, BQueen, BEnPassant, 0, 0,
  1177. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  1178. 0, 0, 0, 0, 0, 0, 0, 0,
  1179. 0, 0, 0, 0, 0, 0, 0, 0,
  1180. ], Color.Black)
  1181. let start = "d5"
  1182. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5", "h1", "g2",
  1183. "f3", "e4", "c4", "b3", "a2", "g8", "f7", "e6", "c6", "b7", "a8"]
  1184. let str = "abcdefgh"
  1185. var move: string
  1186. for cha in str:
  1187. for num in 1..8:
  1188. self.game = pos
  1189. move = $cha & $num
  1190. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1191. if move in legalMoves:
  1192. self.check(test)
  1193. else:
  1194. self.check(not test)
  1195. when isMainModule:
  1196. einheit.runTests()