This file is indexed.

/usr/include/osl/checkmate/fixedDepthSearcher.tcc is in libosl-dev 0.6.0-3.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
/* fixedDepthSearcher.tcc
 */
#ifndef OSL_CHECKMATE_FIXED_DEPTH_SERCHER_TCC
#define OSL_CHECKMATE_FIXED_DEPTH_SERCHER_TCC
#include "osl/checkmate/fixedDepthSearcher.h"
#include "osl/checkmate/immediateCheckmate.h"
#include "osl/checkmate/proofPieces.h"
#include "osl/checkmate/proofNumberTable.h"
#include "osl/checkmate/checkMoveVector.h"
#include "osl/state/numEffectState.h"
#include "osl/container/moveVector.h"
#include "osl/move_action/store.h"
#include "osl/move_action/count.h"
#include "osl/move_generator/addEffectWithEffect.h"
#include "osl/move_generator/escape_.h"
#include "osl/move_classifier/check_.h"
#include "osl/effect_util/effectUtil.h"
#include "osl/neighboring8.h"
#include "osl/stat/ratio.h"
#include <boost/foreach.hpp>

namespace osl
{
  namespace checkmate
  {
    template<Player P, bool SetPieces>
    struct FixedAttackHelper{
      FixedDepthSearcher &searcher;
      Move move;
      int depth;
      ProofDisproof& pdp;
      PieceStand& pieces;
      FixedAttackHelper(FixedDepthSearcher &s,int d,ProofDisproof& p,
			PieceStand& pi)
	: searcher(s), depth(d), pdp(p), pieces(pi)
      {
      }
      void operator()(Square)
      {
	assert(move.isNormal());
	pdp=searcher.defense<P,SetPieces>(move,depth-1,pieces);
      }
    };
   /**
    * Pは動かす側ではなく攻撃側
    */
    template<Player P, bool SetPieces, bool MayUnsafe=false>
    struct FixedDefenseHelper{
      FixedDepthSearcher &searcher;
      int depth;
      ProofDisproof& pdp;
      PieceStand& pieces;
      Move best_move;
      FixedDefenseHelper(FixedDepthSearcher &s,int d,ProofDisproof& p,
			 PieceStand& pi) 
	: searcher(s), depth(d), pdp(p), pieces(pi)
      {
      }
      void operator()(Square)
      {
	if (MayUnsafe)
	  pdp=searcher.attackMayUnsafe<P,SetPieces,false>(depth-1, best_move, pieces);
	else
	  pdp=searcher.attack<P,SetPieces,false>(depth-1, best_move, pieces);
      }
    };
  }
}

template <osl::Player P, bool SetPieces, bool HasGuide>
const osl::checkmate::ProofDisproof 
osl::checkmate::FixedDepthSearcher::
attackMayUnsafe(int depth, Move& best_move, PieceStand& proof_pieces)
{
  assert(state->turn() == P);
  const Square target_king
    = state->template kingSquare<PlayerTraits<P>::opponent>();
  if (state->hasEffectAt<P>(target_king))
    return ProofDisproof::NoEscape();
  return attack<P,SetPieces,HasGuide>(depth, best_move, proof_pieces);
}

template <osl::Player P, bool SetPieces, bool HasGuide>
const osl::checkmate::ProofDisproof 
osl::checkmate::FixedDepthSearcher::
attack(int depth, Move& best_move, PieceStand& proof_pieces)
{
  assert(state->turn() == P);
  assert ((! HasGuide)
	  || (state->isAlmostValidMove(best_move)
	      && move_classifier::
	      Check<P>::isMember(*state, best_move.ptype(), best_move.from(), 
				 best_move.to())));
  addCount();
  const Square target_king
    = state->template kingSquare<PlayerTraits<P>::opponent>();
  assert(! state->hasEffectAt<P>(target_king));
  const King8Info info(state->Iking8Info(alt(P)));
  if ((! state->inCheck())
      && ImmediateCheckmate::hasCheckmateMove<P>(*state, info, target_king,
						 best_move))
  {
    if (SetPieces)
    {
      proof_pieces = PieceStand();
      if (best_move.isDrop())
	proof_pieces.add(best_move.ptype());
    }
    return ProofDisproof::Checkmate();
  }
  if (depth <= 0) 
  {
    const King8Info info_modified 
      = Edge_Table.resetEdgeFromLiberty(alt(P), target_king, info);
    return Proof_Number_Table.attackEstimation(*state, P, info_modified, target_king);
  }

  ProofDisproof pdp;
  typedef FixedAttackHelper<P,SetPieces> helper_t;
  helper_t helper(*this,depth,pdp,proof_pieces);
  int minProof = ProofDisproof::PROOF_MAX;
  int sumDisproof=0;
  if (HasGuide)
  {
    helper.move=best_move;
    state->makeUnmakeMove(Player2Type<P>(),best_move,helper);
    if (pdp.isCheckmateSuccess())
    {
      if (SetPieces)
	proof_pieces = ProofPieces::attack(proof_pieces, best_move, stand(P));
      return ProofDisproof::Checkmate();
    }
    minProof = pdp.proof();
    sumDisproof += pdp.disproof();
  }
  
  const Square targetKing
    = state->template kingSquare<PlayerTraits<P>::opponent>();
  CheckMoveVector moves;
  bool has_pawn_checkmate=false;
  {
    move_action::Store store(moves);    
    move_generator::AddEffectWithEffect<move_action::Store>::template generate<P,true>
      (*state,targetKing,store,has_pawn_checkmate);
  }
  if (moves.size()==0){
    if(has_pawn_checkmate)
      return ProofDisproof::PawnCheckmate();
    else
      return ProofDisproof::NoCheckmate();
  }
  if(has_pawn_checkmate)
    minProof=std::min(minProof,(int)ProofDisproof::PAWN_CHECK_MATE_PROOF);
  BOOST_FOREACH(Move move, moves) {
    if (HasGuide && move == best_move)
      continue;
    helper.move=move;
    state->makeUnmakeMove(Player2Type<P>(), move,helper);
    int proof=pdp.proof();
    if (proof<minProof){
      if (proof==0){
	best_move=move;
	if (SetPieces)
	{
	  proof_pieces = ProofPieces::attack(proof_pieces, best_move, stand(P));
	}
	return ProofDisproof::Checkmate();
      }
      minProof=proof;
    }
    sumDisproof+=pdp.disproof();
  }
  // depth >= 3 では PawnCheckmateの際にunpromoteを試す必要あり
  return ProofDisproof(minProof,sumDisproof);
}

template <osl::Player P, bool SetPieces>
inline
const osl::checkmate::ProofDisproof 
osl::checkmate::FixedDepthSearcher::
defenseEstimation(Move last_move, PieceStand& proof_pieces,
		  Piece attacker_piece, Square target_position) const
{
  assert(state->turn() == alt(P));
  const Player Opponent = PlayerTraits<P>::opponent;
  int count=King8Info(state->Iking8Info(Opponent)).libertyCount();
  // multiple checkなので,pawn dropではない
  if (attacker_piece.isEmpty())
  {
    if (count>0){
      return ProofDisproof(count,1);
    }
    return ProofDisproof::NoEscape();
  }
  const Square attack_from=attacker_piece.square();
  count += state->countEffect(alt(P), attack_from);
  if (Neighboring8::isNeighboring8(attack_from, target_position))
    --count;
  const EffectContent effect
    = Ptype_Table.getEffect(attacker_piece.ptypeO(), 
			    attack_from, target_position);
  if (! effect.hasUnblockableEffect())
  {
    // this is better approximation than naive enumeration of blocking moves,
    // for counting of disproof number in df-pn,
    ++count;
  }

  if (count==0){
    if (last_move.isValid() && last_move.isDrop() && last_move.ptype()==PAWN)
      return ProofDisproof::PawnCheckmate();
    if (SetPieces)
    {
      proof_pieces = ProofPieces::leaf(*state, P, stand(P));
    }
    return ProofDisproof::NoEscape();
  }
  return ProofDisproof(count, 1);
}

template <osl::Player Defense>
void osl::checkmate::FixedDepthSearcher::
generateBlockingWhenLiberty0(Piece defense_king, Square attack_from,
			     CheckMoveVector& moves) const
{
  assert(state->kingPiece(Defense) == defense_king);
  using namespace move_generator;
  using namespace move_action;
  CheckMoveVector all_moves;
  {
    Store store(all_moves);
    Escape<Store>::
      generateBlockingKing<Defense,false>(*state, defense_king, attack_from,store);
  }

  BOOST_FOREACH(Move move, all_moves)
  {
    if (move.isDrop())
    {
      if (! state->hasEffectAt<Defense>(move.to()))
	continue;
    }
    else
    {
      // move
      if (! Neighboring8::isNeighboring8(move.from(), defense_king.square()))
      {
	if (! state->hasMultipleEffectAt(Defense, move.to()))
	  continue;
      }
    }
    moves.push_back(move);
  }
}

template <osl::Player Defense> inline
int osl::checkmate::FixedDepthSearcher::
blockEstimation(Square /*attack_from*/, Square /*defense_king*/) const
{
  // 利きのあるマスを数えようと思ったら効果がなかった
  return 1;
}

template <osl::Player P, bool SetPieces>
const osl::checkmate::ProofDisproof 
osl::checkmate::FixedDepthSearcher::
defense(Move last_move, int depth, PieceStand& proof_pieces)
{
  assert(state->turn() == alt(P));
  addCount();
  const Player Defense = PlayerTraits<P>::opponent;
  const Square attackerKing
    = state->template kingSquare<P>();
  /**
   * 直前の攻め方の手が自殺手
   */
  if (attackerKing.isOnBoard() && state->hasEffectAt<Defense>(attackerKing))
    return ProofDisproof::NoCheckmate();
  const Piece target_king
    = state->template kingPiece<Defense>();
  const Square target_position = target_king.square();
  assert(state->hasEffectAt<P>(target_position));
  Piece attacker_piece;
  state->template findCheckPiece<Defense>(attacker_piece);
  if (depth <= 0)
  {
    return defenseEstimation<P, SetPieces>
      (last_move, proof_pieces, attacker_piece, target_position);
  }

  assert(depth > 0);
  CheckMoveVector moves;
  bool blockable_check = false;
  int nonblock_moves;
  {
    using namespace move_generator;
    using namespace move_action;
    if (attacker_piece.isEmpty()) {
      move_action::Store store(moves);
      Escape<Store>::template
	generateEscape<Defense,KING>(*state,target_king,store);
      nonblock_moves = moves.size();
    }
    else {
      const Square attack_from=attacker_piece.square();
      {
	move_action::Store store(moves);
	Escape<Store>::
	  generateCaptureKing<Defense>(*state, target_king, attack_from, store);
      }
      const int num_captures = moves.size();
      {
	move_action::Store store(moves);
	Escape<Store>::template
	  generateEscape<Defense,KING>(*state, target_king, store);
      }
      nonblock_moves = moves.size();
      blockable_check =
	! effect_util::UnblockableCheck::isMember(alt(P), *state);
      if ((depth <= 1) && num_captures && (nonblock_moves > 2))
      {
	if (nonblock_moves > 3)
	{
	  const int block_estimate = blockable_check 
	    ? blockEstimation<Defense>(attack_from, target_position) 
	    : 0;
	  return ProofDisproof(nonblock_moves + block_estimate, 1);
	}
      } 
      if (moves.empty())
	generateBlockingWhenLiberty0<Defense>(target_king, attack_from, moves);
    }
  }
  const size_t initial_moves = moves.size();
  if (moves.empty() && !blockable_check) {
    if (last_move.isValid() && last_move.isDrop() && last_move.ptype()==PAWN)
      return ProofDisproof::PawnCheckmate();
    if (SetPieces)
    {
      proof_pieces = ProofPieces::leaf(*state, P, stand(P));
    }
    return ProofDisproof::NoEscape();
  }
  const bool cut_candidate = (depth <= 1)
    && (nonblock_moves - (state->hasPieceOnStand<GOLD>(P)
			  || state->hasPieceOnStand<SILVER>(P)) > 4);
  if (cut_candidate)
    return ProofDisproof(nonblock_moves, 1);

  typedef FixedDefenseHelper<P,SetPieces> helper_t;
  if (SetPieces)
    proof_pieces = PieceStand();
  PieceStand child_proof;
  ProofDisproof pdp;
  helper_t helper(*this, depth, pdp, child_proof);
  int minDisproof = ProofDisproof::DISPROOF_MAX;
  int sumProof = 0;
  size_t i=0, no_promote_moves=0;
start_examine:
  for (;i<moves.size();i++){
    state->makeUnmakeMove(Player2Type<PlayerTraits<P>::opponent>(),moves[i],helper);
    const int disproof=pdp.disproof();
    if (disproof<minDisproof){
      if (disproof==0)
      {
	return pdp;		// maybe PawnCheckmate
      }
      minDisproof=disproof;
    }
    sumProof+=pdp.proof();
    if (sumProof == 0)
    {
      if (SetPieces)
	proof_pieces = proof_pieces.max(child_proof);
    }
    else
    {
      if (i+1 < moves.size())
      {
	minDisproof = 1;
	if ((int)i < nonblock_moves)
	  sumProof += nonblock_moves - (i+1);
	if (blockable_check)
	  ++sumProof;
      }
      return ProofDisproof(sumProof,minDisproof);
    }
  }
  if (sumProof == 0)
  {
    if (blockable_check && moves.size() == initial_moves)
    {
      using namespace move_generator;
      using namespace move_action;
      const Square attack_from=attacker_piece.square();
      {
	move_action::Store store(moves);
	Escape<Store>::
	  generateBlockingKing<Defense,false>(*state, target_king, attack_from,store);
      }
      if ((int)moves.size() > nonblock_moves)
	goto start_examine;
      if (moves.empty()) {
	assert(! (last_move.isValid() && last_move.isDrop() && last_move.ptype()==PAWN));
	if (SetPieces)
	  proof_pieces = ProofPieces::leaf(*state, P, stand(P));
	return ProofDisproof::NoEscape();
      }
    }
    if (no_promote_moves == 0) 
    {
      no_promote_moves = moves.size();
      for (size_t i=0; i<no_promote_moves; ++i) 
	if (moves[i].hasIgnoredUnpromote<Defense>())
	  moves.push_back(moves[i].unpromote());
      if (moves.size() > no_promote_moves)
	goto start_examine;
    }
    if (SetPieces && blockable_check)
      ProofPiecesUtil::addMonopolizedPieces(*state, P, stand(P), proof_pieces);
  }
  // depth >= 2 では unprmote も試す必要あり
  return ProofDisproof(sumProof,minDisproof);
}

template <osl::Player P>
const osl::checkmate::ProofDisproof 
osl::checkmate::FixedDepthSearcher::
hasEscapeByMove(Move next_move, int depth, Move& check_move,
		PieceStand& proof_pieces)
{
  typedef FixedDefenseHelper<P,true,true> helper_t;
  proof_pieces = PieceStand();
  ProofDisproof pdp;
  helper_t helper(*this, depth+1, pdp, proof_pieces);
  state->makeUnmakeMove(Player2Type<PlayerTraits<P>::opponent>(),next_move,helper);
  check_move = helper.best_move;
  return pdp;
}

template <osl::Player P>
const osl::checkmate::ProofDisproof 
osl::checkmate::FixedDepthSearcher::
hasEscapeByMove(Move next_move, int depth)
{
  typedef FixedDefenseHelper<P,false,true> helper_t;
  PieceStand proof_pieces;
  ProofDisproof pdp;
  helper_t helper(*this, depth+1, pdp, proof_pieces);
  state->makeUnmakeMove(Player2Type<PlayerTraits<P>::opponent>(),next_move,helper);
  return pdp;
}

template <osl::Player P>
const osl::checkmate::ProofDisproof 
osl::checkmate::FixedDepthSearcher::
hasCheckmateWithGuide(int depth, Move& guide, PieceStand& proof_pieces)
{
  assert(guide.isNormal());
  if (! guide.isDrop())
  {
    const Piece p=state->pieceOnBoard(guide.to());
    if (!p.isPtype<KING>())
      guide=guide.newCapture(p);
  }
  if (state->template isAlmostValidMove<false>(guide)
      && move_classifier::Check<P>
      ::isMember(*state, guide.ptype(), guide.from(), guide.to()))
    return attack<P,true,true>(depth, guide, proof_pieces);
  return attack<P,true,false>(depth, guide, proof_pieces);
}

#endif /* OSL_CHECKMATE_FIXED_DEPTH_SERCHER_TCC */
// ;;; Local Variables:
// ;;; mode:c++
// ;;; c-basic-offset:2
// ;;; End: