src/chess/rules.h

changeset 195
27d02ccb0cef
parent 194
619f07c95894
--- a/src/chess/rules.h	Tue Aug 25 18:59:18 2026 +0200
+++ b/src/chess/rules.h	Tue Aug 25 19:42:15 2026 +0200
@@ -201,17 +201,17 @@
 
 
 static inline void enpassant_threat_add(GameState *gamestate,
-        Rank rank, File file) {
+        File file, Rank rank) {
     gamestate->board[rank][file] |= ENPASSANT_THREAT;
 }
 
 static inline void enpassant_threat_remove(GameState *gamestate,
-        Rank rank, File file) {
+        File file, Rank rank) {
     gamestate->board[rank][file] &= ~ENPASSANT_THREAT;
 }
 
 static inline bool enpassant_threat_exists(const GameState *gamestate,
-        Rank rank, File file) {
+        File file, Rank rank) {
     return gamestate->board[rank][file] & ENPASSANT_THREAT;
 }
 
@@ -229,7 +229,7 @@
     return gamestate->moves[gamestate->movecount - 1].check;
 }
 
-static inline Color field_color(Rank r, File f) {
+static inline Color field_color(File f, Rank r) {
     return (r + f) % 2 == 0 ? BLACK : WHITE;
 }
 
@@ -289,35 +289,35 @@
  * Returns the piece at the specified position.
  *
  * @param gamestate the current game state
+ * @param file the file
  * @param rank the rank
- * @param file the file
  * @return the piece at the specified position
  */
-Piece piece_at(const GameState *gamestate, Rank rank, File file);
+Piece piece_at(const GameState *gamestate, File file, Rank rank);
 
 /**
  * Places a piece at the specified position in the current game state.
  *
  * @param gamestate the current game state
+ * @param file the file
  * @param rank the rank
- * @param file the file
  * @param piece the piece to place at the specified position
  */
-void piece_set(GameState *gamestate, Rank rank, File file, Piece piece);
+void piece_set(GameState *gamestate, File file, Rank rank, Piece piece);
 
 /**
  * Removes the piece at the specified position in the current game state.
  *
  * @param gamestate the current game state
+ * @param file the file
  * @param rank the rank
- * @param file the file
  */
-static inline void piece_remove(GameState *gamestate, Rank rank, File file) {
-    piece_set(gamestate, rank, file, 0);
+static inline void piece_remove(GameState *gamestate, File file, Rank rank) {
+    piece_set(gamestate, file, rank, 0);
 }
 
 typedef size_t(*moves_generator_func)(const GameState *gamestate,
-        Color c, Rank r, File f, Move *moves);
+        Color c, File f, Rank r, Move *moves);
 
 /**
  * Calculates all allowed moves for a specific piece.
@@ -325,13 +325,13 @@
  * Use the macros for the specific pieces instead.
  *
  * @param gamestate the current gamestate
+ * @param f the file of the piece
  * @param r the rank of the piece
- * @param f the file of the piece
  * @param moves target array for the list of moves
  * @return the number of moves stored in the @p moves array
  */
 size_t piece_moves_allowed(const GameState *gamestate,
-        Rank r, File f, Move *moves);
+        File f, Rank r, Move *moves);
 
 /**
  * Internal function used to filter out illegal moves.
@@ -340,14 +340,14 @@
  *
  * @param gamestate the current gamestate
  * @param c color of the piece
+ * @param f the file of the piece
  * @param r the rank of the piece
- * @param f the file of the piece
  * @param moves target array for the list of moves
  * @param func a function that unconditionally generates the moves
  * @return the number of moves stored in the @p moves array
  */
 size_t filter_moves_allowed(const GameState *gamestate,
-    Color c, Rank r, File f, Move *moves, moves_generator_func func);
+    Color c, File f, Rank r, Move *moves, moves_generator_func func);
 
 /**
  * Determines a list of theoretically possible moves to the specified field.
@@ -359,8 +359,8 @@
  * must be set, too.
  *
  * @param gamestate the current game state
+ * @param file file of the field to check
  * @param rank rank of the field to check
- * @param file file of the field to check
  * @param color the color of the piece that should move to the field
  * @param moves the array where to store the moves
  * (must be large enough, 16 is always enough)
@@ -368,7 +368,7 @@
  * @return true, if any piece of the specified color can move to the specified
  * field regardless of being pinned
  */
-bool get_candidates(const GameState *gamestate, Rank rank, File file,
+bool get_candidates(const GameState *gamestate, File file, Rank rank,
         Color color, Move* moves, size_t* movecount);
 
 /**
@@ -382,8 +382,8 @@
  * must be set, too.
  *
  * @param gamestate the current game state
+ * @param file file of the field to check
  * @param rank rank of the field to check
- * @param file file of the field to check
  * @param color the color of the piece that should move to the field
  * @param moves the array where to store the moves
  * (must be large enough, 16 is always enough)
@@ -391,7 +391,7 @@
  * @return true, if any piece of the specified color can move to the specified
  * field and is not pinned
  */
-bool get_real_candidates(const GameState *gamestate, Rank rank, File file,
+bool get_real_candidates(const GameState *gamestate, File file, Rank rank,
         Color color, Move* moves, size_t* movecount);
 
 /**
@@ -404,8 +404,8 @@
  * must be set, too.
  * 
  * @param gamestate the current game state
+ * @param file file of the field to check
  * @param rank rank of the field to check
- * @param file file of the field to check
  * @param color the color of the piece that should threaten the field
  * @param threats the array where to store the threats
  * (must be large enough, 16 is always enough)
@@ -413,7 +413,7 @@
  * @return true, if any piece of the specified color threatens the specified
  * field
  */
-bool get_threats(const GameState *gamestate, Rank rank, File file,
+bool get_threats(const GameState *gamestate, File file, Rank rank,
         Color color, Move* threats, size_t* threatcount);
 
 /**
@@ -424,8 +424,8 @@
  * must be set, too.
  * 
  * @param gamestate the current game state
+ * @param file file of the field to check
  * @param rank rank of the field to check
- * @param file file of the field to check
  * @param color the color of the piece that should threaten the field
  * @param threats the array where to store the threats
  * (must be large enough, 16 is always enough)
@@ -433,7 +433,7 @@
  * @return true, if any piece of the specified color threatens the specified
  * field and is not pinned
  */
-bool get_real_threats(const GameState *gamestate, Rank rank, File file,
+bool get_real_threats(const GameState *gamestate, File file, Rank rank,
         Color color, Move* threats, size_t* threatcount);
 
 /**
@@ -443,30 +443,30 @@
  * capture an opponent piece on this field, regardless of being pinned.
  * 
  * @param gamestate the current game state
+ * @param file file of the field to check
  * @param rank rank of the field to check
- * @param file file of the field to check
  * @param color the color of the piece that should cover the field
  * @return true, if any piece of the specified color threatens the specified
  * field
  */
-#define is_covered(gamestate, rank, file, color) \
-    get_threats(gamestate, rank, file, color, NULL, NULL)
+#define is_covered(gamestate, file, rank, color) \
+    get_threats(gamestate, file, rank, color, NULL, NULL)
 
 /**
  * Checks, if a specified field is attacked by a piece of a certain color.
- * 
+ *
  * I.e. the field is threatened by a piece AND this piece is not pinned and
  * therefore able to perform the move.
- * 
+ *
  * @param gamestate the current game state
+ * @param file file of the field to check
  * @param rank rank of the field to check
- * @param file file of the field to check
  * @param color the color of the piece that should cover the field
  * @return true, if any piece of the specified color threatens the specified
  * field and could capture an opponent piece
  */
-#define is_attacked(gamestate, rank, file, color) \
-    get_real_threats(gamestate, rank, file, color, NULL, NULL)
+#define is_attacked(gamestate, file, rank, color) \
+    get_real_threats(gamestate, file, rank, color, NULL, NULL)
 
 /**
  * Checks, if a specified field is protected by a piece of a certain color.
@@ -475,13 +475,14 @@
  * that field or move to that field (and is not pinned).
  * 
  * @param gamestate the current game state
+ * @param file file of the field to check
  * @param rank rank of the field to check
- * @param file file of the field to check
  * @param color the color of the piece that should cover the field
  * @return true, if any piece (excluding the king) of the specified color
  * can move to the specified field (including capturing moves)
  */
-bool is_protected(const GameState *gamestate, Rank rank, File file, Color color);
+bool is_protected(const GameState *gamestate,
+        File file, Rank rank, Color color);
 
 /**
  * Checks, if the specified move cannot be performed, because the piece is

mercurial