import sys
sys.path.append('../')
import CreativeQiskit

b = CreativeQiskit.twobit()

b.prepare({'Z':True})
print("    bit value =",b.Z_value() )

b.prepare({'Z':False})
print("    bit value =",b.Z_value() )

b.prepare({'X':True})
print("    bit value =",b.X_value() )

b.prepare({'X':False})
print("    bit value =",b.X_value() )

print("    Here are 10 trials with, each with True encoded in the Z basis. The values read out with X are:\n")
for trial in range(1,11):
    b.prepare({'Z':True})
    message = "        Try " + str(trial)+": "
    message += str( b.X_value() ) 
    print( message )

for trial in range(1,11):
    message = "        Try " + str(trial)+": "
    b.prepare({'Z':True})
    for repeat in range(5):
        message += str( b.X_value() ) + ", "
    print(message)

b = CreativeQiskit.twobit()
for trial in range(1,11):
    message = "        Try " + str(trial)+": "
    b.prepare({'Z':True})
    for repeat in range(5):
        message += str( b.X_value(noisy=0.2,mitigate=False) ) + ", "
    print(message)

b = CreativeQiskit.twobit()
for trial in range(1,11):
    message = "        Try " + str(trial)+": "
    b.prepare({'Z':True})
    for repeat in range(5):
        message += str( b.X_value(noisy=True) ) + ", "
    print(message)

ship = CreativeQiskit.twobit()

destroyed = False
while not destroyed:
    basis = input('\n    > Choose a torpedo type (Z or X)...\n    ')
    destroyed = ship.value(basis)
    if destroyed:
        print('\n    *Ship destroyed!*')
    else:
        print('\n    *Attack failed!*')
print('\n    **Mission complete!**')