PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/GoGuiClienteTonto/prolog/goGame.pl

http://go-engine-java-gtp.googlecode.com/
Perl | 86 lines | 65 code | 21 blank | 0 comment | 0 complexity | 657ebff43ff6cf659e39c1707bc7d59a MD5 | raw file
Possible License(s): GPL-3.0
  1. :-consult('goRules.pl').
  2. :- assert(initialConfiguration(0)).
  3. :- assert(isInSquare(0, white(1), 2, 5)).
  4. % :- assert(isInSquare(0, white(2), 1, 4)).
  5. :- assert(isInSquare(0, white(3), 1, 6)).
  6. :- assert(isInSquare(0, white(4), 1, 7)).
  7. :- assert(isInSquare(0, white(5), 1, 8)).
  8. :- assert(isInSquare(0, white(6), 5, 6)).
  9. % :- assert(isInSquare(0, white(7), 4, 8)).
  10. :- assert(isInSquare(0, white(8), 5, 7)).
  11. :- assert(isInSquare(0, white(9), 4, 4)).
  12. :- assert(isInSquare(0, white(10), 3, 6)).
  13. :- assert(isInSquare(0, white(11), 3, 7)).
  14. :- assert(isInSquare(0, white(12), 3, 5)).
  15. :- assert(isInSquare(0, white(13), 5, 5)).
  16. :- assert(isInSquare(0, white(14), 9, 9)).
  17. :- assert(isInSquare(0, white(15), 8, 8)).
  18. :- assert(isInSquare(0, white(16), 8, 9)).
  19. :- assert(isInSquare(0, white(17), 9, 8)).
  20. :- assert(isInSquare(0, black(1), 1, 5)).
  21. :- assert(isInSquare(0, black(2), 4,6)).
  22. :- assert(isInSquare(0, black(3), 4,7)).
  23. :- assert(isInSquare(0, black(4), 4,5)).
  24. :- assert(hasPlayerWithTheMove(0,black)).
  25. :- assert(hasNumberMoves(0,black,6)).
  26. :- assert(hasNumberMoves(0,white,17)).
  27. :- assert(hasNumberOfCapturedStones(0,white,0)).
  28. :- assert(hasNumberOfCapturedStones(0,black,0)).
  29. % Print the entire board
  30. printBoard(P) :- initialConfiguration(C), hasSquareSize(C,S),
  31. write(' '), printHeaderRow(1),
  32. write(' +'), printGridEdge(S),
  33. printRank(P,S),
  34. write(' +'), printGridEdge(S).
  35. % Prints the last element in the header row
  36. printHeaderRow(S) :- initialConfiguration(C), hasSquareSize(C,S),printLetter(S),
  37. writeln(' '),!.
  38. % Prints the header row (A-T)
  39. printHeaderRow(N) :- initialConfiguration(C), hasSquareSize(C,S), N=<S,
  40. printLetter(N), write(' '),
  41. N1 is N+1, printHeaderRow(N1).
  42. printLetter(N) :- isFile(N,L),write(L).
  43. printNumber(N) :- N =< 9, write(' '),write(N).
  44. printNumber(N) :- N >= 10, write(N).
  45. % Prints the horizontal edge of the grid: +-----------+
  46. printGridEdge(1) :- write('-+'),writeln(' '),!.
  47. printGridEdge(S) :- write('--'),
  48. S1 is S-1, printGridEdge(S1).
  49. % Prints the lowest rank
  50. printRank(P,1) :- write(' 1 |'),printFile(P,1,1),writeln(' ').
  51. % Prints the following ranks until lineInGrid is false
  52. printRank(P,I) :- printNumber(I),write(' |'),
  53. lineInGrid(I),printFile(P,I,1),
  54. writeln(' '),
  55. I1 is I-1, printRank(P,I1).
  56. % Prints the last square in a rank
  57. printFile(P,I,M) :- isUEdge(M),
  58. printStone(P,I,M),write('|').
  59. % Prints squares in rank I recursively, with file J
  60. printFile(P,I,J) :- lineInGrid(I),lineInGrid(J),
  61. printStone(P,I,J),write('.'),
  62. J1 is J+1, printFile(P,I,J1).
  63. printStone(P,I,J) :- (not(isInSquare(P,_S,I,J)),write(' '));
  64. (isInSquare(P,white(_X),I,J),write('W'));
  65. (isInSquare(P,black(_Y),I,J),write('B')).