I have a predicate list_moves(Move)
, that gives all the possible moves for a game. Then I have the following predicates :
find_best_move:-
nb_setval(best,0),
list_moves(NewMove),
nb_getval(best,OldMove),
better(OldMove,NewMove).
better(OldMove, NewMove):-
NewMove > OldMove,
nb_setval(best,NewMove), !.
better(_,_).
get_best_move(Move):-
find_best_move,
nb_getval(max,Move).
I want to get only one move when I call get_best_move(Move)
: the best one. The problem is : I do get the best move, but I also get lots of other moves.
Exemple :
Let's say I have the following moves in this order from list_moves(Move)
(the bigger the value, the better the move) :
move1 : 0
move2 : 1
move3 : 2
move4 : 1
move5 : 2
move6 : 0
I will get the following result by calling get_best_move(Move)
:
move1
move2
move3
move3
move3
move3
The thing is : I just want to get move3 once. I don't care about neither move1-2, nore the 3 other occurences of move3.
I think one solution could be to "wait" until the find_best_move
call in get_best_move
is finished, instead of doing nb_getval
for each answer given by find_best_move
.
How can I do this ? Is there an other solution ?