implemented queen

Tue, 01 Apr 2014 10:28:08 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 01 Apr 2014 10:28:08 +0200
changeset 24
4d030da07c88
parent 23
824c9522ce66
child 25
3ab0c2e1a4e2

implemented queen

src/chess/queen.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/chess/queen.c	Mon Mar 31 15:03:25 2014 +0200
     1.2 +++ b/src/chess/queen.c	Tue Apr 01 10:28:08 2014 +0200
     1.3 @@ -28,19 +28,43 @@
     1.4   */
     1.5  
     1.6  #include "rules.h"
     1.7 +#include "rook.h"
     1.8 +#include "bishop.h"
     1.9  #include "queen.h"
    1.10  
    1.11  _Bool queen_chkrules(Move* move) {
    1.12 -    // TODO: implement
    1.13 -    return 0;
    1.14 +    return bishop_chkrules(move) || rook_chkrules(move);
    1.15  }
    1.16  
    1.17  _Bool queen_isblocked(GameState *gamestate, Move *move) {
    1.18 -    // TODO: implement
    1.19 -    return 1;
    1.20 +    if (rook_chkrules(move)) {
    1.21 +        return rook_isblocked(gamestate, move);
    1.22 +    } else {
    1.23 +        return bishop_isblocked(gamestate, move);
    1.24 +    }
    1.25  }
    1.26  
    1.27  int queen_getlocation(GameState *gamestate, Move *move) {
    1.28 -    // TODO: implement
    1.29 -    return INVALID_MOVE_SYNTAX;
    1.30 +    
    1.31 +    Move moveasrook = *move;
    1.32 +    int rookaspect = rook_getlocation(gamestate, &moveasrook);
    1.33 +    
    1.34 +    Move moveasbishop = *move;
    1.35 +    int bishopaspect = bishop_getlocation(gamestate, &moveasbishop);
    1.36 +    
    1.37 +    if (rookaspect == VALID_MOVE_SYNTAX && bishopaspect == VALID_MOVE_SYNTAX) {
    1.38 +        return AMBIGUOUS_MOVE;
    1.39 +    }
    1.40 +    
    1.41 +    if (rookaspect == VALID_MOVE_SYNTAX) {
    1.42 +        *move = moveasrook;
    1.43 +        return VALID_MOVE_SYNTAX;
    1.44 +    }
    1.45 +    
    1.46 +    if (bishopaspect == VALID_MOVE_SYNTAX) {
    1.47 +        *move = moveasbishop;
    1.48 +        return VALID_MOVE_SYNTAX;
    1.49 +    }
    1.50 +    
    1.51 +    return INVALID_POSITION;
    1.52  }

mercurial