Implementing an open/close function in Prolog
Always try hard to avoid assert/1 and retract/1: Using these predicates makes it impossible to reason about your other predicates in isolation, and therefore make debugging and extending your code much harder.

In this case, there is a clear declarative solution:

Represent the state of all doors as a Prolog term, and thread this state through all predicates that need it. For example, a simple representation could be:

[door_state(door1, open), door_state(door2, closed), door_state(door3, open)]

You can thread such a state through as follows:

state0_action_state(S0, Action, S) :-
    ...

This predicate relates an initital state to the next state, depending on Action. Given the example representation above, an action like close(door1) would result in the next state:

[door_state(door1, closed), door_state(door2, closed), door_state(door3, open)]

Thus, your predicates can all be tested in isolation, and do not depend on any implicit state.