How to use get_layout method in fMBT

Best Python code snippet using fMBT_python

Chariot.py

Source:Chariot.py Github

copy

Full Screen

...61 destinations = dict()62 row = source[0] - 163 column = source[1]64 path = (source,)65 piece = board.get_layout().get((row, column), None)66 while piece is None and row >= board.get_rows_min():67 path += ((row, column),)68 destinations[(row, column)] = path69 row -= 170 piece = board.get_layout().get((row, column), None)71 if piece is not None and type(piece) in board.get_red_pieces():72 path += ((row, column),)73 destinations[(row, column)] = path74 return destinations75 def right_destinations_from_source(self, source, board):76 """77 Blue chariot right destinations from source with paths78 :param source: [Tuple[int]]79 :param board: [Board]80 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]81 """82 destinations = dict()83 row = source[0]84 column = source[1] + 185 path = (source,)86 piece = board.get_layout().get((row, column), None)87 while piece is None and column < board.get_columns_max():88 path += ((row, column),)89 destinations[(row, column)] = path90 column += 191 piece = board.get_layout().get((row, column), None)92 if piece is not None and type(piece) in board.get_red_pieces():93 path += ((row, column),)94 destinations[(row, column)] = path95 return destinations96 def down_destinations_from_source(self, source, board):97 """98 Blue chariot down destinations from source with paths99 :param source: [Tuple[int]]100 :param board: [Board]101 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]102 """103 destinations = dict()104 row = source[0] + 1105 column = source[1]106 path = (source,)107 piece = board.get_layout().get((row, column), None)108 while piece is None and row < board.get_rows_max():109 path += ((row, column),)110 destinations[(row, column)] = path111 row += 1112 piece = board.get_layout().get((row, column), None)113 if piece is not None and type(piece) in board.get_red_pieces():114 path += ((row, column),)115 destinations[(row, column)] = path116 return destinations117 def left_destinations_from_source(self, source, board):118 """119 Blue chariot left destinations from source with paths120 :param source: [Tuple[int]]121 :param board: [Board]122 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]123 """124 destinations = dict()125 row = source[0]126 column = source[1] - 1127 path = (source,)128 piece = board.get_layout().get((row, column), None)129 while piece is None and column >= board.get_columns_min():130 path += ((row, column),)131 destinations[(row, column)] = path132 column -= 1133 piece = board.get_layout().get((row, column), None)134 if piece is not None and type(piece) in board.get_red_pieces():135 path += ((row, column),)136 destinations[(row, column)] = path137 return destinations138 def diagonal_destinations_from_upper_left_palace_source(self, source, board):139 """140 Blue chariot diagonal destinations from upper left palace source with paths141 :param source: [Tuple[int]]142 :param board: [Board]143 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]144 """145 destinations = dict()146 blue_palace_upper_left_corner_source = (7, 3)147 red_palace_upper_left_corner_source = (0, 3)148 if source == blue_palace_upper_left_corner_source or source == red_palace_upper_left_corner_source:149 row = source[0]150 column = source[1]151 path = (source,)152 piece = board.get_layout().get((row + 1, column + 1), None)153 if piece and type(piece) in board.get_red_pieces():154 path += ((row + 1, column + 1),)155 destinations[(row + 1, column + 1)] = path156 elif not piece:157 path += ((row + 1, column + 1),)158 destinations[(row + 1, column + 1)] = path159 piece = board.get_layout().get((row + 2, column + 2), None)160 if piece and type(piece) in board.get_red_pieces():161 path += ((row + 2, column + 2),)162 destinations[(row + 2, column + 2)] = path163 elif not piece:164 path += ((row + 2, column + 2),)165 destinations[(row + 2, column + 2)] = path166 return destinations167 def diagonal_destinations_from_upper_right_palace_source(self, source, board):168 """169 Blue chariot diagonal destinations from upper right palace source with paths170 :param source: [Tuple[int]]171 :param board: [Board]172 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]173 """174 destinations = dict()175 blue_palace_upper_right_corner_source = (7, 5)176 red_palace_upper_right_corner_source = (0, 5)177 if source == blue_palace_upper_right_corner_source or source == red_palace_upper_right_corner_source:178 row = source[0]179 column = source[1]180 path = (source,)181 piece = board.get_layout().get((row + 1, column - 1), None)182 if piece and type(piece) in board.get_red_pieces():183 path += ((row + 1, column - 1),)184 destinations[(row + 1, column - 1)] = path185 elif not piece:186 path += ((row + 1, column - 1),)187 destinations[(row + 1, column - 1)] = path188 piece = board.get_layout().get((row + 2, column - 2), None)189 if piece and type(piece) in board.get_red_pieces():190 path += ((row + 2, column - 2),)191 destinations[(row + 2, column - 2)] = path192 elif not piece:193 path += ((row + 2, column - 2),)194 destinations[(row + 2, column - 2)] = path195 return destinations196 def diagonal_destinations_from_lower_right_palace_source(self, source, board):197 """198 Blue chariot diagonal destinations from lower right palace source with paths199 :param source: [Tuple[int]]200 :param board: [Board]201 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]202 """203 destinations = dict()204 blue_palace_lower_right_corner_source = (9, 5)205 red_palace_lower_right_corner_source = (2, 5)206 if source == blue_palace_lower_right_corner_source or source == red_palace_lower_right_corner_source:207 row = source[0]208 column = source[1]209 path = (source,)210 piece = board.get_layout().get((row - 1, column - 1), None)211 if piece and type(piece) in board.get_red_pieces():212 path += ((row - 1, column - 1),)213 destinations[(row - 1, column - 1)] = path214 elif not piece:215 path += ((row - 1, column - 1),)216 destinations[(row - 1, column - 1)] = path217 piece = board.get_layout().get((row - 2, column - 2), None)218 if piece and type(piece) in board.get_red_pieces():219 path += ((row - 2, column - 2),)220 destinations[(row - 2, column - 2)] = path221 elif not piece:222 path += ((row - 2, column - 2),)223 destinations[(row - 2, column - 2)] = path224 return destinations225 def diagonal_destinations_from_lower_left_palace_source(self, source, board):226 """227 Blue chariot diagonal destinations from lower left palace source with paths228 :param source: [Tuple[int]]229 :param board: [Board]230 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]231 """232 destinations = dict()233 blue_palace_lower_left_corner_source = (9, 3)234 red_palace_lower_left_corner_source = (2, 3)235 if source == blue_palace_lower_left_corner_source or source == red_palace_lower_left_corner_source:236 row = source[0]237 column = source[1]238 path = (source,)239 piece = board.get_layout().get((row - 1, column + 1), None)240 if piece and type(piece) in board.get_red_pieces():241 path += ((row - 1, column + 1),)242 destinations[(row - 1, column + 1)] = path243 elif not piece:244 path += ((row - 1, column + 1),)245 destinations[(row - 1, column + 1)] = path246 piece = board.get_layout().get((row - 2, column + 2), None)247 if piece and type(piece) in board.get_red_pieces():248 path += ((row - 2, column + 2),)249 destinations[(row - 2, column + 2)] = path250 elif not piece:251 path += ((row - 2, column + 2),)252 destinations[(row - 2, column + 2)] = path253 return destinations254 def diagonal_destinations_from_center_palace_source(self, source, board):255 """256 Blue chariot diagonal destinations from center palace source with paths257 :param source: [Tuple[int]]258 :param board: [Board]259 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]260 """261 destinations = dict()262 blue_palace_center_source = (8, 4)263 red_palace_center_source = (1, 4)264 if source == blue_palace_center_source or source == red_palace_center_source:265 row = source[0]266 column = source[1]267 up_left_destination = (row - 1, column - 1)268 up_left_piece = board.get_layout().get(up_left_destination, None)269 up_right_destination = (row - 1, column + 1)270 up_right_piece = board.get_layout().get(up_right_destination, None)271 down_right_destination = (row + 1, column + 1)272 down_right_piece = board.get_layout().get(down_right_destination, None)273 down_left_destination = (row + 1, column - 1)274 down_left_piece = board.get_layout().get(down_left_destination, None)275 if up_left_piece and type(up_left_piece) in board.get_red_pieces():276 destinations[up_left_destination] = (source, up_left_destination)277 elif not up_left_piece:278 destinations[up_left_destination] = (source, up_left_destination)279 if up_right_piece and type(up_right_piece) in board.get_red_pieces():280 destinations[up_right_destination] = (source, up_right_destination)281 elif not up_right_piece:282 destinations[up_right_destination] = (source, up_right_destination)283 if down_right_piece and type(down_right_piece) in board.get_red_pieces():284 destinations[down_right_destination] = (source, down_right_destination)285 elif not down_right_piece:286 destinations[down_right_destination] = (source, down_right_destination)287 if down_left_piece and type(down_left_piece) in board.get_red_pieces():288 destinations[down_left_destination] = (source, down_left_destination)289 elif not down_left_piece:290 destinations[down_left_destination] = (source, down_left_destination)291 return destinations292class RedChariot(Chariot):293 """294 RedChariot (Piece) handles finding chariot move destinations from source filtering moves with board layout295 """296 def destinations_from_source(self, source, board, deep_check=True):297 """298 Red chariot destinations from source with paths299 :param source: [Tuple[int]] Board source coordinate300 :param board: [Board]301 :param deep_check: [bool] Piece which checks other general must protect own general302 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]] Destination goes to source to destination path303 """304 all_destinations = self.all_destinations_from_source(source, board)305 destinations = dict()306 for destination in all_destinations:307 add_destination = True308 if deep_check:309 board.try_move(source, destination)310 if board.do_generals_face():311 add_destination = False312 if add_destination and board.is_red_in_check(deep_check=False):313 add_destination = False314 board.undo_move()315 if add_destination:316 destinations[destination] = all_destinations[destination]317 return destinations318 def up_destinations_from_source(self, source, board):319 """320 Red chariot up destinations from source with paths321 :param source: [Tuple[int]]322 :param board: [Board]323 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]324 """325 destinations = dict()326 row = source[0] - 1327 column = source[1]328 path = (source,)329 piece = board.get_layout().get((row, column), None)330 while piece is None and row >= board.get_rows_min():331 path += ((row, column),)332 destinations[(row, column)] = path333 row -= 1334 piece = board.get_layout().get((row, column), None)335 if piece is not None and type(piece) in board.get_blue_pieces():336 path += ((row, column),)337 destinations[(row, column)] = path338 return destinations339 def right_destinations_from_source(self, source, board):340 """341 Red chariot right destinations from source with paths342 :param source: [Tuple[int]]343 :param board: [Board]344 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]345 """346 destinations = dict()347 row = source[0]348 column = source[1] + 1349 path = (source,)350 piece = board.get_layout().get((row, column), None)351 while piece is None and column < board.get_columns_max():352 path += ((row, column),)353 destinations[(row, column)] = path354 column += 1355 piece = board.get_layout().get((row, column), None)356 if piece is not None and type(piece) in board.get_blue_pieces():357 path += ((row, column),)358 destinations[(row, column)] = path359 return destinations360 def down_destinations_from_source(self, source, board):361 """362 Red chariot down destinations from source with paths363 :param source: [Tuple[int]]364 :param board: [Board]365 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]366 """367 destinations = dict()368 row = source[0] + 1369 column = source[1]370 path = (source,)371 piece = board.get_layout().get((row, column), None)372 while piece is None and row < board.get_rows_max():373 path += ((row, column),)374 destinations[(row, column)] = path375 row += 1376 piece = board.get_layout().get((row, column), None)377 if piece is not None and type(piece) in board.get_blue_pieces():378 path += ((row, column),)379 destinations[(row, column)] = path380 return destinations381 def left_destinations_from_source(self, source, board):382 """383 Red chariot left destinations from source with paths384 :param source: [Tuple[int]]385 :param board: [Board]386 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]387 """388 destinations = dict()389 row = source[0]390 column = source[1] - 1391 path = (source,)392 piece = board.get_layout().get((row, column), None)393 while piece is None and column >= board.get_columns_min():394 path += ((row, column),)395 destinations[(row, column)] = path396 column -= 1397 piece = board.get_layout().get((row, column), None)398 if piece is not None and type(piece) in board.get_blue_pieces():399 path += ((row, column),)400 destinations[(row, column)] = path401 return destinations402 def diagonal_destinations_from_lower_left_palace_source(self, source, board):403 """404 Red chariot diagonal destinations from lower left palace source with paths405 :param source: [Tuple[int]]406 :param board: [Board]407 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]408 """409 destinations = dict()410 blue_palace_lower_left_corner_source = (9, 3)411 red_palace_lower_left_corner_source = (2, 3)412 if source == blue_palace_lower_left_corner_source or source == red_palace_lower_left_corner_source:413 row = source[0]414 column = source[1]415 path = (source,)416 piece = board.get_layout().get((row - 1, column + 1), None)417 if piece and type(piece) in board.get_blue_pieces():418 path += ((row - 1, column + 1),)419 destinations[(row - 1, column + 1)] = path420 elif not piece:421 path += ((row - 1, column + 1),)422 destinations[(row - 1, column + 1)] = path423 piece = board.get_layout().get((row - 2, column + 2), None)424 if piece and type(piece) in board.get_blue_pieces():425 path += ((row - 2, column + 2),)426 destinations[(row - 2, column + 2)] = path427 elif not piece:428 path += ((row - 2, column + 2),)429 destinations[(row - 2, column + 2)] = path430 return destinations431 def diagonal_destinations_from_upper_left_palace_source(self, source, board):432 """433 Red chariot diagonal destinations from upper left palace source with paths434 :param source: [Tuple[int]]435 :param board: [Board]436 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]437 """438 destinations = dict()439 blue_palace_upper_left_corner_source = (7, 3)440 red_palace_upper_left_corner_source = (0, 3)441 if source == blue_palace_upper_left_corner_source or source == red_palace_upper_left_corner_source:442 row = source[0]443 column = source[1]444 path = (source,)445 piece = board.get_layout().get((row + 1, column + 1), None)446 if piece and type(piece) in board.get_blue_pieces():447 path += ((row + 1, column + 1),)448 destinations[(row + 1, column + 1)] = path449 elif not piece:450 path += ((row + 1, column + 1),)451 destinations[(row + 1, column + 1)] = path452 piece = board.get_layout().get((row + 2, column + 2), None)453 if piece and type(piece) in board.get_blue_pieces():454 path += ((row + 2, column + 2),)455 destinations[(row + 2, column + 2)] = path456 elif not piece:457 path += ((row + 2, column + 2),)458 destinations[(row + 2, column + 2)] = path459 return destinations460 def diagonal_destinations_from_upper_right_palace_source(self, source, board):461 """462 Red chariot diagonal destinations from upper right palace source with paths463 :param source: [Tuple[int]]464 :param board: [Board]465 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]466 """467 destinations = dict()468 blue_palace_upper_right_corner_source = (7, 5)469 red_palace_upper_right_corner_source = (0, 5)470 if source == blue_palace_upper_right_corner_source or source == red_palace_upper_right_corner_source:471 row = source[0]472 column = source[1]473 path = (source,)474 piece = board.get_layout().get((row + 1, column - 1), None)475 if piece and type(piece) in board.get_blue_pieces():476 path += ((row + 1, column - 1),)477 destinations[(row + 1, column - 1)] = path478 elif not piece:479 path += ((row + 1, column - 1),)480 destinations[(row + 1, column - 1)] = path481 piece = board.get_layout().get((row + 2, column - 2), None)482 if piece and type(piece) in board.get_blue_pieces():483 path += ((row + 2, column - 2),)484 destinations[(row + 2, column - 2)] = path485 elif not piece:486 path += ((row + 2, column - 2),)487 destinations[(row + 2, column - 2)] = path488 return destinations489 def diagonal_destinations_from_lower_right_palace_source(self, source, board):490 """491 Red chariot diagonal destinations from lower right palace source with paths492 :param source: [Tuple[int]]493 :param board: [Board]494 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]495 """496 destinations = dict()497 blue_palace_lower_right_corner_source = (9, 5)498 red_palace_lower_right_corner_source = (2, 5)499 if source == blue_palace_lower_right_corner_source or source == red_palace_lower_right_corner_source:500 row = source[0]501 column = source[1]502 path = (source,)503 piece = board.get_layout().get((row - 1, column - 1), None)504 if piece and type(piece) in board.get_blue_pieces():505 path += ((row - 1, column - 1),)506 destinations[(row - 1, column - 1)] = path507 elif not piece:508 path += ((row - 1, column - 1),)509 destinations[(row - 1, column - 1)] = path510 piece = board.get_layout().get((row - 2, column - 2), None)511 if piece and type(piece) in board.get_blue_pieces():512 path += ((row - 2, column - 2),)513 destinations[(row - 2, column - 2)] = path514 elif not piece:515 path += ((row - 2, column - 2),)516 destinations[(row - 2, column - 2)] = path517 return destinations518 def diagonal_destinations_from_center_palace_source(self, source, board):519 """520 Red chariot diagonal destinations from center palace source with paths521 :param source: [Tuple[int]]522 :param board: [Board]523 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]524 """525 destinations = dict()526 blue_palace_center_source = (8, 4)527 red_palace_center_source = (1, 4)528 if source == blue_palace_center_source or source == red_palace_center_source:529 row = source[0]530 column = source[1]531 up_left_destination = (row - 1, column - 1)532 up_left_piece = board.get_layout().get(up_left_destination, None)533 up_right_destination = (row - 1, column + 1)534 up_right_piece = board.get_layout().get(up_right_destination, None)535 down_right_destination = (row + 1, column + 1)536 down_right_piece = board.get_layout().get(down_right_destination, None)537 down_left_destination = (row + 1, column - 1)538 down_left_piece = board.get_layout().get(down_left_destination, None)539 if up_left_piece and type(up_left_piece) in board.get_blue_pieces():540 destinations[up_left_destination] = (source, up_left_destination)541 elif not up_left_piece:542 destinations[up_left_destination] = (source, up_left_destination)543 if up_right_piece and type(up_right_piece) in board.get_blue_pieces():544 destinations[up_right_destination] = (source, up_right_destination)545 elif not up_right_piece:546 destinations[up_right_destination] = (source, up_right_destination)547 if down_right_piece and type(down_right_piece) in board.get_blue_pieces():548 destinations[down_right_destination] = (source, down_right_destination)549 elif not down_right_piece:550 destinations[down_right_destination] = (source, down_right_destination)551 if down_left_piece and type(down_left_piece) in board.get_blue_pieces():552 destinations[down_left_destination] = (source, down_left_destination)...

Full Screen

Full Screen

Cannon.py

Source:Cannon.py Github

copy

Full Screen

...60 destinations = dict()61 row = source[0] - 162 column = source[1]63 path = (source,)64 piece = board.get_layout().get((row, column), None)65 # Find up jump piece66 while piece is None and row >= board.get_rows_min():67 row -= 168 piece = board.get_layout().get((row, column), None)69 if piece is not None and type(piece) not in {BlueCannon, RedCannon}:70 row -= 171 piece = board.get_layout().get((row, column), None)72 # Find paths after up jump piece73 while piece is None and row >= board.get_rows_min():74 path += ((row, column),)75 destinations[(row, column)] = path76 row -= 177 piece = board.get_layout().get((row, column), None)78 if piece is not None and type(piece) in board.get_red_pieces() and not isinstance(piece, RedCannon):79 path += ((row, column),)80 destinations[(row, column)] = path81 return destinations82 def right_destinations_from_source(self, source, board):83 """84 Blue cannon right destinations from source with paths85 :param source: [Tuple[int]]86 :param board: [Board]87 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]88 """89 destinations = dict()90 row = source[0]91 column = source[1] + 192 path = (source,)93 piece = board.get_layout().get((row, column), None)94 # Find jump piece95 while piece is None and column < board.get_columns_max():96 column += 197 piece = board.get_layout().get((row, column), None)98 if piece is not None and type(piece) not in {BlueCannon, RedCannon}:99 column += 1100 piece = board.get_layout().get((row, column), None)101 # Find paths after jump piece102 while piece is None and column < board.get_columns_max():103 path += ((row, column),)104 destinations[(row, column)] = path105 column += 1106 piece = board.get_layout().get((row, column), None)107 if piece is not None and type(piece) in board.get_red_pieces() and not isinstance(piece, RedCannon):108 path += ((row, column),)109 destinations[(row, column)] = path110 return destinations111 def down_destinations_from_source(self, source, board):112 """113 Blue cannon down destinations from source with paths114 :param source: [Tuple[int]]115 :param board: [Board]116 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]117 """118 destinations = dict()119 row = source[0] + 1120 column = source[1]121 path = (source,)122 piece = board.get_layout().get((row, column), None)123 # Find jump piece124 while piece is None and row < board.get_rows_max():125 row += 1126 piece = board.get_layout().get((row, column), None)127 if piece is not None and type(piece) not in {BlueCannon, RedCannon}:128 row += 1129 piece = board.get_layout().get((row, column), None)130 # Find paths after jump piece131 while piece is None and row < board.get_rows_max():132 path += ((row, column),)133 destinations[(row, column)] = path134 row += 1135 piece = board.get_layout().get((row, column), None)136 if piece is not None and type(piece) in board.get_red_pieces() and not isinstance(piece, RedCannon):137 path += ((row, column),)138 destinations[(row, column)] = path139 return destinations140 def left_destinations_from_source(self, source, board):141 """142 Blue cannon left destinations from source with paths143 :param source: [Tuple[int]]144 :param board: [Board]145 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]146 """147 destinations = dict()148 row = source[0]149 column = source[1] - 1150 path = (source,)151 piece = board.get_layout().get((row, column), None)152 # Find jump piece153 while piece is None and column >= board.get_columns_min():154 column -= 1155 piece = board.get_layout().get((row, column), None)156 if piece is not None and type(piece) not in {BlueCannon, RedCannon}:157 column -= 1158 piece = board.get_layout().get((row, column), None)159 # Find paths after jump piece160 while piece is None and column >= board.get_columns_min():161 path += ((row, column),)162 destinations[(row, column)] = path163 column -= 1164 piece = board.get_layout().get((row, column), None)165 if piece is not None and type(piece) in board.get_red_pieces() and not isinstance(piece, RedCannon):166 path += ((row, column),)167 destinations[(row, column)] = path168 return destinations169 def diagonal_destinations_from_lower_left_palace_source(self, source, board):170 """171 Blue cannon diagonal destinations from lower left palace source with paths172 :param source: [Tuple[int]]173 :param board: [Board]174 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]175 """176 destinations = dict()177 lower_left_blue_palace_source = (9, 3)178 lower_left_red_palace_source = (2, 3)179 if source == lower_left_blue_palace_source or source == lower_left_red_palace_source:180 row = source[0]181 column = source[1]182 center_source = (row - 1, column + 1)183 center_piece = board.get_layout().get(center_source, None)184 upper_right_corner_source = (row - 2, column + 2)185 upper_right_corner_piece = board.get_layout().get(upper_right_corner_source, None)186 center_piece_ok = center_piece is not None and type(center_piece) not in {BlueCannon, RedCannon}187 upper_right_corner_piece_ok = upper_right_corner_piece is None or (upper_right_corner_piece is not None and type(upper_right_corner_piece) in board.get_red_pieces() and not isinstance(upper_right_corner_piece, RedCannon))188 if center_piece_ok and upper_right_corner_piece_ok:189 destinations[upper_right_corner_source] = (source, upper_right_corner_source)190 return destinations191 def diagonal_destinations_from_upper_left_palace_source(self, source, board):192 """193 Blue cannon diagonal destinations from upper left palace source with paths194 :param source: [Tuple[int]]195 :param board: [Board]196 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]197 """198 destinations = dict()199 upper_left_blue_palace_source = (7, 3)200 upper_left_red_palace_source = (0, 3)201 if source == upper_left_blue_palace_source or source == upper_left_red_palace_source:202 row = source[0]203 column = source[1]204 center_source = (row + 1, column + 1)205 center_piece = board.get_layout().get(center_source, None)206 lower_right_corner_source = (row + 2, column + 2)207 lower_right_corner_piece = board.get_layout().get(lower_right_corner_source, None)208 center_piece_ok = center_piece is not None and type(center_piece) not in {BlueCannon, RedCannon}209 lower_right_corner_piece_ok = lower_right_corner_piece is None or (lower_right_corner_piece is not None and type(lower_right_corner_piece) in board.get_red_pieces() and not isinstance(lower_right_corner_piece, RedCannon))210 if center_piece_ok and lower_right_corner_piece_ok:211 destinations[lower_right_corner_source] = (source, lower_right_corner_source)212 return destinations213 def diagonal_destinations_from_upper_right_palace_source(self, source, board):214 """215 Blue cannon diagonal destinations from upper right palace source with paths216 :param source: [Tuple[int]]217 :param board: [Board]218 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]219 """220 destinations = dict()221 upper_right_blue_palace_source = (7, 5)222 upper_right_red_palace_source = (0, 5)223 if source == upper_right_blue_palace_source or source == upper_right_red_palace_source:224 row = source[0]225 column = source[1]226 center_source = (row + 1, column - 1)227 center_piece = board.get_layout().get(center_source, None)228 lower_left_corner_source = (row + 2, column - 2)229 lower_left_corner_piece = board.get_layout().get(lower_left_corner_source, None)230 center_piece_ok = center_piece is not None and type(center_piece) not in {BlueCannon, RedCannon}231 lower_left_corner_piece_ok = lower_left_corner_piece is None or (lower_left_corner_piece is not None and type(lower_left_corner_piece) in board.get_red_pieces() and not isinstance(lower_left_corner_piece, RedCannon))232 if center_piece_ok and lower_left_corner_piece_ok:233 destinations[lower_left_corner_source] = (source, lower_left_corner_source)234 return destinations235 def diagonal_destinations_from_lower_right_palace_source(self, source, board):236 """237 Blue cannon diagonal destinations from lower right palace source with paths238 :param source: [Tuple[int]]239 :param board: [Board]240 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]241 """242 destinations = dict()243 lower_right_blue_palace_source = (9, 5)244 lower_right_red_palace_source = (2, 5)245 if source == lower_right_blue_palace_source or source == lower_right_red_palace_source:246 row = source[0]247 column = source[1]248 center_source = (row - 1, column - 1)249 center_piece = board.get_layout().get(center_source, None)250 upper_left_corner_source = (row - 2, column - 2)251 upper_left_corner_piece = board.get_layout().get(upper_left_corner_source, None)252 center_piece_ok = center_piece is not None and type(center_piece) not in {BlueCannon, RedCannon}253 upper_left_corner_piece_ok = upper_left_corner_piece is None or (upper_left_corner_piece is not None and type(upper_left_corner_piece) in board.get_red_pieces() and not isinstance(upper_left_corner_piece, RedCannon))254 if center_piece_ok and upper_left_corner_piece_ok:255 destinations[upper_left_corner_source] = (source, upper_left_corner_source)256 return destinations257class RedCannon(Cannon):258 """259 RedCannon (Piece) handles finding cannon move destinations from source filtering moves with board layout260 """261 def destinations_from_source(self, source, board, deep_check=True):262 """263 Red cannon destinations from source with paths264 :param source: [Tuple[int]] Board source coordinate265 :param board: [Board]266 :param deep_check: [bool] Piece which checks other general must protect own general267 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]] Destination goes to source to destination path268 """269 all_destinations = self.all_destinations_from_source(source, board)270 destinations = dict()271 for destination in all_destinations:272 add_destination = True273 if deep_check:274 board.try_move(source, destination)275 if board.do_generals_face():276 add_destination = False277 if add_destination and board.is_red_in_check(deep_check=False):278 add_destination = False279 board.undo_move()280 if add_destination:281 destinations[destination] = all_destinations[destination]282 return destinations283 def up_destinations_from_source(self, source, board):284 """285 Red cannon up destinations from source with paths286 :param source: [Tuple[int]]287 :param board: [Board]288 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]289 """290 destinations = dict()291 row = source[0] - 1292 column = source[1]293 path = (source,)294 piece = board.get_layout().get((row, column), None)295 # Find up jump piece296 while piece is None and row >= board.get_rows_min():297 row -= 1298 piece = board.get_layout().get((row, column), None)299 if piece is not None and type(piece) not in {BlueCannon, RedCannon}:300 row -= 1301 piece = board.get_layout().get((row, column), None)302 # Find paths after up jump piece303 while piece is None and row >= board.get_rows_min():304 path += ((row, column),)305 destinations[(row, column)] = path306 row -= 1307 piece = board.get_layout().get((row, column), None)308 if piece is not None and type(piece) in board.get_blue_pieces() and not isinstance(piece, BlueCannon):309 path += ((row, column),)310 destinations[(row, column)] = path311 return destinations312 def right_destinations_from_source(self, source, board):313 """314 Red cannon right destinations from source with paths315 :param source: [Tuple[int]]316 :param board: [Board]317 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]318 """319 destinations = dict()320 row = source[0]321 column = source[1] + 1322 path = (source,)323 piece = board.get_layout().get((row, column), None)324 # Find jump piece325 while piece is None and column < board.get_columns_max():326 column += 1327 piece = board.get_layout().get((row, column), None)328 if piece is not None and type(piece) not in {BlueCannon, RedCannon}:329 column += 1330 piece = board.get_layout().get((row, column), None)331 # Find paths after jump piece332 while piece is None and column < board.get_columns_max():333 path += ((row, column),)334 destinations[(row, column)] = path335 column += 1336 piece = board.get_layout().get((row, column), None)337 if piece is not None and type(piece) in board.get_blue_pieces() and not isinstance(piece, BlueCannon):338 path += ((row, column),)339 destinations[(row, column)] = path340 return destinations341 def down_destinations_from_source(self, source, board):342 """343 Red cannon down destinations from source with paths344 :param source: [Tuple[int]]345 :param board: [Board]346 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]347 """348 destinations = dict()349 row = source[0] + 1350 column = source[1]351 path = (source,)352 piece = board.get_layout().get((row, column), None)353 # Find jump piece354 while piece is None and row < board.get_rows_max():355 row += 1356 piece = board.get_layout().get((row, column), None)357 if piece is not None and type(piece) not in {BlueCannon, RedCannon}:358 row += 1359 piece = board.get_layout().get((row, column), None)360 # Find paths after jump piece361 while piece is None and row < board.get_rows_max():362 path += ((row, column),)363 destinations[(row, column)] = path364 row += 1365 piece = board.get_layout().get((row, column), None)366 if piece is not None and type(piece) in board.get_blue_pieces() and not isinstance(piece, BlueCannon):367 path += ((row, column),)368 destinations[(row, column)] = path369 return destinations370 def left_destinations_from_source(self, source, board):371 """372 Red cannon left destinations from source with paths373 :param source: [Tuple[int]]374 :param board: [Board]375 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]376 """377 destinations = dict()378 row = source[0]379 column = source[1] - 1380 path = (source,)381 piece = board.get_layout().get((row, column), None)382 # Find jump piece383 while piece is None and column >= board.get_columns_min():384 column -= 1385 piece = board.get_layout().get((row, column), None)386 if piece is not None and type(piece) not in {BlueCannon, RedCannon}:387 column -= 1388 piece = board.get_layout().get((row, column), None)389 # Find paths after jump piece390 while piece is None and column >= board.get_columns_min():391 path += ((row, column),)392 destinations[(row, column)] = path393 column -= 1394 piece = board.get_layout().get((row, column), None)395 if piece is not None and type(piece) in board.get_blue_pieces() and not isinstance(piece, BlueCannon):396 path += ((row, column),)397 destinations[(row, column)] = path398 return destinations399 def diagonal_destinations_from_lower_left_palace_source(self, source, board):400 """401 Red cannon diagonal destinations from lower left palace source with paths402 :param source: [Tuple[int]]403 :param board: [Board]404 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]405 """406 destinations = dict()407 lower_left_blue_palace_source = (9, 3)408 lower_left_red_palace_source = (2, 3)409 if source == lower_left_blue_palace_source or source == lower_left_red_palace_source:410 row = source[0]411 column = source[1]412 center_source = (row - 1, column + 1)413 center_piece = board.get_layout().get(center_source, None)414 upper_right_corner_source = (row - 2, column + 2)415 upper_right_corner_piece = board.get_layout().get(upper_right_corner_source, None)416 center_piece_ok = center_piece is not None and type(center_piece) not in {BlueCannon, RedCannon}417 upper_right_corner_piece_ok = upper_right_corner_piece is None or (upper_right_corner_piece is not None and type(upper_right_corner_piece) in board.get_blue_pieces() and not isinstance(upper_right_corner_piece, BlueCannon))418 if center_piece_ok and upper_right_corner_piece_ok:419 destinations[upper_right_corner_source] = (source, upper_right_corner_source)420 return destinations421 def diagonal_destinations_from_upper_left_palace_source(self, source, board):422 """423 Red cannon diagonal destinations from upper left palace source with paths424 :param source: [Tuple[int]]425 :param board: [Board]426 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]427 """428 destinations = dict()429 upper_left_blue_palace_source = (7, 3)430 upper_left_red_palace_source = (0, 3)431 if source == upper_left_blue_palace_source or source == upper_left_red_palace_source:432 row = source[0]433 column = source[1]434 center_source = (row + 1, column + 1)435 center_piece = board.get_layout().get(center_source, None)436 lower_right_corner_source = (row + 2, column + 2)437 lower_right_corner_piece = board.get_layout().get(lower_right_corner_source, None)438 center_piece_ok = center_piece is not None and type(center_piece) not in {BlueCannon, RedCannon}439 lower_right_corner_piece_ok = lower_right_corner_piece is None or (lower_right_corner_piece is not None and type(lower_right_corner_piece) in board.get_blue_pieces() and not isinstance(lower_right_corner_piece, BlueCannon))440 if center_piece_ok and lower_right_corner_piece_ok:441 destinations[lower_right_corner_source] = (source, lower_right_corner_source)442 return destinations443 def diagonal_destinations_from_upper_right_palace_source(self, source, board):444 """445 Red cannon diagonal destinations from upper right palace source with paths446 :param source: [Tuple[int]]447 :param board: [Board]448 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]449 """450 destinations = dict()451 upper_right_blue_palace_source = (7, 5)452 upper_right_red_palace_source = (0, 5)453 if source == upper_right_blue_palace_source or source == upper_right_red_palace_source:454 row = source[0]455 column = source[1]456 center_source = (row + 1, column - 1)457 center_piece = board.get_layout().get(center_source, None)458 lower_left_corner_source = (row + 2, column - 2)459 lower_left_corner_piece = board.get_layout().get(lower_left_corner_source, None)460 center_piece_ok = center_piece is not None and type(center_piece) not in {BlueCannon, RedCannon}461 lower_left_corner_piece_ok = lower_left_corner_piece is None or (lower_left_corner_piece is not None and type(lower_left_corner_piece) in board.get_blue_pieces() and not isinstance(lower_left_corner_piece, BlueCannon))462 if center_piece_ok and lower_left_corner_piece_ok:463 destinations[lower_left_corner_source] = (source, lower_left_corner_source)464 return destinations465 def diagonal_destinations_from_lower_right_palace_source(self, source, board):466 """467 Red cannon diagonal destinations from lower right palace source with paths468 :param source: [Tuple[int]]469 :param board: [Board]470 :return: [Dict[Tuple[int], Tuple[Tuple[int]]]]471 """472 destinations = dict()473 lower_right_blue_palace_source = (9, 5)474 lower_right_red_palace_source = (2, 5)475 if source == lower_right_blue_palace_source or source == lower_right_red_palace_source:476 row = source[0]477 column = source[1]478 center_source = (row - 1, column - 1)479 center_piece = board.get_layout().get(center_source, None)480 upper_left_corner_source = (row - 2, column - 2)481 upper_left_corner_piece = board.get_layout().get(upper_left_corner_source, None)482 center_piece_ok = center_piece is not None and type(center_piece) not in {BlueCannon, RedCannon}483 upper_left_corner_piece_ok = upper_left_corner_piece is None or (upper_left_corner_piece is not None and type(upper_left_corner_piece) in board.get_blue_pieces() and not isinstance(upper_left_corner_piece, BlueCannon))484 if center_piece_ok and upper_left_corner_piece_ok:485 destinations[upper_left_corner_source] = (source, upper_left_corner_source)...

Full Screen

Full Screen

display_server.py

Source:display_server.py Github

copy

Full Screen

...45def display_page(pathname):46 if pathname is None:47 return dash.no_update48 if pathname == app_prefix + "/":49 return main_page.get_layout()50 if pathname == app_prefix + "/config":51 return config_menu.get_layout()52 elif pathname == app_prefix + "/add/sensor":53 return add_sensor.get_layout(update = False)54 elif pathname == app_prefix + "/update/sensor":55 return add_sensor.get_layout(update = True)56 elif pathname == app_prefix + "/list/sensor":57 return add_sensor.get_layout(dolist = True)58 elif pathname == app_prefix + "/list/publications":59 return publications.get_layout()60 elif pathname == app_prefix + "/add/dashboard":61 return add_dashboard.get_layout(update = False)62 elif pathname == app_prefix + "/update/dashboard":63 return add_dashboard.get_layout(update = True)64 elif pathname[:11 + len(app_prefix)] == app_prefix + '/dashboard/':65 return dashboard.generate_layout(pathname.split("/")[-1])66 else:67 return '404'68# Run the app69if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful