Sat, 22 Mar 2014 17:23:07 +0100
prepared code base for implementing rules
1.1 --- a/Makefile Sat Mar 22 16:25:49 2014 +0100 1.2 +++ b/Makefile Sat Mar 22 17:23:07 2014 +0100 1.3 @@ -30,11 +30,15 @@ 1.4 1.5 all: clean compile 1.6 1.7 -compile: build 1.8 +compile: build build/rules 1.9 cd src; $(MAKE) 1.10 1.11 build: 1.12 $(MKDIR) build 1.13 + 1.14 +build/rules: 1.15 + $(MKDIR) build/rules 1.16 1.17 clean: 1.18 $(RM) -f -R build 1.19 + $(RM) -f -R build/rules
2.1 --- a/src/Makefile Sat Mar 22 16:25:49 2014 +0100 2.2 +++ b/src/Makefile Sat Mar 22 17:23:07 2014 +0100 2.3 @@ -35,6 +35,13 @@ 2.4 SRC += client.c 2.5 SRC += game.c 2.6 2.7 +SRC += rules/pawn.c 2.8 +SRC += rules/rook.c 2.9 +SRC += rules/knight.c 2.10 +SRC += rules/bishop.c 2.11 +SRC += rules/queen.c 2.12 +SRC += rules/king.c 2.13 + 2.14 OBJ = $(SRC:%.c=../build/%$(OBJ_EXT)) 2.15 2.16 all: $(OBJ)
3.1 --- a/src/game.c Sat Mar 22 16:25:49 2014 +0100 3.2 +++ b/src/game.c Sat Mar 22 17:23:07 2014 +0100 3.3 @@ -29,6 +29,7 @@ 3.4 3.5 #include "game.h" 3.6 #include "input.h" 3.7 +#include "rules/rules.h" 3.8 #include <ncurses.h> 3.9 #include <string.h> 3.10 3.11 @@ -91,16 +92,39 @@ 3.12 } 3.13 3.14 static _Bool validate_move(Board board, uint8_t mycolor, Move *move) { 3.15 - _Bool result = TRUE; 3.16 + _Bool result; 3.17 3.18 /* does piece exist */ 3.19 - result &= board[move->fromrow][move->fromfile] == move->piece; 3.20 + result = board[move->fromrow][move->fromfile] == move->piece; 3.21 3.22 - /* does move comply to rules */ 3.23 - // TODO: make it so 3.24 - 3.25 - /* is piece blocked */ 3.26 - // TODO: make it so 3.27 + switch (move->piece & PIECE_MASK) { 3.28 + case PAWN: 3.29 + result = result && pawn_chkrules(board, move); 3.30 + result = result && !pawn_isblocked(board, move); 3.31 + break; 3.32 + case ROOK: 3.33 + result = result && rook_chkrules(board, move); 3.34 + result = result && !rook_isblocked(board, move); 3.35 + break; 3.36 + case KNIGHT: 3.37 + result = result && knight_chkrules(board, move); 3.38 + result = result && !knight_isblocked(board, move); 3.39 + break; 3.40 + case BISHOP: 3.41 + result = result && bishop_chkrules(board, move); 3.42 + result = result && !bishop_isblocked(board, move); 3.43 + break; 3.44 + case QUEEN: 3.45 + result = result && queen_chkrules(board, move); 3.46 + result = result && !queen_isblocked(board, move); 3.47 + break; 3.48 + case KING: 3.49 + result = result && king_chkrules(board, move); 3.50 + result = result && !king_isblocked(board, move); 3.51 + break; 3.52 + default: 3.53 + result = FALSE; 3.54 + } 3.55 3.56 /* is piece pinned */ 3.57 // TODO: make it so 3.58 @@ -122,28 +146,17 @@ 3.59 if (len == 2) { 3.60 /* pawn move (e.g. "e4") */ 3.61 if (isfile(mstr[0]) && isrow(mstr[1])) { 3.62 - move->piece = PAWN; 3.63 - move->fromfile = move->tofile = fileidx(mstr[0]); 3.64 + move->piece = PAWN|mycolor; 3.65 + move->tofile = fileidx(mstr[0]); 3.66 move->torow = rowidx(mstr[1]); 3.67 - move->fromrow = rowidx(mstr[1]) + (mycolor == WHITE ? -1 : 1); 3.68 - if (move->fromrow > 6) { 3.69 + if (!pawn_getlocation(board, move)) { 3.70 move->piece = 0; 3.71 - } else { 3.72 - /* advanced first move */ 3.73 - if (move->fromrow == (mycolor == WHITE ? 2 : 5) && 3.74 - board[move->fromrow][move->fromfile] != (mycolor|PAWN)) { 3.75 - 3.76 - move->fromrow += (mycolor == WHITE ? -1 : 1); 3.77 - if (move->fromrow > 6) { 3.78 - move->piece = 0; 3.79 - } 3.80 - } 3.81 } 3.82 } 3.83 } else if (len == 3) { 3.84 if (strcmp(mstr, "O-O") == 0) { 3.85 /* king side castling */ 3.86 - move->piece = KING; 3.87 + move->piece = KING|mycolor; 3.88 move->fromfile = fileidx('e'); 3.89 move->tofile = fileidx('g'); 3.90 move->fromrow = move->torow = mycolor == WHITE ? 0 : 7; 3.91 @@ -159,7 +172,7 @@ 3.92 } else if (len == 5) { 3.93 if (strcmp(mstr, "O-O-O") == 0) { 3.94 /* queen side castling "O-O-O" */ 3.95 - move->piece = KING; 3.96 + move->piece = KING|mycolor; 3.97 move->fromfile = fileidx('e'); 3.98 move->tofile = fileidx('c'); 3.99 move->fromrow = move->torow = mycolor == WHITE ? 0 : 7; 3.100 @@ -174,12 +187,7 @@ 3.101 /* long notation capture (e.g. "Nc5xf3") */ 3.102 } 3.103 3.104 - if (move->piece) { 3.105 - move->piece |= mycolor; 3.106 - return TRUE; 3.107 - } else { 3.108 - return FALSE; 3.109 - } 3.110 + return move->piece != 0; 3.111 } 3.112 3.113 static int sendmove(Board board, uint8_t mycolor, int opponent) {
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/src/rules/bishop.c Sat Mar 22 17:23:07 2014 +0100 4.3 @@ -0,0 +1,45 @@ 4.4 +/* 4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 4.6 + * 4.7 + * Copyright 2014 Mike Becker. All rights reserved. 4.8 + * 4.9 + * Redistribution and use in source and binary forms, with or without 4.10 + * modification, are permitted provided that the following conditions are met: 4.11 + * 4.12 + * 1. Redistributions of source code must retain the above copyright 4.13 + * notice, this list of conditions and the following disclaimer. 4.14 + * 4.15 + * 2. Redistributions in binary form must reproduce the above copyright 4.16 + * notice, this list of conditions and the following disclaimer in the 4.17 + * documentation and/or other materials provided with the distribution. 4.18 + * 4.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 4.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 4.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 4.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 4.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 4.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 4.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 4.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 4.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 4.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4.29 + * POSSIBILITY OF SUCH DAMAGE. 4.30 + * 4.31 + */ 4.32 + 4.33 +#include "bishop.h" 4.34 + 4.35 +_Bool bishop_chkrules(Board board, Move* move) { 4.36 + // TODO: implement 4.37 + return TRUE; 4.38 +} 4.39 + 4.40 +_Bool bishop_isblocked(Board board, Move *move) { 4.41 + // TODO: implement 4.42 + return FALSE; 4.43 +} 4.44 + 4.45 +_Bool bishop_getlocation(Board board, Move *move) { 4.46 + // TODO: implement 4.47 + return TRUE; 4.48 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/src/rules/bishop.h Sat Mar 22 17:23:07 2014 +0100 5.3 @@ -0,0 +1,48 @@ 5.4 +/* 5.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 5.6 + * 5.7 + * Copyright 2014 Mike Becker. All rights reserved. 5.8 + * 5.9 + * Redistribution and use in source and binary forms, with or without 5.10 + * modification, are permitted provided that the following conditions are met: 5.11 + * 5.12 + * 1. Redistributions of source code must retain the above copyright 5.13 + * notice, this list of conditions and the following disclaimer. 5.14 + * 5.15 + * 2. Redistributions in binary form must reproduce the above copyright 5.16 + * notice, this list of conditions and the following disclaimer in the 5.17 + * documentation and/or other materials provided with the distribution. 5.18 + * 5.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 5.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 5.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 5.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 5.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 5.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 5.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 5.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 5.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 5.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 5.29 + * POSSIBILITY OF SUCH DAMAGE. 5.30 + * 5.31 + */ 5.32 + 5.33 +#ifndef BISHOP_H 5.34 +#define BISHOP_H 5.35 + 5.36 +#include "../game.h" 5.37 + 5.38 +#ifdef __cplusplus 5.39 +extern "C" { 5.40 +#endif 5.41 + 5.42 +_Bool bishop_chkrules(Board board, Move *move); 5.43 +_Bool bishop_isblocked(Board board, Move *move); 5.44 +_Bool bishop_getlocation(Board board, Move *move); 5.45 + 5.46 +#ifdef __cplusplus 5.47 +} 5.48 +#endif 5.49 + 5.50 +#endif /* BISHOP_H */ 5.51 +
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/src/rules/king.c Sat Mar 22 17:23:07 2014 +0100 6.3 @@ -0,0 +1,45 @@ 6.4 +/* 6.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 6.6 + * 6.7 + * Copyright 2014 Mike Becker. All rights reserved. 6.8 + * 6.9 + * Redistribution and use in source and binary forms, with or without 6.10 + * modification, are permitted provided that the following conditions are met: 6.11 + * 6.12 + * 1. Redistributions of source code must retain the above copyright 6.13 + * notice, this list of conditions and the following disclaimer. 6.14 + * 6.15 + * 2. Redistributions in binary form must reproduce the above copyright 6.16 + * notice, this list of conditions and the following disclaimer in the 6.17 + * documentation and/or other materials provided with the distribution. 6.18 + * 6.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 6.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 6.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 6.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 6.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 6.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 6.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 6.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 6.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 6.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 6.29 + * POSSIBILITY OF SUCH DAMAGE. 6.30 + * 6.31 + */ 6.32 + 6.33 +#include "king.h" 6.34 + 6.35 +_Bool king_chkrules(Board board, Move* move) { 6.36 + // TODO: implement 6.37 + return TRUE; 6.38 +} 6.39 + 6.40 +_Bool king_isblocked(Board board, Move *move) { 6.41 + // TODO: implement 6.42 + return FALSE; 6.43 +} 6.44 + 6.45 +_Bool king_getlocation(Board board, Move *move) { 6.46 + // TODO: implement 6.47 + return TRUE; 6.48 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/src/rules/king.h Sat Mar 22 17:23:07 2014 +0100 7.3 @@ -0,0 +1,49 @@ 7.4 +/* 7.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 7.6 + * 7.7 + * Copyright 2014 Mike Becker. All rights reserved. 7.8 + * 7.9 + * Redistribution and use in source and binary forms, with or without 7.10 + * modification, are permitted provided that the following conditions are met: 7.11 + * 7.12 + * 1. Redistributions of source code must retain the above copyright 7.13 + * notice, this list of conditions and the following disclaimer. 7.14 + * 7.15 + * 2. Redistributions in binary form must reproduce the above copyright 7.16 + * notice, this list of conditions and the following disclaimer in the 7.17 + * documentation and/or other materials provided with the distribution. 7.18 + * 7.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 7.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 7.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 7.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 7.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 7.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 7.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 7.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 7.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 7.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 7.29 + * POSSIBILITY OF SUCH DAMAGE. 7.30 + * 7.31 + */ 7.32 + 7.33 + 7.34 +#ifndef KING_H 7.35 +#define KING_H 7.36 + 7.37 +#include "../game.h" 7.38 + 7.39 +#ifdef __cplusplus 7.40 +extern "C" { 7.41 +#endif 7.42 + 7.43 +_Bool king_chkrules(Board board, Move *move); 7.44 +_Bool king_isblocked(Board board, Move *move); 7.45 +_Bool king_getlocation(Board board, Move *move); 7.46 + 7.47 +#ifdef __cplusplus 7.48 +} 7.49 +#endif 7.50 + 7.51 +#endif /* KING_H */ 7.52 +
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/src/rules/knight.c Sat Mar 22 17:23:07 2014 +0100 8.3 @@ -0,0 +1,45 @@ 8.4 +/* 8.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 8.6 + * 8.7 + * Copyright 2014 Mike Becker. All rights reserved. 8.8 + * 8.9 + * Redistribution and use in source and binary forms, with or without 8.10 + * modification, are permitted provided that the following conditions are met: 8.11 + * 8.12 + * 1. Redistributions of source code must retain the above copyright 8.13 + * notice, this list of conditions and the following disclaimer. 8.14 + * 8.15 + * 2. Redistributions in binary form must reproduce the above copyright 8.16 + * notice, this list of conditions and the following disclaimer in the 8.17 + * documentation and/or other materials provided with the distribution. 8.18 + * 8.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 8.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 8.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 8.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 8.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 8.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 8.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 8.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 8.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 8.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 8.29 + * POSSIBILITY OF SUCH DAMAGE. 8.30 + * 8.31 + */ 8.32 + 8.33 +#include "knight.h" 8.34 + 8.35 +_Bool knight_chkrules(Board board, Move *move) { 8.36 + // TODO: implement 8.37 + return TRUE; 8.38 +} 8.39 + 8.40 +_Bool knight_isblocked(Board board, Move *move) { 8.41 + // TODO: implement 8.42 + return FALSE; 8.43 +} 8.44 + 8.45 +_Bool knight_getlocation(Board board, Move *move) { 8.46 + // TODO: implement 8.47 + return TRUE; 8.48 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/src/rules/knight.h Sat Mar 22 17:23:07 2014 +0100 9.3 @@ -0,0 +1,48 @@ 9.4 +/* 9.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 9.6 + * 9.7 + * Copyright 2014 Mike Becker. All rights reserved. 9.8 + * 9.9 + * Redistribution and use in source and binary forms, with or without 9.10 + * modification, are permitted provided that the following conditions are met: 9.11 + * 9.12 + * 1. Redistributions of source code must retain the above copyright 9.13 + * notice, this list of conditions and the following disclaimer. 9.14 + * 9.15 + * 2. Redistributions in binary form must reproduce the above copyright 9.16 + * notice, this list of conditions and the following disclaimer in the 9.17 + * documentation and/or other materials provided with the distribution. 9.18 + * 9.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 9.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 9.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 9.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 9.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 9.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 9.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 9.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 9.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 9.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 9.29 + * POSSIBILITY OF SUCH DAMAGE. 9.30 + * 9.31 + */ 9.32 + 9.33 +#ifndef KNIGHT_H 9.34 +#define KNIGHT_H 9.35 + 9.36 +#include "../game.h" 9.37 + 9.38 +#ifdef __cplusplus 9.39 +extern "C" { 9.40 +#endif 9.41 + 9.42 +_Bool knight_chkrules(Board board, Move *move); 9.43 +_Bool knight_isblocked(Board board, Move *move); 9.44 +_Bool knight_getlocation(Board board, Move *move); 9.45 + 9.46 +#ifdef __cplusplus 9.47 +} 9.48 +#endif 9.49 + 9.50 +#endif /* KNIGHT_H */ 9.51 +
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/src/rules/pawn.c Sat Mar 22 17:23:07 2014 +0100 10.3 @@ -0,0 +1,61 @@ 10.4 +/* 10.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 10.6 + * 10.7 + * Copyright 2014 Mike Becker. All rights reserved. 10.8 + * 10.9 + * Redistribution and use in source and binary forms, with or without 10.10 + * modification, are permitted provided that the following conditions are met: 10.11 + * 10.12 + * 1. Redistributions of source code must retain the above copyright 10.13 + * notice, this list of conditions and the following disclaimer. 10.14 + * 10.15 + * 2. Redistributions in binary form must reproduce the above copyright 10.16 + * notice, this list of conditions and the following disclaimer in the 10.17 + * documentation and/or other materials provided with the distribution. 10.18 + * 10.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 10.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 10.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 10.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 10.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 10.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 10.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 10.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 10.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 10.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 10.29 + * POSSIBILITY OF SUCH DAMAGE. 10.30 + * 10.31 + */ 10.32 + 10.33 +#include "pawn.h" 10.34 + 10.35 +_Bool pawn_chkrules(Board board, Move *move) { 10.36 + // TODO: implement 10.37 + return TRUE; 10.38 +} 10.39 + 10.40 +_Bool pawn_isblocked(Board board, Move *move) { 10.41 + // TODO: implement 10.42 + return FALSE; 10.43 +} 10.44 + 10.45 +_Bool pawn_getlocation(Board board, Move *move) { 10.46 + int8_t d = ((move->piece & COLOR_MASK) == WHITE ? -1 : 1); 10.47 + 10.48 + move->fromfile = move->tofile; 10.49 + move->fromrow = move->torow + d; 10.50 + if (move->fromrow > 6) { 10.51 + return FALSE; 10.52 + } else { 10.53 + /* advanced first move */ 10.54 + if (move->fromrow == (d < 0 ? 2 : 5) && 10.55 + board[move->fromrow][move->fromfile] != move->piece) { 10.56 + 10.57 + move->fromrow += d; 10.58 + if (move->fromrow > 6) { 10.59 + return FALSE; 10.60 + } 10.61 + } 10.62 + } 10.63 + return TRUE; 10.64 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/src/rules/pawn.h Sat Mar 22 17:23:07 2014 +0100 11.3 @@ -0,0 +1,48 @@ 11.4 +/* 11.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 11.6 + * 11.7 + * Copyright 2014 Mike Becker. All rights reserved. 11.8 + * 11.9 + * Redistribution and use in source and binary forms, with or without 11.10 + * modification, are permitted provided that the following conditions are met: 11.11 + * 11.12 + * 1. Redistributions of source code must retain the above copyright 11.13 + * notice, this list of conditions and the following disclaimer. 11.14 + * 11.15 + * 2. Redistributions in binary form must reproduce the above copyright 11.16 + * notice, this list of conditions and the following disclaimer in the 11.17 + * documentation and/or other materials provided with the distribution. 11.18 + * 11.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 11.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 11.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 11.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 11.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 11.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 11.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 11.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 11.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 11.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 11.29 + * POSSIBILITY OF SUCH DAMAGE. 11.30 + * 11.31 + */ 11.32 + 11.33 +#ifndef PAWN_H 11.34 +#define PAWN_H 11.35 + 11.36 +#include "../game.h" 11.37 + 11.38 +#ifdef __cplusplus 11.39 +extern "C" { 11.40 +#endif 11.41 + 11.42 +_Bool pawn_chkrules(Board board, Move *move); 11.43 +_Bool pawn_isblocked(Board board, Move *move); 11.44 +_Bool pawn_getlocation(Board board, Move *move); 11.45 + 11.46 +#ifdef __cplusplus 11.47 +} 11.48 +#endif 11.49 + 11.50 +#endif /* PAWN_H */ 11.51 +
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/src/rules/queen.c Sat Mar 22 17:23:07 2014 +0100 12.3 @@ -0,0 +1,45 @@ 12.4 +/* 12.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 12.6 + * 12.7 + * Copyright 2014 Mike Becker. All rights reserved. 12.8 + * 12.9 + * Redistribution and use in source and binary forms, with or without 12.10 + * modification, are permitted provided that the following conditions are met: 12.11 + * 12.12 + * 1. Redistributions of source code must retain the above copyright 12.13 + * notice, this list of conditions and the following disclaimer. 12.14 + * 12.15 + * 2. Redistributions in binary form must reproduce the above copyright 12.16 + * notice, this list of conditions and the following disclaimer in the 12.17 + * documentation and/or other materials provided with the distribution. 12.18 + * 12.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 12.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 12.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 12.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 12.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 12.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 12.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 12.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 12.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 12.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 12.29 + * POSSIBILITY OF SUCH DAMAGE. 12.30 + * 12.31 + */ 12.32 + 12.33 +#include "queen.h" 12.34 + 12.35 +_Bool queen_chkrules(Board board, Move* move) { 12.36 + // TODO: implement 12.37 + return TRUE; 12.38 +} 12.39 + 12.40 +_Bool queen_isblocked(Board board, Move *move) { 12.41 + // TODO: implement 12.42 + return FALSE; 12.43 +} 12.44 + 12.45 +_Bool queen_getlocation(Board board, Move *move) { 12.46 + // TODO: implement 12.47 + return TRUE; 12.48 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/src/rules/queen.h Sat Mar 22 17:23:07 2014 +0100 13.3 @@ -0,0 +1,48 @@ 13.4 +/* 13.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 13.6 + * 13.7 + * Copyright 2014 Mike Becker. All rights reserved. 13.8 + * 13.9 + * Redistribution and use in source and binary forms, with or without 13.10 + * modification, are permitted provided that the following conditions are met: 13.11 + * 13.12 + * 1. Redistributions of source code must retain the above copyright 13.13 + * notice, this list of conditions and the following disclaimer. 13.14 + * 13.15 + * 2. Redistributions in binary form must reproduce the above copyright 13.16 + * notice, this list of conditions and the following disclaimer in the 13.17 + * documentation and/or other materials provided with the distribution. 13.18 + * 13.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 13.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 13.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 13.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 13.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 13.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 13.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 13.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 13.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 13.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 13.29 + * POSSIBILITY OF SUCH DAMAGE. 13.30 + * 13.31 + */ 13.32 + 13.33 +#ifndef QUEEN_H 13.34 +#define QUEEN_H 13.35 + 13.36 +#include "../game.h" 13.37 + 13.38 +#ifdef __cplusplus 13.39 +extern "C" { 13.40 +#endif 13.41 + 13.42 +_Bool queen_chkrules(Board board, Move *move); 13.43 +_Bool queen_isblocked(Board board, Move *move); 13.44 +_Bool queen_getlocation(Board board, Move *move); 13.45 + 13.46 +#ifdef __cplusplus 13.47 +} 13.48 +#endif 13.49 + 13.50 +#endif /* QUEEN_H */ 13.51 +
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/src/rules/rook.c Sat Mar 22 17:23:07 2014 +0100 14.3 @@ -0,0 +1,45 @@ 14.4 +/* 14.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 14.6 + * 14.7 + * Copyright 2014 Mike Becker. All rights reserved. 14.8 + * 14.9 + * Redistribution and use in source and binary forms, with or without 14.10 + * modification, are permitted provided that the following conditions are met: 14.11 + * 14.12 + * 1. Redistributions of source code must retain the above copyright 14.13 + * notice, this list of conditions and the following disclaimer. 14.14 + * 14.15 + * 2. Redistributions in binary form must reproduce the above copyright 14.16 + * notice, this list of conditions and the following disclaimer in the 14.17 + * documentation and/or other materials provided with the distribution. 14.18 + * 14.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 14.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 14.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 14.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 14.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 14.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 14.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 14.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 14.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 14.29 + * POSSIBILITY OF SUCH DAMAGE. 14.30 + * 14.31 + */ 14.32 + 14.33 +#include "rook.h" 14.34 + 14.35 +_Bool rook_chkrules(Board board, Move *move) { 14.36 + // TODO: implement 14.37 + return TRUE; 14.38 +} 14.39 + 14.40 +_Bool rook_isblocked(Board board, Move *move) { 14.41 + // TODO: implement 14.42 + return FALSE; 14.43 +} 14.44 + 14.45 +_Bool rook_getlocation(Board board, Move *move) { 14.46 + // TODO: implement 14.47 + return TRUE; 14.48 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/src/rules/rook.h Sat Mar 22 17:23:07 2014 +0100 15.3 @@ -0,0 +1,48 @@ 15.4 +/* 15.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 15.6 + * 15.7 + * Copyright 2014 Mike Becker. All rights reserved. 15.8 + * 15.9 + * Redistribution and use in source and binary forms, with or without 15.10 + * modification, are permitted provided that the following conditions are met: 15.11 + * 15.12 + * 1. Redistributions of source code must retain the above copyright 15.13 + * notice, this list of conditions and the following disclaimer. 15.14 + * 15.15 + * 2. Redistributions in binary form must reproduce the above copyright 15.16 + * notice, this list of conditions and the following disclaimer in the 15.17 + * documentation and/or other materials provided with the distribution. 15.18 + * 15.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 15.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 15.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 15.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 15.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 15.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 15.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 15.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 15.29 + * POSSIBILITY OF SUCH DAMAGE. 15.30 + * 15.31 + */ 15.32 + 15.33 +#ifndef ROOK_H 15.34 +#define ROOK_H 15.35 + 15.36 +#include "../game.h" 15.37 + 15.38 +#ifdef __cplusplus 15.39 +extern "C" { 15.40 +#endif 15.41 + 15.42 +_Bool rook_chkrules(Board board, Move *move); 15.43 +_Bool rook_isblocked(Board board, Move *move); 15.44 +_Bool rook_getlocation(Board board, Move *move); 15.45 + 15.46 +#ifdef __cplusplus 15.47 +} 15.48 +#endif 15.49 + 15.50 +#endif /* ROOK_H */ 15.51 +
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/src/rules/rules.h Sat Mar 22 17:23:07 2014 +0100 16.3 @@ -0,0 +1,41 @@ 16.4 +/* 16.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 16.6 + * 16.7 + * Copyright 2014 Mike Becker. All rights reserved. 16.8 + * 16.9 + * Redistribution and use in source and binary forms, with or without 16.10 + * modification, are permitted provided that the following conditions are met: 16.11 + * 16.12 + * 1. Redistributions of source code must retain the above copyright 16.13 + * notice, this list of conditions and the following disclaimer. 16.14 + * 16.15 + * 2. Redistributions in binary form must reproduce the above copyright 16.16 + * notice, this list of conditions and the following disclaimer in the 16.17 + * documentation and/or other materials provided with the distribution. 16.18 + * 16.19 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.21 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.22 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 16.23 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 16.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 16.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 16.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 16.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 16.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 16.29 + * POSSIBILITY OF SUCH DAMAGE. 16.30 + * 16.31 + */ 16.32 + 16.33 +#ifndef RULES_H 16.34 +#define RULES_H 16.35 + 16.36 +#include "pawn.h" 16.37 +#include "rook.h" 16.38 +#include "knight.h" 16.39 +#include "bishop.h" 16.40 +#include "queen.h" 16.41 +#include "king.h" 16.42 + 16.43 +#endif /* RULES_H */ 16.44 +