Prolog “winning position”

2019-08-14 05:45发布

问题:

This is a game for 2 people to remove numbers from a list. A player will lose if the player picks up the last number. Given the 2 rules of removing numbers in a list,

  1. Prolog search for possible combination for subtracting 2 elements from a list
  2. Prolog possible removal of elements in a list

There is a question,

write a predicate win(S), that succeed if S is a winning position for the player whose turn it is to play and fails otherwise. Besides giving the correct answers, your code for this should avoid evaluating the same position more than once. For example, there are only 960 positions that can be reached from [30,30], but many billions of games that could be played starting from there...

I am really confused how can [30,30] reach 960 positions. According to the 2 rules, if I subtract N from one element only, I can only reach 60 states.

Y = [29, 30]  or  Y = [30, 29]
Y = [28, 30]  or  Y = [30, 28]
Y = [27, 30]  or  ...
...
Y = [1, 30]
Y = [30]

Or If I subtract N from 2 elements, I can only reach 30 states..

Y = [29, 29]
Y = [28, 28]
...
Y = [1, 1]
Y = []

I am really confused how 960 position can be reached. Yet, win(S), will evaluate whether the S is a winning position... Does it mean that current S can directly leads to [1] by just one move? or the current S can lead to [1] by multiple moves?

标签: prolog