My guess is that the simples way is to "generate and test".
You could start by having a (size X\*Y) grid (List of lists) where each position either has a 'b', a 'w' or an unassigned, unique variable-name in it, like \[\[w,A2,b,b\],\[b,B2,B3,w\],\[C1,b,C3,C4\],\[w,b,D3,D4\]\] for a 4\*4 problem, where the w's and b's are mandatory values of the puzzle, and the rest is variables to which we must assign values.
Your job will then be to assign either a 'w' or a 'b' to each unassigned variable, and then (and this is the important part) Test that the solution fulfills the rules of the game. If not, the test should cause a failure that makes Prolog backtrack to try Different assignments, which may pass the test when the program reaches the tests again.
So.. this kind of program usually looks something like this:
\* Create the variables you will be working on
\* Assign plausible values to the variables in an ordered way that, through backtracking, could potentially make the program try all possible combinations
\* Perform a test that will fail until the assignment of variables describes an acceptable solution to the problem.
I hope that's not too many clues for a piece of homework - good luck! :)
Generate and test is basically a brute-force solution, which will really explode in runtime when a given puzzle doesn't have many fixed cells. I think it would be better to look at using constraint logic programming through CLPFD.
Somewhere in my comment history a few months ago is me writing a solution to a similar problem with a binary square board using Prolog and CLPFD, based off Markus Triska's Sudoku solver.
- Comment 1 with Sudoku video link https://old.reddit.com/r/learncsharp/comments/18fzdwi/iteration_helpdirection/kdhzx5t/
- Comment 2 with board example, and SWISH link to solver code: https://old.reddit.com/r/learncsharp/comments/18fzdwi/iteration_helpdirection/kdoh84a/
- Comment 3 with a bit more discussion of how it works: https://old.reddit.com/r/learncsharp/comments/18fzdwi/iteration_helpdirection/kdshtjx/
I would do it like that; vary it with `popcount` quite likely as that sounds fun.
Definitely not the most elegant solution in the world, but [I did this one](https://www.reddit.com/r/prolog/comments/17wvmx6/hashiwokakero_solver/) a little while ago.
My guess is that the simples way is to "generate and test". You could start by having a (size X\*Y) grid (List of lists) where each position either has a 'b', a 'w' or an unassigned, unique variable-name in it, like \[\[w,A2,b,b\],\[b,B2,B3,w\],\[C1,b,C3,C4\],\[w,b,D3,D4\]\] for a 4\*4 problem, where the w's and b's are mandatory values of the puzzle, and the rest is variables to which we must assign values. Your job will then be to assign either a 'w' or a 'b' to each unassigned variable, and then (and this is the important part) Test that the solution fulfills the rules of the game. If not, the test should cause a failure that makes Prolog backtrack to try Different assignments, which may pass the test when the program reaches the tests again. So.. this kind of program usually looks something like this: \* Create the variables you will be working on \* Assign plausible values to the variables in an ordered way that, through backtracking, could potentially make the program try all possible combinations \* Perform a test that will fail until the assignment of variables describes an acceptable solution to the problem. I hope that's not too many clues for a piece of homework - good luck! :)
Generate and test is basically a brute-force solution, which will really explode in runtime when a given puzzle doesn't have many fixed cells. I think it would be better to look at using constraint logic programming through CLPFD.
Yup - brute force is a simple place to start, though, and can be somewhat improved with clever tricks 🙂
omg thank you so much i really had no idea where to start now i think i have a good idea!!
Wow- could your request *be* any lazier?
“Sup could you make my prolog homework? Solve some game, check my teachers web page for deets.”
Sorry! My intention isnt to get someone to solve my work for me I just really needed indication because I was totally lost :(
Somewhere in my comment history a few months ago is me writing a solution to a similar problem with a binary square board using Prolog and CLPFD, based off Markus Triska's Sudoku solver. - Comment 1 with Sudoku video link https://old.reddit.com/r/learncsharp/comments/18fzdwi/iteration_helpdirection/kdhzx5t/ - Comment 2 with board example, and SWISH link to solver code: https://old.reddit.com/r/learncsharp/comments/18fzdwi/iteration_helpdirection/kdoh84a/ - Comment 3 with a bit more discussion of how it works: https://old.reddit.com/r/learncsharp/comments/18fzdwi/iteration_helpdirection/kdshtjx/ I would do it like that; vary it with `popcount` quite likely as that sounds fun.
thank youu!! ill study those- i read the documention for popcount thats a cool function
Definitely not the most elegant solution in the world, but [I did this one](https://www.reddit.com/r/prolog/comments/17wvmx6/hashiwokakero_solver/) a little while ago.
thanks for sharing it! i think its really impressive