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.

1067 lines
39 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. ## Tests for Pawn moves
  97. method testCheckedMovePawnSingleTrue() =
  98. self.setup()
  99. var test: bool
  100. for file in "abcdefgh":
  101. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  102. self.check(test)
  103. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  104. self.check(test)
  105. test = self.game.checkedMove(notationToMove($file & "3" & $file & "4", Color.White))
  106. self.check(test)
  107. test = self.game.checkedMove(notationToMove($file & "6" & $file & "5", Color.Black))
  108. self.check(test)
  109. method testCheckedMovePawnSingleFalseIntoEnemyPiece() =
  110. var test: bool
  111. let pos = initGame([
  112. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  113. 0, 0, 0, 0, 0, 0, 0, 0,
  114. 0, 0, 0, 0, 0, 0, 0, 0,
  115. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  116. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  117. 0, 0, 0, 0, 0, 0, 0, 0,
  118. 0, 0, 0, 0, 0, 0, 0, 0,
  119. BRook, 0, 0, BKing, 0, 0, 0, BRook
  120. ], Color.White)
  121. self.game = pos
  122. for file in "abcdefgh":
  123. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  124. self.check(not test)
  125. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  126. self.check(not test)
  127. method testCheckedMovePawnSingleFalseIntoOwnPiece() =
  128. var test: bool
  129. let pos = initGame([
  130. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  131. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  132. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  133. 0, 0, 0, 0, 0, 0, 0, 0,
  134. 0, 0, 0, 0, 0, 0, 0, 0,
  135. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  136. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  137. BRook, 0, 0, BKing, 0, 0, 0, BRook
  138. ], Color.White)
  139. self.game = pos
  140. for file in "abcdefgh":
  141. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  142. self.check(not test)
  143. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  144. self.check(not test)
  145. method testCheckedMovePawnDoubleTrue() =
  146. self.setup()
  147. var test: bool
  148. for file in "abcdefgh":
  149. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  150. self.check(test)
  151. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  152. self.check(test)
  153. method testCheckedMovePawnDoubleFalseAlreadyMoved() =
  154. var test: bool
  155. let pos = initGame([
  156. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  157. 0, 0, 0, 0, 0, 0, 0, 0,
  158. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  159. 0, 0, 0, 0, 0, 0, 0, 0,
  160. 0, 0, 0, 0, 0, 0, 0, 0,
  161. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  162. 0, 0, 0, 0, 0, 0, 0, 0,
  163. BRook, 0, 0, BKing, 0, 0, 0, BRook
  164. ], Color.White)
  165. self.game = pos
  166. for file in "abcdefgh":
  167. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  168. self.check(not test)
  169. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  170. self.check(not test)
  171. method testCheckedMovePawnDoubleFalseThroughEnemyPiece() =
  172. var test: bool
  173. let pos = initGame([
  174. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  175. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  176. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  177. 0, 0, 0, 0, 0, 0, 0, 0,
  178. 0, 0, 0, 0, 0, 0, 0, 0,
  179. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  180. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  181. BRook, 0, 0, BKing, 0, 0, 0, BRook
  182. ], Color.White)
  183. self.game = pos
  184. for file in "abcdefgh":
  185. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  186. self.check(not test)
  187. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  188. self.check(not test)
  189. method testCheckedMovePawnDoubleFalseThroughOwnPiece() =
  190. var test: bool
  191. let pos = initGame([
  192. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  193. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  194. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  195. 0, 0, 0, 0, 0, 0, 0, 0,
  196. 0, 0, 0, 0, 0, 0, 0, 0,
  197. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  198. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  199. BRook, 0, 0, BKing, 0, 0, 0, BRook
  200. ], Color.White)
  201. self.game = pos
  202. for file in "abcdefgh":
  203. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  204. self.check(not test)
  205. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  206. self.check(not test)
  207. method testCheckedMovePawnDoubleFalseIntoEnemyPiece() =
  208. var test: bool
  209. let pos = initGame([
  210. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  211. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  212. 0, 0, 0, 0, 0, 0, 0, 0,
  213. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  214. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  215. 0, 0, 0, 0, 0, 0, 0, 0,
  216. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  217. BRook, 0, 0, BKing, 0, 0, 0, BRook
  218. ], Color.White)
  219. self.game = pos
  220. for file in "abcdefgh":
  221. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  222. self.check(not test)
  223. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  224. self.check(not test)
  225. method testCheckedMovePawnDoubleFalseIntoOwnPiece() =
  226. var test: bool
  227. let pos = initGame([
  228. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  229. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  230. 0, 0, 0, 0, 0, 0, 0, 0,
  231. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  232. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  233. 0, 0, 0, 0, 0, 0, 0, 0,
  234. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  235. BRook, 0, 0, BKing, 0, 0, 0, BRook
  236. ], Color.White)
  237. self.game = pos
  238. for file in "abcdefgh":
  239. test = self.game.checkedMove(notationToMove($file & "3" & $file & "5", Color.White))
  240. self.check(not test)
  241. test = self.game.checkedMove(notationToMove($file & "6" & $file & "4", Color.Black))
  242. self.check(not test)
  243. method testCheckedMovePawnCaptureTrueWhite() =
  244. var test: bool
  245. let pos = initGame([
  246. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  247. 0, 0, 0, 0, 0, 0, 0, 0,
  248. 0, 0, 0, 0, 0, 0, 0, 0,
  249. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  250. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  251. 0, 0, 0, 0, 0, 0, 0, 0,
  252. 0, 0, 0, 0, 0, 0, 0, 0,
  253. BRook, 0, 0, BKing, 0, 0, 0, BRook
  254. ], Color.White)
  255. var str: string
  256. str = "abcdefgh"
  257. for ind, file in str:
  258. if ind < len(str)-1:
  259. self.game = pos
  260. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  261. "5", Color.White))
  262. self.check(test)
  263. str.reverse()
  264. for ind, file in str:
  265. if ind < len(str)-1:
  266. self.game = pos
  267. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  268. "5", Color.White))
  269. self.check(test)
  270. method testCheckedMovePawnCaptureTrueBlack() =
  271. var test: bool
  272. let pos = initGame([
  273. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  274. 0, 0, 0, 0, 0, 0, 0, 0,
  275. 0, 0, 0, 0, 0, 0, 0, 0,
  276. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  277. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  278. 0, 0, 0, 0, 0, 0, 0, 0,
  279. 0, 0, 0, 0, 0, 0, 0, 0,
  280. BRook, 0, 0, BKing, 0, 0, 0, BRook
  281. ], Color.Black)
  282. var str: string
  283. str = "abcdefgh"
  284. for ind, file in str:
  285. if ind < len(str)-1:
  286. self.game = pos
  287. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  288. "4", Color.Black))
  289. self.check(test)
  290. str.reverse()
  291. for ind, file in str:
  292. if ind < len(str)-1:
  293. self.game = pos
  294. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  295. "4", Color.Black))
  296. self.check(test)
  297. method testCheckedMovePawnCaptureFalseWhite() =
  298. var test: bool
  299. let pos = initGame([
  300. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  301. 0, 0, 0, 0, 0, 0, 0, 0,
  302. 0, 0, 0, 0, 0, 0, 0, 0,
  303. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  304. 0, 0, 0, 0, 0, 0, 0, 0,
  305. 0, 0, 0, 0, 0, 0, 0, 0,
  306. 0, 0, 0, 0, 0, 0, 0, 0,
  307. BRook, 0, 0, BKing, 0, 0, 0, BRook
  308. ], Color.White)
  309. var str: string
  310. str = "abcdefgh"
  311. for ind, file in str:
  312. if ind < len(str)-1:
  313. self.game = pos
  314. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  315. "5", Color.White))
  316. self.check(not test)
  317. str.reverse()
  318. for ind, file in str:
  319. if ind < len(str)-1:
  320. self.game = pos
  321. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  322. "5", Color.White))
  323. self.check(not test)
  324. method testCheckedMovePawnCaptureFalseBlack() =
  325. var test: bool
  326. let pos = initGame([
  327. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  328. 0, 0, 0, 0, 0, 0, 0, 0,
  329. 0, 0, 0, 0, 0, 0, 0, 0,
  330. 0, 0, 0, 0, 0, 0, 0, 0,
  331. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  332. 0, 0, 0, 0, 0, 0, 0, 0,
  333. 0, 0, 0, 0, 0, 0, 0, 0,
  334. BRook, 0, 0, BKing, 0, 0, 0, BRook
  335. ], Color.Black)
  336. var str: string
  337. str = "abcdefgh"
  338. for ind, file in str:
  339. if ind < len(str)-1:
  340. self.game = pos
  341. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  342. "4", Color.Black))
  343. self.check(not test)
  344. str.reverse()
  345. for ind, file in str:
  346. if ind < len(str)-1:
  347. self.game = pos
  348. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  349. "4", Color.Black))
  350. self.check(not test)
  351. method testCheckedMovePawnEnPassantTrueWhite() =
  352. var test: bool
  353. let pos = initGame([
  354. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  355. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  356. 0, 0, 0, 0, 0, 0, 0, 0,
  357. 0, 0, 0, 0, 0, 0, 0, 0,
  358. 0, 0, 0, 0, 0, 0, 0, 0,
  359. 0, 0, 0, 0, 0, 0, 0, 0,
  360. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  361. BRook, 0, 0, BKing, 0, 0, 0, BRook
  362. ], Color.White)
  363. var str: string
  364. str = "abcdefgh"
  365. for ind, file in str:
  366. if ind < len(str)-1:
  367. self.game = pos
  368. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  369. self.check(test)
  370. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  371. self.check(test)
  372. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  373. self.check(test)
  374. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  375. ind+1] & "5", Color.Black))
  376. self.check(test)
  377. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  378. "6", Color.White))
  379. self.check(test)
  380. test = (0 == self.game.pieces.getField(fieldToInd($str[ind+1] & "5")))
  381. self.check(test)
  382. str.reverse()
  383. for ind, file in str:
  384. if ind < len(str)-1:
  385. self.game = pos
  386. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  387. self.check(test)
  388. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  389. self.check(test)
  390. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  391. self.check(test)
  392. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  393. ind+1] & "5", Color.Black))
  394. self.check(test)
  395. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  396. "6", Color.White))
  397. self.check(test)
  398. test = (0 == self.game.pieces.getField(fieldToInd($str[ind+1] & "5")))
  399. self.check(test)
  400. method testCheckedMovePawnEnPassantTrueBlack() =
  401. var test: bool
  402. let pos = initGame([
  403. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  404. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  405. 0, 0, 0, 0, 0, 0, 0, 0,
  406. 0, 0, 0, 0, 0, 0, 0, 0,
  407. 0, 0, 0, 0, 0, 0, 0, 0,
  408. 0, 0, 0, 0, 0, 0, 0, 0,
  409. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  410. BRook, 0, 0, BKing, 0, 0, 0, BRook
  411. ], Color.Black)
  412. var str: string
  413. str = "abcdefgh"
  414. for ind, file in str:
  415. if ind < len(str)-1:
  416. self.game = pos
  417. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  418. self.check(test)
  419. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  420. self.check(test)
  421. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  422. self.check(test)
  423. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  424. ind+1] & "4", Color.White))
  425. self.check(test)
  426. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  427. "3", Color.Black))
  428. self.check(test)
  429. test = (0 == self.game.pieces.getField(fieldToInd($str[ind+1] & "4")))
  430. self.check(test)
  431. str.reverse()
  432. for ind, file in str:
  433. if ind < len(str)-1:
  434. self.game = pos
  435. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  436. self.check(test)
  437. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  438. self.check(test)
  439. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  440. self.check(test)
  441. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  442. ind+1] & "4", Color.White))
  443. self.check(test)
  444. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  445. "3", Color.Black))
  446. self.check(test)
  447. test = (0 == self.game.pieces.getField(fieldToInd($str[ind+1] & "4")))
  448. self.check(test)
  449. method testCheckedMovePawnEnPassantFalseWhite() =
  450. var test: bool
  451. let pos = initGame([
  452. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  453. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  454. 0, 0, 0, 0, 0, 0, 0, 0,
  455. 0, 0, 0, 0, 0, 0, 0, 0,
  456. 0, 0, 0, 0, 0, 0, 0, 0,
  457. 0, 0, 0, 0, 0, 0, 0, 0,
  458. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  459. BRook, 0, 0, BKing, 0, 0, 0, BRook
  460. ], Color.White)
  461. var str: string
  462. str = "abcdefgh"
  463. for ind, file in str:
  464. if ind < len(str)-1:
  465. self.game = pos
  466. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  467. self.check(test)
  468. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  469. ind+1] & "5", Color.Black))
  470. self.check(test)
  471. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  472. self.check(test)
  473. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  474. self.check(test)
  475. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  476. "6", Color.White))
  477. self.check(not test)
  478. test = (0 == self.game.pieces.getField(fieldToInd($str[ind+1] & "5")))
  479. self.check(not test)
  480. str.reverse()
  481. for ind, file in str:
  482. if ind < len(str)-1:
  483. self.game = pos
  484. test = self.game.checkedMove(notationToMove($file & "2" & $file & "4", Color.White))
  485. self.check(test)
  486. test = self.game.checkedMove(notationToMove($str[ind+1] & "7" & $str[
  487. ind+1] & "5", Color.Black))
  488. self.check(test)
  489. test = self.game.checkedMove(notationToMove($file & "4" & $file & "5", Color.White))
  490. self.check(test)
  491. test = self.game.checkedMove(notationToMove($file & "7" & $file & "6", Color.Black))
  492. self.check(test)
  493. test = self.game.checkedMove(notationToMove($file & "5" & $str[ind+1] &
  494. "6", Color.White))
  495. self.check(not test)
  496. test = (0 == self.game.pieces.getField(fieldToInd($str[ind+1] & "5")))
  497. self.check(not test)
  498. method testCheckedMovePawnEnPassantFalseBlack() =
  499. var test: bool
  500. let pos = initGame([
  501. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  502. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  503. 0, 0, 0, 0, 0, 0, 0, 0,
  504. 0, 0, 0, 0, 0, 0, 0, 0,
  505. 0, 0, 0, 0, 0, 0, 0, 0,
  506. 0, 0, 0, 0, 0, 0, 0, 0,
  507. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  508. BRook, 0, 0, BKing, 0, 0, 0, BRook
  509. ], Color.Black)
  510. var str: string
  511. str = "abcdefgh"
  512. for ind, file in str:
  513. if ind < len(str)-1:
  514. self.game = pos
  515. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  516. self.check(test)
  517. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  518. ind+1] & "4", Color.White))
  519. self.check(test)
  520. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  521. self.check(test)
  522. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  523. self.check(test)
  524. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  525. "3", Color.Black))
  526. self.check(not test)
  527. test = (0 == self.game.pieces.getField(fieldToInd($str[ind+1] & "4")))
  528. self.check(not test)
  529. str.reverse()
  530. for ind, file in str:
  531. if ind < len(str)-1:
  532. self.game = pos
  533. test = self.game.checkedMove(notationToMove($file & "7" & $file & "5", Color.Black))
  534. self.check(test)
  535. test = self.game.checkedMove(notationToMove($str[ind+1] & "2" & $str[
  536. ind+1] & "4", Color.White))
  537. self.check(test)
  538. test = self.game.checkedMove(notationToMove($file & "5" & $file & "4", Color.Black))
  539. self.check(test)
  540. test = self.game.checkedMove(notationToMove($file & "2" & $file & "3", Color.White))
  541. self.check(test)
  542. test = self.game.checkedMove(notationToMove($file & "4" & $str[ind+1] &
  543. "3", Color.Black))
  544. self.check(not test)
  545. test = (0 == self.game.pieces.getField(fieldToInd($str[ind+1] & "4")))
  546. self.check(not test)
  547. ## Tests for King moves
  548. method testCheckedMoveKingCastleTrueWhite() =
  549. var test: bool
  550. let pos = initGame([
  551. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  552. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  553. 0, 0, 0, 0, 0, 0, 0, 0,
  554. 0, 0, 0, 0, 0, 0, 0, 0,
  555. 0, 0, 0, 0, 0, 0, 0, 0,
  556. 0, 0, 0, 0, 0, 0, 0, 0,
  557. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  558. BRook, 0, 0, BKing, 0, 0, 0, BRook
  559. ], Color.White)
  560. self.game = pos
  561. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  562. self.check(test)
  563. self.game = pos
  564. self.game.checkedMove(notationToMove("e1g1", Color.White))
  565. self.check(test)
  566. method testCheckedMoveKingCastleTrueBlack() =
  567. var test: bool
  568. let pos = initGame([
  569. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  570. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  571. 0, 0, 0, 0, 0, 0, 0, 0,
  572. 0, 0, 0, 0, 0, 0, 0, 0,
  573. 0, 0, 0, 0, 0, 0, 0, 0,
  574. 0, 0, 0, 0, 0, 0, 0, 0,
  575. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  576. BRook, 0, 0, BKing, 0, 0, 0, BRook
  577. ], Color.Black)
  578. self.game = pos
  579. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  580. self.check(test)
  581. self.game = pos
  582. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  583. self.check(test)
  584. method testCheckedMoveKingCastleFalseAlreadyMovedKing() =
  585. var test: bool
  586. let pos = initGame([
  587. WRook, 0, 0, 0, WKing, 0, 0, WRook,
  588. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  589. 0, 0, 0, 0, 0, 0, 0, 0,
  590. 0, 0, 0, 0, 0, 0, 0, 0,
  591. 0, 0, 0, 0, 0, 0, 0, 0,
  592. 0, 0, 0, 0, 0, 0, 0, 0,
  593. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  594. BRook, 0, 0, 0, BKing, 0, 0, BRook
  595. ], Color.White)
  596. self.game.checkedMove(notationToMove("d1e1", Color.White))
  597. self.game.checkedMove(notationToMove("d8e8", Color.White))
  598. self.game = pos
  599. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  600. self.check(not test)
  601. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  602. self.check(not test)
  603. self.game.checkedMove(notationToMove("e1g1", Color.White))
  604. self.check(not test)
  605. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  606. self.check(not test)
  607. method testCheckedMoveKingCastleFalseAlreadyMovedRook() =
  608. var test: bool
  609. let pos = initGame([
  610. 0, WRook, 0, WKing, 0, 0, WRook, 0,
  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. 0, BRook, 0, BKing, 0, 0, BRook, 0
  618. ], Color.White)
  619. self.game = pos
  620. self.game.checkedMove(notationToMove("b1a1", Color.White))
  621. self.game.checkedMove(notationToMove("b8a8", Color.Black))
  622. self.game.checkedMove(notationToMove("g1h1", Color.White))
  623. self.game.checkedMove(notationToMove("g8h8", Color.Black))
  624. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  625. self.check(not test)
  626. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  627. self.check(not test)
  628. self.game.checkedMove(notationToMove("e1g1", Color.White))
  629. self.check(not test)
  630. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  631. self.check(not test)
  632. method testCheckedMoveKingCastleFalseThroughCheck() =
  633. var test: bool
  634. let pos = initGame([
  635. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  636. WPawn, WPawn, BRook, WPawn, BRook, WPawn, WPawn, WPawn,
  637. 0, 0, 0, 0, 0, 0, 0, 0,
  638. 0, 0, 0, 0, 0, 0, 0, 0,
  639. 0, 0, 0, 0, 0, 0, 0, 0,
  640. 0, 0, 0, 0, 0, 0, 0, 0,
  641. BPawn, BPawn, WRook, BPawn, WRook, BPawn, BPawn, BPawn,
  642. BRook, 0, 0, BKing, 0, 0, 0, BRook
  643. ], Color.White)
  644. self.game = pos
  645. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  646. self.check(not test)
  647. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  648. self.check(not test)
  649. self.game.checkedMove(notationToMove("e1g1", Color.White))
  650. self.check(not test)
  651. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  652. self.check(not test)
  653. method testCheckedMoveKingCastleFalseIntoCheck() =
  654. var test: bool
  655. let pos = initGame([
  656. WRook, 0, 0, WKing, 0, 0, 0, WRook,
  657. WPawn, BRook, WPawn, WPawn, WPawn, BRook, WPawn, WPawn,
  658. 0, 0, 0, 0, 0, 0, 0, 0,
  659. 0, 0, 0, 0, 0, 0, 0, 0,
  660. 0, 0, 0, 0, 0, 0, 0, 0,
  661. 0, 0, 0, 0, 0, 0, 0, 0,
  662. BPawn, WRook, BPawn, BPawn, BPawn, WRook, BPawn, BPawn,
  663. BRook, 0, 0, BKing, 0, 0, 0, BRook
  664. ], Color.White)
  665. self.game = pos
  666. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  667. self.check(not test)
  668. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  669. self.check(not test)
  670. self.game.checkedMove(notationToMove("e1g1", Color.White))
  671. self.check(not test)
  672. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  673. self.check(not test)
  674. method testCheckedMoveKingCastleFalseThroughOwnPiece() =
  675. var test: bool
  676. let pos = initGame([
  677. WRook, 0, WBishop, WKing, WBishop, 0, 0, WRook,
  678. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  679. 0, 0, 0, 0, 0, 0, 0, 0,
  680. 0, 0, 0, 0, 0, 0, 0, 0,
  681. 0, 0, 0, 0, 0, 0, 0, 0,
  682. 0, 0, 0, 0, 0, 0, 0, 0,
  683. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  684. BRook, 0, BBishop, BKing, BBishop, 0, 0, BRook
  685. ], Color.White)
  686. self.game = pos
  687. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  688. self.check(not test)
  689. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  690. self.check(not test)
  691. self.game.checkedMove(notationToMove("e1g1", Color.White))
  692. self.check(not test)
  693. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  694. self.check(not test)
  695. method testCheckedMoveKingCastleFalseThroughEnemyPiece() =
  696. var test: bool
  697. let pos = initGame([
  698. WRook, 0, BBishop, WKing, BBishop, 0, 0, WRook,
  699. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  700. 0, 0, 0, 0, 0, 0, 0, 0,
  701. 0, 0, 0, 0, 0, 0, 0, 0,
  702. 0, 0, 0, 0, 0, 0, 0, 0,
  703. 0, 0, 0, 0, 0, 0, 0, 0,
  704. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  705. BRook, 0, WBishop, BKing, WBishop, 0, 0, BRook
  706. ], Color.White)
  707. self.game = pos
  708. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  709. self.check(not test)
  710. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  711. self.check(not test)
  712. self.game.checkedMove(notationToMove("e1g1", Color.White))
  713. self.check(not test)
  714. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  715. self.check(not test)
  716. method testCheckedMoveKingCastleFalseIntoOwnPiece() =
  717. var test: bool
  718. let pos = initGame([
  719. WRook, WBishop, 0, WKing, 0, WBishop, 0, WRook,
  720. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  721. 0, 0, 0, 0, 0, 0, 0, 0,
  722. 0, 0, 0, 0, 0, 0, 0, 0,
  723. 0, 0, 0, 0, 0, 0, 0, 0,
  724. 0, 0, 0, 0, 0, 0, 0, 0,
  725. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  726. BRook, BBishop, 0, BKing, 0, BBishop, 0, BRook
  727. ], Color.White)
  728. self.game = pos
  729. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  730. self.check(not test)
  731. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  732. self.check(not test)
  733. self.game.checkedMove(notationToMove("e1g1", Color.White))
  734. self.check(not test)
  735. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  736. self.check(not test)
  737. method testCheckedMoveKingCastleFalseIntoEnemyPiece() =
  738. var test: bool
  739. let pos = initGame([
  740. WRook, BBishop, 0, WKing, 0, BBishop, 0, WRook,
  741. WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn, WPawn,
  742. 0, 0, 0, 0, 0, 0, 0, 0,
  743. 0, 0, 0, 0, 0, 0, 0, 0,
  744. 0, 0, 0, 0, 0, 0, 0, 0,
  745. 0, 0, 0, 0, 0, 0, 0, 0,
  746. BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn, BPawn,
  747. BRook, WBishop, 0, BKing, 0, WBishop, 0, BRook
  748. ], Color.White)
  749. self.game = pos
  750. test = self.game.checkedMove(notationToMove("e1c1", Color.White))
  751. self.check(not test)
  752. test = self.game.checkedMove(notationToMove("e8c8", Color.Black))
  753. self.check(not test)
  754. self.game.checkedMove(notationToMove("e1g1", Color.White))
  755. self.check(not test)
  756. test = self.game.checkedMove(notationToMove("e8g8", Color.Black))
  757. self.check(not test)
  758. method testCheckedMoveKingWhite() =
  759. var test: bool
  760. let pos = initGame([
  761. 0, 0, 0, 0, 0, 0, 0, 0,
  762. 0, 0, 0, 0, 0, 0, 0, 0,
  763. 0, 0, 0, 0, 0, 0, 0, 0,
  764. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  765. 0, 0, BPawn, WKing, WPawn, 0, 0, 0,
  766. 0, 0, BEnPassant, 0, 0, 0, 0, 0,
  767. 0, 0, 0, 0, 0, 0, 0, 0,
  768. 0, 0, 0, 0, 0, 0, 0, 0,
  769. ], Color.White)
  770. let start = "e5"
  771. let legalMoves = ["f4", "d4", "f5", "f6", "e6", "d6"]
  772. let str = "abcdefgh"
  773. var move: string
  774. for cha in str:
  775. for num in 1..8:
  776. self.game = pos
  777. move = $cha & $num
  778. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  779. if move in legalMoves:
  780. self.check(test)
  781. else:
  782. self.check(not test)
  783. method testCheckedMoveKingBlack() =
  784. var test: bool
  785. let pos = initGame([
  786. 0, 0, 0, 0, 0, 0, 0, 0,
  787. 0, 0, 0, 0, 0, 0, 0, 0,
  788. 0, 0, 0, 0, 0, 0, 0, 0,
  789. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  790. 0, 0, WPawn, BKing, BPawn, 0, 0, 0,
  791. 0, 0, WEnPassant, 0, 0, 0, 0, 0,
  792. 0, 0, 0, 0, 0, 0, 0, 0,
  793. 0, 0, 0, 0, 0, 0, 0, 0,
  794. ], Color.Black)
  795. let start = "e5"
  796. let legalMoves = ["f4", "d4", "f5", "f6", "e4", "d6"]
  797. let str = "abcdefgh"
  798. var move: string
  799. for cha in str:
  800. for num in 1..8:
  801. self.game = pos
  802. move = $cha & $num
  803. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  804. if move in legalMoves:
  805. self.check(test)
  806. else:
  807. self.check(not test)
  808. ## Tests for Bishop moves
  809. method testCheckedMoveBishopWhite() =
  810. var test: bool
  811. let pos = initGame([
  812. 0, 0, 0, 0, 0, 0, 0, 0,
  813. 0, 0, 0, 0, 0, 0, 0, 0,
  814. 0, 0, 0, 0, 0, 0, 0, 0,
  815. 0, 0, 0, BEnPassant, 0, WPawn, 0, 0,
  816. 0, 0, 0, 0, WBishop, 0, 0, 0,
  817. 0, 0, 0, BPawn, 0, WEnPassant, 0, 0,
  818. 0, 0, 0, 0, 0, 0, 0, 0,
  819. 0, 0, 0, 0, 0, 0, 0, 0,
  820. ], Color.White)
  821. let start = "d5"
  822. let legalMoves = ["e4", "f3", "g2", "h1", "c6", "b7", "a8", "e6"]
  823. let str = "abcdefgh"
  824. var move: string
  825. for cha in str:
  826. for num in 1..8:
  827. self.game = pos
  828. move = $cha & $num
  829. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  830. if move in legalMoves:
  831. self.check(test)
  832. else:
  833. self.check(not test)
  834. method testCheckedMoveBishopBlack() =
  835. var test: bool
  836. let pos = initGame([
  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, WEnPassant, 0, BPawn, 0, 0,
  841. 0, 0, 0, 0, BBishop, 0, 0, 0,
  842. 0, 0, 0, WPawn, 0, BEnPassant, 0, 0,
  843. 0, 0, 0, 0, 0, 0, 0, 0,
  844. 0, 0, 0, 0, 0, 0, 0, 0,
  845. ], Color.Black)
  846. let start = "d5"
  847. let legalMoves = ["e4", "f3", "g2", "h1", "c6", "b7", "a8", "e6"]
  848. let str = "abcdefgh"
  849. var move: string
  850. for cha in str:
  851. for num in 1..8:
  852. self.game = pos
  853. move = $cha & $num
  854. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  855. if move in legalMoves:
  856. self.check(test)
  857. else:
  858. self.check(not test)
  859. ## Tests for Knight moves
  860. method testCheckedMoveKnightWhite() =
  861. var test: bool
  862. let pos = initGame([
  863. 0, 0, 0, 0, 0, 0, 0, 0,
  864. 0, 0, 0, 0, 0, 0, 0, 0,
  865. 0, 0, 0, WEnPassant, 0, WPawn, 0, 0,
  866. 0, 0, BEnPassant, 0, 0, 0, 0, 0,
  867. 0, 0, 0, 0, WKnight, 0, 0, 0,
  868. 0, 0, BPawn, 0, 0, 0, 0, 0,
  869. 0, 0, 0, 0, 0, 0, 0, 0,
  870. 0, 0, 0, 0, 0, 0, 0, 0,
  871. ], Color.White)
  872. let start = "d5"
  873. let legalMoves = ["f6", "f4", "e3", "b4", "b6", "c7", "e7"]
  874. let str = "abcdefgh"
  875. var move: string
  876. for cha in str:
  877. for num in 1..8:
  878. self.game = pos
  879. move = $cha & $num
  880. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  881. if move in legalMoves:
  882. self.check(test)
  883. else:
  884. self.check(not test)
  885. method testCheckedMoveKnightBlack() =
  886. var test: bool
  887. let pos = initGame([
  888. 0, 0, 0, 0, 0, 0, 0, 0,
  889. 0, 0, 0, 0, 0, 0, 0, 0,
  890. 0, 0, 0, BEnPassant, 0, BPawn, 0, 0,
  891. 0, 0, WEnPassant, 0, 0, 0, 0, 0,
  892. 0, 0, 0, 0, BKnight, 0, 0, 0,
  893. 0, 0, WPawn, 0, 0, 0, 0, 0,
  894. 0, 0, 0, 0, 0, 0, 0, 0,
  895. 0, 0, 0, 0, 0, 0, 0, 0,
  896. ], Color.Black)
  897. let start = "d5"
  898. let legalMoves = ["f6", "f4", "e3", "b4", "b6", "c7", "e7"]
  899. let str = "abcdefgh"
  900. var move: string
  901. for cha in str:
  902. for num in 1..8:
  903. self.game = pos
  904. move = $cha & $num
  905. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  906. if move in legalMoves:
  907. self.check(test)
  908. else:
  909. self.check(not test)
  910. ## Tests for Rook moves
  911. method testCheckedMoveRookWhite() =
  912. var test: bool
  913. let pos = initGame([
  914. 0, 0, 0, 0, 0, 0, 0, 0,
  915. 0, 0, 0, 0, 0, 0, 0, 0,
  916. 0, 0, 0, 0, 0, 0, 0, 0,
  917. 0, 0, 0, 0, WPawn, 0, 0, 0,
  918. 0, 0, 0, BPawn, WRook, WEnPassant, 0, 0,
  919. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  920. 0, 0, 0, 0, 0, 0, 0, 0,
  921. 0, 0, 0, 0, 0, 0, 0, 0,
  922. ], Color.White)
  923. let start = "d5"
  924. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5"]
  925. let str = "abcdefgh"
  926. var move: string
  927. for cha in str:
  928. for num in 1..8:
  929. self.game = pos
  930. move = $cha & $num
  931. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  932. if move in legalMoves:
  933. self.check(test)
  934. else:
  935. self.check(not test)
  936. method testCheckedMoveRookBlack() =
  937. var test: bool
  938. let pos = initGame([
  939. 0, 0, 0, 0, 0, 0, 0, 0,
  940. 0, 0, 0, 0, 0, 0, 0, 0,
  941. 0, 0, 0, 0, 0, 0, 0, 0,
  942. 0, 0, 0, 0, BPawn, 0, 0, 0,
  943. 0, 0, 0, WPawn, BRook, BEnPassant, 0, 0,
  944. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  945. 0, 0, 0, 0, 0, 0, 0, 0,
  946. 0, 0, 0, 0, 0, 0, 0, 0,
  947. ], Color.Black)
  948. let start = "d5"
  949. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5"]
  950. let str = "abcdefgh"
  951. var move: string
  952. for cha in str:
  953. for num in 1..8:
  954. self.game = pos
  955. move = $cha & $num
  956. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  957. if move in legalMoves:
  958. self.check(test)
  959. else:
  960. self.check(not test)
  961. ## Tests for Queen moves
  962. method testCheckedMoveQueenWhite() =
  963. var test: bool
  964. let pos = initGame([
  965. 0, 0, 0, 0, 0, 0, 0, 0,
  966. 0, 0, 0, 0, 0, 0, 0, 0,
  967. 0, 0, 0, 0, 0, 0, 0, 0,
  968. 0, 0, 0, 0, WPawn, 0, 0, 0,
  969. 0, 0, 0, BPawn, WQueen, WEnPassant, 0, 0,
  970. 0, 0, 0, 0, BEnPassant, 0, 0, 0,
  971. 0, 0, 0, 0, 0, 0, 0, 0,
  972. 0, 0, 0, 0, 0, 0, 0, 0,
  973. ], Color.White)
  974. let start = "d5"
  975. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5", "h1", "g2",
  976. "f3", "e4", "c4", "b3", "a2", "g8", "f7", "e6", "c6", "b7", "a8"]
  977. let str = "abcdefgh"
  978. var move: string
  979. for cha in str:
  980. for num in 1..8:
  981. self.game = pos
  982. move = $cha & $num
  983. test = self.game.checkedMove(notationToMove(start & move, Color.White))
  984. if move in legalMoves:
  985. self.check(test)
  986. else:
  987. self.check(not test)
  988. method testCheckedMoveQueenBlack() =
  989. var test: bool
  990. let pos = initGame([
  991. 0, 0, 0, 0, 0, 0, 0, 0,
  992. 0, 0, 0, 0, 0, 0, 0, 0,
  993. 0, 0, 0, 0, 0, 0, 0, 0,
  994. 0, 0, 0, 0, BPawn, 0, 0, 0,
  995. 0, 0, 0, WPawn, BQueen, BEnPassant, 0, 0,
  996. 0, 0, 0, 0, WEnPassant, 0, 0, 0,
  997. 0, 0, 0, 0, 0, 0, 0, 0,
  998. 0, 0, 0, 0, 0, 0, 0, 0,
  999. ], Color.Black)
  1000. let start = "d5"
  1001. let legalMoves = ["e5", "d6", "d7", "d8", "c5", "b5", "a5", "h1", "g2",
  1002. "f3", "e4", "c4", "b3", "a2", "g8", "f7", "e6", "c6", "b7", "a8"]
  1003. let str = "abcdefgh"
  1004. var move: string
  1005. for cha in str:
  1006. for num in 1..8:
  1007. self.game = pos
  1008. move = $cha & $num
  1009. test = self.game.checkedMove(notationToMove(start & move, Color.Black))
  1010. if move in legalMoves:
  1011. self.check(test)
  1012. else:
  1013. self.check(not test)
  1014. when isMainModule:
  1015. einheit.runTests()