3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 int rules_verify (game_t
*game
, int zx
, int zy
, int cx
, int cy
)
36 char f
= game
->board
[(int)zy
][(int)zx
];
38 if (game
->player
== 'w') {
39 if (f
> 'a' && f
< 'z')
41 } else if (game
->player
== 'b')
42 if (f
> 'A' && f
< 'Z')
46 case 'p': // cerny pesec
49 if ((game
->board
[cy
][cx
] == '.') && (abs (cy
-zy
)== 1))
51 // pokud je cilove policko volne a pohyb je o 1 pole tak je to OK
52 if ((game
->board
[cy
][cx
] == '.') && (game
->board
[cy
+1][cx
] == '.') && (zy
== 6) && (abs (cy
-zy
) == 2))
53 ok
--; // pocatecni pozice
55 // pokud je cilove a predcilove policko volne a pohyb je o 2 pole tak je to OK
56 if ((abs (cx
-zx
)== 1) && ((zy
-cy
)== 1) && (game
->board
[cy
][cx
] < 'Z') && (game
->board
[cy
][cx
] > '.'))
57 ok
--; // jiny sloupec -> bere figuru, pouze souperovu
62 case 'P': // BILY pesec
64 if ((game
->board
[cy
][cx
] == '.') && ((cy
- zy
)== 1))
66 // pokud je cilove policko volne a pohyb je o 1 pole tak je to OK
68 if ((game
->board
[cy
][cx
] == '.') &&
69 (game
->board
[cy
-1][cx
] == '.') &&
70 (zy
== 1) && // pocatecni pozice
73 // pokud je cilove a predcilove policko volne a pohyb je o 2 pole tak je to OK
75 if ((abs (cx
- zx
) == 1) && ((cy
- zy
) == 1) &&
76 (game
->board
[cy
][cx
] > 'Z'))
78 // jiny sloupec -> bere figuru, pouze souperovu
86 if (abs (cx
- zx
) <= 1)
87 ok
--; // pohyb pouze o jedno pole v libovolnem smeru
89 if (abs (cy
- zy
) <= 1)
97 if ((cx
== zx
) || (cy
== zy
)) { // pohyb pouze horizontalne nebo vertikalne
98 for (i
= zx
; i
< cx
; i
++)
99 if (game
->board
[zy
][i
] != '.')
100 ok
++; // f stoji v ceste
102 for (i
= zx
; i
> cx
; i
--)
103 if (game
->board
[zy
][i
] != '.')
104 ok
++; // f stoji v ceste
106 for (i
= zy
; i
<cy
; i
++)
107 if (game
->board
[i
][zx
] != '.')
108 ok
++; // f stoji v ceste
110 for (i
= zy
; i
>cy
; i
--)
111 if (game
->board
[i
][zx
] != '.')
112 ok
++; // f stoji v ceste
116 for (i
= 0; i
< (cx
- zx
); i
++) {
118 if (game
->board
[zy
+i
][zx
+i
] != '.')
121 if (game
->board
[zy
-i
][zx
+i
] != '.')
125 for (i
= 0; i
> (cx
- zx
); i
--) {
127 if (game
->board
[zy
+i
][zx
+i
] != '.')
130 if (game
->board
[zy
-i
][zx
+i
] != '.')
131 ok
++; // f stoji v ceste
144 for (i
= 0; i
< (cx
- zx
); i
++) {
146 if (game
->board
[zy
+i
][zx
+i
] != '.')
149 if (game
->board
[zy
-i
][zx
+i
] != '.')
154 for (i
= 0; i
> (cx
- zx
); i
--) {
156 if (game
->board
[zy
+i
][zx
+i
] != '.')
159 if (game
->board
[zy
-i
][zx
+i
] != '.')
160 ok
++; // f stoji v ceste
169 case 'J': // jezdec / kun
172 if (((abs (cx
- zx
) == 2) && (abs (cy
- zy
) == 1))
173 || ((abs (cy
- zy
) == 2) && (abs (cx
- zx
) == 1)))
174 ok
--; // pohyb pouze do "L"
180 if ((cx
== zx
) || (cy
== zy
))
181 ok
--; // pohyb pouze horizontalne nebo vertikalne
183 for (i
= zx
; i
< cx
; i
++)
184 if (game
->board
[zy
][i
] != '.')
185 ok
++; // f stoji v ceste
187 for (i
= zx
; i
> cx
; i
--)
188 if (game
->board
[zy
][i
] != '.') ok
++; // f stoji v ceste
190 for (i
= zy
; i
< cy
; i
++)
191 if (game
->board
[i
][zx
] != '.')
192 ok
++; // f stoji v ceste
194 for (i
= zy
; i
> cy
; i
--)
195 if (game
->board
[i
][zx
] != '.')
196 ok
++; // f stoji v ceste
198 ok
-= 1; // 1x se testuje pozice veze samotne
201 default: return FAIL
;