# L-16 MCS 507 Wed 27 Sep 2023 : pexpect_guessing_game.py

"""
This script spawns the game_oracle_number.py and then simply
sends all consecutive integers till the game ends.
"""

print('spawning the oracle ...\n')
import pexpect
CHILD = pexpect.spawn('/usr/bin/env python game_oracle_number.py')
for i in range(10):
    CHILD.expect(':')
    CHILD.sendline(str(i))
    CHILD.read(6)
    REPLY = CHILD.after.decode()
    print('reply of oracle', REPLY)
    if REPLY[-2:] == 'Co':
        print('We guessed the secret!')
        break
CHILD.close()
print('\nBye, script ends.')
