aIexandria

Untitled

Sep 25th, 2019
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.64 KB | None | 0 0
  1. print ("Welcome to Checkers!", "\n")
  2. board= [ ["-" , "x" , "-" , "x" , "-" , "x", "-", "x" , 8 ] ,
  3. ["x" , "-" , "x" , "-" , "x" , "-", "x", "-" , 7 ],
  4. ["-" , "x" , "-" , "x" , "-" , "x", "-", "x" , 6 ],
  5. ["-" , "-" , "-" , "-" , "-" , "-", "-", "-" , 5 ],
  6. ["-" , "-" , "-" , "-" , "-" , "-", "-", "-" , 4 ],
  7. ["o" , "-" , "o" , "-" , "o" , "-", "o", "-" , 3 ],
  8. ["-" , "o" , "-" , "o" , "-" , "o", "-", "o" , 2 ],
  9. ["o" , "-" , "o" , "-" , "o" , "-", "o", "-" , 1 ],
  10. ["A" , "B" , "C" , "D" , "E" , "F", "G", "H"] ]
  11. for i in range (len(board)) :
  12. for j in range (len(board[i])) :
  13. print (board[i][j], end = " ")
  14. print ()
  15.  
  16. letter = {"A":0, "B":1 , "C":2 , "D":3 , "E":4 , "F":5 , "G":6, "H":7}
  17. number = {"8":0, "7":1, "6":2, "5":3, "4":4, "3":5, "2":6, "1":7}
  18. rettel = {0:"A", 1:"B", 2:"C", 3:"D", 4:"E", 5:"F", 6:"G", 7:"H"}
  19. rebmun = {0:"8", 1:"7", 2:"6", 3:"5", 4:"4", 5:"3", 6:"2", 7:"1"}
  20.  
  21. def move_d():
  22. global dmove
  23. dmove = input("Dark pieces to play. Enter your move:")
  24.  
  25.  
  26. def move_l():
  27. global lmove
  28. lmove = input("Light pieces to play. Enter your move:")
  29.  
  30.  
  31. def convertdmove(dmove):
  32.  
  33. da = dmove[0]
  34. db = dmove[1]
  35. dc = dmove[3]
  36. dd = dmove[4]
  37. global dx1
  38. global dy1
  39. global dx2
  40. global dy2
  41. dx1 = number[db]
  42. dx1 = int(dx1)
  43. dy1 = letter[da]
  44. dy1 = int(dy1)
  45. dx2 = number[dd]
  46. dx2 = int(dx2)
  47. dy2 = letter[dc]
  48. dy2 = int(dy2)
  49.  
  50.  
  51. def convertlmove(lmove):
  52.  
  53. if len(lmove)==5:
  54. la = lmove[0]
  55. lb = lmove[1]
  56. lc = lmove[3]
  57. ld = lmove[4]
  58. global lx1
  59. global ly1
  60. global lx2
  61. global ly2
  62. lx1 = number[lb]
  63. lx1 = int(lx1)
  64. ly1 = letter[la]
  65. ly1 = int(ly1)
  66. lx2 = number[ld]
  67. lx2 = int(lx2)
  68. ly2 = letter[lc]
  69. ly2 = int(ly2)
  70.  
  71. def dmovement(board,dx1,dy1,dx2,dy2):
  72. board[dx1][dy1],board[dx2][dy2]=board[dx2][dy2],board[dx1][dy1]
  73. return board
  74.  
  75. def lmovement(board,lx1,ly1,lx2,ly2):
  76. board[lx1][ly1],board[lx2][ly2]=board[lx2][ly2],board[lx1][ly1]
  77. return board
  78.  
  79. def validity_check_d():
  80. if len(dmove)>=5:
  81. if board[dx1][dy1]=="x":
  82. if dx2==dx1+1 and dy2==dy1-1:
  83. dmovement(board,dx1,dy1,dx2,dy2)
  84. elif dx2==dx1+1 and dy2==dy1+1:
  85. dmovement(board,dx1,dy1,dx2,dy2)
  86. elif dx2!=dx1+1 or dy2!=dy1-1 or dy2!=dy1+1:
  87. print("Invalid input.Try again.")
  88. move_d()
  89. convertdmove(dmove)
  90. validity_check_d()
  91. elif board[dx1][dy1]!="x":
  92. print("Invalid input. Wrong piece. Try again.")
  93. move_d()
  94. convertdmove(dmove)
  95. validity_check_d()
  96. elif len(dmove)<5:
  97. print("Invalid input. Try again.")
  98. move_d()
  99. convertdmove(dmove)
  100. validity_check_d()
  101. if dmove=="END" or lmove=="end" or lmove=="End":
  102. end()
  103.  
  104. def validity_check_l():
  105. if len(lmove)>=5:
  106. if board[lx1][ly1]=="o":
  107. if lx2==lx1-1 and ly2==ly1-1:
  108. lmovement(board,lx1,ly1,lx2,ly2)
  109. elif lx2==lx1-1 and ly2==ly1+1:
  110. lmovement(board,lx1,ly1,lx2,ly2)
  111. elif lx2!=lx1+1 or ly2!=ly1-1 or ly2!=ly1+1:
  112. print("Invalid input.Try again.")
  113. move_l()
  114. convertlmove(lmove)
  115. validity_check_l()
  116. elif board[lx1][ly1]!="o":
  117. print("Invalid input. Wrong piece. Try again.")
  118. move_l()
  119. convertlmove(lmove)
  120. validity_check_l()
  121. elif len(lmove)<5:
  122. print("Invalid input. Try again.")
  123. move_l()
  124. convertlmove(lmove)
  125. validity_check_l()
  126. if lmove=="END" or lmove=="end" or lmove=="End":
  127. end()
  128.  
  129.  
  130.  
  131. def darkcapture():
  132. global dcapture
  133. dcapture = 0
  134. while dcapture>=0:
  135. if dx2==dx1-2 and dy2==dy1-2:
  136. board[dx1][dy1]="-"
  137. board[dx1-1][dy1-1]="-"
  138. board[dx1-2][dy1-2]="x"
  139. elif dx2==dx1-2 and dy2==dy1-2:
  140. board[dx1][dy1]="-"
  141. board[dx1-1][dy1+1]="-"
  142. board[dx1-2][dy1+2]="x"
  143. elif dx2==dx1+2 and dy2==dy1-2:
  144. board[dx1][dy1]="-"
  145. board[dx1+1][dy1-1]="-"
  146. board[dx1+2][dy1-2]="x"
  147. elif dx2==dx1+2 and dy2==ly1+2:
  148. board[dx1][dy1]="-"
  149. board[dx1+1][dy1+1]="-"
  150. board[dx1+2][dy1+2]="x"
  151. dcapture += 1
  152.  
  153. def lightcapture():
  154. global lcapture
  155. lcapture = 0
  156. while lcapture>=0:
  157. if lx2==lx1-2 and ly2==ly1-2:
  158. board[lx1][ly1]="-"
  159. board[lx1-1][ly1-1]="-"
  160. board[lx1-2][ly1-2]="o"
  161. elif lx2==lx1-2 and ly2==ly1-2:
  162. board[lx1][ly1]="-"
  163. board[lx1-1][ly1+1]="-"
  164. board[lx1-2][ly1+2]="o"
  165. elif lx2==lx1+2 and ly2==ly1-2:
  166. board[lx1][ly1]="-"
  167. board[lx1+1][ly1-1]="-"
  168. board[lx1+2][ly1-2]="o"
  169. elif lx2==lx1+2 and ly2==ly1+2:
  170. board[lx1][ly1]="-"
  171. board[lx1+1][ly1+1]="-"
  172. board[lx1+2][ly1+2]="x"
  173. lcapture += 1
  174.  
  175. def checkcapture_men_d():
  176. for dx1 in range (0,7):
  177. for dy1 in range(0,7):
  178. if dx1+2 < 8 or dy1+2 < 8:
  179. if "x" in board[dx1][dy1]:
  180. if "o" in board[dx1-1][dy1-1]:
  181. if "-" in board[dx1-2][dy1-2]:
  182. if dx2==dx1-2 and dy2==dy1-2:
  183. darkcapture()
  184. else:
  185. print("Invalid input. Mandatory capture on", rettel[dx2],rebmun[dy2],".")
  186. move_d()
  187. convertdmove(dmove)
  188. checkcapture_men_d(board)
  189. darkcapture()
  190. elif "o" in board[dx1-1][dy1+1]:
  191. if "-" in board[dx1-2][dy1+2]:
  192. if dx2==dx1-2 and dy2==dy1+2:
  193. darkcapture()
  194. else:
  195. print("Invalid input. Mandatory capture on", rettel[dy2],rebmun[dx2],".")
  196. move_d()
  197. convertdmove(dmove)
  198. checkcapture_men_d()
  199. darkcapture()
  200. elif "o" in board[dx1+1][dy1-1]:
  201. if "-" in board[dx1+2][dy1-2]:
  202. if dx2==dx1+2 and dy2==dy1-2:
  203. darkcapture()
  204. else:
  205. print("Invalid input. Mandatory capture on", rettel[dy2],rebmun[dx2],".")
  206. move_d()
  207. convertdmove(dmove)
  208. checkcapture_men_d()
  209. darkcapture()
  210. elif "o" in board[dx1+1][dy1+1]:
  211. if "-" in board[dx1+2][dy1+2]:
  212. if dx2==dx1+2 and dy2==dy1+2:
  213. darkcapture()
  214. else:
  215. print("Invalid input. Mandatory capture on", rettel[dy2],rebmun[dx2],".")
  216. move_d()
  217. convertdmove(dmove)
  218. checkcapture_men_d()
  219. darkcapture()
  220. else:
  221. continue
  222. else:
  223. continue
  224.  
  225. def checkcapture_men_l():
  226. for lx1 in range (8):
  227. for ly1 in range(8):
  228. if lx1+2 < 8 or ly1+2 < 8:
  229. if board[lx1][ly1]==" o ":
  230. if board[lx1-1][ly1-1]==" x ":
  231. if board[lx1-2][ly1-2]==" - ":
  232. if lx2==lx1-2 and ly2==ly1-2:
  233. lightcapture()
  234. else:
  235. print("Invalid input. Mandatory capture on", rettel[ly2],rebmun[lx2],".")
  236. move_l()
  237. convertlmove(lmove)
  238. validity_check_l(lmove,board,lx1,ly1,lx2,ly2)
  239. checkcapture_men_l()
  240. lightcapture()
  241. elif "x" in board[lx1-1][ly1+1]:
  242. if "-" in board[lx1-2][ly1+2]:
  243. if lx2==lx1-2 and ly2==ly1+2:
  244. lightcapture()
  245. else:
  246. print("Invalid input. Mandatory capture on", rettel[ly2],rebmun[lx2],".")
  247. move_l()
  248. convertlmove(lmove)
  249. checkcapture_men_l()
  250. lightcapture()
  251. elif "x" in board[lx1+1][ly1-1]:
  252. if "-" in board[lx1+2][ly1-2]:
  253. if lx2==lx1+2 and ly2==ly1-2:
  254. lightcapture()
  255. else:
  256. print("Invalid input. Mandatory capture on", rettel[ly2],rebmun[lx2],".")
  257. move_l()
  258. convertlmove(lmove)
  259. checkcapture_men_l()
  260. lightcapture()
  261. elif "x" in board[lx1+1][ly1+1]:
  262. if "-" in board[lx1+2][ly1+2]:
  263. if lx2==lx1+2 and ly2==ly1+2:
  264. lightcapture()
  265. else:
  266. print("Invalid input. Mandatory capture on", rettel[ly2],number[lx2],".")
  267. move_l()
  268. convertlmove(lmove)
  269. checkcapture_men_l()
  270. lightcapture()
  271. else:
  272. continue
  273. else:
  274. continue
  275.  
  276.  
  277.  
  278. def darkmove():
  279. move_d()
  280. convertdmove(dmove)
  281. checkcapture_men_d()
  282. validity_check_d()
  283. for i in range (len(board)) :
  284. for j in range (len(board[i])) :
  285. print (board[i][j], end = " ")
  286. print ()
  287. print ("\n","Dark player played:", dmove)
  288.  
  289.  
  290. def lightmove():
  291. move_l()
  292. convertlmove(lmove)
  293. checkcapture_men_l()
  294. validity_check_l()
  295. for i in range (len(board)) :
  296. for j in range (len(board[i])) :
  297. print (board[i][j], end = " ")
  298. print ()
  299. print ("\n","Light player played:", lmove)
  300.  
  301. def end():
  302. print("END.", "\n", "LIGHT PIECES =", lcapture, "POINTS.", "\n", "DARK PIECES = ", dcapture,"POINTS." )
  303. if lcapture>dcapture:
  304. print("LIGHT PIECES WON!", "\n")
  305. if dcapture>lcapture:
  306. print("DARK PIECES WON!", "\n")
  307. if dcapture==lcapture:
  308. print("DRAW!")
  309.  
  310.  
  311. turn = 1
  312. while turn>=1:
  313. if turn%2==0:
  314. darkmove()
  315. else:
  316. lightmove()
  317. turn +=1
Advertisement
Add Comment
Please, Sign In to add comment