Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.21 KB | None | 0 0
  1. :- dynamic(move/2).
  2. :- dynamic(hits/2).
  3. :- dynamic(misses/2).
  4. :- dynamic(sunks/2).
  5. :- dynamic(position/2).
  6.  
  7. move(1,1).
  8. move(1,2).
  9. move(1,3).
  10. move(1,4).
  11. move(1,5).
  12. move(2,1).
  13. move(2,2).
  14. move(2,3).
  15. move(2,4).
  16. move(2,5).
  17. move(3,1).
  18. move(3,2).
  19. move(3,3).
  20. move(3,4).
  21. move(3,5).
  22. move(4,1).
  23. move(4,2).
  24. move(4,3).
  25. move(4,4).
  26. move(4,5).
  27. move(5,1).
  28. move(5,2).
  29. move(5,3).
  30. move(5,4).
  31. move(5,5).
  32.  
  33. target(X,Y):-
  34.     move(X,Y),
  35.   retract(move(X,Y)),
  36.   assert(position(X,Y)).
  37.  
  38. hit:-
  39.   position(X,Y),
  40.   assert(hits(X,Y)),
  41.   retract(position(X,Y)).
  42.  
  43. sunk:-
  44.   position(X,Y),
  45.   assert(hits(X,Y)),
  46.   hits_to_sunks,
  47.   retract(position(X,Y)).
  48.  
  49. miss:-
  50.   position(X,Y),
  51.   assert(misses(X,Y)),
  52.   retract(position(X,Y)).
  53.  
  54.  
  55. hits_to_sunks:-
  56.   hits(X,Y),
  57.   assert(sunks(X,Y)),
  58.   remove_perimeter(X,Y).
  59.  
  60. remove_perimeter(X,Y):-
  61.  Right is Y + 1,
  62.  Top is X - 1,
  63.  Bottom is X + 1,
  64.  %RemoveBottom
  65.  (X < 5, retract(move(Bottom,Y)));
  66.  %RemoveTop
  67.  (X > 1 , retract(move(Top,Y)));
  68.  %RemoveRight
  69.  (Y < 5, retract(move(X,Right)));
  70.  %RemoveTopRight
  71.  (Y < 5, X >1 , retract(move(Top,Right)));
  72.   %RemoveBottomRight
  73.  (Y < 5, X < 5 , retract(move(Bottom,Right))).
  74.  
  75. remove_move(X,Y):-
  76.   retract(move(X,Y)).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement