Python
python class를 사용해서 작은 게임룰을 만들고 있는데 디버깅을 돌리면 답이 나오지만 실행을 하면 계속 에러가 뜹니다. 한번만 도와주세요
class Amazons:
    def __init__(self):
        #setting standard place
        self.amazons = {(3, 0): 'A', (0, 3): 'B', (0, 6): 'C', (3, 9): 'D', (6, 0): 'a', (9, 3): 'b', (9, 6): 'c',
                        (6, 9): 'd'}

        star_list = []
        # making star_list for append the star'*'
        self.star_list = list(star_list)
        self.arrows = set()
        #making star board do not confuse the star file
        self.star_board = self.amazons.copy()

    def __str__(self):
        board_list = []
        all_list = []
        self.star_board = self.amazons.copy()
        for i in self.star_list:
            self.star_board[i] = '*'
        for z in range(10):
            for i in range(10):
                a = (z, i)
                if a not in self.star_board:
                    board_list.append('_')
                else:
                    board_list.append(self.star_board[a])
            all_list.append(''.join(board_list))
            board_list = []
        return '\n'.join(all_list)

    def position(self, letter):
        return {value: key for key, value in self.amazons.items()}[letter]

    def possible_directions(self, letter):
        all_dir = {'E': (0, 1), 'S': (1, 0), 'SW': (1, -1), 'NW': (-1, -1), 'NE': (-1, 1), 'SE': (1, 1), 'W': (0, -1),
                   'N': (-1, 0)}
        direction_list = []
        a = {value: key for key, value in self.amazons.items()}[letter]
        for direction in all_dir:
            y_axis = tuple(sum(elem) for elem in zip(a, all_dir[direction]))[0]
            x_axis = tuple(sum(elem) for elem in zip(a, all_dir[direction]))[1]
            if 0 <= y_axis <= 9 and 0 <= x_axis <= 9:
                if (y_axis, x_axis) not in self.amazons:
                    direction_list.append(direction)

        return set(direction_list)

    # 그 방향으로 갈 수있는지 없는 지 확인하기
    def way_go(self, letter, direction, number):
        a = {value: key for key, value in self.amazons.items()}[letter]
        check_number = 0
        for i in range(1, number+1):
            all_dir = {'E': (0, i), 'S': (i, 0), 'SW': (i, -i), 'NW': (-i, -i), 'NE': (-i, i), 'SE': (i, i),'W': (0, -i),'N': (-i, 0)}
            check_space = tuple(sum(elem) for elem in zip(a, all_dir[direction]))
            if 0 <= check_space[0] <= 9 and 0 <= check_space[1] <= 9:
                if check_space in self.star_board:
                    raise AssertionError('invalid move')
                else:
                    check_number += 1
        return check_number

    def move_amazon(self, letter, direction, number):
        a = {value: key for key, value in self.amazons.items()}[letter] # 현재의 위치 파악
        move_dir = {'E': (0, number), 'S': (number, 0), 'SW': (number, -number), 'NW': (-number, -number),
                    'NE': (-number, number), 'SE': (number, number), 'W': (0, -number), 'N': (-number, 0)}
        move_space = tuple(sum(elem) for elem in zip(a, move_dir[direction]))
        way = Amazons.way_go(self, letter, direction, number)
        if way == number:
            del(self.amazons[a])
            self.amazons[move_space[0],move_space[1]] = letter
            return board
        else:
            raise AssertionError('invalid move')

    def shoot_arrow(self, letter, direction, number):
        a = {value: key for key, value in self.amazons.items()}[letter]
        move_dir = {'E': (0, number), 'S': (number, 0), 'SW': (number, -number), 'NW': (-number, -number), 'NE': (-number, number), 'SE': (number, number), 'W': (0, -number), 'N': (-number, 0)}
        arrow_space = tuple(sum(elem) for elem in zip(a, move_dir[direction]))
        way = Amazons.way_go(self, letter, direction, number)
        if way == number:
            self.star_list.append(arrow_space)
            self.arrows = set(self.star_list)
            return board
        else:
            raise AssertionError('invalid move')

 

문제가 되는 부분은 def move_amazon과 shoot_arrow 부분입니다.

board = Amazons()

print(board.move_amazon('b', 'W', 1).shoot_arrow('b', 'W', 1))
print(board.move_amazon('B', 'W', 3).shoot_arrow('B', 'E', 4))

두번째 프린티에서 에러가 납니다. 선배님들 한번만 도와주세요 ㅠㅠ

댓글 1