:- 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, 0, 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(Max) :-
        findall(R^numberscor(Condition, R, U, 0, Conclusion), numberscor(Condition,R,U,0,Conclusion), List),
        findmax(List, 0^foo, MaxR^Max),
	checkR(MaxR, Max), !.

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

checkR(R, Max) :-
        getnumscor(Max, _Cond, R, U, _W, Concl),
        R >= 4, U is 0,
        write('U bent ziek:'), write(Concl).
	
checkR(_R, _Condition) :- write('niet ziek').

findmax([], Result, Result).

%not higher, accu is still best match
findmax([HR^_|Tail], AR^Accu, Result) :-
        nonvar(AR), nonvar(HR),
        AR >= HR,
        findmax(Tail, AR^Accu, Result).

%found a higher match
findmax([HR^H|Tail], AR^_, Result) :-
        nonvar(AR), nonvar(HR),
        AR < HR,
        findmax(Tail, HR^H, Result).
