All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
effect5x3Table.cc
Go to the documentation of this file.
1 /* effect5x3Table.cc
2  */
3 
5 #include "osl/centering5x3.h"
6 #include "osl/ptype.h"
7 #include "osl/ptypeTable.h"
8 #include "osl/boardTable.h"
9 
10 #include <iostream>
11 
12 namespace osl
13 {
14  namespace progress
15  {
16  namespace
17  {
24  int countShort(PtypeO ptypeO,int center_dx, int center_dy){
25  int ret=0;
26  for(int dy=std::max(-8,center_dy-1);
27  dy<=std::min(8,center_dy+1);dy++)
28  for(int dx=std::max(-8,center_dx-2);
29  dx<=std::min(8,center_dx+2);dx++){
30  EffectContent ec=Ptype_Table.getEffect(ptypeO,Offset32(dx,dy));
31  // unBlockableではなくて,ほんとのshortが欲しい
32  if(ec == EffectContent::DIRECT()){
33  ret+=8;
34  }
35  }
36  return ret;
37  }
44  LongEffect calcLong(Direction d,int center_dx, int center_dy){
45  LongEffect ret;
46  ret.minIndex=0;
47  ret.maxIndex=0;
48  int dy_min=std::max(-8,center_dy-1);
49  int dy_max=std::min(8,center_dy+1);
50  int dx_min=std::max(-8,center_dx-2);
51  int dx_max=std::min(8,center_dx+2);
52  int dx=Board_Table.getDxForBlack(d);
53  int dy=Board_Table.getDyForBlack(d);
54  assert(dx!=0 || dy!=0);
55  int i;
56 
57  for(i=1;i<9;i++){
58  if(dx_min<=dx*i && dx*i <=dx_max &&
59  dy_min<=dy*i && dy*i <=dy_max) break;
60  }
61  if(i==9) return ret;
62  ret.minIndex=i;
63  for(;i<9;i++){
64  if(!(dx_min<=dx*i && dx*i <=dx_max &&
65  dy_min<=dy*i && dy*i <=dy_max)) break;
66  }
67  ret.maxIndex=i-1;
68  ret.offset=Offset(dx,dy);
69  assert(!ret.offset.zero());
70  return ret;
71  }
78  LongEffect4 calcLong4(PtypeO ptypeO,int center_dx, int center_dy){
79  LongEffect4 ret;
80  int index=0;
81 
82  Player pl=getOwner(ptypeO);
83  for(int i=0;i<8;i++){
84  Direction d=static_cast<Direction>(i);
91  if((Ptype_Table.getMoveMask(getPtype(ptypeO))&
92  dirToMask(shortToLong(d)))!=0){
93  assert(index<4);
94  ret[index]=calcLong(longD,center_dx,center_dy);
95  if(!ret[index].offset.zero())index++;
96  }
97  }
98  return ret;
99  }
100  }
101 #ifndef MINIMAL
102  std::ostream& operator<<(std::ostream& os,LongEffect const& longEffect){
103  return os << "(" << longEffect.offset << "," << longEffect.minIndex
104  << "," << longEffect.maxIndex << ")";
105  }
106 #endif
107  }
108 }
109 
111 {
119  for(int i=PTYPE_PIECE_MIN;i<=PTYPE_MAX;i++){
120  Ptype ptype=static_cast<Ptype>(i);
121  if(unpromote(ptype)!=ptype)
122  onStand[ptype]=onStand[unpromote(ptype)];
123  }
124 }
125 
126 
128 {
129  Player pl=BLACK;
130  for(int i=0;i<2;i++,pl=alt(pl)){
131  for(int j=PTYPE_PIECE_MIN;j<=PTYPE_MAX;j++){
132  PtypeO ptypeO=newPtypeO(pl,static_cast<Ptype>(j));
133  for(int dy= -8;dy<=8;dy++)
134  for(int dx= -8;dx<=8;dx++){
135  Offset32 o32(dx,dy);
136  shortEffect[ptypeOIndex(ptypeO)][o32.index()]=
137  countShort(ptypeO,dx,dy);
138  }
139  }
140  }
141 }
143 {
144  Player pl=BLACK;
145  for(int i=0;i<2;i++,pl=alt(pl)){
146  for(int j=0;j<8;j++){
147  Direction d=static_cast<Direction>(j);
148  for(int dy= -8;dy<=8;dy++)
149  for(int dx= -8;dx<=8;dx++){
150  Offset32 o32(dx,dy);
151  blockEffect[j][o32.index()]=
152  calcLong(d,dx,dy);
153  }
154  }
155  }
156 }
158 {
159  Player pl=BLACK;
160  for(int i=0;i<2;i++,pl=alt(pl)){
161  for(int j=PTYPE_PIECE_MIN;j<=PTYPE_MAX;j++){
162  PtypeO ptypeO=newPtypeO(pl,static_cast<Ptype>(j));
163  for(int dy= -8;dy<=8;dy++)
164  for(int dx= -8;dx<=8;dx++){
165  Offset32 o32(dx,dy);
166  longEffect[ptypeOIndex(ptypeO)][o32.index()]=
167  calcLong4(ptypeO,dx,dy);
168  }
169  }
170  }
171 }
172 
174 {
175  // 黒の攻める際のテーブルを作成
176  // 玉は白
177  for(int x=1;x<=9;x++)
178  for(int y=1;y<=9;y++){
179  const Square king(x,y);
181  for(int dx=0;dx<5;dx++){
182  for(int dy=0;dy<3;dy++){
183  const Square p(center.x()+dx-2,center.y()+dy-1);
184  int val=16-std::abs(p.x()-king.x());
185  attackEffect[BLACK][king.index()][dx*3+dy]=val;
186  }
187  }
188  }
189  for(int x=1;x<=9;x++)
190  for(int y=1;y<=9;y++){
191  const Square king(x,y);
192  const Square r_king=king.rotate180();
193  for(int dx=0;dx<5;dx++){
194  for(int dy=0;dy<3;dy++){
195  int r_dx=4-dx,r_dy=2-dy;
196  attackEffect[WHITE][king.index()][dx*3+dy]=
197  attackEffect[BLACK][r_king.index()][r_dx*3+r_dy];
198  }
199  }
200  }
201 }
203 {
204  // 白が守る際のテーブルを作成
205  // 玉は白
206  for(int x=1;x<=9;x++)
207  for(int y=1;y<=9;y++){
208  const Square king(x,y);
210  for(int dx=0;dx<5;dx++){
211  for(int dy=0;dy<3;dy++){
212  const Square p(center.x()+dx-2,center.y()+dy-1);
213  int val=16-std::abs(p.x()-king.x());
214  defenseEffect[WHITE][king.index()][dx*3+dy]=val;
215  }
216  }
217  }
218  for(int x=1;x<=9;x++)
219  for(int y=1;y<=9;y++){
220  const Square king(x,y);
221  const Square r_king=king.rotate180();
222  for(int dx=0;dx<5;dx++){
223  for(int dy=0;dy<3;dy++){
224  int r_dx=4-dx,r_dy=2-dy;
225  defenseEffect[BLACK][king.index()][dx*3+dy]=
226  defenseEffect[WHITE][r_king.index()][r_dx*3+r_dy];
227  }
228  }
229  }
230 }
231 
233 {
234  setupOnStand();
235  setupShortEffect();
236  setupBlockEffect();
237  setupLongEffect();
238  setupAttackEffect();
239  setupDefenseEffect();
240 }
241 
242 /* ------------------------------------------------------------------------- */
243 // ;;; Local Variables:
244 // ;;; mode:c++
245 // ;;; c-basic-offset:2
246 // ;;; End: