from random import randint

class CatcherPiece:
    character = "-"
    color = "white_on_indigo"
    z = 1
    def __init__(self, position):
        self.position = position

class Catcher:
    width = 6
    display = False
    pieces = []
    name = "catcher"
    color = "white_on_indigo"

    def __init__(self, position):
        self.position = position

    def play_turn(self, game):
        if not self.pieces:
            self.create_pieces(game)

    def handle_keystroke(self, keystroke, game):
        x, y = self.position
        width, height = game.board_size
        if keystroke.name == "KEY_LEFT":
            new_x = max(0, x - 3)
            self.position = (new_x, y)
            self.update_piece_positions()
        if keystroke.name == "KEY_RIGHT":
            new_x = min(width - self.width, x + 3)
            self.position = (new_x, y)
            self.update_piece_positions()

    def create_pieces(self, game):
        x, y = self.position
        self.pieces = []
        for i in range(self.width):
            piece = CatcherPiece((x + i, y))
            self.pieces.append(piece)
            game.add_agent(piece)

    def update_piece_positions(self):
        x, y = self.position
        for i, piece in enumerate(self.pieces):
            piece.position = (x + i, y)

    def can_move(self, position, game):
        on_board = game.on_board(position)
        empty = game.is_empty(position)
