per test
[rattatechess.git] / pawntracking.cpp
blob398e621950a30238cb6d6626e8fad7afff943c99
1 /***************************************************************************
2 check.cpp - description
3 -------------------
4 begin : Mon Sep 19 2005
5 copyright : (C) 2005 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #include "board.h"
21 void
22 Board::add_pawn(uint8_t col, uint8_t where)
24 LinePawns *lp = &line_pawns[IS_WHITE(col)][X(where)];
25 int row = IS_WHITE(col) ? Y(where) : 7-Y(where);
26 int f = lp->count;
28 #ifdef DEBUG
29 ASSERT(lp->count < 7);
30 for(int i=0;i<lp->count;i++)
31 ASSERT(lp->pos[i] != row);
32 #endif
34 while(f && (lp->pos[f-1]>row))
36 lp->pos[f] = lp->pos[f-1];
37 f--;
39 lp->pos[f] = row;
40 lp->count++;
43 void
44 Board::del_pawn(uint8_t col, uint8_t where)
46 LinePawns *lp = &line_pawns[IS_WHITE(col)][X(where)];
47 int row = IS_WHITE(col) ? Y(where) : 7-Y(where);
48 int f = 0;
50 while(lp->pos[f] != row)
52 f++;
53 ASSERT(f < lp->count);
55 while(f < lp->count)
57 f++;
58 lp->pos[f-1] = lp->pos[f];
60 lp->count--;
63 void
64 Board::recalc_line_pawns()
66 for(int i=0;i<2;i++)
67 for(int j=0;j<8;j++)
68 line_pawns[i][j].count = 0;
70 int piece_pos = 128;
71 for(int i=7;i>=0;i--)
73 piece_pos -= 8;
74 for(int j=7;j>=0;j--)
76 piece_pos--;
77 if(PIECE_OF(data[piece_pos])==PAWN)
78 add_pawn(data[piece_pos], piece_pos);
83 void
84 Board::check_line_pawns()
86 for(int i=0;i<2;i++)
87 for(int j=0;j<8;j++)
89 LinePawns *lp = &line_pawns[i][j];
90 for(int k=0;k<lp->count;k++)
91 ASSERT(data[POS_XY(j, i ? lp->pos[k] : 7-lp->pos[k])] == (i?WP:BP));
92 int n = 0;
93 for(int k=0;k<8;k++)
94 if(data[POS_XY(j, k)] == (i?WP:BP))
95 n++;
96 ASSERT(n == lp->count);