序言多米诺骨牌游戏

编程入门 行业动态 更新时间:2024-10-12 05:46:38
本文介绍了序言多米诺骨牌游戏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在 prolog 中制作一个游戏,使用一组给定的多米诺骨牌,它应该使用初始集合中的所有碎片制作一个正确的多米诺行.我们必须使用一个推理系统,其中我们必须像这样构建初始状态和最终状态:

i'm making a game in prolog, with a given set of domino pieces, it should make a correct domino row using all the pieces in the initial set. we must use an inference system in which we must build the initial state and the final state like this:

initial(dominos([[1,4],[2,3],[4,2]],[])). final(dominos([],[[1,4],[4,2],[2,3]])).

第一个转换只是从第一个列表中选择一个并将其放入第二个列表中,但接下来的转换应验证第二个数字是否与要放置的作品的第一个数字匹配.我想我有第二个过渡的头

the first transtion is just pick one pice from the 1st list and put it into the 2nd list, but the next ones should verify if the 2nd number matches the 1st number of the piece to be put. i think i have the 2nd transition's head

第一次过渡:

transition(dominos(L,[]),A,dominos(L1,[A])):- select(A,L,L1).

第二次转换:

transition(dominos(L,B),A,dominos(L1,[[X,Y]|[Y,_])):- select(B,L,L1).

我如何验证条件?

推荐答案

考虑这样的事情:

% L1 is a list of domino pieces (of the form X-Y) % L2 is L1 in domino order domino_order(L1, L2) :- domino_order(L1, _, L2). domino_order([], _, []) :- !. domino_order(In, X, [X-Y | Out]) :- select(Piece, In, Remaining), swap_or_not(Piece, X-Y), domino_order(Remaining, Y, Out). swap_or_not(X-Y, X-Y). swap_or_not(X-Y, Y-X).

用法:

?- domino_order([5-4, 1-2, 4-3, 2-3], Out). Out = [5-4, 4-3, 3-2, 2-1] ; Out = [1-2, 2-3, 3-4, 4-5] ; false.

更多推荐

序言多米诺骨牌游戏

本文发布于:2023-11-29 11:44:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646304.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序言   多米诺骨牌   游戏

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!