"""
Create a program that will play the “cows and bulls” game with the user. The game works like this:

Randomly generate a 4-digit number. Ask the user to guess a 4-digit number.
For every digit that the user guessed correctly in the correct place, they have a “cow”.
For every digit the user guessed correctly in the wrong place is a “bull.”
Every time the user makes a guess, tell them how many “cows” and “bulls” they have.
Once the user guesses the correct number, the game is over. Keep track of the number of guesses the user makes
throughout teh game and tell the user at the end.

Say the number generated by the computer is 1038. An example interaction could look like this:

  Welcome to the Cows and Bulls Game!
  Enter a number:
  >>> 1234
  2 cows, 0 bulls
  >>> 1256
  1 cow, 1 bull
  ...
Until the user guesses the number.
"""
from random import choice


def generate_ai_numbers(min_num: int, max_num: int) -> list:
    ai_numbers = []
    for i in range(min_num, max_num + 1):
        ai_numbers.append(str(i))
    return ai_numbers


def test_if_the_generated_numbers_are_correct():
    min_value = 1000
    max_value = 1005
    result = generate_ai_numbers(min_value, max_value)
    assert result == ['1000', '1001', '1002', '1003', '1004', '1005']


def ai_choice(values: list) -> str:
    return tuple(choice(values))


def get_game_result(player_choice: str, ai_number: str):
    cows = 0
    bulls = 0

    for i in range(0, len(player_choice)):
        if player_choice[i] == ai_number[i]:
            cows += 1
        if player_choice[i] in ai_number and player_choice[i] != ai_number[i]:
            bulls += 1

    results = {
        'Cows': cows,
        'Bulls': bulls,
        'Wybór komputera': ai_number
    }

    return results


def test_player_and_ai_results():
    player = '1000'
    ai = '1002'
    result = get_game_result(player, ai)
    assert result == []


if __name__ == '__main__':
    print('Welcome to the Cows and Bulls Game!')
    result = generate_ai_numbers(1000, 1100)
    generate = ai_choice(result)
    while True:
        users_number = tuple(input('Enter a number: \n'))

        if users_number == generate:
            print('Poprawna liczba!')
            break
        game_result = get_game_result(users_number, generate)
        for result in game_result:
            print(f'{result}: {game_result[result]}, ')
