Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
Created March 27, 2012 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunlebron/2221478 to your computer and use it in GitHub Desktop.
Save shaunlebron/2221478 to your computer and use it in GitHub Desktop.
Carcassonne Contiguous River Generator
% the tile width of the rectangular map
#const width=4.
positions(0..11).
rotations(0..3).
% piece(number, side, side type [g=grass, w=water, c=city, r=road]).
piece( 1,0,g ;; 1,1,g ;; 1,2,g ;; 1,3,w).
piece( 2,0,g ;; 2,1,g ;; 2,2,g ;; 2,3,w).
piece( 3,0,g ;; 3,1,w ;; 3,2,g ;; 3,3,w).
piece( 4,0,g ;; 4,1,w ;; 4,2,g ;; 4,3,w).
piece( 5,0,g ;; 5,1,g ;; 5,2,w ;; 5,3,w).
piece( 6,0,g ;; 6,1,g ;; 6,2,w ;; 6,3,w).
piece( 7,0,g ;; 7,1,g ;; 7,2,w ;; 7,3,w).
piece( 8,0,c ;; 8,1,w ;; 8,2,c ;; 8,3,w).
piece( 9,0,r ;; 9,1,w ;; 9,2,r ;; 9,3,w).
piece(10,0,w ;;10,1,w ;;10,2,c ;;10,3,c).
piece(11,0,w ;;11,1,w ;;11,2,r ;;11,3,r).
piece(12,0,g ;;12,1,w ;;12,2,r ;;12,3,w).
piece(P) :- piece(P,_,_).
% choose an arbitrary position and rotation for each piece.
1 { place(P,R,I) :rotations(R) :positions(I) } 1 :- piece(P).
% prevent multiple pieces from occupying the same position
:- place(P1,_,I), place(P2,_,I), P1 != P2.
% ensure horizontal edges match
:- place(P1,R1,I), I/width > 0, place(P2,R2,I-width),
piece(P1,#mod(0+R1,4),T1),
piece(P2,#mod(2+R2,4),T2),
T1 != T2.
% ensure vertical edges match
:- place(P1,R1,I), #mod(I,width) > 0, place(P2,R2,I-1),
piece(P1,#mod(3+R1,4),T1),
piece(P2,#mod(1+R2,4),T2),
T1 != T2.
% ensure contiguous river
:- place(P,R,I), #mod(I,width) == 0, piece(P,#mod(3+R,4),w).
:- place(P,R,I), #mod(I,width) == width-1, piece(P,#mod(1+R,4),w).
:- place(P,R,I), I/width == 0, piece(P,#mod(0+R,4),w).
:- place(P,R,I), not positions(I+width), piece(P,#mod(2+R,4),w).
#hide.
#show place/3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment