代码之家  ›  专栏  ›  技术社区  ›  Mostowski Collapse ninesided

CHR可以用于对抗性搜索吗?

  •  0
  • Mostowski Collapse ninesided  · 技术社区  · 5 年前

    在不到100ms的时间内,只需对否定进行快速优化,就可以搜索出完整的tic-tac-toe博弈树。这就是为什么 solution 使用游戏状态的整体表示作为单个序言术语:

    ?- time((init(X), best(X, x, _))).
    % 92,055 inferences, 0.031 CPU in 0.031 seconds (99% CPU, 2984342 Lips)
    false.
    

    init([[-, -, -], [-, -, -], [-, -, -]]).
    

    here 在斯坦福大学的游戏中。

    (init (cell 1 1 b))
    (init (cell 1 2 b))
    (init (cell 1 3 b))
    (init (cell 2 1 b))
    (init (cell 2 2 b))
    (init (cell 2 3 b))
    (init (cell 3 1 b))
    (init (cell 3 2 b))
    (init (cell 3 3 b))
    

    我在考虑CHR:约束处理规则,因为它可以添加和删除事实,但我不知道它是否适合于对抗性搜索。

    0 回复  |  直到 5 年前
        1
  •  1
  •   boisvert    5 年前

    您可以使用断言:

    :- dynamic play/2. % declare as dynamic (that is, assert is permitted)
    
    % initial state
    cell(1, 1, b). cell(1, 2, b). cell(1, 3, b).
    cell(2, 1, b). cell(2, 2, b). cell(3, 3, b).
    cell(3, 1, b). cell(3, 2, b). cell(3, 3, b).
    
    % play/2: use to mark the cells.
    play(Player,Row-Col) :-
       retract(cell(Row,Col,b)), % if retract fails, the cell is not blank
       assertz(cell(Row,Col,Player)).
    
    % test of play/2
    :- play(white,2-2).
    

    assert将一个事实添加到数据库中,之后可以查询该事实。assertz将其添加到数据库的末尾,asserta添加到数据库的开头。retract删除与数据匹配的第一个事实。


    play(Player,Row-Col) :-
       \+ cell(Row,Col,_)), % check the cell is not already taken
       assertz(cell(Row,Col,Player)).
    
    推荐文章