Prolog-搜索最佳响应-井字游戏

时间:2018-12-03 23:47:57

标签: prolog

我正在尝试了解井字游戏的响应方式。此时,我有winningLine个事实,可以判断是否有人赢得了比赛。用户可以输入一个职位,该职位将被填补,然后Prolog会回答一个简单的事实。
我正在尝试了解如何搜索对玩家输入的最佳响应并发送回响应。
我想使用forall并在每个用户输入中循环选择以找到响应的最佳位置。

到目前为止,我对球员的了解是

% Specify the the 2 players and empty space for the board  
player(X) :- x(X).

% This will be the computer  
player(X) :- o(X).

% This is the blank space that we print out first and if the spot has not 
been taken yet  
blankSpace(X) :- not(player(X)).  

% Print the board 3 rows across by 3 columns wide
buildBoard :- printBox(1),printBox(2),printBox(3),nl,  
              printBox(4),printBox(5),printBox(6),nl,  
              printBox(7),printBox(8),printBox(9),nl.  

next_move(('[x]','[2]','[3]','[4]','[5]','[6]','[7]','[8]','[9]',8).
next_move(6). 


playersMove :- 
    repeat, write('Your turn, please choose a space between 1-9'),

    % Read Input
    read(X), 

    % Check if the number the user (X) entered is between 1 and 9
    between(1,9,X), 

    % Select the numbered blank space the user has specified
    blankSpace(X), 

    % Replace the numbered space with the text for the X player
    assert(x(X)).

computerMove :- 
    next_move(X), 
    blankSpace(X), 
    assert(o(X)).

我的问题:如何找到用户输入并使用computerMove在板上找到最佳响应。

0 个答案:

没有答案