PageRenderTime 48ms CodeModel.GetById 2ms app.highlight 43ms RepoModel.GetById 2ms 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
 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
21:- assert(isInSquare(0, black(1), 1, 5)).
22:- assert(isInSquare(0, black(2), 4,6)).
23:- assert(isInSquare(0, black(3), 4,7)).
24:- assert(isInSquare(0, black(4), 4,5)).
25
26:- assert(hasPlayerWithTheMove(0,black)).
27:- assert(hasNumberMoves(0,black,6)).
28:- assert(hasNumberMoves(0,white,17)).
29:- assert(hasNumberOfCapturedStones(0,white,0)).
30:- assert(hasNumberOfCapturedStones(0,black,0)).
31
32% Print the entire board
33printBoard(P) :- initialConfiguration(C), hasSquareSize(C,S),
34	         write('    '), printHeaderRow(1),
35		 write('   +'), printGridEdge(S),
36		                printRank(P,S),
37		 write('   +'), printGridEdge(S).
38
39% Prints the last element in the header row
40printHeaderRow(S) :- initialConfiguration(C), hasSquareSize(C,S),printLetter(S),
41	             writeln(' '),!.
42% Prints the header row (A-T)
43printHeaderRow(N) :- initialConfiguration(C), hasSquareSize(C,S), N=<S,
44	             printLetter(N), write(' '),
45		     N1 is N+1, printHeaderRow(N1).
46
47printLetter(N) :- isFile(N,L),write(L).
48printNumber(N) :- N =< 9, write(' '),write(N).
49printNumber(N) :- N >= 10, write(N).
50
51% Prints the horizontal edge of the grid: +-----------+
52printGridEdge(1) :- write('-+'),writeln(' '),!.
53printGridEdge(S) :- write('--'),
54	            S1 is S-1, printGridEdge(S1).
55
56% Prints the lowest rank
57printRank(P,1) :- write(' 1 |'),printFile(P,1,1),writeln(' ').
58% Prints the following ranks until lineInGrid is false
59printRank(P,I) :- printNumber(I),write(' |'),
60	          lineInGrid(I),printFile(P,I,1),
61		  writeln(' '),
62		  I1 is I-1, printRank(P,I1).
63
64% Prints the last square in a rank
65printFile(P,I,M) :- isUEdge(M),
66		    printStone(P,I,M),write('|').
67
68% Prints squares in rank I recursively, with file J
69printFile(P,I,J) :- lineInGrid(I),lineInGrid(J),
70	            printStone(P,I,J),write('.'),
71		    J1 is J+1, printFile(P,I,J1).
72
73printStone(P,I,J) :- (not(isInSquare(P,_S,I,J)),write(' '));
74		     (isInSquare(P,white(_X),I,J),write('W'));
75		     (isInSquare(P,black(_Y),I,J),write('B')).
76
77
78
79
80
81
82
83
84
85
86