effectedNumTable.cc
Go to the documentation of this file.
/* effectedNumTable.cc
*/
#include "osl/bits/effectedNumTable.h"
#include "osl/bits/ptypeTable.h"
#include "osl/bits/boardTable.h"
#include <iostream>
void
osl::effect::EffectedNumTable::clear()
{
for(int i=0;i<40;i++) contents[i].clear();
}
osl::effect::EffectedNumTable::EffectedNumTable(SimpleState const& state)
{
clear();
for(int num=32;num<=39;num++){
osl::Piece p=state.pieceOf(num);
if(!p.isOnBoard()) continue;
int moveMask=Ptype_Table.getMoveMask(p.ptype());
for(int i=0;i<8;i++){
Direction d=static_cast<Direction>(i);
if(p.owner()==WHITE) d=inverse(d);
Direction longD=shortToLong(d);
if((moveMask&dirToMask(longD))==0) continue;
Offset o=Board_Table.getOffsetForBlack(static_cast<Direction>(i));
Square pos=p.square()+o;
Piece p1;
for(;(p1=state.pieceAt(pos)).isEmpty();pos+=o) ;
if(pos.isEdge()) continue;
int num1=p1.number();
contents[num1][static_cast<Direction>(i)]=num1;
}
}
}
std::ostream& osl::effect::operator<<(std::ostream& os,osl::EffectedNumTable const& et)
{
os << "[\n";
for(int num=0;num<=39;num++){
os << " [";
for(int d=0;d<7;d++) os << et[num][static_cast<Direction>(d)] << ",";
os << et[num][static_cast<Direction>(7)] << "],\n";
}
return os << "]\n";
}
bool osl::effect::operator==(EffectedNumTable const& e1, EffectedNumTable const& e2)
{
for(int i=0;i<8;i++){
for(int num=0;num<=39;num++){
if(e1[num][static_cast<Direction>(i)]!=e2[num][static_cast<Direction>(i)]) return false;
}
}
return true;
}
boardTable.h
osl::Offset
座標の差分
Definition basic_type.h:430
osl::Piece
駒.
Definition basic_type.h:788
osl::Piece::ptype
Ptype ptype() const
Definition basic_type.h:821
osl::Piece::square
const Square square() const
Definition basic_type.h:832
osl::Piece::owner
Player owner() const
Definition basic_type.h:963
osl::Piece::number
int number() const
Definition basic_type.h:828
osl::Piece::isOnBoard
bool isOnBoard() const
Definition basic_type.h:985
osl::SimpleState
Definition simpleState.h:35
osl::SimpleState::pieceOf
const Piece pieceOf(int num) const
Definition simpleState.h:76
osl::SimpleState::pieceAt
const Piece pieceAt(Square sq) const
Definition simpleState.h:167
osl::Square
Definition basic_type.h:532
osl::Square::isEdge
bool isEdge() const
onBoardから8近傍のオフセットを足した点がedgeかどうかの判定 そこそこ速くなった．
Definition basic_type.h:591
osl::effect::EffectedNumTable
Definition effectedNumTable.h:44
osl::effect::EffectedNumTable::EffectedNumTable
EffectedNumTable()
Definition effectedNumTable.h:51
osl::effect::EffectedNumTable::clear
void clear()
Definition effectedNumTable.cc:9
osl::effect::EffectedNumTable::contents
CArray< EffectedNum, 40 > contents
Definition effectedNumTable.h:49
effectedNumTable.h
osl::effect::operator<<
std::ostream & operator<<(std::ostream &, const EffectedNumTable &)
Definition effectedNumTable.cc:37
osl::effect::operator==
bool operator==(const EffectedNumTable &, const EffectedNumTable &)
Definition effectedNumTable.cc:47
osl::Ptype_Table
const PtypeTable Ptype_Table
Definition tables.cc:97
osl::dirToMask
constexpr int dirToMask(Direction dir)
Definition basic_type.h:393
osl::Board_Table
const BoardTable Board_Table
Definition tables.cc:95
osl::Direction
Direction
Definition basic_type.h:310
osl::WHITE
@ WHITE
Definition basic_type.h:10
osl::shortToLong
constexpr Direction shortToLong(Direction d)
引数に longDirを与えてはいけない
Definition basic_type.h:388
osl::inverse
constexpr Direction inverse(Direction d)
Definition basic_type.h:358
ptypeTable.h