# elect_bug2.py - AIPython code referred to in AIFCA, Exercise 5.6. Put in aipython folder 
# AIPython documentation at http://aipython.org
# Download the zip file and read aipython.pdf for documentation

# Artificial Intelligence: Foundations of Computational Agents http://artint.info
# Copyright David L Poole and Alan K Mackworth 2017-2023.
# This work is licensed under a Creative Commons
# Attribution-NonCommercial-ShareAlike 4.0 International License.
# See: http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en

from logicProblem import KB, Clause

elect_bug2 = KB([
    Clause('live_w6', ['live_w5', 'ok_cb2']),
    Clause('live_w0', ['live_w2', 'down_s2']),
    Clause('live_w2', ['live_w3', 'down_s1']),
    Clause('live_l2', ['live_w4']),
    Clause('live_w4', ['live_w3', 'up_s3']),
    Clause('live_p_1', ['live_w3']),
    Clause('live_w3', ['live_w5', 'ok_cb1']),
    Clause('live_p_2', ['live_w6']),
    Clause('live_w1', ['live_w3', 'up_s1']),
    Clause('live_w5', ['live_outside']),
    Clause('lit_l1', ['light_l1', 'live_l1', 'ok_l1']),
    Clause('lit_l2', ['light_l2', 'live_l2', 'ok_l2']),
    Clause('live_l1', ['live_w0']),
    Clause('live_w0', ['live_w1', 'up_s2']),
    Clause('down_s1'),
    Clause('up_s2'),
    Clause('up_s3'),
    Clause('ok_cb2'),
    Clause('live_outside'),
    Clause('ok_l2'),
    Clause('ok_cb1'),
    Clause('light_l1'),
    Clause('light_l2'),
    Clause('ok_l1'),
    Clause('up_s1')
    ])

# Look through the code. Can you spot the bug?

# If you are familiar with a Python debugger, try it to find the error

#Try tracing the execution of the code:
from logicTopDown import prove
# elect_bug2.max_display_level=3  # give detailed trace
# prove(elect_bug2,['lit_l1'])

from logicExplain import interact
# elect_bug2.max_display_level=1  # make default value again
# interact(elect_bug2)
# logicExplain: ask lit_l1
# how
# how 1
