summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-07-24 06:57:46 +0200
committerkdx <kikoodx@paranoici.org>2023-07-24 06:57:46 +0200
commit5315f69a8aee47b2be50fb4a5b51e29c1ae9acc8 (patch)
tree416e8cb6894dd593fa1a8bbbf377b13a033f7f58
parent0eb8f630dfc94b3fa562fd1e2a98231d2d83f6f8 (diff)
downloadegecs-5315f69a8aee47b2be50fb4a5b51e29c1ae9acc8.tar.gz
dry
-rw-r--r--board.golem37
1 files changed, 21 insertions, 16 deletions
diff --git a/board.golem b/board.golem
index 6b858b9..ee86f11 100644
--- a/board.golem
+++ b/board.golem
@@ -1,5 +1,6 @@
define BOARD_SIZE = 64;
global gBoard[BOARD_SIZE] = 0;
+global gTargets[BOARD_SIZE] = 0;
board_init() {
memset(gBoard, EMPTY, BOARD_SIZE);
@@ -37,36 +38,40 @@ board_init() {
board_set("h7", piece(BLACK, PAWN));
}
+board_targets(pos) {
+ local x, y, col = 0;
+ if (pos == NULL)
+ return putstr("pos is NULL\n");
+ board_pos(pos, &x, &y);
+ memset(gTargets, EMPTY, BOARD_SIZE);
+}
+
board_pos(pos, x, y) {
+ if (pos == NULL) {
+ putstr("pos is NULL\n");
+ return 1;
+ }
[x] = [pos + 0] - 'a';
[y] = 7 - ([pos + 1] - '1');
+ if (([x] > 7) | ([y] > 7)) {
+ putstr("wrong pos ");
+ putstr(pos);
+ wrt '\n';
+ return 1;
+ }
}
board_set(pos, v) {
local x, y;
- if (pos == NULL)
- return putstr("pos is NULL\n");
- board_pos(pos, &x, &y);
- if ((x > 7) | (y > 7)) {
- putstr("wrong pos ");
- putstr(pos);
- wrt '\n';
+ if (board_pos(pos, &x, &y))
return;
- }
[gBoard + x + y * 8] = v;
}
board_get(pos) {
local x, y;
- if (pos == NULL)
- return putstr("pos is NULL\n");
- board_pos(pos, &x, &y);
- if ((x > 7) | (y > 7)) {
- putstr("wrong pos ");
- putstr(pos);
- wrt '\n';
+ if (board_pos(pos, &x, &y))
return INVALID;
- }
return [gBoard + x + y * 8];
}