Пример #1
0
    def test_init(self):
        xs = [chr(ord('a') + i) for i in range(0, 8)]
        ys = [i for i in range(1, 9)]

        for x, y in product(xs, ys):
            b = Bishop(x, y)
            verifica = []
            count = 0
            for n in range(1, 9):
                if n <= 8:
                    count += 1
                    moves = list(product([ord(b.pos_in_x) + count], [b.pos_in_y + count]))
                    for x_m, y_m in moves:
                        if ord('a') <= x_m <= ord('h') and 1 <= y_m <= 8:
                            verifica.append((chr(x_m), y_m))
                    moves.clear()
            count = 0
            for n in range(1, 9):
                if n <= 8:
                    count += 1
                    moves_1 = list(product([ord(b.pos_in_x) - count], [b.pos_in_y + count]))
                    for x_m, y_m in moves_1:
                        if ord('a') <= x_m <= ord('h') and 1 <= y_m <= 8:
                            verifica.append((chr(x_m), y_m))
                    moves_1.clear()

            count = 0
            for n in range(1, 9):
                count += 1
                moves_2 = list(product([ord(b.pos_in_x) - count], [b.pos_in_y - count]))
                for x_m, y_m in moves_2:
                    if ord('a') <= x_m <= ord('h') and 1 <= y_m <= 8:
                        verifica.append((chr(x_m), y_m))
                moves_2.clear()

            count = 0
            for n in range(1, 9):
                count += 1
                moves_3 = list(product([ord(b.pos_in_x) + count], [b.pos_in_y - count]))
                for x_m, y_m in moves_3:
                    if ord('a') <= x_m <= ord('h') and 1 <= y_m <= 8:
                        verifica.append((chr(x_m), y_m))
                moves_3.clear()

            try:
                self.assertTrue(sorted(verifica) == sorted(b.possible_poss()))


            except:
                print('Something is wrong')
                break
Пример #2
0
#ped_1 = Pawn(input("metti posizione x: "), int(input("metti posizione y: ")))
#ped_1.pos_pawn()

#cav_1 = Knight(input("metti posizione x: "), int(input("metti posizione y: ")))
#cav_1.pos_knight()

#king_1 = King(input("metti posizione x: "), int(input("metti posizione y: ")))
#king_1.pos_king()

#tor_1 = Rook(input("metti posizione x: "), int(input("metti posizione y: ")))
#tor_1.pos_rook()

alfiere_1 = Bishop(input("metti posizione x: "),
                   int(input("metti posizione y: ")))
alfiere_1.possible_poss()
print(alfiere_1.possible_poss())

# input_x = input("metti posizione x: ")
# input_y = int(input("metti posizione y: "))
regina_1 = Queen('a', 3)
regina_2 = Queen('h', 8)
alfiere = Bishop('b', 3)
#pedone = Pawn('g', 7)
# questo è comodo. Può stampare a video perchè ha ereditato da ChessPiece __str__
#regina_1.pos_queen()

c = Chess()
c.set_piece(regina_1)
c.set_piece(regina_2)
c.set_piece(alfiere)