Wed, 26 Mar 2014 14:53:15 +0100
fixed crucial bug where both players could move at the same time + added pawn rules (TODO: en passant)
universe@6 | 1 | /* |
universe@6 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
universe@6 | 3 | * |
universe@6 | 4 | * Copyright 2014 Mike Becker. All rights reserved. |
universe@6 | 5 | * |
universe@6 | 6 | * Redistribution and use in source and binary forms, with or without |
universe@6 | 7 | * modification, are permitted provided that the following conditions are met: |
universe@6 | 8 | * |
universe@6 | 9 | * 1. Redistributions of source code must retain the above copyright |
universe@6 | 10 | * notice, this list of conditions and the following disclaimer. |
universe@6 | 11 | * |
universe@6 | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
universe@6 | 13 | * notice, this list of conditions and the following disclaimer in the |
universe@6 | 14 | * documentation and/or other materials provided with the distribution. |
universe@6 | 15 | * |
universe@6 | 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
universe@6 | 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
universe@6 | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
universe@6 | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
universe@6 | 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
universe@6 | 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
universe@6 | 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
universe@6 | 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
universe@6 | 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
universe@6 | 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
universe@6 | 26 | * POSSIBILITY OF SUCH DAMAGE. |
universe@6 | 27 | * |
universe@6 | 28 | */ |
universe@6 | 29 | |
universe@6 | 30 | #ifndef GAME_H |
universe@6 | 31 | #define GAME_H |
universe@6 | 32 | |
universe@6 | 33 | #include "terminal-chess.h" |
universe@7 | 34 | #include <stdint.h> |
universe@6 | 35 | |
universe@6 | 36 | #ifdef __cplusplus |
universe@6 | 37 | extern "C" { |
universe@6 | 38 | #endif |
universe@6 | 39 | |
universe@14 | 40 | #define PIECE_MASK 0x0F |
universe@14 | 41 | #define COLOR_MASK 0x30 |
universe@14 | 42 | #define ENPASSANT_THREAT 0x40 |
universe@7 | 43 | |
universe@7 | 44 | #define WHITE 0x10 |
universe@7 | 45 | #define BLACK 0x20 |
universe@7 | 46 | |
universe@7 | 47 | #define PAWN 0x01 |
universe@7 | 48 | #define ROOK 0x02 |
universe@7 | 49 | #define KNIGHT 0x03 |
universe@7 | 50 | #define BISHOP 0x04 |
universe@7 | 51 | #define QUEEN 0x05 |
universe@7 | 52 | #define KING 0x06 |
universe@7 | 53 | |
universe@7 | 54 | #define WPAWN (WHITE|PAWN) |
universe@7 | 55 | #define WROOK (WHITE|ROOK) |
universe@7 | 56 | #define WKNIGHT (WHITE|KNIGHT) |
universe@7 | 57 | #define WBISHOP (WHITE|BISHOP) |
universe@7 | 58 | #define WQUEEN (WHITE|QUEEN) |
universe@7 | 59 | #define WKING (WHITE|KING) |
universe@7 | 60 | #define BPAWN (BLACK|PAWN) |
universe@7 | 61 | #define BROOK (BLACK|ROOK) |
universe@7 | 62 | #define BKNIGHT (BLACK|KNIGHT) |
universe@7 | 63 | #define BBISHOP (BLACK|BISHOP) |
universe@7 | 64 | #define BQUEEN (BLACK|QUEEN) |
universe@7 | 65 | #define BKING (BLACK|KING) |
universe@7 | 66 | |
universe@7 | 67 | typedef uint8_t Board[8][8]; |
universe@7 | 68 | |
universe@8 | 69 | typedef struct { |
universe@8 | 70 | uint8_t piece; |
universe@8 | 71 | uint8_t fromfile; |
universe@8 | 72 | uint8_t fromrow; |
universe@8 | 73 | uint8_t tofile; |
universe@8 | 74 | uint8_t torow; |
universe@8 | 75 | _Bool check; |
universe@11 | 76 | _Bool checkmate; |
universe@8 | 77 | _Bool capture; |
universe@8 | 78 | } Move; |
universe@8 | 79 | |
universe@12 | 80 | #define POS_UNSPECIFIED UINT8_MAX |
universe@14 | 81 | #define mdst(b,m) b[m->torow][m->tofile] |
universe@14 | 82 | #define msrc(b,m) b[m->fromrow][m->fromfile] |
universe@12 | 83 | |
universe@13 | 84 | #define isidx(idx) ((uint8_t)idx < 8) |
universe@13 | 85 | |
universe@8 | 86 | #define isfile(file) (file >= 'a' && file <= 'h') |
universe@8 | 87 | #define isrow(row) (row >= '1' && row <= '8') |
universe@13 | 88 | |
universe@8 | 89 | #define rowidx(row) (row-'1') |
universe@8 | 90 | #define fileidx(file) (file-'a') |
universe@8 | 91 | |
universe@13 | 92 | #define chkidx(move) (isidx(move->fromfile) && isidx(move->fromrow) && \ |
universe@13 | 93 | isidx(move->tofile) && isidx(move->torow)) |
universe@13 | 94 | |
universe@13 | 95 | /* secure versions - use, if index is not checked with isidx() */ |
universe@13 | 96 | #define fileidx_s(c) (isfile(c)?fileidx(c):POS_UNSPECIFIED) |
universe@13 | 97 | #define rowidx_s(c) (isrow(c)?rowidx(c):POS_UNSPECIFIED) |
universe@13 | 98 | |
universe@6 | 99 | void game_start(Settings *settings, int opponent); |
universe@6 | 100 | |
universe@6 | 101 | #ifdef __cplusplus |
universe@6 | 102 | } |
universe@6 | 103 | #endif |
universe@6 | 104 | |
universe@6 | 105 | #endif /* GAME_H */ |
universe@6 | 106 |