mobilityTable.cc
Go to the documentation of this file.
/* mobilityTable.cc
*/
#include "osl/mobility/mobilityTable.h"
#include "osl/bits/ptypeTable.h"
#include "osl/bits/boardTable.h"
#include <iostream>
osl::mobility::MobilityTable::MobilityTable(osl::SimpleState const& state)
{
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);
d=shortToLong(d);
if((moveMask&dirToMask(d))==0) continue;
Offset o=Board_Table.getOffsetForBlack(static_cast<Direction>(i));
Square pos=p.square()+o;
for(;state.pieceAt(pos).isEmpty();pos+=o) ;
if(state.pieceAt(pos)==Piece::EDGE()) pos-=o;
this->set(static_cast<Direction>(i),num,pos);
}
}
}
std::ostream& osl::mobility::operator<<(std::ostream& os,osl::mobility::MobilityContent const& mc)
{
os << "[";
for(int i=0;i<7;i++) os << mc.get(static_cast<Direction>(i)) << ",";
return os << mc.get(static_cast<Direction>(7)) << "]";
}
std::ostream& osl::mobility::operator<<(std::ostream& os,osl::mobility::MobilityTable const& mt)
{
os << "MobilityTable(\n";
for(int num=32;num<=39;num++){
os << "num=" << num << ",[";
for(int i=0;i<8;i++){
Direction d=static_cast<Direction>(i);
os << " " << mt.get(d,num);
}
os << "]\n";
}
return os << ")" << std::endl;
}
bool osl::mobility::operator==(MobilityTable const& mt1, MobilityTable const& mt2)
{
for(int num=32;num<=39;num++){
for(int i=0;i<8;i++){
Direction d=static_cast<Direction>(i);
if(mt1.get(d,num)!=mt2.get(d,num) ) return false;
}
}
return true;
}
/* ------------------------------------------------------------------------- */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End:
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::isOnBoard
bool isOnBoard() const
Definition basic_type.h:985
osl::Piece::EDGE
static const Piece EDGE()
Definition basic_type.h:798
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::mobility::MobilityContent
駒毎に指定の方向の利きを持つ最後のSquare.
Definition mobilityTable.h:30
osl::mobility::MobilityContent::get
const Square get(Direction d) const
Definition mobilityTable.h:39
osl::mobility::MobilityTable
駒番号からMobilityContentを得る
Definition mobilityTable.h:52
osl::mobility::MobilityTable::get
const Square get(Direction d, int num) const
Definition mobilityTable.h:65
osl::mobility::MobilityTable::set
void set(Direction d, int num, Square pos)
Definition mobilityTable.h:61
osl::mobility::MobilityTable::MobilityTable
MobilityTable()
Definition mobilityTable.h:59
mobilityTable.h
osl::mobility::operator==
bool operator==(const MobilityTable &, const MobilityTable &)
Definition mobilityTable.cc:49
osl::mobility::operator<<
std::ostream & operator<<(std::ostream &os, MobilityContent const &mc)
Definition mobilityTable.cc:28
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