From d3058d7617e134d0ff645de1fc01ffe94d7dcc79 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 1 Jun 2022 18:40:01 +0800 Subject: When switching, coerce piece inside boundary --- sirtet.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sirtet.c') 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; } } -- cgit v1.2.3