Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :- set_prolog_flag(toplevel_print_options,
- [quoted(true), portray(true), max_depth(120),
- priority(699)]).
- :- pce_image_directory('/home/alex/prog/prolog/').
- resource(tablero, image, image('tablero-ajedrez.jpg')).
- resource(reina, image, image('reina.jpg')).
- inicio :-
- b_setval(contador,1),
- new(@ventana, window('Solucion de las 8 reinas', size(600,600))),
- new(D, dialog('Control de 8 reinas')),
- new(@boton1, button('Limpiar', message(@prolog,limpiar))),
- new(@boton2, button('Siguiente', message(@prolog, siguiente))),
- new(@boton3, button('Finalizar', message(@prolog, fin, D))),
- new(@boton4, label('nombLabel', '0')),
- send(D, append(@boton1)),
- send(D, append(@boton2)),
- send(D, append(@boton3)),
- send(D, append(@boton4)),
- send(D, open).
- halla_abcisa(Y,NY) :- NY is 86 + 53*(Y - 1).
- ajedrez([Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8]) :-
- nueva_imagen(tablero, point(40,40)),
- halla_abcisa(Y1,NY1),
- nueva_imagen(reina,point(NY1,87)),
- halla_abcisa(Y2,NY2),
- nueva_imagen(reina,point(NY2,140)),
- halla_abcisa(Y3,NY3),
- nueva_imagen(reina,point(NY3,193)),
- halla_abcisa(Y4,NY4),
- nueva_imagen(reina,point(NY4,246)),
- halla_abcisa(Y5,NY5),
- nueva_imagen(reina,point(NY5,299)),
- halla_abcisa(Y6,NY6),
- nueva_imagen(reina,point(NY6,352)),
- halla_abcisa(Y7,NY7),
- nueva_imagen(reina,point(NY7,405)),
- halla_abcisa(Y8,NY8),
- nueva_imagen(reina,point(NY8,458)),send(@ventana,open).
- nueva_imagen(Imagen, Posicion) :-
- new(Figura, figure),
- new(Bitmap, bitmap(resource(Imagen),@on)),
- send(Bitmap, name, 1),
- send(Figura, display, Bitmap),
- send(Figura, status, 1),
- send(@ventana, display, Figura, Posicion).
- limpiar :-
- nueva_imagen(tablero,point(40,40)),
- send(@ventana,flush).
- siguiente :-
- b_getval(contador, C),
- ( C = [] -> K is 1
- ;
- K is C
- ),
- todas_las_soluciones(LL),
- length(LL,M),
- b_setval(maximo,M),
- nth1(K,LL,L),
- ajedrez(L),
- send(@boton4,selection,K),
- K1 is K + 1,
- b_setval(contador, K1),!.
- siguiente :- K is 1, b_setval(contador,K).
- anterior :-
- b_getval(contador, C),
- K1 is C - 2,
- C > 2,
- b_setval(contador,K1),
- siguiente,!.
- anterior :-
- K is 92,b_setval(contador,K),siguiente.
- fin(Dialogo) :-
- send(@ventana,free),
- send(@boton1,free),
- send(@boton2,free),
- send(@boton3,free),
- send(@boton4, free),
- send(Dialogo,destroy),
- send(Dialogo,free).
- todas_las_soluciones(LL) :- findall(L,reinas(L),LL).
- solucion([]).
- solucion([[X,Y]|Otros]) :-
- solucion(Otros),
- member(Y,[1,2,3,4,5,6,7,8]),
- noataca([X,Y],Otros).
- noataca(_,[]).
- noataca([X,Y],[[X1,Y1]|Otros]) :-
- Y =\= Y1,
- Y1 - Y =\= X1 - X,
- Y1 - Y =\= X - X1,
- noataca([X,Y],Otros).
- reinas(L) :-
- L1 = [[1,Y1],[2,Y2],[3,Y3],[4,Y4],[5,Y5],[6,Y6],[7,Y7],[8,Y8]],
- solucion(L1),
- L = [Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8].
Add Comment
Please, Sign In to add comment