]> git.sesse.net Git - stockfish/blob - src/position.h
7e5aa8660c0e150b4a0d8934220a1aa3535d5902
[stockfish] / src / position.h
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
5   Glaurung is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9   
10   Glaurung is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14   
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20 #if !defined(POSITION_H_INCLUDED)
21 #define POSITION_H_INCLUDED
22
23 // Disable a silly and noisy warning from MSVC compiler
24 #if defined(_MSC_VER)
25
26 // Forcing value to bool 'true' or 'false' (performance warning)
27 #pragma warning(disable: 4800) \r
28 \r
29 #endif
30
31 ////
32 //// Includes
33 ////
34
35 #include "bitboard.h"
36 #include "color.h"
37 #include "direction.h"
38 #include "move.h"
39 #include "piece.h"
40 #include "phase.h"
41 #include "square.h"
42 #include "value.h"
43
44
45 ////
46 //// Constants
47 ////
48
49 /// FEN string for the initial position:
50 const std::string StartPosition = 
51   "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
52
53 /// Maximum number of plies per game (220 should be enough, because the
54 /// maximum search depth is 100, and during position setup we reset the
55 /// move counter for every non-reversible move):
56 const int MaxGameLength = 220;
57
58
59 ////
60 //// Types
61 ////
62
63 /// Castle rights, encoded as bit fields:
64
65 enum CastleRights {
66   NO_CASTLES = 0, 
67   WHITE_OO = 1,
68   BLACK_OO = 2, 
69   WHITE_OOO = 4,
70   BLACK_OOO = 8,
71   ALL_CASTLES = 15
72 };
73
74
75 /// The UndoInfo struct stores information we need to restore a Position
76 /// object to its previous state when we retract a move.  Whenever a move
77 /// is made on the board (by calling Position::do_move), an UndoInfo object
78 /// must be passed as a parameter.  When the move is unmade (by calling
79 /// Position::undo_move), the same UndoInfo object must be passed again.
80
81 struct UndoInfo {
82   int castleRights;
83   Square epSquare;
84   Bitboard checkersBB;
85   Key key, pawnKey, materialKey;
86   int rule50;
87   Move lastMove;
88   PieceType capture;
89   Value mgValue, egValue;
90 };
91
92
93 /// The position data structure.  A position consists of the following data:
94 ///    
95 ///    * For each piece type, a bitboard representing the squares occupied
96 ///      by pieces of that type.
97 ///    * For each color, a bitboard representing the squares occupiecd by
98 ///      pieces of that color.
99 ///    * A bitboard of all occupied squares.
100 ///    * A bitboard of all checking pieces.
101 ///    * A 64-entry array of pieces, indexed by the squares of the board.
102 ///    * The current side to move.
103 ///    * Information about the castling rights for both sides.
104 ///    * The initial files of the kings and both pairs of rooks.  This is
105 ///      used to implement the Chess960 castling rules.
106 ///    * The en passant square (which is SQ_NONE if no en passant capture is
107 ///      possible).
108 ///    * The squares of the kings for both sides.
109 ///    * The last move played.
110 ///    * Hash keys for the position itself, the current pawn structure, and
111 ///      the current material situation.
112 ///    * Hash keys for all previous positions in the game (for detecting
113 ///      repetition draws.
114 ///    * A counter for detecting 50 move rule draws.
115
116 class Position {
117
118   friend class MaterialInfo;
119
120 public:
121   // Constructors
122   Position() {};
123   Position(const Position &pos);
124   Position(const std::string &fen);
125
126   // Text input/output
127   void from_fen(const std::string &fen);
128   const std::string to_fen() const;
129   void print() const;
130
131   // Copying
132   void copy(const Position &pos);
133   void flipped_copy(const Position &pos);
134
135   // The piece on a given square
136   Piece piece_on(Square s) const;
137   PieceType type_of_piece_on(Square s) const;
138   Color color_of_piece_on(Square s) const;
139   bool square_is_empty(Square s) const;
140   bool square_is_occupied(Square s) const;
141   Value midgame_value_of_piece_on(Square s) const;
142   Value endgame_value_of_piece_on(Square s) const;
143
144   // Side to move
145   Color side_to_move() const;
146
147   // Bitboard representation of the position
148   Bitboard empty_squares() const;
149   Bitboard occupied_squares() const;
150   Bitboard pieces_of_color(Color c) const;
151   Bitboard pieces_of_type(PieceType pt) const;
152   Bitboard pieces_of_color_and_type(Color c, PieceType pt) const;
153   Bitboard pawns() const;
154   Bitboard knights() const;
155   Bitboard bishops() const;
156   Bitboard rooks() const;
157   Bitboard queens() const;
158   Bitboard kings() const;
159   Bitboard rooks_and_queens() const;
160   Bitboard bishops_and_queens() const;
161   Bitboard sliders() const;
162   Bitboard pawns(Color c) const;
163   Bitboard knights(Color c) const;
164   Bitboard bishops(Color c) const;
165   Bitboard rooks(Color c) const;
166   Bitboard queens(Color c) const;
167   Bitboard kings(Color c) const;
168   Bitboard rooks_and_queens(Color c) const;
169   Bitboard bishops_and_queens(Color c) const;
170   Bitboard sliders_of_color(Color c) const;
171
172   // Number of pieces of each color and type
173   int piece_count(Color c, PieceType pt) const;
174   int pawn_count(Color c) const;
175   int knight_count(Color c) const;
176   int bishop_count(Color c) const;
177   int rook_count(Color c) const;
178   int queen_count(Color c) const;
179
180   // The en passant square:
181   Square ep_square() const;
182
183   // Current king position for each color
184   Square king_square(Color c) const;
185
186   // Castling rights.
187   bool can_castle_kingside(Color c) const;
188   bool can_castle_queenside(Color c) const;
189   bool can_castle(Color c) const;
190   Square initial_kr_square(Color c) const;
191   Square initial_qr_square(Color c) const;
192
193   // Attack bitboards
194   Bitboard sliding_attacks(Square s, Direction d) const;
195   Bitboard ray_attacks(Square s, SignedDirection d) const;
196   Bitboard pawn_attacks(Color c, Square s) const;
197   Bitboard white_pawn_attacks(Square s) const;
198   Bitboard black_pawn_attacks(Square s) const;
199
200   template<PieceType>
201   Bitboard piece_attacks(Square s) const;
202
203   // Bitboards for pinned pieces and discovered check candidates
204   Bitboard discovered_check_candidates(Color c) const;
205   Bitboard pinned_pieces(Color c) const;
206
207   // Checking pieces
208   Bitboard checkers() const;
209
210   // Piece lists:
211   Square piece_list(Color c, PieceType pt, int index) const;
212   Square pawn_list(Color c, int index) const;
213   Square knight_list(Color c, int index) const;
214   Square bishop_list(Color c, int index) const;
215   Square rook_list(Color c, int index) const;
216   Square queen_list(Color c, int index) const;
217
218   // Attack information for a given square
219   bool square_is_attacked(Square s, Color c) const;
220   Bitboard attacks_to(Square s) const;
221   Bitboard attacks_to(Square s, Color c) const;
222   bool is_check() const;
223   bool piece_attacks_square(Square f, Square t) const;
224   bool white_pawn_attacks_square(Square f, Square t) const;
225   bool black_pawn_attacks_square(Square f, Square t) const;
226   bool knight_attacks_square(Square f, Square t) const;
227   bool bishop_attacks_square(Square f, Square t) const;
228   bool rook_attacks_square(Square f, Square t) const;
229   bool queen_attacks_square(Square f, Square t) const;
230   bool king_attacks_square(Square f, Square t) const;
231
232   // Properties of moves
233   bool move_is_legal(Move m) const;
234   bool move_is_legal(Move m, Bitboard pinned) const;
235   bool move_is_check(Move m) const;
236   bool move_is_check(Move m, Bitboard dcCandidates) const;
237   bool move_is_capture(Move m) const;
238   bool move_is_deep_pawn_push(Move m) const;
239   bool move_is_pawn_push_to_7th(Move m) const;
240   bool move_is_passed_pawn_push(Move m) const;
241   bool move_was_passed_pawn_push(Move m) const;
242   bool move_attacks_square(Move m, Square s) const;
243
244   // Information about pawns
245   bool pawn_is_passed(Color c, Square s) const;
246   bool pawn_is_isolated(Color c, Square s) const;
247   bool pawn_is_doubled(Color c, Square s) const;
248
249   // Open and half-open files
250   bool file_is_open(File f) const;
251   bool file_is_half_open(Color c, File f) const;
252
253   // Weak squares
254   bool square_is_weak(Square s, Color c) const;
255
256   // Doing and undoing moves
257   void backup(UndoInfo &u) const;
258   void restore(const UndoInfo &u);
259   void do_move(Move m, UndoInfo &u);
260   void do_move(Move m, UndoInfo &u, Bitboard dcCandidates);
261   void undo_move(Move m, const UndoInfo &u);
262   void do_null_move(UndoInfo &u);
263   void undo_null_move(const UndoInfo &u);
264
265   // Static exchange evaluation
266   int see(Square from, Square to) const;
267   int see(Move m) const;
268
269   // Accessing hash keys
270   Key get_key() const;
271   Key get_pawn_key() const;
272   Key get_material_key() const;
273
274   // Incremental evaluation
275   Value mg_value() const;
276   Value eg_value() const;
277   Value non_pawn_material(Color c) const;
278   Phase game_phase() const;
279   Value mg_pst_delta(Move m) const;
280
281   // Game termination checks
282   bool is_mate();
283   bool is_draw() const;
284
285   // Check if one side threatens a mate in one
286   bool has_mate_threat(Color c);
287
288   // Number of plies since the last non-reversible move
289   int rule_50_counter() const;
290
291   // Other properties of the position
292   bool opposite_colored_bishops() const;
293   bool has_pawn_on_7th(Color c) const;
294
295   // Reset the gamePly variable to 0
296   void reset_game_ply();
297   
298   // Position consistency check, for debugging
299   bool is_ok(int* failedStep = NULL) const;
300
301   // Static member functions:
302   static void init_zobrist();
303   static void init_piece_square_tables();
304
305 private:
306   // Initialization helper functions (used while setting up a position)
307   void clear();
308   void put_piece(Piece p, Square s);
309   void allow_oo(Color c);
310   void allow_ooo(Color c);
311
312   // Helper functions for doing and undoing moves
313   void do_castle_move(Move m);
314   void do_promotion_move(Move m, UndoInfo &u);
315   void do_ep_move(Move m);
316   void undo_castle_move(Move m);
317   void undo_promotion_move(Move m, const UndoInfo &u);
318   void undo_ep_move(Move m);
319   void find_checkers();
320
321   // Computing hash keys from scratch (for initialization and debugging)
322   Key compute_key() const;
323   Key compute_pawn_key() const;
324   Key compute_material_key() const;
325
326   // Computing incremental evaluation scores and material counts
327   Value mg_pst(Color c, PieceType pt, Square s) const;
328   Value eg_pst(Color c, PieceType pt, Square s) const;
329   Value compute_mg_value() const;
330   Value compute_eg_value() const;
331   Value compute_non_pawn_material(Color c) const;
332
333   // Bitboards
334   Bitboard byColorBB[2], byTypeBB[8];
335   Bitboard checkersBB;
336
337   // Board
338   Piece board[64];
339
340   // Piece counts
341   int pieceCount[2][8]; // [color][pieceType]
342   
343   // Piece lists
344   Square pieceList[2][8][16]; // [color][pieceType][index]
345   int index[64];
346
347   // Other info
348   Color sideToMove;
349   int castleRights;
350   File initialKFile, initialKRFile, initialQRFile;
351   Square epSquare;
352   Square kingSquare[2];
353   Move lastMove;
354   Key key, pawnKey, materialKey, history[MaxGameLength];
355   int rule50, gamePly;
356   Value mgValue, egValue;
357   Value npMaterial[2];
358
359   // Static variables
360   static int castleRightsMask[64];
361   static Key zobrist[2][8][64];
362   static Key zobEp[64];
363   static Key zobCastle[16];
364   static Key zobMaterial[2][8][16];
365   static Key zobSideToMove;
366   static Value MgPieceSquareTable[16][64];
367   static Value EgPieceSquareTable[16][64];
368 };
369
370
371 ////
372 //// Inline functions
373 ////
374
375 inline Piece Position::piece_on(Square s) const {
376   return board[s];
377 }
378
379 inline Color Position::color_of_piece_on(Square s) const {
380   return color_of_piece(piece_on(s));
381 }
382
383 inline PieceType Position::type_of_piece_on(Square s) const {
384   return type_of_piece(piece_on(s));
385 }
386
387 inline bool Position::square_is_empty(Square s) const {
388   return piece_on(s) == EMPTY;
389 }
390
391 inline bool Position::square_is_occupied(Square s) const {
392   return !square_is_empty(s);
393 }
394
395 inline Value Position::midgame_value_of_piece_on(Square s) const {
396   return piece_value_midgame(piece_on(s));
397 }
398
399 inline Value Position::endgame_value_of_piece_on(Square s) const {
400   return piece_value_endgame(piece_on(s));
401 }
402
403 inline Color Position::side_to_move() const {
404   return sideToMove;
405 }
406
407 inline Bitboard Position::occupied_squares() const {
408   return byTypeBB[0];
409 }
410
411 inline Bitboard Position::empty_squares() const {
412   return ~(occupied_squares());
413 }
414
415 inline Bitboard Position::pieces_of_color(Color c) const {
416   return byColorBB[c];
417 }
418
419 inline Bitboard Position::pieces_of_type(PieceType pt) const {
420   return byTypeBB[pt];
421 }
422
423 inline Bitboard Position::pieces_of_color_and_type(Color c, PieceType pt) const {
424   return pieces_of_color(c) & pieces_of_type(pt);
425 }
426
427 inline Bitboard Position::pawns() const {
428   return pieces_of_type(PAWN);
429 }
430
431 inline Bitboard Position::knights() const {
432   return pieces_of_type(KNIGHT);
433 }
434
435 inline Bitboard Position::bishops() const {
436   return pieces_of_type(BISHOP);
437 }
438
439 inline Bitboard Position::rooks() const {
440   return pieces_of_type(ROOK);
441 }
442
443 inline Bitboard Position::queens() const {
444   return pieces_of_type(QUEEN);
445 }
446
447 inline Bitboard Position::kings() const {
448   return pieces_of_type(KING);
449 }
450
451 inline Bitboard Position::rooks_and_queens() const {
452   return rooks() | queens();
453 }
454
455 inline Bitboard Position::bishops_and_queens() const {
456   return bishops() | queens();
457 }
458
459 inline Bitboard Position::sliders() const {
460   return bishops() | queens() | rooks();
461 }
462
463 inline Bitboard Position::pawns(Color c) const {
464   return pieces_of_color_and_type(c, PAWN);
465 }
466
467 inline Bitboard Position::knights(Color c) const {
468   return pieces_of_color_and_type(c, KNIGHT);
469 }
470
471 inline Bitboard Position::bishops(Color c) const {
472   return pieces_of_color_and_type(c, BISHOP);
473 }
474
475 inline Bitboard Position::rooks(Color c) const {
476   return pieces_of_color_and_type(c, ROOK);
477 }
478
479 inline Bitboard Position::queens(Color c) const {
480   return pieces_of_color_and_type(c, QUEEN);
481 }
482
483 inline Bitboard Position::kings(Color c) const {
484   return pieces_of_color_and_type(c, KING);
485 }
486
487 inline Bitboard Position::rooks_and_queens(Color c) const {
488   return rooks_and_queens() & pieces_of_color(c);
489 }
490
491 inline Bitboard Position::bishops_and_queens(Color c) const {
492   return bishops_and_queens() & pieces_of_color(c);
493 }
494
495 inline Bitboard Position::sliders_of_color(Color c) const {
496   return sliders() & pieces_of_color(c);
497 }
498
499 inline int Position::piece_count(Color c, PieceType pt) const {
500   return pieceCount[c][pt];
501 }
502
503 inline int Position::pawn_count(Color c) const {
504   return piece_count(c, PAWN);
505 }
506
507 inline int Position::knight_count(Color c) const {
508   return piece_count(c, KNIGHT);
509 }
510
511 inline int Position::bishop_count(Color c) const {
512   return piece_count(c, BISHOP);
513 }
514
515 inline int Position::rook_count(Color c) const {
516   return piece_count(c, ROOK);
517 }
518
519 inline int Position::queen_count(Color c) const {
520   return piece_count(c, QUEEN);
521 }
522
523 inline Square Position::piece_list(Color c, PieceType pt, int index) const {
524   return pieceList[c][pt][index];
525 }
526
527 inline Square Position::pawn_list(Color c, int index) const {
528   return piece_list(c, PAWN, index);
529 }
530
531 inline Square Position::knight_list(Color c, int index) const {
532   return piece_list(c, KNIGHT, index);
533 }
534
535 inline Square Position::bishop_list(Color c, int index) const {
536   return piece_list(c, BISHOP, index);
537 }
538
539 inline Square Position::rook_list(Color c, int index) const {
540   return piece_list(c, ROOK, index);
541 }
542
543 inline Square Position::queen_list(Color c, int index) const {
544   return piece_list(c, QUEEN, index);
545 }
546
547 inline Square Position::ep_square() const {
548   return epSquare;
549 }
550
551 inline Square Position::king_square(Color c) const {
552   return kingSquare[c];
553 }
554
555 inline bool Position::can_castle_kingside(Color side) const {
556   return castleRights & (1+int(side));
557 }
558
559 inline bool Position::can_castle_queenside(Color side) const {
560   return castleRights & (4+4*int(side));
561 }
562
563 inline bool Position::can_castle(Color side) const {
564   return can_castle_kingside(side) || can_castle_queenside(side);
565 }
566
567 inline Square Position::initial_kr_square(Color c) const {
568   return relative_square(c, make_square(initialKRFile, RANK_1));
569 }
570
571 inline Square Position::initial_qr_square(Color c) const {
572   return relative_square(c, make_square(initialQRFile, RANK_1));
573 }
574
575 inline Bitboard Position::pawn_attacks(Color c, Square s) const {
576   return StepAttackBB[pawn_of_color(c)][s];
577 }
578
579 inline Bitboard Position::white_pawn_attacks(Square s) const {
580   return pawn_attacks(WHITE, s);
581 }
582
583 inline Bitboard Position::black_pawn_attacks(Square s) const {
584   return pawn_attacks(BLACK, s);
585 }
586
587 template<>
588 inline Bitboard Position::piece_attacks<KNIGHT>(Square s) const {
589   return StepAttackBB[KNIGHT][s];
590 }
591
592 template<>
593 inline Bitboard Position::piece_attacks<BISHOP>(Square s) const {
594   return bishop_attacks_bb(s, occupied_squares());
595 }
596
597 template<>
598 inline Bitboard Position::piece_attacks<ROOK>(Square s) const {
599   return rook_attacks_bb(s, occupied_squares());
600 }
601
602 template<>
603 inline Bitboard Position::piece_attacks<QUEEN>(Square s) const {
604   return piece_attacks<ROOK>(s) | piece_attacks<BISHOP>(s);
605 }
606
607 template<>
608 inline Bitboard Position::piece_attacks<KING>(Square s) const {
609   return StepAttackBB[KING][s];
610 }
611
612 inline Bitboard Position::checkers() const {
613   return checkersBB;
614 }
615
616 inline bool Position::is_check() const {
617   return checkers() != EmptyBoardBB;
618 }
619
620 inline bool Position::white_pawn_attacks_square(Square f, Square t) const {
621   return bit_is_set(white_pawn_attacks(f), t);
622 }
623
624 inline bool Position::black_pawn_attacks_square(Square f, Square t) const {
625   return bit_is_set(black_pawn_attacks(f), t);
626 }
627
628 inline bool Position::knight_attacks_square(Square f, Square t) const {
629   return bit_is_set(piece_attacks<KNIGHT>(f), t);
630 }
631
632 inline bool Position::bishop_attacks_square(Square f, Square t) const {
633   return bit_is_set(piece_attacks<BISHOP>(f), t);
634 }
635
636 inline bool Position::rook_attacks_square(Square f, Square t) const {
637   return bit_is_set(piece_attacks<ROOK>(f), t);
638 }
639
640 inline bool Position::queen_attacks_square(Square f, Square t) const {
641   return bit_is_set(piece_attacks<QUEEN>(f), t);
642 }
643
644 inline bool Position::king_attacks_square(Square f, Square t) const {
645   return bit_is_set(piece_attacks<KING>(f), t);
646 }
647
648 inline bool Position::pawn_is_passed(Color c, Square s) const {
649   return !(pawns(opposite_color(c)) & passed_pawn_mask(c, s));
650 }
651
652 inline bool Position::pawn_is_isolated(Color c, Square s) const {
653   return !(pawns(c) & neighboring_files_bb(s));
654 }
655
656 inline bool Position::pawn_is_doubled(Color c, Square s) const {
657   return pawns(c) & squares_behind(c, s);
658 }
659
660 inline bool Position::file_is_open(File f) const {
661   return !(pawns() & file_bb(f));
662 }
663
664 inline bool Position::file_is_half_open(Color c, File f) const {
665   return !(pawns(c) & file_bb(f));
666 }
667
668 inline bool Position::square_is_weak(Square s, Color c) const {
669   return !(pawns(c) & outpost_mask(opposite_color(c), s));
670 }
671                                 
672 inline Key Position::get_key() const {
673   return key;
674 }
675
676 inline Key Position::get_pawn_key() const {
677   return pawnKey;
678 }
679
680 inline Key Position::get_material_key() const {
681   return materialKey;
682 }
683
684 inline Value Position::mg_pst(Color c, PieceType pt, Square s) const {
685   return MgPieceSquareTable[piece_of_color_and_type(c, pt)][s];
686 }
687
688 inline Value Position::mg_pst_delta(Move m) const {
689   return MgPieceSquareTable[piece_on(move_from(m))][move_to(m)]
690         -MgPieceSquareTable[piece_on(move_from(m))][move_from(m)];
691 }
692
693 inline Value Position::eg_pst(Color c, PieceType pt, Square s) const {
694   return EgPieceSquareTable[piece_of_color_and_type(c, pt)][s];
695 }
696
697 inline Value Position::mg_value() const {
698   return mgValue;
699 }
700
701 inline Value Position::eg_value() const {
702   return egValue;
703 }
704
705 inline Value Position::non_pawn_material(Color c) const {
706   return npMaterial[c];
707 }
708
709 inline Phase Position::game_phase() const {
710
711   // The purpose of the Value(325) terms below is to make sure the difference
712   // between MidgameLimit and EndgameLimit is a power of 2, which should make
713   // the division at the end of the function a bit faster.
714   static const Value MidgameLimit =  2 * QueenValueMidgame
715                                    + 2 * RookValueMidgame
716                                    + 6 * BishopValueMidgame
717                                    + Value(325);
718
719   static const Value EndgameLimit = 4 * RookValueMidgame - Value(325);
720
721   Value npm = non_pawn_material(WHITE) + non_pawn_material(BLACK);
722   
723   if (npm >= MidgameLimit)
724       return PHASE_MIDGAME;
725   else if(npm <= EndgameLimit)
726       return PHASE_ENDGAME;
727   else
728       return Phase(((npm - EndgameLimit) * 128) / (MidgameLimit - EndgameLimit));
729 }
730
731 inline bool Position::move_is_deep_pawn_push(Move m) const {
732
733   Color c = side_to_move();
734   return   piece_on(move_from(m)) == pawn_of_color(c)
735         && relative_rank(c, move_to(m)) > RANK_4;
736 }
737
738 inline bool Position::move_is_pawn_push_to_7th(Move m) const {
739
740   Color c = side_to_move();
741   return   piece_on(move_from(m)) == pawn_of_color(c)
742         && relative_rank(c, move_to(m)) == RANK_7;
743 }
744
745 inline bool Position::move_is_passed_pawn_push(Move m) const {
746
747   Color c = side_to_move();
748   return   piece_on(move_from(m)) == pawn_of_color(c)
749         && pawn_is_passed(c, move_to(m));
750 }
751
752 inline bool Position::move_was_passed_pawn_push(Move m) const {
753
754   Color c = opposite_color(side_to_move());
755   return   piece_on(move_to(m)) == pawn_of_color(c)
756         && pawn_is_passed(c, move_to(m));
757 }
758
759 inline int Position::rule_50_counter() const {
760
761   return rule50;
762 }
763
764 inline bool Position::opposite_colored_bishops() const {
765
766   return   bishop_count(WHITE) == 1
767         && bishop_count(BLACK) == 1
768         && square_color(bishop_list(WHITE, 0)) != square_color(bishop_list(BLACK, 0));
769 }
770
771 inline bool Position::has_pawn_on_7th(Color c) const {
772
773   return pawns(c) & relative_rank_bb(c, RANK_7);
774 }
775                    
776
777 #endif // !defined(POSITION_H_INCLUDED)