Warnings: correctly use #ifdef for declarations.
[gnushogi.git] / gnushogi / eval.c
index 391cdb8..97b748e 100644 (file)
@@ -4,6 +4,7 @@
  * ----------------------------------------------------------------------
  * Copyright (c) 1993, 1994, 1995 Matthias Mutz
  * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
+ * Copyright (c) 2008, 2013, 2014 Yann Dirson and the Free Software Foundation
  *
  * GNU SHOGI is based on GNU CHESS
  *
@@ -32,9 +33,6 @@
 #include "gnushogi.h"
 #include "pattern.h"
 
-extern void
-ShowStage(void);
-
 /* Hash table for preventing multiple scoring of the same position */
 
 int EADD = 0;       /* number of writes to the cache table */
@@ -341,6 +339,7 @@ on_csquare(short side, short piece, short square)
 }
 
 
+#ifndef MINISHOGI
 inline static short
 on_column(short side, short piece, short c)
 {
@@ -387,13 +386,12 @@ on_right_side(short side, short piece)
 
     return false;
 }
+#endif
 
 
 short pscore[2];  /* piece score for each side */
 
 
-
-
 /*
  * Fill array attack[side][] with info about attacks to a square.  Bits
  * 16-31 are set if the piece (king .. pawn) attacks the square.  Bits 0-15
@@ -828,7 +826,10 @@ BRLscan(short sq, short *mob)
 #endif
 
     short s, mobx;
-    short u, xu, pin, ptyp, csq = column(sq);
+    short u, xu, pin, ptyp;
+#ifndef MINISHOGI
+    short csq = column(sq);
+#endif
     short piece, upiece, xupiece, rvalue, ds;
     small_short *Kd = Kdist[c2];
 
@@ -1262,13 +1263,12 @@ trapped(short sq)
 
 
 static int
-AttackedPieceValue(short sq, short side)
+AttackedPieceValue(short sq)
 {
-    short s, ds;
+    short s;
 
     s = 0;
 
-       ds = -fv1[HUNGP] * 2;
     hung[c1]++;
     shung[sq]++;
 
@@ -1337,7 +1337,9 @@ PawnValue(short sq, short side)
 {
     short s = 0;
     short ds;
+#ifndef MINISHOGI
     short ccol = ccolumn(c1, sq);
+#endif
 
     PromotionZoneDistanceValue(sq, 3);
 
@@ -1354,6 +1356,12 @@ PawnValue(short sq, short side)
 
     if (in_opening_stage)
     {
+#ifndef MINISHOGI
+/* FIXME: [HGM] The 3rd-rank Pawn section is meaningless in mini-Shogi,
+ * (which does not have opposing Pawns), and can do out-of-bound access,
+ * as the promotion zone is only 1 rank, so Pawns can be closer than 3 ranks
+ * to the board edge.
+ */
         if (crow(c1, sq) == 2) /* pawn on 3d rank */
         {
             if (board[(c1 == black) ?
@@ -1383,6 +1391,9 @@ PawnValue(short sq, short side)
             }
         }
 
+/* FIXME: calculations below are wrong for minishogi, all done for 9x9
+ * board - and anyway we don't know the stage really :)
+ */
         if ((GameType[c1] == STATIC_ROOK) && (sq == csquare(c1, 43)))
         {
             if ((atk2[csquare(c1, 52)] & CNT_MASK) < 2)
@@ -1404,6 +1415,7 @@ PawnValue(short sq, short side)
                 s += (ds = -2 * fv1[ATTACKED]);
             }
         }
+#endif
     }
 
     return s;
@@ -1416,7 +1428,7 @@ PawnValue(short sq, short side)
  */
 
 static inline int
-LanceValue(short sq, short side)
+LanceValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1446,7 +1458,7 @@ LanceValue(short sq, short side)
  */
 
 static inline int
-KnightValue(short sq, short side)
+KnightValue(short sq)
 {
     short s = 0, ad;
     short ds, checked_trapped = false;
@@ -1483,7 +1495,7 @@ KnightValue(short sq, short side)
  */
 
 static inline int
-SilverValue(short sq, short side)
+SilverValue(short sq)
 {
     short s= 0, ds, ad;
 
@@ -1497,6 +1509,10 @@ SilverValue(short sq, short side)
 
     if (in_opening_stage)
     {
+#ifndef MINISHOGI
+/* FIXME: calculations below are wrong for minishogi, all done for 9x9
+ * board - and anyway we don't know the stage really :)
+ */
         if (GameType[c1] == STATIC_ROOK)
         {
             if (csquare(c1, sq) == 12)
@@ -1510,6 +1526,7 @@ SilverValue(short sq, short side)
                 }
             }
         }
+#endif
     }
     else
     {
@@ -1526,7 +1543,7 @@ SilverValue(short sq, short side)
  */
 
 static inline int
-GoldValue(short sq, short side)
+GoldValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1540,6 +1557,10 @@ GoldValue(short sq, short side)
 
     if (in_opening_stage)
     {
+#ifndef MINISHOGI
+/* FIXME: calculations below are wrong for minishogi, all done for 9x9
+ * board - and anyway we don't know the stage really :)
+ */
         if ((GameType[c1] == STATIC_ROOK) && (GameType[c2] != STATIC_ROOK))
         {
             if (Mvboard[csquare(c1, 3)])
@@ -1547,6 +1568,7 @@ GoldValue(short sq, short side)
                 s += (ds = -2 * fv1[OPENWRONG]);
             }
         }
+#endif
     }
     else
     {
@@ -1563,12 +1585,16 @@ GoldValue(short sq, short side)
  */
 
 static inline int
-BishopValue(short sq, short side)
+BishopValue(short sq)
 {
     short s = 0, ds, ad;
 
     if (in_opening_stage)
     {
+#ifndef MINISHOGI
+/* FIXME: calculations below are wrong for minishogi, all done for 9x9
+ * board - and anyway we don't know the stage really :)
+ */
         if (GameType[c1] == RANGING_ROOK)
         {
             /* Bishops diagonal should not be open */
@@ -1590,6 +1616,7 @@ BishopValue(short sq, short side)
                 s += (ds = -fv1[OPENWRONG]);
             }
         }
+#endif
     }
     else
     {
@@ -1614,6 +1641,10 @@ RookValue(short sq, short side)
 
     if (in_opening_stage)
     {
+#ifndef MINISHOGI
+/* FIXME: calculations below are wrong for minishogi, all done for 9x9
+ * board - and anyway we don't know the stage really :)
+ */
         short WRONG = fv1[OPENWRONG], OPOK = WRONG / 3;
 
         if (GameType[c1] == STATIC_ROOK)
@@ -1672,6 +1703,7 @@ RookValue(short sq, short side)
                 }
             }
         }
+#endif
     }
     else
     {
@@ -1688,7 +1720,7 @@ RookValue(short sq, short side)
  */
 
 static inline int
-PPawnValue(short sq, short side)
+PPawnValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1705,7 +1737,7 @@ PPawnValue(short sq, short side)
  */
 
 static inline int
-PLanceValue(short sq, short side)
+PLanceValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1721,7 +1753,7 @@ PLanceValue(short sq, short side)
  */
 
 static inline int
-PKnightValue(short sq, short side)
+PKnightValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1738,7 +1770,7 @@ PKnightValue(short sq, short side)
  */
 
 static inline int
-PSilverValue(short sq, short side)
+PSilverValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1754,7 +1786,7 @@ PSilverValue(short sq, short side)
  */
 
 static inline int
-PBishopValue(short sq, short side)
+PBishopValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1770,7 +1802,7 @@ PBishopValue(short sq, short side)
  */
 
 static inline int
-PRookValue(short sq, short side)
+PRookValue(short sq)
 {
     short s = 0, ds, ad;
 
@@ -1788,13 +1820,17 @@ PRookValue(short sq, short side)
  */
 
 static inline int
-KingValue(short sq, short side)
+KingValue(short sq)
 {
     short s = 0, ds;
 
     if (fv1[KSFTY] != 0)
         s += KingScan(sq);
 
+#ifndef MINISHOGI
+/* FIXME: calculations below are wrong for minishogi, all done for 9x9
+ * board - and anyway we don't know the stage really :)
+ */
     if (in_opening_stage)
     {
         if ((GameType[c1] != UNKNOWN) && (ccolumn(c1, sq) == 4))
@@ -1810,6 +1846,7 @@ KingValue(short sq, short side)
             s += (ds = -fv1[OPENWRONG] / 2);
         }
     }
+#endif
 
     /* CHECKME: is this correct? */
     if ((ds = fv1[HOPN]))
@@ -1869,7 +1906,7 @@ PieceValue(short sq, short side)
         if (a1 == 0)
         {
             /* undefended piece */
-            s += AttackedPieceValue(sq, side);
+            s += AttackedPieceValue(sq);
         }
         else
         {
@@ -1880,7 +1917,7 @@ PieceValue(short sq, short side)
             if (attack_value < piece_value)
             {
                 /* attacked by a weaker piece */
-                s += AttackedPieceValue(sq, side) / 2;
+                s += AttackedPieceValue(sq) / 2;
             }
             else if (abs(attack_value - piece_value) < 10)
             {
@@ -1947,24 +1984,24 @@ PieceValue(short sq, short side)
 
 #ifndef MINISHOGI
     case lance:
-        s += LanceValue(sq, side);
+        s += LanceValue(sq);
         break;
 
     case knight:
-        s += KnightValue(sq, side);
+        s += KnightValue(sq);
         break;
 #endif
 
     case silver:
-        s += SilverValue(sq, side);
+        s += SilverValue(sq);
         break;
 
     case gold:
-        s += GoldValue(sq, side);
+        s += GoldValue(sq);
         break;
 
     case bishop:
-        s += BishopValue(sq, side);
+        s += BishopValue(sq);
         break;
 
     case rook:
@@ -1972,33 +2009,33 @@ PieceValue(short sq, short side)
         break;
 
     case king:
-        s += KingValue(sq, side);
+        s += KingValue(sq);
         break;
 
     case ppawn:
-        s += PPawnValue(sq, side);
+        s += PPawnValue(sq);
         break;
 
 #ifndef MINISHOGI
     case plance:
-        s += PLanceValue(sq, side);
+        s += PLanceValue(sq);
         break;
 
     case pknight:
-        s += PKnightValue(sq, side);
+        s += PKnightValue(sq);
         break;
 #endif
 
     case psilver:
-        s += PSilverValue(sq, side);
+        s += PSilverValue(sq);
         break;
 
     case pbishop:
-        s += PBishopValue(sq, side);
+        s += PBishopValue(sq);
         break;
 
     case prook:
-        s += PRookValue(sq, side);
+        s += PRookValue(sq);
         break;
     }
 
@@ -2103,7 +2140,7 @@ UpdatePatterns(short side, short GameCnt)
     }
 
     if (flag.post)
-        ShowPatternCount(side, n);
+        dsp->ShowPatternCount(side, n);
 
     if (os != END_OF_SEQUENCES)
         update_advance_bonus(side, os);
@@ -2495,8 +2532,8 @@ DetermineGameType(short side_to_move)
     }
     else
     {
-        ShowPatternCount(black, -1);
-        ShowPatternCount(white, -1);
+        dsp->ShowPatternCount(black, -1);
+        dsp->ShowPatternCount(white, -1);
     }
 }
 
@@ -2544,6 +2581,7 @@ ExaminePosition(short side)
 
 
 
+/* FIXME: calculations below are wrong for minishogi, all done for 9x9 */
 void
 DetermineStage(short side)
 {
@@ -2672,7 +2710,7 @@ DetermineStage(short side)
         stage = 0;
 
     if (flag.post)
-        ShowStage();
+        dsp->ShowStage();
 
     /* Determine stage dependant weights */
 
@@ -2708,6 +2746,7 @@ DetermineStage(short side)
 void
 UpdateWeights(short stage)
 {
+  /* FIXME: this was emptied between 1.1p02 ans 1.2p03, do we keep it ? */
 }