summaryrefslogtreecommitdiff
path: root/sirtet.c
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-06-01 18:40:01 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-06-01 18:40:01 +0800
commitd3058d7617e134d0ff645de1fc01ffe94d7dcc79 (patch)
tree773329ca64e683cf22684fa119c80e606a3b9520 /sirtet.c
parent3b8ecc1d1864f4368e1621284b482996ed87b72f (diff)
When switching, coerce piece inside boundary
Diffstat (limited to 'sirtet.c')
-rw-r--r--sirtet.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/sirtet.c b/sirtet.c
index 2ec0b19..aa37feb 100644
--- a/sirtet.c
+++ b/sirtet.c
@@ -158,6 +158,11 @@ void sirtet(int H, int W, int P) {
pc_idx = (pc_idx + P - 1) % P;
if (hand[pc_idx] != NULL) {
pc = hand[pc_idx];
+ // move piece inside boundary if necessary
+ if (row + (pc->h) > H)
+ row = H - pc->h;
+ if (col + (pc->w) > W)
+ col = W - pc->w;
break;
}
}
@@ -168,6 +173,10 @@ void sirtet(int H, int W, int P) {
pc_idx = (pc_idx + 1) % P;
if (hand[pc_idx] != NULL) {
pc = hand[pc_idx];
+ if (row + (pc->h) > H)
+ row = H - pc->h;
+ if (col + (pc->w) > W)
+ col = W - pc->w;
break;
}
}