diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-03-17 22:26:45 +0100 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-03-17 22:26:45 +0100 |
commit | 972346f900204b7cc66fea35a950e81704c9685b (patch) | |
tree | c1f3c53f6ff452f787dce0157e30e8c737f74732 | |
parent | b34d7c64d89fcf05a0372f837f7ac5789ebff266 (diff) |
Reformatted is_move()
-rw-r--r-- | FICS/movecheck.c | 144 |
1 files changed, 73 insertions, 71 deletions
diff --git a/FICS/movecheck.c b/FICS/movecheck.c index 6c93f9e..df24a3b 100644 --- a/FICS/movecheck.c +++ b/FICS/movecheck.c @@ -38,78 +38,80 @@ #include "playerdb.h" #include "utils.h" -/* Simply tests if the input string is a move or not. */ -/* If it matches patterns below */ -/* Add to this list as you improve the move parser */ -/* MS_COMP e2e4 */ -/* MS_COMPDASH e2-e4 */ -/* MS_CASTLE o-o, o-o-o */ -/* Not done yet */ -/* MS_ALG e4, Nd5 Ncd5 */ -PUBLIC int is_move(char *mstr) +/* + * Simply tests if the input string is a move or not. If it matches + * patterns below. Add to this list as you improve the move parser. + * + * - MS_COMP e2e4 + * - MS_COMPDASH e2-e4 + * - MS_CASTLE o-o, o-o-o + * + * Not done yet + * MS_ALG e4, Nd5 Ncd5 + */ +PUBLIC int +is_move(char *mstr) { - int len = strlen(mstr); - if ((len > 3) && (mstr[len - 2] == '=')) - len -= 2; - - if (len == 4) { /* Test for e2e4 */ - if (isfile(mstr[0]) && isrank(mstr[1]) && - isfile(mstr[2]) && isrank(mstr[3])) { - return MS_COMP; - } - } - if (len == 5) { /* Test for e2-e4 */ - if (isfile(mstr[0]) && isrank(mstr[1]) && - (mstr[2] == '-') && - isfile(mstr[3]) && isrank(mstr[4])) { - return MS_COMPDASH; - } - } - if (len == 3) { /* Test for o-o */ - if ((mstr[0] == 'o') && (mstr[1] == '-') && (mstr[2] == 'o')) { - return MS_KCASTLE; - } - if ((mstr[0] == 'O') && (mstr[1] == '-') && (mstr[2] == 'O')) { - return MS_KCASTLE; - } - if ((mstr[0] == '0') && (mstr[1] == '-') && (mstr[2] == '0')) { - return MS_KCASTLE; - } - } - if (len == 2) { /* Test for oo */ - if ((mstr[0] == 'o') && (mstr[1] == 'o')) { - return MS_KCASTLE; - } - if ((mstr[0] == 'O') && (mstr[1] == 'O')) { - return MS_KCASTLE; - } - if ((mstr[0] == '0') && (mstr[1] == '0')) { - return MS_KCASTLE; - } - } - if (len == 5) { /* Test for o-o-o */ - if ((mstr[0] == 'o') && (mstr[1] == '-') && (mstr[2] == 'o') && (mstr[3] == '-') && (mstr[4] == 'o')) { - return MS_QCASTLE; - } - if ((mstr[0] == 'O') && (mstr[1] == '-') && (mstr[2] == 'O') && (mstr[3] == '-') && (mstr[4] == 'O')) { - return MS_QCASTLE; - } - if ((mstr[0] == '0') && (mstr[1] == '-') && (mstr[2] == '0') && (mstr[3] == '-') && (mstr[4] == '0')) { - return MS_QCASTLE; - } - } - if (len == 3) { /* Test for ooo */ - if ((mstr[0] == 'o') && (mstr[1] == 'o') && (mstr[2] == 'o')) { - return MS_QCASTLE; - } - if ((mstr[0] == 'O') && (mstr[1] == 'O') && (mstr[2] == 'O')) { - return MS_QCASTLE; - } - if ((mstr[0] == '0') && (mstr[1] == '0') && (mstr[2] == '0')) { - return MS_QCASTLE; - } - } - return alg_is_move(mstr); + int len = strlen(mstr); + + if (len > 3 && mstr[len - 2] == '=') + len -= 2; + + if (len == 4) { // Test for e2e4 + if (isfile(mstr[0]) && isrank(mstr[1]) && + isfile(mstr[2]) && isrank(mstr[3])) + return MS_COMP; + } + + if (len == 5) { // Test for e2-e4 + if (isfile(mstr[0]) && + isrank(mstr[1]) && + mstr[2] == '-' && + isfile(mstr[3]) && + isrank(mstr[4])) + return MS_COMPDASH; + } + + if (len == 3) { // Test for o-o + if (mstr[0] == 'o' && mstr[1] == '-' && mstr[2] == 'o') + return MS_KCASTLE; + if (mstr[0] == 'O' && mstr[1] == '-' && mstr[2] == 'O') + return MS_KCASTLE; + if (mstr[0] == '0' && mstr[1] == '-' && mstr[2] == '0') + return MS_KCASTLE; + } + + if (len == 2) { // Test for oo + if (mstr[0] == 'o' && mstr[1] == 'o') + return MS_KCASTLE; + if (mstr[0] == 'O' && mstr[1] == 'O') + return MS_KCASTLE; + if (mstr[0] == '0' && mstr[1] == '0') + return MS_KCASTLE; + } + + if (len == 5) { // Test for o-o-o + if (mstr[0] == 'o' && mstr[1] == '-' && mstr[2] == 'o' && + mstr[3] == '-' && mstr[4] == 'o') + return MS_QCASTLE; + if (mstr[0] == 'O' && mstr[1] == '-' && mstr[2] == 'O' && + mstr[3] == '-' && mstr[4] == 'O') + return MS_QCASTLE; + if (mstr[0] == '0' && mstr[1] == '-' && mstr[2] == '0' && + mstr[3] == '-' && mstr[4] == '0') + return MS_QCASTLE; + } + + if (len == 3) { // Test for ooo + if (mstr[0] == 'o' && mstr[1] == 'o' && mstr[2] == 'o') + return MS_QCASTLE; + if (mstr[0] == 'O' && mstr[1] == 'O' && mstr[2] == 'O') + return MS_QCASTLE; + if (mstr[0] == '0' && mstr[1] == '0' && mstr[2] == '0') + return MS_QCASTLE; + } + + return alg_is_move(mstr); } PUBLIC int |