Best Python code snippet using avocado_python
blackStrategy.py
Source:blackStrategy.py
...31 Calcula todos los movimientos posibles de los peones del tablero32 Devuelve una lista con los movimientos posibles33 34 """35 if self.board[i].get_name() == "p" and 0<self.board[i].get_row()<15:36 if self.board[i + 16].get_name() == " " and self.board[i].row<=3:37 if self.board[i + 32].get_name() == " ":38 "calcula el score del movimiento"39 score = MoveScore().moveScore(self.board[i],self.board[i + 32].get_name())40 "lo agrega a la lista"41 moves.append(42 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 32].get_row(),43 self.board[i + 32].get_column(),score+5])44 if self.board[i + 16].get_name() == " " and self.board[i].row>3:45 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())46 moves.append(47 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),48 self.board[i + 16].get_column(),score +6])49 return moves50 def movesAtack(self):51 movesAtack = []52 for i in range(0,len(self.board)):53 if self.board[i].get_name() == "p":54 if self.board[i + 17].get_colour() == "white" and 0<=self.board[i].get_column()<15:55 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())56 movesAtack.append(57 [self.board[i].get_row(),self.board[i].get_column(),58 self.board[i + 17].get_row(),59 self.board[i + 17].get_column(),score+1])60 if self.board[i + 15].get_colour() == "white" and 0<self.board[i].get_column()<=15:61 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())62 movesAtack.append(63 [self.board[i].get_row(),self.board[i].get_column(),64 self.board[i + 15].get_row(),65 self.board[i + 15].get_column(),score+1])66 return movesAtack67class QueenBlack(PiecesStrategy):68 def moves(self):69 moves = []70 for i in range(0,len(self.board)):71 if self.board[i].get_name() == "q":72 """73 Calcula todos los movimientos posibles de las reinas del tablero74 Devuelve una lista con los movimientos posibles75 """76 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":77 "calcula los espacios libres para hacer un movimiento "78 spaceUp = MovesBoard().moveLine("up",self.board,self.board[i])79 if spaceUp:80 score = MoveScore().moveScore(self.board[i],spaceUp[0].get_name())81 moves.append(82 [self.board[i].get_row(),self.board[i].get_column(),spaceUp[0].get_row(),83 spaceUp[0].get_column(),score-15])84 else:85 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())86 moves.append(87 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),88 self.board[i + 16].get_column(),score-15])89 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":90 spaceDown = MovesBoard().moveLine("down",self.board,self.board[i])91 if spaceDown:92 score = MoveScore().moveScore(self.board[i],spaceDown[0].get_name())93 moves.append(94 [self.board[i].get_row(),self.board[i].get_column(),spaceDown[0].get_row(),95 spaceDown[0].get_column(),score-15])96 else:97 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())98 moves.append(99 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),100 self.board[i - 16].get_column(),score-15])101 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":102 spaceRight = MovesBoard().moveLine("right",self.board,self.board[i])103 if spaceRight:104 score = MoveScore().moveScore(self.board[i],spaceRight[0].get_name())105 moves.append(106 [self.board[i].get_row(),self.board[i].get_column(),spaceRight[0].get_row(),107 spaceRight[0].get_column(),score-15])108 else:109 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())110 moves.append(111 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),112 self.board[i + 1].get_column(),score-15])113 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":114 spaceLeft = MovesBoard().moveLine("left",self.board,self.board[i])115 if spaceLeft:116 score = MoveScore().moveScore(self.board[i],spaceLeft[0].get_name())117 moves.append(118 [self.board[i].get_row(),self.board[i].get_column(),spaceLeft[0].get_row(),119 spaceLeft[0].get_column(),score-15])120 else:121 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())122 moves.append(123 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),124 self.board[i - 1].get_column(),score-15])125 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[126 i + 17].get_name() == " ":127 spaceRD = MovesBoard().moveDiagonal("rd",self.board,self.board[i])128 if spaceRD:129 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())130 moves.append(131 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),132 spaceRD[0].get_column(),score-15])133 else:134 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())135 moves.append(136 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 17].get_row(),137 self.board[i + 17].get_column(),score-15])138 if 0<=self.board[i].get_row()<15 and 0<self.board[i].get_column()<15 and self.board[139 i + 15].get_name() == " ":140 spaceRD = MovesBoard().moveDiagonal("ldd",self.board,self.board[i])141 if spaceRD:142 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())143 moves.append(144 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),145 spaceRD[0].get_column(),score-15])146 else:147 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())148 moves.append(149 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 15].get_row(),150 self.board[i + 15].get_column(),score-15])151 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[152 i - 17].get_name() == " ":153 spaceDR = MovesBoard().moveDiagonal("dl",self.board,self.board[i])154 if spaceDR:155 score = MoveScore().moveScore(self.board[i],spaceDR[0].get_name())156 moves.append(157 [self.board[i].get_row(),self.board[i].get_column(),spaceDR[0].get_row(),158 spaceDR[0].get_column(),score-15])159 else:160 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())161 moves.append(162 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 17].get_row(),163 self.board[i - 17].get_column(),score-15])164 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[165 i - 15].get_name() == " ":166 spaceRD = MovesBoard().moveDiagonal("dr",self.board,self.board[i])167 if spaceRD:168 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())169 moves.append(170 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),171 spaceRD[0].get_column(),score-15])172 else:173 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())174 moves.append(175 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 15].get_row(),176 self.board[i - 15].get_column(),score-15])177 return moves178 def movesAtack(self):179 movesAtack = []180 for i in range(0,len(self.board)):181 if self.board[i].get_name() == "q":182 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_colour() == "white":183 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())184 movesAtack.append(185 [self.board[i].get_row(),self.board[i].get_column(),186 self.board[i + 16].get_row(),187 self.board[i + 16].get_column(),score])188 elif 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":189 space = MovesBoard().moveLineEnemy("up",self.board,self.board[i + 16],"white")190 if space:191 score = MoveScore().moveScore(self.board[i],space[0].get_name())192 movesAtack.append(193 [self.board[i].get_row(),self.board[i].get_column(),194 space[0].get_row(),space[0].get_column(),score])195 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_colour() == "white":196 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())197 movesAtack.append(198 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),199 self.board[i - 16].get_column(),score])200 elif 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":201 space = MovesBoard().moveLineEnemy("down",self.board,self.board[i - 16],"white")202 if space:203 score = MoveScore().moveScore(self.board[i],space[0].get_name())204 movesAtack.append(205 [self.board[i].get_row(),self.board[i].get_column(),206 space[0].get_row(),space[0].get_column(),score])207 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_colour() == "white":208 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())209 movesAtack.append(210 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),211 self.board[i + 1].get_column(),score])212 elif 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":213 space = MovesBoard().moveLineEnemy("right",self.board,self.board[i + 1],"white")214 if space:215 score = MoveScore().moveScore(self.board[i],space[0].get_name())216 movesAtack.append(217 [self.board[i].get_row(),self.board[i].get_column(),218 space[0].get_row(),space[0].get_column(),score])219 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_colour() == "white":220 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())221 movesAtack.append(222 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),223 self.board[i - 1].get_column(),score])224 elif 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":225 space = MovesBoard().moveLineEnemy("left",self.board,self.board[i - 1],"white")226 if space:227 score = MoveScore().moveScore(self.board[i],space[0].get_name())228 movesAtack.append(229 [self.board[i].get_row(),self.board[i].get_column(),230 space[0].get_row(),space[0].get_column(),score])231 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[232 i + 17].get_colour() == "white":233 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())234 movesAtack.append(235 [self.board[i].get_row(),self.board[i].get_column(),236 self.board[i + 17].get_row(),self.board[i + 17].get_column(),score])237 elif 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[238 i + 17].get_name() == " ":239 space = MovesBoard().moveDiagonalEnemy("rd",self.board,self.board[i + 17],"white")240 if space:241 score = MoveScore().moveScore(self.board[i],space[0].get_name())242 movesAtack.append(243 [self.board[i].get_row(),self.board[i].get_column(),244 space[0].get_row(),space[0].get_column(),score])245 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[246 i + 15].get_colour() == "white":247 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())248 movesAtack.append(249 [self.board[i].get_row(),self.board[i].get_column(),250 self.board[i + 15].get_row(),self.board[i + 15].get_column(),score])251 elif 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[252 i + 15].get_name() == " ":253 space = MovesBoard().moveDiagonalEnemy("ldd",self.board,self.board[i + 15],"white")254 if space:255 score = MoveScore().moveScore(self.board[i],space[0].get_name())256 movesAtack.append(257 [self.board[i].get_row(),self.board[i].get_column(),space[0].get_row(),258 space[0].get_column(),score])259 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[260 i - 17].get_colour() == "white":261 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())262 movesAtack.append(263 [self.board[i].get_row(),self.board[i].get_column(),264 self.board[i - 17].get_row(),self.board[i - 17].get_column(),score])265 elif 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[266 i - 17].get_name() == " ":267 space = MovesBoard().moveDiagonalEnemy("dl",self.board,self.board[i - 17],"white")268 if space:269 score = MoveScore().moveScore(self.board[i],space[0].get_name())270 movesAtack.append(271 [self.board[i].get_row(),self.board[i].get_column(),272 space[0].get_row(),space[0].get_column(),score])273 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[274 i - 15].get_colour() == "white":275 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())276 movesAtack.append(277 [self.board[i].get_row(),self.board[i].get_column(),278 self.board[i - 15].get_row(),self.board[i - 15].get_column(),score])279 elif 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[280 i - 15].get_name() == " ":281 space = MovesBoard().moveDiagonalEnemy("dr",self.board,self.board[i - 15],"white")282 if space:283 score = MoveScore().moveScore(self.board[i],space[0].get_name())284 movesAtack.append(285 [self.board[i].get_row(),self.board[i].get_column(),space[0].get_row(),286 space[0].get_column(),score])287 return movesAtack288class KingBlack(PiecesStrategy):289 def moves(self):290 moves = []291 for i in range(0,len(self.board)):292 if self.board[i].get_name() == "k":293 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":294 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())295 moves.append(296 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),297 self.board[i + 16].get_column(),score-85])298 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":299 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())300 moves.append(301 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),302 self.board[i - 16].get_column(),score-85])303 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":304 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())305 moves.append(306 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),307 self.board[i + 1].get_column(),score-85])308 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":309 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())310 moves.append(311 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),312 self.board[i - 1].get_column(),score-85])313 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[314 i + 15].get_name() == " ":315 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())316 moves.append(317 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 15].get_row(),318 self.board[i + 15].get_column(),score-85])319 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[320 i - 17].get_name() == " ":321 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())322 moves.append(323 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 17].get_row(),324 self.board[i - 17].get_column(),score-85])325 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[326 i + 17].get_name() == " ":327 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())328 moves.append(329 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 17].get_row(),330 self.board[i + 17].get_column(),score-85])331 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[332 i - 15].get_name() == " ":333 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())334 moves.append(335 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 15].get_row(),336 self.board[i - 15].get_column(),score-85])337 return moves338 def movesAtack(self):339 movesAtack = []340 for i in range(0,len(self.board)):341 if self.board[i].get_name() == "k":342 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_colour() == "white":343 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())344 movesAtack.append(345 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),346 self.board[i + 16].get_column(),score])347 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_colour() == "white":348 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())349 movesAtack.append(350 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),351 self.board[i - 16].get_column(),score])352 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_colour() == "white":353 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())354 movesAtack.append(355 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),356 self.board[i + 1].get_column(),score])357 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_colour() == "white":358 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())359 movesAtack.append(360 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),361 self.board[i - 1].get_column(),score])362 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[363 i + 15].get_colour() == "white":364 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())365 movesAtack.append(366 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 15].get_row(),367 self.board[i + 15].get_column(),score])368 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[369 i - 17].get_colour() == "white":370 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())371 movesAtack.append(372 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 17].get_row(),373 self.board[i - 17].get_column(),score])374 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[375 i + 17].get_colour() == "white":376 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())377 movesAtack.append(378 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 17].get_row(),379 self.board[i + 17].get_column(),score])380 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[381 i - 15].get_colour() == "white":382 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())383 movesAtack.append(384 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 15].get_row(),385 self.board[i - 15].get_column(),score])386 return movesAtack387class RookBlack(PiecesStrategy):388 def moves(self):389 moves = []390 for i in range(0,len(self.board)):391 if self.board[i].get_name() == "r":392 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":393 spaceUp = MovesBoard().moveLine("up",self.board,self.board[i])394 if spaceUp:395 score = MoveScore().moveScore(self.board[i],spaceUp[0].get_name())396 moves.append(397 [self.board[i].get_row(),self.board[i].get_column(),spaceUp[0].get_row(),398 spaceUp[0].get_column(),score-45])399 else:400 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())401 moves.append(402 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),403 self.board[i + 16].get_column(),score-45])404 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":405 spaceDown = MovesBoard().moveLine("down",self.board,self.board[i])406 if spaceDown:407 score = MoveScore().moveScore(self.board[i],spaceDown[0].get_name())408 moves.append(409 [self.board[i].get_row(),self.board[i].get_column(),spaceDown[0].get_row(),410 spaceDown[0].get_column(),score-45])411 else:412 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())413 moves.append(414 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),415 self.board[i - 16].get_column(),score-45])416 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":417 spaceRight = MovesBoard().moveLine("right",self.board,self.board[i])418 if spaceRight:419 score = MoveScore().moveScore(self.board[i],spaceRight[0].get_name())420 moves.append(421 [self.board[i].get_row(),self.board[i].get_column(),spaceRight[0].get_row(),422 spaceRight[0].get_column(),score-45])423 else:424 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())425 moves.append(426 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),427 self.board[i + 1].get_column(),score-45])428 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":429 spaceLeft = MovesBoard().moveLine("left",self.board,self.board[i])430 if spaceLeft:431 score = MoveScore().moveScore(self.board[i],spaceLeft[0].get_name())432 moves.append(433 [self.board[i].get_row(),self.board[i].get_column(),spaceLeft[0].get_row(),434 spaceLeft[0].get_column(),score-45])435 else:436 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())437 moves.append(438 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),439 self.board[i - 1].get_column(),score-45])440 return moves441 def movesAtack(self):442 movesAtack = []443 for i in range(0,len(self.board)):444 if self.board[i].get_name() == "r":445 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_colour() == "white":446 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())447 movesAtack.append(448 [self.board[i].get_row(),self.board[i].get_column(),449 self.board[i + 16].get_row(),450 self.board[i + 16].get_column(),score])451 elif 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":452 space = MovesBoard().moveLineEnemy("up",self.board,self.board[i + 16],"white")453 if space:454 score = MoveScore().moveScore(self.board[i],space[0].get_name())455 movesAtack.append(456 [self.board[i].get_row(),self.board[i].get_column(),457 space[0].get_row(),space[0].get_column(),score])458 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_colour() == "white":459 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())460 movesAtack.append(461 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),462 self.board[i - 16].get_column(),score])463 elif 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":464 space = MovesBoard().moveLineEnemy("down",self.board,self.board[i - 16],"white")465 if space:466 score = MoveScore().moveScore(self.board[i],space[0].get_name())467 movesAtack.append(468 [self.board[i].get_row(),self.board[i].get_column(),469 space[0].get_row(),space[0].get_column(),score])470 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_colour() == "white":471 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())472 movesAtack.append(473 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),474 self.board[i + 1].get_column(),score])475 elif 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":476 space = MovesBoard().moveLineEnemy("right",self.board,self.board[i + 1],"white")477 if space:478 score = MoveScore().moveScore(self.board[i],space[0].get_name())479 movesAtack.append(480 [self.board[i].get_row(),self.board[i].get_column(),481 space[0].get_row(),space[0].get_column(),score])482 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_colour() == "white":483 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())484 movesAtack.append(485 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),486 self.board[i - 1].get_column(),score])487 elif 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":488 space = MovesBoard().moveLineEnemy("right",self.board,self.board[i - 1],"white")489 if space:490 score = MoveScore().moveScore(self.board[i],space[0].get_name())491 movesAtack.append(492 [self.board[i].get_row(),self.board[i].get_column(),493 space[0].get_row(),space[0].get_column(),score])494 return movesAtack495class BishopBlack(PiecesStrategy):496 def moves(self):497 moves = []498 for i in range(0,len(self.board)):499 if self.board[i].get_name() == "b":500 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[501 i + 17].get_name() == " ":502 spaceRD = MovesBoard().moveDiagonal("rd",self.board,self.board[i])503 if spaceRD:504 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())505 moves.append(506 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),507 spaceRD[0].get_column(),score-25])508 else:509 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())510 moves.append(511 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 17].get_row(),512 self.board[i + 17].get_column(),score-25])513 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[514 i + 15].get_name() == " ":515 spaceRD = MovesBoard().moveDiagonal("ldd",self.board,self.board[i])516 if spaceRD:517 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())518 moves.append(519 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),520 spaceRD[0].get_column(),score-25])521 else:522 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())523 moves.append(524 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 15].get_row(),525 self.board[i + 15].get_column(),score-25])526 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[527 i - 17].get_name() == " ":528 spaceDR = MovesBoard().moveDiagonal("dl",self.board,self.board[i])529 if spaceDR:530 score = MoveScore().moveScore(self.board[i],spaceDR[0].get_name())531 moves.append(532 [self.board[i].get_row(),self.board[i].get_column(),spaceDR[0].get_row(),533 spaceDR[0].get_column(),score-25])534 else:535 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())536 moves.append(537 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 17].get_row(),538 self.board[i - 17].get_column(),score-25])539 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[540 i - 15].get_name() == " ":541 spaceRD = MovesBoard().moveDiagonal("dr",self.board,self.board[i])542 if spaceRD:543 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())544 moves.append(545 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),546 spaceRD[0].get_column(),score-25])547 else:548 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())549 moves.append(550 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 15].get_row(),551 self.board[i - 15].get_column(),score-25])552 return moves553 def movesAtack(self):554 movesAtack = []555 for i in range(0,len(self.board)):556 if self.board[i].get_name() == "b":557 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[i + 17].get_colour() == "white":558 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())559 movesAtack.append(560 [self.board[i].get_row(),self.board[i].get_column(),561 self.board[i + 17].get_row(),self.board[i + 17].get_column(),score])562 elif 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[i + 17].get_name() == " ":563 space = MovesBoard().moveDiagonalEnemy("rd",self.board,self.board[i + 17],"white")564 if space:565 score = MoveScore().moveScore(self.board[i],space[0].get_name())566 movesAtack.append(567 [self.board[i].get_row(),self.board[i].get_column(),568 space[0].get_row(),space[0].get_column(),score])569 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[i + 15].get_colour() == "white":570 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())571 movesAtack.append(572 [self.board[i].get_row(),self.board[i].get_column(),573 self.board[i + 15].get_row(),self.board[i + 15].get_column(),score])574 elif 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[i + 15].get_name() == " ":575 space = MovesBoard().moveDiagonalEnemy("ldd",self.board,self.board[i + 15],"white")576 if space:577 score = MoveScore().moveScore(self.board[i],space[0].get_name())578 movesAtack.append(579 [self.board[i].get_row(),self.board[i].get_column(),space[0].get_row(),580 space[0].get_column(),score])581 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[i - 17].get_colour() == "white":582 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())583 movesAtack.append(584 [self.board[i].get_row(),self.board[i].get_column(),585 self.board[i - 17].get_row(),self.board[i - 17].get_column(),score])586 elif 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[i - 17].get_name() == " ":587 space = MovesBoard().moveDiagonalEnemy("dl",self.board,self.board[i - 17],"white")588 if space:589 score = MoveScore().moveScore(self.board[i],space[0].get_name())590 movesAtack.append(591 [self.board[i].get_row(),self.board[i].get_column(),592 space[0].get_row(),space[0].get_column(),score])593 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[i - 15].get_colour() == "white":594 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())595 movesAtack.append(596 [self.board[i].get_row(),self.board[i].get_column(),597 self.board[i - 15].get_row(),self.board[i - 15].get_column(),score])598 elif 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[i - 15].get_name() == " ":599 space = MovesBoard().moveDiagonalEnemy("dr",self.board,self.board[i - 15],"white")600 if space:601 score = MoveScore().moveScore(self.board[i],space[0].get_name())602 movesAtack.append(603 [self.board[i].get_row(),self.board[i].get_column(),space[0].get_row(),604 space[0].get_column(),score])605 return movesAtack606class KnightBlack(PiecesStrategy):607 def moves(self):608 moves = []609 for i in range(0,len(self.board)):610 if self.board[i].get_name() == "h":611 if 2<=self.board[i].get_column()<=15 and 0<=self.board[i].get_row()<15 and self.board[i + 14].get_name() == " ":612 score = MoveScore().moveScore(self.board[i],self.board[i + 14].get_name())613 moves.append(614 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 14].get_row(),self.board[i + 14].get_column(),score-15])615 if 0<=self.board[i].get_column()<14 and 0<=self.board[i].get_row()<15 and self.board[i + 18].get_name() == " ":616 score = MoveScore().moveScore(self.board[i],self.board[i + 18].get_name())617 moves.append(618 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 18].get_row(),619 self.board[i + 18].get_column(),score-15])620 if 1<=self.board[i].get_column()<=15 and 0<=self.board[i].get_row()<14 and self.board[i + 31].get_name() == " ":621 score = MoveScore().moveScore(self.board[i],self.board[i + 31].get_name())622 moves.append(623 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 31].get_row(),624 self.board[i + 31].get_column(),score-15])625 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<14 and self.board[i + 33].get_name() == " ":626 score = MoveScore().moveScore(self.board[i],self.board[i + 33].get_name())627 moves.append(628 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 33].get_row(),629 self.board[i + 33].get_column(),score-15])630 if 0<=self.board[i].get_column()<14 and 0<self.board[i].get_row()<=15 and self.board[i - 14].get_name() == " ":631 score = MoveScore().moveScore(self.board[i],self.board[i - 14].get_name())632 moves.append(633 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 14].get_row(),self.board[i - 14].get_column(),score])634 if 2<=self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[i - 18].get_name() == " ":635 score = MoveScore().moveScore(self.board[i],self.board[i - 18].get_name())636 moves.append(637 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 18].get_row(),638 self.board[i - 18].get_column(),score-15])639 if 0<=self.board[i].get_column()<15 and 1<self.board[i].get_row()<=15 and self.board[i - 31].get_name() == " ":640 score = MoveScore().moveScore(self.board[i],self.board[i - 31].get_name())641 moves.append(642 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 31].get_row(),643 self.board[i - 31].get_column(),score-15])644 if 0<self.board[i].get_column()<=15 and 1<self.board[i].get_row()<=15 and self.board[i - 33].get_name() == " ":645 score = MoveScore().moveScore(self.board[i],self.board[i - 33].get_name())646 moves.append(647 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 33].get_row(),648 self.board[i - 33].get_column(),score-15])649 return moves650 def movesAtack(self):651 movesAtack = []652 for i in range(0,len(self.board)):653 if self.board[i].get_name() == "h":654 if 2<=self.board[i].get_column()<=15 and 0<=self.board[i].get_row()<15 and self.board[i + 14].get_colour() == "white":655 score = MoveScore().moveScore(self.board[i],self.board[i + 14].get_name())656 movesAtack.append(657 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 14].get_row(),658 self.board[i + 14].get_column(),score])659 if 0<=self.board[i].get_column()<14 and 0<=self.board[i].get_row()<15 and self.board[i + 18].get_colour() == "white":660 score = MoveScore().moveScore(self.board[i],self.board[i + 18].get_name())661 movesAtack.append(662 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 18].get_row(),663 self.board[i + 18].get_column(),score])664 if 1<=self.board[i].get_column()<=15 and 0<=self.board[i].get_row()<14 and self.board[i + 31].get_colour() == "white":665 score = MoveScore().moveScore(self.board[i],self.board[i + 31].get_name())666 movesAtack.append(667 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 31].get_row(),668 self.board[i + 31].get_column(),score])669 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<14 and self.board[i + 33].get_colour() == "white":670 score = MoveScore().moveScore(self.board[i],self.board[i + 33].get_name())671 movesAtack.append(672 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 33].get_row(),673 self.board[i + 33].get_column(),score])674 if 0<=self.board[i].get_column()<14 and 0<self.board[i].get_row()<=15 and self.board[i - 14].get_colour() == "white":675 score = MoveScore().moveScore(self.board[i],self.board[i - 14].get_name())676 movesAtack.append(677 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 14].get_row(),678 self.board[i - 14].get_column(),score])679 if 2<=self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[i - 18].get_colour() == "white":680 score = MoveScore().moveScore(self.board[i],self.board[i - 18].get_name())681 movesAtack.append(682 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 18].get_row(),683 self.board[i - 18].get_column(),score])684 if 0<=self.board[i].get_column()<15 and 1<self.board[i].get_row()<=15 and self.board[i - 31].get_colour() == "white":685 score = MoveScore().moveScore(self.board[i],self.board[i - 31].get_name())686 movesAtack.append(687 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 31].get_row(),688 self.board[i - 31].get_column(),score])689 if 0<self.board[i].get_column()<=15 and 1<self.board[i].get_row()<=15 and self.board[i - 33].get_colour() == "white":690 score = MoveScore().moveScore(self.board[i],self.board[i - 33].get_name())691 movesAtack.append(692 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 33].get_row(),693 self.board[i - 33].get_column(),score])...
whiteStrategy.py
Source:whiteStrategy.py
...26 if self.board[i - 16].get_name() == " " and (self.board[i].row == 2 or self.board[i].row == 3):27 if self.board[i - 32].get_name() == " ":28 score = MoveScore().moveScore(self.board[i],self.board[i - 32].get_name())29 moves.append(30 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 32].get_row(),31 self.board[i - 32].get_column(),score])32 if self.board[i - 16].get_name() == " " and self.board[i].row>3:33 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())34 moves.append(35 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),36 self.board[i - 16].get_column(),score+5])37 return moves38 def movesAtack(self):39 movesAtack = []40 for i in range(0,len(self.board)):41 if self.board[i].get_name() == "P":42 if self.board[i - 17].get_colour() == "black" and 0<self.board[i].get_column()<=15:43 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())44 movesAtack.append(45 [self.board[i].get_row(),self.board[i].get_column(),46 self.board[i - 17].get_row(),47 self.board[i - 17].get_column(),score+1])48 if self.board[i - 15].get_colour() == "black" and 0<=self.board[i].get_column()<15:49 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())50 movesAtack.append(51 [self.board[i].get_row(),self.board[i].get_column(),52 self.board[i - 15].get_row(),53 self.board[i - 15].get_column(),score+1])54 return movesAtack55class QueenWhite(PiecesStrategy):56 def moves(self):57 moves = []58 for i in range(0,len(self.board)):59 if self.board[i].get_name() == "Q":60 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":61 spaceUp = MovesBoard().moveLine("up",self.board,self.board[i])62 if spaceUp:63 score = MoveScore().moveScore(self.board[i],spaceUp[0].get_name())64 moves.append(65 [self.board[i].get_row(),self.board[i].get_column(),spaceUp[0].get_row(),66 spaceUp[0].get_column(),score-15])67 else:68 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())69 moves.append(70 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),71 self.board[i + 16].get_column(),score-15])72 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":73 spaceDown = MovesBoard().moveLine("down",self.board,self.board[i])74 if spaceDown:75 score = MoveScore().moveScore(self.board[i],spaceDown[0].get_name())76 moves.append(77 [self.board[i].get_row(),self.board[i].get_column(),spaceDown[0].get_row(),78 spaceDown[0].get_column(),score-15])79 else:80 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())81 moves.append(82 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),83 self.board[i - 16].get_column(),score-15])84 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":85 spaceRight = MovesBoard().moveLine("right",self.board,self.board[i])86 if spaceRight:87 score = MoveScore().moveScore(self.board[i],spaceRight[0].get_name())88 moves.append(89 [self.board[i].get_row(),self.board[i].get_column(),spaceRight[0].get_row(),90 spaceRight[0].get_column(),score-15])91 else:92 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())93 moves.append(94 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),95 self.board[i + 1].get_column(),score-15])96 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":97 spaceLeft = MovesBoard().moveLine("left",self.board,self.board[i])98 if spaceLeft:99 score = MoveScore().moveScore(self.board[i],spaceLeft[0].get_name())100 moves.append(101 [self.board[i].get_row(),self.board[i].get_column(),spaceLeft[0].get_row(),102 spaceLeft[0].get_column(),score-15])103 else:104 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())105 moves.append(106 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),107 self.board[i - 1].get_column(),score-15])108 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[109 i + 17].get_name() == " ":110 spaceRD = MovesBoard().moveDiagonal("rd",self.board,self.board[i])111 if spaceRD:112 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())113 moves.append(114 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),115 spaceRD[0].get_column(),score-15])116 else:117 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())118 moves.append(119 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 17].get_row(),120 self.board[i + 17].get_column(),score-15])121 if 0<=self.board[i].get_row()<15 and 0<self.board[i].get_column()<15 and self.board[122 i + 15].get_name() == " ":123 spaceRD = MovesBoard().moveDiagonal("ldd",self.board,self.board[i])124 if spaceRD:125 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())126 moves.append(127 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),128 spaceRD[0].get_column(),score-15])129 else:130 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())131 moves.append(132 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 15].get_row(),133 self.board[i + 15].get_column(),score-15])134 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[135 i - 17].get_name() == " ":136 spaceDR = MovesBoard().moveDiagonal("dl",self.board,self.board[i])137 if spaceDR:138 score = MoveScore().moveScore(self.board[i],spaceDR[0].get_name())139 moves.append(140 [self.board[i].get_row(),self.board[i].get_column(),spaceDR[0].get_row(),141 spaceDR[0].get_column(),score-15])142 else:143 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())144 moves.append(145 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 17].get_row(),146 self.board[i - 17].get_column(),score-15])147 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[148 i - 15].get_name() == " ":149 spaceRD = MovesBoard().moveDiagonal("dr",self.board,self.board[i])150 if spaceRD:151 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())152 moves.append(153 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),154 spaceRD[0].get_column(),score-15])155 else:156 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())157 moves.append(158 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 15].get_row(),159 self.board[i - 15].get_column(),score-15])160 return moves161 def movesAtack(self):162 movesAtack = []163 for i in range(0,len(self.board)):164 if self.board[i].get_name() == "Q":165 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_colour() == "black":166 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())167 movesAtack.append(168 [self.board[i].get_row(),self.board[i].get_column(),169 self.board[i + 16].get_row(),170 self.board[i + 16].get_column(),score])171 elif 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":172 space = MovesBoard().moveLineEnemy("up",self.board,self.board[i + 16],"black")173 if space:174 score = MoveScore().moveScore(self.board[i],space[0].get_name())175 movesAtack.append(176 [self.board[i].get_row(),self.board[i].get_column(),177 space[0].get_row(),space[0].get_column(),score])178 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_colour() == "black":179 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())180 movesAtack.append(181 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),182 self.board[i - 16].get_column(),score])183 elif 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":184 space = MovesBoard().moveLineEnemy("down",self.board,self.board[i - 16],"black")185 if space:186 score = MoveScore().moveScore(self.board[i],space[0].get_name())187 movesAtack.append(188 [self.board[i].get_row(),self.board[i].get_column(),189 space[0].get_row(),space[0].get_column(),score])190 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_colour() == "black":191 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())192 movesAtack.append(193 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),194 self.board[i + 1].get_column(),score])195 elif 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":196 space = MovesBoard().moveLineEnemy("right",self.board,self.board[i + 1],"black")197 if space:198 score = MoveScore().moveScore(self.board[i],space[0].get_name())199 movesAtack.append(200 [self.board[i].get_row(),self.board[i].get_column(),201 space[0].get_row(),space[0].get_column(),score])202 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_colour() == "black":203 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())204 movesAtack.append(205 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),206 self.board[i - 1].get_column(),score])207 elif 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":208 space = MovesBoard().moveLineEnemy("left",self.board,self.board[i - 1],"black")209 if space:210 score = MoveScore().moveScore(self.board[i],space[0].get_name())211 movesAtack.append(212 [self.board[i].get_row(),self.board[i].get_column(),213 space[0].get_row(),space[0].get_column(),score])214 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[215 i + 17].get_colour() == "black":216 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())217 movesAtack.append(218 [self.board[i].get_row(),self.board[i].get_column(),219 self.board[i + 17].get_row(),self.board[i + 17].get_column(),score])220 elif 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[221 i + 17].get_name() == " ":222 space = MovesBoard().moveDiagonalEnemy("rd",self.board,self.board[i + 17],"black")223 if space:224 score = MoveScore().moveScore(self.board[i],space[0].get_name())225 movesAtack.append(226 [self.board[i].get_row(),self.board[i].get_column(),227 space[0].get_row(),space[0].get_column(),score])228 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[229 i + 15].get_colour() == "black":230 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())231 movesAtack.append(232 [self.board[i].get_row(),self.board[i].get_column(),233 self.board[i + 15].get_row(),self.board[i + 15].get_column(),score])234 elif 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[235 i + 15].get_name() == " ":236 space = MovesBoard().moveDiagonalEnemy("ldd",self.board,self.board[i + 15],"black")237 if space:238 score = MoveScore().moveScore(self.board[i],space[0].get_name())239 movesAtack.append(240 [self.board[i].get_row(),self.board[i].get_column(),space[0].get_row(),241 space[0].get_column(),score])242 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[243 i - 17].get_colour() == "black":244 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())245 movesAtack.append(246 [self.board[i].get_row(),self.board[i].get_column(),247 self.board[i - 17].get_row(),self.board[i - 17].get_column(),score])248 elif 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[249 i - 17].get_name() == " ":250 space = MovesBoard().moveDiagonalEnemy("dl",self.board,self.board[i - 17],"black")251 if space:252 score = MoveScore().moveScore(self.board[i],space[0].get_name())253 movesAtack.append(254 [self.board[i].get_row(),self.board[i].get_column(),255 space[0].get_row(),space[0].get_column(),score])256 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[257 i - 15].get_colour() == "black":258 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())259 movesAtack.append(260 [self.board[i].get_row(),self.board[i].get_column(),261 self.board[i - 15].get_row(),self.board[i - 15].get_column(),score])262 elif 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[263 i - 15].get_name() == " ":264 space = MovesBoard().moveDiagonalEnemy("dr",self.board,self.board[i - 15],"black")265 if space:266 score = MoveScore().moveScore(self.board[i],space[0].get_name())267 movesAtack.append(268 [self.board[i].get_row(),self.board[i].get_column(),space[0].get_row(),269 space[0].get_column(),score])270 return movesAtack271class KingWhite(PiecesStrategy):272 def moves(self):273 moves = []274 for i in range(0,len(self.board)):275 if self.board[i].get_name() == "K":276 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":277 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())278 moves.append(279 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),280 self.board[i + 16].get_column(),score-85])281 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":282 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())283 moves.append(284 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),285 self.board[i - 16].get_column(),score-85])286 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":287 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())288 moves.append(289 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),290 self.board[i + 1].get_column(),score-85])291 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":292 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())293 moves.append(294 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),295 self.board[i - 1].get_column(),score-85])296 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[297 i + 15].get_name() == " ":298 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())299 moves.append(300 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 15].get_row(),301 self.board[i + 15].get_column(),score-85])302 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[303 i - 17].get_name() == " ":304 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())305 moves.append(306 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 17].get_row(),307 self.board[i - 17].get_column(),score])308 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[309 i + 17].get_name() == " ":310 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())311 moves.append(312 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 17].get_row(),313 self.board[i + 17].get_column(),score-85])314 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[315 i - 15].get_name() == " ":316 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())317 moves.append(318 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 15].get_row(),319 self.board[i - 15].get_column(),score-85])320 return moves321 def movesAtack(self):322 movesAtack = []323 for i in range(0,len(self.board)):324 if self.board[i].get_name() == "K":325 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_colour() == "black":326 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())327 movesAtack.append(328 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),329 self.board[i + 16].get_column(),score])330 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_colour() == "black":331 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())332 movesAtack.append(333 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),334 self.board[i - 16].get_column(),score])335 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_colour() == "black":336 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())337 movesAtack.append(338 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),339 self.board[i + 1].get_column(),score])340 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_colour() == "black":341 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())342 movesAtack.append(343 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),344 self.board[i - 1].get_column(),score])345 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[346 i + 15].get_colour() == "black":347 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())348 movesAtack.append(349 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 15].get_row(),350 self.board[i + 15].get_column(),score])351 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[352 i - 17].get_colour() == "black":353 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())354 movesAtack.append(355 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 17].get_row(),356 self.board[i - 17].get_column(),score])357 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[358 i + 17].get_colour() == "black":359 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())360 movesAtack.append(361 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 17].get_row(),362 self.board[i + 17].get_column(),score])363 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[364 i - 15].get_colour() == "black":365 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())366 movesAtack.append(367 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 15].get_row(),368 self.board[i - 15].get_column(),score])369 return movesAtack370class RookWhite(PiecesStrategy):371 def moves(self):372 moves = []373 for i in range(0,len(self.board)):374 if self.board[i].get_name() == "R":375 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":376 spaceUp = MovesBoard().moveLine("up",self.board,self.board[i])377 if spaceUp:378 score = MoveScore().moveScore(self.board[i],spaceUp[0].get_name())379 moves.append(380 [self.board[i].get_row(),self.board[i].get_column(),spaceUp[0].get_row(),381 spaceUp[0].get_column(),score-45])382 else:383 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())384 moves.append(385 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 16].get_row(),386 self.board[i + 16].get_column(),score-45])387 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":388 spaceDown = MovesBoard().moveLine("down",self.board,self.board[i])389 if spaceDown:390 score = MoveScore().moveScore(self.board[i],spaceDown[0].get_name())391 moves.append(392 [self.board[i].get_row(),self.board[i].get_column(),spaceDown[0].get_row(),393 spaceDown[0].get_column(),score-45])394 else:395 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())396 moves.append(397 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),398 self.board[i - 16].get_column(),score-45])399 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":400 spaceRight = MovesBoard().moveLine("right",self.board,self.board[i])401 if spaceRight:402 score = MoveScore().moveScore(self.board[i],spaceRight[0].get_name())403 moves.append(404 [self.board[i].get_row(),self.board[i].get_column(),spaceRight[0].get_row(),405 spaceRight[0].get_column(),score-45])406 else:407 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())408 moves.append(409 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),410 self.board[i + 1].get_column(),score-45])411 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":412 spaceLeft = MovesBoard().moveLine("left",self.board,self.board[i])413 if spaceLeft:414 score = MoveScore().moveScore(self.board[i],spaceLeft[0].get_name())415 moves.append(416 [self.board[i].get_row(),self.board[i].get_column(),spaceLeft[0].get_row(),417 spaceLeft[0].get_column(),score-45])418 else:419 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())420 moves.append(421 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),422 self.board[i - 1].get_column(),score-45])423 return moves424 def movesAtack(self):425 movesAtack = []426 for i in range(0,len(self.board)):427 if self.board[i].get_name() == "R":428 if 0<=self.board[i].get_row()<15 and self.board[i + 16].get_colour() == "black":429 score = MoveScore().moveScore(self.board[i],self.board[i + 16].get_name())430 movesAtack.append(431 [self.board[i].get_row(),self.board[i].get_column(),432 self.board[i + 16].get_row(),433 self.board[i + 16].get_column(),score])434 elif 0<=self.board[i].get_row()<15 and self.board[i + 16].get_name() == " ":435 space = MovesBoard().moveLineEnemy("up",self.board,self.board[i + 16],"black")436 if space:437 score = MoveScore().moveScore(self.board[i],space[0].get_name())438 movesAtack.append(439 [self.board[i].get_row(),self.board[i].get_column(),440 space[0].get_row(),space[0].get_column(),score])441 if 0<self.board[i].get_row()<=15 and self.board[i - 16].get_colour() == "black":442 score = MoveScore().moveScore(self.board[i],self.board[i - 16].get_name())443 movesAtack.append(444 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 16].get_row(),445 self.board[i - 16].get_column(),score])446 elif 0<self.board[i].get_row()<=15 and self.board[i - 16].get_name() == " ":447 space = MovesBoard().moveLineEnemy("down",self.board,self.board[i - 16],"black")448 if space:449 score = MoveScore().moveScore(self.board[i],space[0].get_name())450 movesAtack.append(451 [self.board[i].get_row(),self.board[i].get_column(),452 space[0].get_row(),space[0].get_column(),score])453 if 0<=self.board[i].get_column()<15 and self.board[i + 1].get_colour() == "black":454 score = MoveScore().moveScore(self.board[i],self.board[i + 1].get_name())455 movesAtack.append(456 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 1].get_row(),457 self.board[i + 1].get_column(),score])458 elif 0<=self.board[i].get_column()<15 and self.board[i + 1].get_name() == " ":459 space = MovesBoard().moveLineEnemy("right",self.board,self.board[i + 1],"black")460 if space:461 score = MoveScore().moveScore(self.board[i],space[0].get_name())462 movesAtack.append(463 [self.board[i].get_row(),self.board[i].get_column(),464 space[0].get_row(),space[0].get_column(),score])465 if 0<self.board[i].get_column()<=15 and self.board[i - 1].get_colour() == "black":466 score = MoveScore().moveScore(self.board[i],self.board[i - 1].get_name())467 movesAtack.append(468 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 1].get_row(),469 self.board[i - 1].get_column(),score])470 elif 0<self.board[i].get_column()<=15 and self.board[i - 1].get_name() == " ":471 space = MovesBoard().moveLineEnemy("right",self.board,self.board[i - 1],"black")472 if space:473 score = MoveScore().moveScore(self.board[i],space[0].get_name())474 movesAtack.append(475 [self.board[i].get_row(),self.board[i].get_column(),476 space[0].get_row(),space[0].get_column(),score])477 return movesAtack478class BishopWhite(PiecesStrategy):479 def moves(self):480 moves = []481 for i in range(0,len(self.board)):482 if self.board[i].get_name() == "B":483 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[484 i + 17].get_name() == " ":485 spaceRD = MovesBoard().moveDiagonal("rd",self.board,self.board[i])486 if spaceRD:487 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())488 moves.append(489 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),490 spaceRD[0].get_column(),score-25])491 else:492 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())493 moves.append(494 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 17].get_row(),495 self.board[i + 17].get_column(),score-25])496 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[497 i + 15].get_name() == " ":498 spaceRD = MovesBoard().moveDiagonal("ldd",self.board,self.board[i])499 if spaceRD:500 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())501 moves.append(502 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),503 spaceRD[0].get_column(),score-25])504 else:505 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())506 moves.append(507 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 15].get_row(),508 self.board[i + 15].get_column(),score-25])509 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[510 i - 17].get_name() == " ":511 spaceDR = MovesBoard().moveDiagonal("dl",self.board,self.board[i])512 if spaceDR:513 score = MoveScore().moveScore(self.board[i],spaceDR[0].get_name())514 moves.append(515 [self.board[i].get_row(),self.board[i].get_column(),spaceDR[0].get_row(),516 spaceDR[0].get_column(),score-25])517 else:518 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())519 moves.append(520 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 17].get_row(),521 self.board[i - 17].get_column(),score-25])522 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[523 i - 15].get_name() == " ":524 spaceRD = MovesBoard().moveDiagonal("dr",self.board,self.board[i])525 if spaceRD:526 score = MoveScore().moveScore(self.board[i],spaceRD[0].get_name())527 moves.append(528 [self.board[i].get_row(),self.board[i].get_column(),spaceRD[0].get_row(),529 spaceRD[0].get_column(),score-25])530 else:531 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())532 moves.append(533 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 15].get_row(),534 self.board[i - 15].get_column(),score-25])535 return moves536 def movesAtack(self):537 movesAtack = []538 for i in range(0,len(self.board)):539 if self.board[i].get_name() == "B":540 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[541 i + 17].get_colour() == "black":542 score = MoveScore().moveScore(self.board[i],self.board[i + 17].get_name())543 movesAtack.append(544 [self.board[i].get_row(),self.board[i].get_column(),545 self.board[i + 17].get_row(),self.board[i + 17].get_column(),score])546 elif 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[547 i + 17].get_name() == " ":548 space = MovesBoard().moveDiagonalEnemy("rd",self.board,self.board[i + 17],"black")549 if space:550 score = MoveScore().moveScore(self.board[i],space[0].get_name())551 movesAtack.append(552 [self.board[i].get_row(),self.board[i].get_column(),553 space[0].get_row(),space[0].get_column(),score])554 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[555 i + 15].get_colour() == "black":556 score = MoveScore().moveScore(self.board[i],self.board[i + 15].get_name())557 movesAtack.append(558 [self.board[i].get_row(),self.board[i].get_column(),559 self.board[i + 15].get_row(),self.board[i + 15].get_column(),score])560 elif 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<15 and self.board[561 i + 15].get_name() == " ":562 space = MovesBoard().moveDiagonalEnemy("ldd",self.board,self.board[i + 15],"black")563 if space:564 score = MoveScore().moveScore(self.board[i],space[0].get_name())565 movesAtack.append(566 [self.board[i].get_row(),self.board[i].get_column(),space[0].get_row(),567 space[0].get_column(),score])568 if 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[569 i - 17].get_colour() == "black":570 score = MoveScore().moveScore(self.board[i],self.board[i - 17].get_name())571 movesAtack.append(572 [self.board[i].get_row(),self.board[i].get_column(),573 self.board[i - 17].get_row(),self.board[i - 17].get_column(),score])574 elif 0<self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[575 i - 17].get_name() == " ":576 space = MovesBoard().moveDiagonalEnemy("dl",self.board,self.board[i - 17],"black")577 if space:578 score = MoveScore().moveScore(self.board[i],space[0].get_name())579 movesAtack.append(580 [self.board[i].get_row(),self.board[i].get_column(),581 space[0].get_row(),space[0].get_column(),score])582 if 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[583 i - 15].get_colour() == "black":584 score = MoveScore().moveScore(self.board[i],self.board[i - 15].get_name())585 movesAtack.append(586 [self.board[i].get_row(),self.board[i].get_column(),587 self.board[i - 15].get_row(),self.board[i - 15].get_column(),score])588 elif 0<=self.board[i].get_column()<15 and 0<self.board[i].get_row()<=15 and self.board[589 i - 15].get_name() == " ":590 space = MovesBoard().moveDiagonalEnemy("dr",self.board,self.board[i - 15],"black")591 if space:592 score = MoveScore().moveScore(self.board[i],space[0].get_name())593 movesAtack.append(594 [self.board[i].get_row(),self.board[i].get_column(),space[0].get_row(),595 space[0].get_column(),score])596 return movesAtack597class KnightWhite(PiecesStrategy):598 def moves(self):599 moves = []600 for i in range(0,len(self.board)):601 if self.board[i].get_name() == "H":602 if 2<=self.board[i].get_column()<=15 and 0<=self.board[i].get_row()<15 and self.board[603 i + 14].get_name() == " ":604 score = MoveScore().moveScore(self.board[i],self.board[i + 14].get_name())605 moves.append(606 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 14].get_row(),607 self.board[i + 14].get_column(),score-15])608 if 0<=self.board[i].get_column()<14 and 0<=self.board[i].get_row()<15 and self.board[609 i + 18].get_name() == " ":610 score = MoveScore().moveScore(self.board[i],self.board[i + 18].get_name())611 moves.append(612 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 18].get_row(),613 self.board[i + 18].get_column(),score-15])614 if 1<=self.board[i].get_column()<=15 and 0<=self.board[i].get_row()<14 and self.board[615 i + 31].get_name() == " ":616 score = MoveScore().moveScore(self.board[i],self.board[i + 31].get_name())617 moves.append(618 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 31].get_row(),619 self.board[i + 31].get_column(),score-15])620 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<14 and self.board[621 i + 33].get_name() == " ":622 score = MoveScore().moveScore(self.board[i],self.board[i + 33].get_name())623 moves.append(624 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 33].get_row(),625 self.board[i + 33].get_column(),score-15])626 if 0<=self.board[i].get_column()<14 and 0<self.board[i].get_row()<=15 and self.board[627 i - 14].get_name() == " ":628 score = MoveScore().moveScore(self.board[i],self.board[i - 14].get_name())629 moves.append(630 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 14].get_row(),631 self.board[i - 14].get_column(),score-15])632 if 2<=self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[633 i - 18].get_name() == " ":634 score = MoveScore().moveScore(self.board[i],self.board[i - 18].get_name())635 moves.append(636 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 18].get_row(),637 self.board[i - 18].get_column(),score-15])638 if 0<=self.board[i].get_column()<15 and 1<self.board[i].get_row()<=15 and self.board[639 i - 31].get_name() == " ":640 score = MoveScore().moveScore(self.board[i],self.board[i - 31].get_name())641 moves.append(642 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 31].get_row(),643 self.board[i - 31].get_column(),score-15])644 if 0<self.board[i].get_column()<=15 and 1<self.board[i].get_row()<=15 and self.board[645 i - 33].get_name() == " ":646 score = MoveScore().moveScore(self.board[i],self.board[i - 33].get_name())647 moves.append(648 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 33].get_row(),649 self.board[i - 33].get_column(),score-15])650 return moves651 def movesAtack(self):652 movesAtack = []653 for i in range(0,len(self.board)):654 if self.board[i].get_name() == "H":655 if 2<=self.board[i].get_column()<=15 and 0<=self.board[i].get_row()<15 and self.board[656 i + 14].get_colour() == "black":657 score = MoveScore().moveScore(self.board[i],self.board[i + 14].get_name())658 movesAtack.append(659 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 14].get_row(),660 self.board[i + 14].get_column(),score])661 if 0<=self.board[i].get_column()<14 and 0<=self.board[i].get_row()<15 and self.board[662 i + 18].get_colour() == "black":663 score = MoveScore().moveScore(self.board[i],self.board[i + 18].get_name())664 movesAtack.append(665 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 18].get_row(),666 self.board[i + 18].get_column(),score])667 if 1<=self.board[i].get_column()<=15 and 0<=self.board[i].get_row()<14 and self.board[668 i + 31].get_colour() == "black":669 score = MoveScore().moveScore(self.board[i],self.board[i + 31].get_name())670 movesAtack.append(671 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 31].get_row(),672 self.board[i + 31].get_column(),score])673 if 0<=self.board[i].get_column()<15 and 0<=self.board[i].get_row()<14 and self.board[674 i + 33].get_colour() == "black":675 score = MoveScore().moveScore(self.board[i],self.board[i + 33].get_name())676 movesAtack.append(677 [self.board[i].get_row(),self.board[i].get_column(),self.board[i + 33].get_row(),678 self.board[i + 33].get_column(),score])679 if 0<=self.board[i].get_column()<14 and 0<self.board[i].get_row()<=15 and self.board[680 i - 14].get_colour() == "black":681 score = MoveScore().moveScore(self.board[i],self.board[i - 14].get_name())682 movesAtack.append(683 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 14].get_row(),684 self.board[i - 14].get_column(),score])685 if 2<=self.board[i].get_column()<=15 and 0<self.board[i].get_row()<=15 and self.board[686 i - 18].get_colour() == "black":687 score = MoveScore().moveScore(self.board[i],self.board[i - 18].get_name())688 movesAtack.append(689 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 18].get_row(),690 self.board[i - 18].get_column(),score])691 if 0<=self.board[i].get_column()<15 and 1<self.board[i].get_row()<=15 and self.board[692 i - 31].get_colour() == "black":693 score = MoveScore().moveScore(self.board[i],self.board[i - 31].get_name())694 movesAtack.append(695 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 31].get_row(),696 self.board[i - 31].get_column(),score])697 if 0<self.board[i].get_column()<=15 and 1<self.board[i].get_row()<=15 and self.board[698 i - 33].get_colour() == "black":699 score = MoveScore().moveScore(self.board[i],self.board[i - 33].get_name())700 movesAtack.append(701 [self.board[i].get_row(),self.board[i].get_column(),self.board[i - 33].get_row(),702 self.board[i - 33].get_column(),score])...
add_animals_to_db.py
Source:add_animals_to_db.py
...9# python manage.py shell10# paste code below11import csv12from animals.models import Cat, Dog, Bird13def get_row(row):14 row = row.strip()15 if len(row) > 0:16 return row17 return None18# Cats19with open('../data/code/cat.csv') as f:20 reader = csv.DictReader(f, delimiter=',')21 for row in reader:22 breed = get_row(row['breed'])23 summary = get_row(row['summary'])24 image = get_row(row['image'])25 other_names = get_row(row['other_names'])26 nicknames = get_row(row['nicknames'])27 origin = get_row(row['origin'])28 _, created = Cat.objects.get_or_create(29 name=breed,30 image_url=image,31 summary=summary,32 other_names=other_names,33 nicknames=nicknames,34 origin=origin35 )36 37# Dogs38# (Paste after above)39with open('../data/code/dog.csv') as f:40 reader = csv.DictReader(f, delimiter=',')41 for row in reader:42 breed = get_row(row['breed'])43 summary = get_row(row['summary'])44 image = get_row(row['image'])45 other_names = get_row(row['other_names'])46 nicknames = get_row(row['nicknames'])47 origin = get_row(row['origin'])48 weight = get_row(row['weight'])49 height = get_row(row['height'])50 coat = get_row(row['coat'])51 color = get_row(row['color'])52 lifespan = get_row(row['lifespan'])53 _, created = Dog.objects.get_or_create(54 name=breed,55 image_url=image,56 summary=summary,57 other_names=other_names,58 nicknames=nicknames,59 origin=origin,60 weight=weight,61 height=height,62 coat=coat,63 color=color,64 lifespan=lifespan65 )66# Birds67# (Paste after above)68with open('../data/code/bird.csv') as f:69 reader = csv.DictReader(f, delimiter=',')70 for row in reader:71 breed = get_row(row['breed'])72 summary = get_row(row['summary'])73 image = get_row(row['image'])74 conservation_status = get_row(row['conservation_status'])75 kingdom = get_row(row['kingdom'])76 phylum = get_row(row['phylum'])77 order = get_row(row['order'])78 family = get_row(row['family'])79 binomial_name = get_row(row['binomial_name'])80 _, created = Bird.objects.get_or_create(81 name=breed,82 image_url=image,83 summary=summary,84 conservation_status=conservation_status,85 kingdom=kingdom,86 phylum=phylum,87 order=order,88 family=family,89 binomial_name=binomial_name...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!