How can I list all possible boards after (for example) one player performs some action in a 4x4 board (with 8 different pions)?
The pions should be, for example:
([1,2,3,4,5,6,7,8])
and each time you play one automatically it cannot re-used.
The board should be like this board
([1,1,-,-],(1,2,-,-)...(1,3,-,-)(1,4,-,-)
[2,1,-,-],(2,2,-,-)...(2,3,-,-)(2,4,-,-)
[3,1,-,-],(3,2,-,-)...(3,3,-,-)(3,4,-,-)
[4,1,-,-],(4,2,-,-)...(4,3,-,-)(4,4,-,-)
And one player per round puts one pion on the board until it's full.
I assume you have a predicate like board0_move_board/3
, which is a ternary relation between a board B, a move M, and the resulting board after the move M is made on B. Further, I assume you have a predicate board_move/2
that relates a board to a move that is possible on that board, and on backtracking successively gives all moves that are possible. With these predicates, you can get all possible boards with:
findall(Board, (board_move(Board0, Move), board0_move_board(Board0, Move, Board)), Boards)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With