00001
00002
00003 #ifndef PROGRESS_PTYPE_PROGRESS_H
00004 #define PROGRESS_PTYPE_PROGRESS_H
00005
00006 #include "osl/ptype.h"
00007 #include "osl/state/simpleState.h"
00008 #include "osl/misc/carray.h"
00009 #include <iosfwd>
00010 namespace osl
00011 {
00012 namespace progress
00013 {
00016 class PtypeProgressTable
00017 {
00018 private:
00019 CArray<int,PTYPE_SIZE> ptype2Val;
00020 CArray2d<int,PTYPEO_SIZE,Position::SIZE> pos2Val;
00021 static const CArray<int,10> yVals;
00022 public:
00023 PtypeProgressTable();
00024 ~PtypeProgressTable();
00025 int progress(PtypeO ptypeo,Position pos) const{
00026 return pos2Val[ptypeo-PTYPEO_MIN][pos.index()];
00027 }
00028 };
00029 extern const PtypeProgressTable Ptype_Progress_Table;
00030
00031 class PtypeProgress
00032 {
00033 int val;
00034 public:
00035 explicit PtypeProgress(SimpleState const& state);
00036 int progress() const{ return val; }
00037 private:
00038 void addVal(int d) { val+=d; }
00039 public:
00040 void changeTurn() {}
00041 static int getProgress(const SimpleState& state)
00042 {
00043 const PtypeProgress progress(state);
00044 return progress.progress();
00045 }
00046 void update(const SimpleState& new_state, Move last_move)
00047 {
00048 const PtypeO ptypeo = last_move.ptypeO();
00049 if (last_move.isDrop()) {
00050 val += Ptype_Progress_Table.progress(ptypeo,last_move.to())
00051 - Ptype_Progress_Table.progress(ptypeo,Position::STAND());
00052 return;
00053 }
00054 val += Ptype_Progress_Table.progress(ptypeo,last_move.to())
00055 - Ptype_Progress_Table.progress(ptypeo,last_move.from());
00056 Ptype ptype = last_move.capturePtype();
00057 if (ptype != PTYPE_EMPTY)
00058 val += Ptype_Progress_Table.progress(last_move.capturePtypeO(), Position::STAND())
00059 - Ptype_Progress_Table.progress(last_move.capturePtypeO(), last_move.to());
00060 }
00061
00062 bool operator==(const PtypeProgress rhs) const { return val == rhs.val; }
00063 };
00064 std::ostream& operator<<(std::ostream& os, PtypeProgress prog);
00065 }
00066 using progress::PtypeProgress;
00067 }
00068
00069
00070 #endif
00071
00072
00073
00074