Wed, 26 Mar 2014 13:16:49 +0100
interface for retrieving locations when using short algebraic notation
inverted return values of not yet implemented functions to prevent bugs
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@7 | 40 | #define PIECE_MASK 0x0F |
universe@7 | 41 | #define COLOR_MASK 0xF0 |
universe@7 | 42 | |
universe@7 | 43 | #define WHITE 0x10 |
universe@7 | 44 | #define BLACK 0x20 |
universe@7 | 45 | |
universe@7 | 46 | #define PAWN 0x01 |
universe@7 | 47 | #define ROOK 0x02 |
universe@7 | 48 | #define KNIGHT 0x03 |
universe@7 | 49 | #define BISHOP 0x04 |
universe@7 | 50 | #define QUEEN 0x05 |
universe@7 | 51 | #define KING 0x06 |
universe@7 | 52 | |
universe@7 | 53 | #define WPAWN (WHITE|PAWN) |
universe@7 | 54 | #define WROOK (WHITE|ROOK) |
universe@7 | 55 | #define WKNIGHT (WHITE|KNIGHT) |
universe@7 | 56 | #define WBISHOP (WHITE|BISHOP) |
universe@7 | 57 | #define WQUEEN (WHITE|QUEEN) |
universe@7 | 58 | #define WKING (WHITE|KING) |
universe@7 | 59 | #define BPAWN (BLACK|PAWN) |
universe@7 | 60 | #define BROOK (BLACK|ROOK) |
universe@7 | 61 | #define BKNIGHT (BLACK|KNIGHT) |
universe@7 | 62 | #define BBISHOP (BLACK|BISHOP) |
universe@7 | 63 | #define BQUEEN (BLACK|QUEEN) |
universe@7 | 64 | #define BKING (BLACK|KING) |
universe@7 | 65 | |
universe@7 | 66 | typedef uint8_t Board[8][8]; |
universe@7 | 67 | |
universe@8 | 68 | typedef struct { |
universe@8 | 69 | uint8_t piece; |
universe@8 | 70 | uint8_t fromfile; |
universe@8 | 71 | uint8_t fromrow; |
universe@8 | 72 | uint8_t tofile; |
universe@8 | 73 | uint8_t torow; |
universe@8 | 74 | _Bool check; |
universe@11 | 75 | _Bool checkmate; |
universe@8 | 76 | _Bool capture; |
universe@8 | 77 | } Move; |
universe@8 | 78 | |
universe@12 | 79 | #define POS_UNSPECIFIED UINT8_MAX |
universe@12 | 80 | |
universe@8 | 81 | #define isfile(file) (file >= 'a' && file <= 'h') |
universe@8 | 82 | #define isrow(row) (row >= '1' && row <= '8') |
universe@8 | 83 | #define rowidx(row) (row-'1') |
universe@8 | 84 | #define fileidx(file) (file-'a') |
universe@8 | 85 | |
universe@6 | 86 | void game_start(Settings *settings, int opponent); |
universe@6 | 87 | |
universe@6 | 88 | #ifdef __cplusplus |
universe@6 | 89 | } |
universe@6 | 90 | #endif |
universe@6 | 91 | |
universe@6 | 92 | #endif /* GAME_H */ |
universe@6 | 93 |