:- op(200, xfy, and).
:- op(700, xfx, then).

numberscor(z and y and b and d, 1, 3, 0, p).
numberscor(a and b and e, 2, 1, 0, c).
numberscor(rode_sproeten and snotneus, 4, 1, 0, mazelen).
numberscor(a and c, 1, 1, 0, d).
numberscor(c and d, 0, 2, 0, e).
numberscor(symptoom(hoofdpijn)and symptoom('hoofdpijn achter ogen'), 0, 2, 0, ziekte(dengue)).
numberscor(symptoom(spierpijn)and symptoom(hoofdpijn), 0, 2, 0, ziekte(dengue)).
numberscor(symptoom(gewrichtspijn)and symptoom(spierpijn)and symptoom(hoofdpijn), 0, 3, 0, ziekte(dengue)).
numberscor(symptoom('onregelmatige koorts')and symptoom(klierzwellingen), 1, 1, 0, ziekte('afrikaanse slaapziekte')).

returnhighestfact(Result) :-
	findall(numberscor(Condition, R, U, 0, Conclusion), numberscor(Condition,R,U,0,Conclusion), List),
	findmax(List, Max), write(max).
	%(getnumscor(Max, Cond, 4, 0, 0, Concl,
	%write('U bent ziek:   '), write(Condition) ; true).

getnumscor(numberscor(Cond, R, U, W, Concl), Cond, R, U, W, Concl).

checkMatch(R, Condition) :-
	R >= 4,
	write('U bent ziek:'), write(Condition).

findmax([H|Tail], Result) :- findmax2(Tail, H, Result).

findmax2([], Result, Result).

%not higher, accu is still best match
findmax2([H|Tail], Accu, Result) :-
	getnumscor(H, _Cond, HR, _U, _W, _Concl),
	getnumscor(Accu, _Cond, AR, _U, _W, _Concl),
	AR >= HR,
	findmax2(Tail, Accu, Result).

%found a higher match
findmax2([H|Tail], Accu, Result) :-
	getnumscor(H, _Cond, HR, _U, _W, _Concl),
	getnumscor(Accu, _Cond, AR, _U, _W, _Concl),
	AR < HR,
	findmax2(Tail, H, Result).
