core-logic

2018-11-26T07:39:39.039400Z

I'm trying to write a program to calculate the solution in the board game Clue. I'm very new to core.logic, so I'm starting off with a really simple version: given all the cards in my hand and in my opponents' hands, what are the three remaining cards? I've written the code below, but (do-query) just makes the CPU max out and never returns. How should I write this? Should I take a different approach?

(def players [:green :scarlet :peacock :mustard :white :plum])
(def rooms [:study :hall :lounge :dining-room :kitchen :ballroom
            :conservatory :billiard-room :library])
(def weapons [:candlestick :lead-pipe :revolver :wrench :rope :knife])
(def all-cards (concat players rooms weapons))

(defn do-query []
  (let [cards (repeatedly 21 logic/lvar)
        [solution remaining] (split-at 3 cards)
        [my-cards remaining] (split-at 6 remaining)
        [green-cards scarlet-cards] (split-at 6 remaining)]
    (logic/run 1 [p r w]
      (logic/== solution [p r w])
      (logic/permuteo all-cards cards)
      (logic/== my-cards [:rope :study :scarlet
                          :conservatory :mustard :wrench])
      (logic/== green-cards [:green :lead-pipe :knife :dining-room
                             :billiard-room :library])
      (logic/== scarlet-cards [:revolver :plum :hall
                               :lounge :kitchen :white])
      (logic/membero p players)
      (logic/membero r rooms)
      (logic/membero w weapons))))

2018-11-26T17:05:58.039700Z

the permuteo is what does it

2018-11-26T17:07:55.040300Z

it results in a search tree with a lot of branches

2018-11-26T17:09:52.040800Z

come to think of it, I don't think I've ever played clue

2018-11-26T17:22:08.042300Z

I think I would start from a map of card names to lvars, where each lvar will have a value like :mine, :opponent, or :deck (if deck is valid in clue)

2018-11-28T03:33:54.049Z

thanks, I'll try going down that route

schmee 2018-11-26T21:22:28.043300Z

if I have a core.logic goal that looks like this

(fresh [?1 ?2 ?3 ?4]
      (membero ?1 vars)
      (membero ?2 vars)
      (membero ?3 vars)
      (membero ?4 vars)
      ...)
will that expand into vars × vars × vars × vars in memory, even if I have other goals that constrain the answer set to something much smaller?

2018-11-26T21:23:26.043600Z

it depends what you mean by expands in memory

2018-11-26T21:24:15.044600Z

you will end up with a search tree that has at least that many branches, but the search tree typically is walked in a lazy fashion so the whole thing isn't realized at once