def __call__(self): iswhiteturn = self.iswhiteturn for strmove in self.strmoves: fromcell = algn.str_to_algebraic(strmove[0:2]) tocell = algn.str_to_algebraic(strmove[2:4]) piece = self.listpiece.get_piece_by_cell(fromcell) capturedpiece = self.listpiece.get_piece_by_cell(tocell) promotionto = self.listpiece.get_promoted_piece(piece, tocell) if (fromcell, tocell) == (e1, h1) and piece == 'wK': move = mvm.Move(None, None, None, True, None, True, False, None, False, False) elif (fromcell, tocell) == (e1, a1) and piece == 'wK': move = mvm.Move(None, None, None, True, None, False, True, None, False, False) elif (fromcell, tocell) == (e8, h8) and piece == 'bK': move = mvm.Move(None, None, None, False, None, True, False, None, False, False) elif (fromcell, tocell) == (e8, a8) and piece == 'bK': move = mvm.Move(None, None, None, False, None, False, True, None, False, False) else: move = mvm.Move(piece, fromcell, tocell, iswhiteturn, capturedpiece, False, False, promotionto, False, False) self.listpiece.applymove(move) iswhiteturn = not iswhiteturn
def black_pawn_move_factory(fromcell, tocell): iskingcastling = 'bk' in whitecastlingrights isqueencastling = 'bq' in whitecastlingrights capturedpiece = get_white_captured_piece(tocell) if tocell in promotioncells: promotionto = 'bQ' else: promotionto = None if tocell.absfiledifference(fromcell) == 2: isenpassant = True else: isenpassant = False return mvm.Move('bP', fromcell, tocell, False, capturedpiece, iskingcastling, isqueencastling, promotionto, isenpassant, False)
def getrandomoutmove(self): index = random.randint(0, len(self.position.moves) - 1) strmove = self.position.moves[index].short__str__() return strmove def __str__(self): return self.position.__str__() if __name__ == '__main__': initnewgame() initgameposition( "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 0 moves".split( )) move1 = mvm.Move('wP', e2, e4, True, None, False, False, None, True, False) move2 = mvm.Move('bP', e7, e5, False, None, False, False, None, False, False) move3 = mvm.Move('wP', d2, d4, True, None, False, False, None, False, False) rootposition.listpiece.applymove(move1) rootposition.listpiece.applymove(move2) rootposition.listpiece.applymove(move3) newkey = rootposition.listpiece.gethashkey() print("Initial key: ", rootposition.listpiece.originhashvalue, "Final key: ", newkey) rootposition.listpiece.undomove(move3) rootposition.listpiece.undomove(move2) rootposition.listpiece.undomove(move1) rootposition.listpiece.applymove(move3)
def queen_castling_move_factory(iswhiteturn): return mvm.Move(None, None, None, iswhiteturn, None, False, True, None, False, False)
def black_piece_move_factory(fromcell, tocell, piece): iskingcastling = 'wk' in blackcastlingrights isqueencastling = 'wq' in blackcastlingrights capturedpiece = get_white_captured_piece(tocell) return mvm.Move(piece, fromcell, tocell, False, capturedpiece, iskingcastling, isqueencastling, None, False, False)