ptypeProgress.cc
Go to the documentation of this file.
#include "osl/progress/ptypeProgress.h"
#include "osl/bits/pieceTable.h"
#include "osl/oslConfig.h"
#include <iostream>
osl::progress::PtypeProgressTable osl::progress::Ptype_Progress_Table;
static osl::SetUpRegister _initializer([](){
osl::progress::Ptype_Progress_Table.init();
});
const osl::CArray<int,10> osl::progress::PtypeProgressTable::yVals =
{{
0,4,4,4,3,2,1,0,0,0
}};
namespace osl
{
namespace progress
{
template<Ptype T>
struct PtypeProgressTraits;
// 歩
template<>
struct PtypeProgressTraits<PAWN>{
static const int val=2;
};
template<>
struct PtypeProgressTraits<PPAWN>{
static const int val=2;
};
//
template<>
struct PtypeProgressTraits<LANCE>{
static const int val=5;
};
template<>
struct PtypeProgressTraits<PLANCE>{
static const int val=5;
};
//
template<>
struct PtypeProgressTraits<KNIGHT>{
static const int val=5;
};
template<>
struct PtypeProgressTraits<PKNIGHT>{
static const int val=5;
};
//
template<>
struct PtypeProgressTraits<SILVER>{
static const int val=7;
};
template<>
struct PtypeProgressTraits<PSILVER>{
static const int val=7;
};
//
template<>
struct PtypeProgressTraits<GOLD>{
static const int val=8;
};
//
template<>
struct PtypeProgressTraits<BISHOP>{
static const int val=7;
};
template<>
struct PtypeProgressTraits<PBISHOP>{
static const int val=7;
};
//
template<>
struct PtypeProgressTraits<ROOK>{
static const int val=10;
};
template<>
struct PtypeProgressTraits<PROOK>{
static const int val=10;
};
//
template<>
struct PtypeProgressTraits<KING>{
static const int val=15;
};
} // namespace progress
} // namespace osl
osl::progress::
PtypeProgress::PtypeProgress(SimpleState const& state)
{
int ret=0;
for (int num=0; num<Piece::SIZE; num++)
{
if(state.standMask(BLACK).test(num)){
ret+=Ptype_Progress_Table.progress(newPtypeO(BLACK,Piece_Table.getPtypeOf(num)),
Square::STAND());
}
else if(state.standMask(WHITE).test(num)){
ret+=Ptype_Progress_Table.progress(newPtypeO(WHITE,Piece_Table.getPtypeOf(num)),
Square::STAND());
}
else{
assert(state.isOnBoard(num));
const Piece p=state.pieceOf(num);
ret+=Ptype_Progress_Table.progress(p.ptypeO(),p.square());
}
}
val=ret;
}
void osl::progress::PtypeProgressTable::init()
{
ptype2Val[PAWN]=PtypeProgressTraits<PAWN>::val;
ptype2Val[PPAWN]=PtypeProgressTraits<PPAWN>::val;
ptype2Val[LANCE]=PtypeProgressTraits<LANCE>::val;
ptype2Val[PLANCE]=PtypeProgressTraits<PLANCE>::val;
ptype2Val[KNIGHT]=PtypeProgressTraits<KNIGHT>::val;
ptype2Val[PKNIGHT]=PtypeProgressTraits<PKNIGHT>::val;
ptype2Val[SILVER]=PtypeProgressTraits<SILVER>::val;
ptype2Val[PSILVER]=PtypeProgressTraits<PSILVER>::val;
ptype2Val[GOLD]=PtypeProgressTraits<GOLD>::val;
ptype2Val[KING]=PtypeProgressTraits<KING>::val;
ptype2Val[BISHOP]=PtypeProgressTraits<BISHOP>::val;
ptype2Val[PBISHOP]=PtypeProgressTraits<PBISHOP>::val;
ptype2Val[ROOK]=PtypeProgressTraits<ROOK>::val;
ptype2Val[PROOK]=PtypeProgressTraits<PROOK>::val;
for(int i=PTYPE_MIN;i<=PTYPE_MAX;i++){
Ptype ptype=static_cast<Ptype>(i);
pos2Val[newPtypeO(BLACK,ptype)-PTYPEO_MIN][Square::STAND().index()]=ptype2Val[i]*yVals[5];
pos2Val[newPtypeO(WHITE,ptype)-PTYPEO_MIN][Square::STAND().index()]=ptype2Val[i]*yVals[5];
for(int y=1;y<10;y++)
{
for(int x=9;x>0;x--)
{
pos2Val[newPtypeO(BLACK,ptype)-PTYPEO_MIN][Square(x,y).index()]
= ptype2Val[i]*yVals[y];
pos2Val[newPtypeO(WHITE,ptype)-PTYPEO_MIN][Square(x,10-y).index()]
= ptype2Val[i]*yVals[y];
}
}
}
}
osl::progress::PtypeProgressTable::~PtypeProgressTable() {
}
#ifndef MINIMAL
std::ostream& osl::progress::operator<<(std::ostream& os, PtypeProgress prog)
{
return os << "progress " << prog.progress();
}
#endif
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; coding:utf-8
// ;;; End:
osl::CArray
Definition container.h:20
osl::PieceMask::test
bool test(int num) const
Definition pieceMask.h:45
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptypeO
PtypeO ptypeO() const
Definition basic_type.h:824
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::SIZE
static const int SIZE
Definition basic_type.h:794
osl::SimpleState
Definition simpleState.h:35
osl::SimpleState::standMask
PieceMask & standMask(Player p)
Definition simpleState.h:124
osl::SimpleState::isOnBoard
bool isOnBoard(int num) const
Definition simpleState.h:176
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::Square
Definition basic_type.h:532
osl::Square::index
unsigned int index() const
Definition basic_type.h:572
osl::Square::STAND
static const Square STAND()
Definition basic_type.h:548
osl::progress::PtypeProgressTable
ゲームの進行度を駒が自陣からどの程度前に進んでいるかの和で表現
Definition ptypeProgress.h:15
osl::progress::PtypeProgressTable::~PtypeProgressTable
~PtypeProgressTable()
Definition ptypeProgress.cc:146
osl::progress::PtypeProgressTable::yVals
static const CArray< int, 10 > yVals
y 座標に対応した進行度の係数、最初は0 (使用しない)
Definition ptypeProgress.h:11
osl::progress::PtypeProgressTable::pos2Val
CArray2d< int, PTYPEO_SIZE, Square::SIZE > pos2Val
Definition ptypeProgress.h:18
osl::progress::PtypeProgressTable::ptype2Val
CArray< int, PTYPE_SIZE > ptype2Val
Definition ptypeProgress.h:17
osl::progress::PtypeProgressTable::init
void init()
Definition ptypeProgress.cc:113
osl::progress::PtypeProgress
Definition ptypeProgress.h:30
osl::progress::PtypeProgress::progress
int progress() const
Definition ptypeProgress.h:34
osl::progress::PtypeProgress::val
int val
Definition ptypeProgress.h:31
osl::progress::PtypeProgress::PtypeProgress
PtypeProgress(SimpleState const &state)
Definition ptypeProgress.cc:91
osl::progress
Definition progress.cc:754
osl::progress::operator<<
std::ostream & operator<<(std::ostream &os, LongEffect const &longEffect)
Definition effect5x3Table.cc:106
osl::progress::Ptype_Progress_Table
PtypeProgressTable Ptype_Progress_Table
Definition ptypeProgress.cc:6
osl
Definition additionalEffect.h:6
osl::Ptype
Ptype
駒の種類を4ビットでコード化する
Definition basic_type.h:84
osl::PTYPE_MAX
@ PTYPE_MAX
Definition basic_type.h:105
osl::ROOK
@ ROOK
Definition basic_type.h:100
osl::PPAWN
@ PPAWN
Definition basic_type.h:87
osl::BISHOP
@ BISHOP
Definition basic_type.h:99
osl::PROOK
@ PROOK
Definition basic_type.h:92
osl::PAWN
@ PAWN
Definition basic_type.h:95
osl::KING
@ KING
Definition basic_type.h:93
osl::KNIGHT
@ KNIGHT
Definition basic_type.h:97
osl::SILVER
@ SILVER
Definition basic_type.h:98
osl::PKNIGHT
@ PKNIGHT
Definition basic_type.h:89
osl::GOLD
@ GOLD
Definition basic_type.h:94
osl::PLANCE
@ PLANCE
Definition basic_type.h:88
osl::PBISHOP
@ PBISHOP
Definition basic_type.h:91
osl::LANCE
@ LANCE
Definition basic_type.h:96
osl::PTYPE_MIN
@ PTYPE_MIN
Definition basic_type.h:102
osl::PSILVER
@ PSILVER
Definition basic_type.h:90
osl::Piece_Table
const PieceTable Piece_Table
Definition tables.cc:94
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::BLACK
@ BLACK
Definition basic_type.h:9
osl::PTYPEO_MIN
@ PTYPEO_MIN
Definition basic_type.h:200
osl::newPtypeO
PtypeO newPtypeO(Player player, Ptype ptype)
Definition basic_type.h:211
oslConfig.h
pieceTable.h
_initializer
static osl::SetUpRegister _initializer([](){ osl::progress::Ptype_Progress_Table.init();})
ptypeProgress.h
osl::SetUpRegister
Definition oslConfig.h:128
osl::progress::PtypeProgressTraits< BISHOP >::val
static const int val
Definition ptypeProgress.cc:67
osl::progress::PtypeProgressTraits< GOLD >::val
static const int val
Definition ptypeProgress.cc:62
osl::progress::PtypeProgressTraits< KING >::val
static const int val
Definition ptypeProgress.cc:85
osl::progress::PtypeProgressTraits< KNIGHT >::val
static const int val
Definition ptypeProgress.cc:44
osl::progress::PtypeProgressTraits< LANCE >::val
static const int val
Definition ptypeProgress.cc:35
osl::progress::PtypeProgressTraits< PAWN >::val
static const int val
Definition ptypeProgress.cc:26
osl::progress::PtypeProgressTraits< PBISHOP >::val
static const int val
Definition ptypeProgress.cc:71
osl::progress::PtypeProgressTraits< PKNIGHT >::val
static const int val
Definition ptypeProgress.cc:48
osl::progress::PtypeProgressTraits< PLANCE >::val
static const int val
Definition ptypeProgress.cc:39
osl::progress::PtypeProgressTraits< PPAWN >::val
static const int val
Definition ptypeProgress.cc:30
osl::progress::PtypeProgressTraits< PROOK >::val
static const int val
Definition ptypeProgress.cc:80
osl::progress::PtypeProgressTraits< PSILVER >::val
static const int val
Definition ptypeProgress.cc:57
osl::progress::PtypeProgressTraits< ROOK >::val
static const int val
Definition ptypeProgress.cc:76
osl::progress::PtypeProgressTraits< SILVER >::val
static const int val
Definition ptypeProgress.cc:53
osl::progress::PtypeProgressTraits
ゲームの進行度を測る駒の種類別の係数
Definition ptypeProgress.cc:22