File: boardBitMask.cc

package info (click to toggle)
libosl 0.6.0-3.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 148,792 kB
  • ctags: 151,985
  • sloc: cpp: 131,133; ansic: 7,228; ruby: 1,290; makefile: 569; perl: 309; sh: 35
file content (75 lines) | stat: -rw-r--r-- 1,978 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "osl/effect/boardBitMask.h"
#include "osl/ptype.h"
#include "osl/ptypeTable.h"
#include <iostream>

namespace osl
{
namespace effect
{

  std::ostream& operator<<(std::ostream& os,BoardBitMask const& boardBitMask){
    os << "[";
    for(int i=15;i>=0;i--){
      unsigned char uc=boardBitMask.bMask[i];
      for(int j=7;j>=0;j--){
	if((uc&(1<<j))!=0) os << "1";
	else os<<"0";
      }
      os<<" ";
    }
    return os << "]";
  }
  

  void BoardBitMaskTable::initMaskOfSquare(){
    for(int i=0;i<Square::SIZE;i++){
      maskOfSquare[i].clearAll();
    }
    for(int y=1;y<=9;y++)
      for(int x=1;x<=9;x++){
	Square pos(x,y);
	maskOfSquare[pos.index()].setBit(BoardBitMask::positionToOffset(pos));
      }
  }

  static void setBetweenMask(BoardBitMask& mask,Square from,Square to,
			     Ptype ptype){
    const EffectContent effect=Ptype_Table.getEffect(newPtypeO(BLACK,ptype),Offset32(to,from));
    if(!effect.hasBlockableEffect()) return;
    const Offset offset=effect.offset();
    mask.clearAll();
    for(Square pos=from+offset;pos!=to;pos+=offset){
      mask.setBit(pos);
    }
  }
  void BoardBitMaskTable::initBetweenMask(){
    for(int j=0;j<Square::SIZE;j++){
      for(int i=0;i<Square::SIZE;i++){
	rookBetweenMask[i][j].setAll();
	lanceBetweenMask[i][j].setAll();
	bishopBetweenMask[i][j].setAll();
      }
    }
    for(int y1=1;y1<=9;y1++)
      for(int x1=1;x1<=9;x1++){
	Square from(x1,y1);
	for(int y2=1;y2<=9;y2++)
	  for(int x2=1;x2<=9;x2++){
	    Square to(x2,y2);
	    /**
	     * 利きがあったら対応するビットを立てる
	     */
	    setBetweenMask(lanceBetweenMask[from.index()][to.index()],from,to,LANCE);
	    setBetweenMask(bishopBetweenMask[from.index()][to.index()],from,to,BISHOP);
	    setBetweenMask(rookBetweenMask[from.index()][to.index()],from,to,ROOK);
	  }
      }
  }

  BoardBitMaskTable::BoardBitMaskTable(){
    initMaskOfSquare();
    initBetweenMask();
  }
} // namespace effect
} // namespace osl