mobilityTable.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mobilityTable.cc
Go to the documentation of this file.
1 /* mobilityTable.cc
2 */
3 #include "osl/mobility/mobilityTable.h"
4 #include "osl/ptypeTable.h"
5 #include "osl/boardTable.h"
6
7 osl::mobility::MobilityTable::MobilityTable(osl::state::SimpleState const& state)
8 {
9 for(int num=32;num<=39;num++){
10 osl::Piece p=state.pieceOf(num);
11 if(!p.isOnBoard()) continue;
12 int moveMask=Ptype_Table.getMoveMask(p.ptype());
13 for(int i=0;i<8;i++){
14 Direction d=static_cast<Direction>(i);
15 if(p.owner()==WHITE) d=inverse(d);
16 d=shortToLong(d);
17 if((moveMask&dirToMask(d))==0) continue;
18 Offset o=Board_Table.getOffsetForBlack(static_cast<Direction>(i));
19 Square pos=p.square()+o;
20 for(;state.pieceAt(pos).isEmpty();pos+=o) ;
21 if(state.pieceAt(pos)==Piece::EDGE()) pos-=o;
22 this->set(static_cast<Direction>(i),num,pos);
23 }
24 }
25 }
26
27 std::ostream& osl::mobility::operator<<(std::ostream& os,osl::mobility::MobilityContent const& mc)
28 {
29 os << "[";
30 for(int i=0;i<7;i++) os << mc.get(static_cast<Direction>(i)) << ",";
31 return os << mc.get(static_cast<Direction>(7)) << "]";
32 }
33
34 std::ostream& osl::mobility::operator<<(std::ostream& os,osl::mobility::MobilityTable const& mt)
35 {
36 os << "MobilityTable(\n";
37 for(int num=32;num<=39;num++){
38 os << "num=" << num << ",[";
39 for(int i=0;i<8;i++){
40 Direction d=static_cast<Direction>(i);
41 os << " " << mt.get(d,num);
42 }
43 os << "]\n";
44 }
45 return os << ")" << std::endl;
46 }
47
48 bool osl::mobility::operator==(MobilityTable const& mt1, MobilityTable const& mt2)
49 {
50 for(int num=32;num<=39;num++){
51 for(int i=0;i<8;i++){
52 Direction d=static_cast<Direction>(i);
53 if(mt1.get(d,num)!=mt2.get(d,num) ) return false;
54 }
55 }
56 return true;
57 }
58
59 /* ------------------------------------------------------------------------- */
60 // ;;; Local Variables:
61 // ;;; mode:c++
62 // ;;; c-basic-offset:2
63 // ;;; End: