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
--- a/src/chess/queen.c	Mon Mar 31 15:03:25 2014 +0200
+++ b/src/chess/queen.c	Tue Apr 01 10:28:08 2014 +0200
@@ -28,19 +28,43 @@
  */
 
 #include "rules.h"
+#include "rook.h"
+#include "bishop.h"
 #include "queen.h"
 
 _Bool queen_chkrules(Move* move) {
-    // TODO: implement
-    return 0;
+    return bishop_chkrules(move) || rook_chkrules(move);
 }
 
 _Bool queen_isblocked(GameState *gamestate, Move *move) {
-    // TODO: implement
-    return 1;
+    if (rook_chkrules(move)) {
+        return rook_isblocked(gamestate, move);
+    } else {
+        return bishop_isblocked(gamestate, move);
+    }
 }
 
 int queen_getlocation(GameState *gamestate, Move *move) {
-    // TODO: implement
-    return INVALID_MOVE_SYNTAX;
+    
+    Move moveasrook = *move;
+    int rookaspect = rook_getlocation(gamestate, &moveasrook);
+    
+    Move moveasbishop = *move;
+    int bishopaspect = bishop_getlocation(gamestate, &moveasbishop);
+    
+    if (rookaspect == VALID_MOVE_SYNTAX && bishopaspect == VALID_MOVE_SYNTAX) {
+        return AMBIGUOUS_MOVE;
+    }
+    
+    if (rookaspect == VALID_MOVE_SYNTAX) {
+        *move = moveasrook;
+        return VALID_MOVE_SYNTAX;
+    }
+    
+    if (bishopaspect == VALID_MOVE_SYNTAX) {
+        *move = moveasbishop;
+        return VALID_MOVE_SYNTAX;
+    }
+    
+    return INVALID_POSITION;
 }

mercurial