00001
00002
00003 #ifndef OSL_EVAL_ML_PIECEPAIRKING_H
00004 #define OSL_EVAL_ML_PIECEPAIRKING_H
00005
00006 #include "osl/state/numEffectState.h"
00007 #include <boost/cstdint.hpp>
00008 namespace osl
00009 {
00010 namespace eval
00011 {
00012 namespace ml
00013 {
00014 class Weights;
00015 class PiecePairKing
00016 {
00017 public:
00018 enum
00019 {
00020 ONE_DIM = 1488375,
00021 DIM = ONE_DIM
00022 };
00023 static void setUp(const Weights &weights);
00024 static CArray<int,2> eval(const NumEffectState&);
00025 template <Player P>
00026 static void evalWithUpdateBang(const NumEffectState& state, Move moved, CArray<int,2>& last_value);
00027
00028 template <Player King>
00029 static int evalOne(const NumEffectState&);
00030 private:
00031 template <Player King>
00032 static int add(const NumEffectState& state, Position to, Ptype ptype);
00033 template <Player King>
00034 static int sub(const NumEffectState& state, Position from, Ptype ptype);
00035 template <Player King>
00036 static int addSub(const NumEffectState& state, Position to, Ptype ptype, Position from);
00037 static int composeIndex(int king, int i0, int i1)
00038 {
00039 return king + i0*45*7 + i1;
00040 }
00041 static int indexWhite(Position p)
00042 {
00043 return p.x()-1 + (p.y()-1)*9;
00044 }
00045 static int indexKing(Player owner, Position king, bool& flipx)
00046 {
00047 if (owner == BLACK)
00048 king = king.rotate180();
00049 assert(king.y() <= 3);
00050 if (king.x() > 5)
00051 {
00052 king = king.flipHorizontal();
00053 flipx = true;
00054 }
00055 else
00056 flipx = false;
00057 return (king.x()-1 + (king.y()-1)*5)*45*7*45*7;
00058 }
00059 template <bool FlipX>
00060 static int indexPiece(Player owner, Position position, Ptype ptype)
00061 {
00062 assert(! isPromoted(ptype));
00063 if (owner == BLACK)
00064 position = position.rotate180();
00065 if (FlipX)
00066 position = position.flipHorizontal();
00067 assert(position.y() <= 5);
00068 return indexWhite(position)*7 + ptype-PTYPE_BASIC_MIN-1;
00069 }
00070 static osl::CArray<int16_t, ONE_DIM> table;
00071 };
00072 }
00073 }
00074 }
00075
00076
00077 #endif
00078
00079
00080
00081