int search(State state) {
if (complete(state)) return value(state);
int answer = identity();
for (Choice choice : choices(state)) {
if (!valid(state, choice)) continue;
apply(state, choice);
answer = combine(answer, search(state));
undo(state, choice);
}
return answer;
}
def search(state) -> int:
if complete(state):
return value(state)
answer = identity()
for choice in choices(state):
if not valid(state, choice):
continue
apply(state, choice)
answer = combine(answer, search(state))
undo(state, choice)
return answer
def search(state: State): Int =
if complete(state) then value(state)
else
var answer = identity()
for choice <- choices(state) do
if valid(state, choice) then
applyChoice(state, choice)
answer = combine(answer, search(state))
undoChoice(state, choice)
answer
int search(State& state) {
if (complete(state)) return value(state);
int answer = identity();
for (const Choice& choice : choices(state)) {
if (!valid(state, choice)) continue;
apply(state, choice);
answer = combine(answer, search(state));
undo(state, choice);
}
return answer;
}