~ubuntu-branches/ubuntu/karmic/brutalchess/karmic

« back to all changes in this revision

Viewing changes to board.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2006-04-07 10:41:25 UTC
  • Revision ID: james.westby@ubuntu.com-20060407104125-18mnxbl1yzju7e84
Tags: upstream-0.0.20060314cvs
Import upstream version 0.0.20060314cvs

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
*       Brutal Chess
 
3
*       - board.cpp
 
4
*
 
5
*       Authors: Maxwell Lazaroff, Michael Cook, and Joe Flint
 
6
*       Date Created : May 3rd, 2005
 
7
*       Last Modified: November 5th, 2005
 
8
*
 
9
*       - description - Implements a chessboard, with methods for checking
 
10
*   bounds, etc.
 
11
***************************************************************************/
 
12
 
 
13
#include <iostream>
 
14
 
 
15
#include "board.h"
 
16
#include "boardmove.h"
 
17
#include "chessplayer.h"
 
18
 
 
19
using namespace std;
 
20
 
 
21
/***************************************************************************
 
22
*       Piece Class Member Functions
 
23
***************************************************************************/
 
24
 
 
25
//******** ACCESSORS ********
 
26
 
 
27
Color        Piece::getColor()     const { return this->_color; }
 
28
Unit         Piece::getUnit()      const { return this->_piece; }
 
29
unsigned int Piece::getMovecount() const { return this->_movecount; }
 
30
bool         Piece::getJustMoved() const { return this->_justMoved; }
 
31
 
 
32
string 
 
33
Piece::getName() const
 
34
{
 
35
        switch( this->_piece ) {
 
36
                case EMPTY:
 
37
                        return "Empty";
 
38
                case PAWN:
 
39
                        return "Pawn";
 
40
                case KNIGHT:
 
41
                        return "Knight";
 
42
                case BISHOP:
 
43
                        return "Bishop";
 
44
                case ROOK:
 
45
                        return "Rook";
 
46
                case QUEEN:
 
47
                        return "Queen";
 
48
                case KING:
 
49
                        return "King";
 
50
                default:
 
51
                        exit(1);
 
52
        }
 
53
}
 
54
 
 
55
//******** UTILITIES ********
 
56
 
 
57
void Piece::setColor(Color color) { this->_color = color; }
 
58
void Piece::setUnit(Unit unit)    { this->_piece = unit;  }
 
59
void Piece::setMovecount(unsigned int movecount) { this->_movecount = movecount; }
 
60
void Piece::setJustMoved()        { this->_justMoved = true; }
 
61
void Piece::unsetJustMoved()      { this->_justMoved = false; }
 
62
 
 
63
/***************************************************************************
 
64
*       Board Class Member Functions
 
65
***************************************************************************/
 
66
 
 
67
void 
 
68
Board::reset()
 
69
/***************************************************************************
 
70
*       Board::reset()
 
71
*       
 
72
*       - Resets the board to its initial setup.
 
73
***************************************************************************/
 
74
{
 
75
        // Clearing the board
 
76
    for(uint i = 0; i < 8; i++) {
 
77
        for(uint j = 0; j < 8; j++) {
 
78
           _board[i][j].setColor(BLANK);
 
79
           _board[i][j].setUnit(EMPTY);
 
80
                   _board[i][j].setMovecount( 0 );
 
81
                   _board[i][j].unsetJustMoved();
 
82
        }
 
83
    }
 
84
 
 
85
        // Setting up the pawns
 
86
    for(int i = 0; i < 8; i++)
 
87
    {
 
88
        _board[0][i].setColor(BLACK);
 
89
        _board[1][i].setColor(BLACK);
 
90
        _board[1][i].setUnit(PAWN);
 
91
        _board[6][i].setColor(WHITE);
 
92
        _board[6][i].setUnit(PAWN);
 
93
        _board[7][i].setColor(WHITE);
 
94
    }
 
95
 
 
96
        // Setting up the remaining pieces
 
97
        _board[0][0].setUnit(ROOK);
 
98
        _board[0][1].setUnit(KNIGHT);
 
99
        _board[0][2].setUnit(BISHOP);
 
100
        _board[0][3].setUnit(QUEEN);
 
101
        _board[0][4].setUnit(KING);
 
102
        _board[0][5].setUnit(BISHOP);
 
103
        _board[0][6].setUnit(KNIGHT);
 
104
        _board[0][7].setUnit(ROOK);
 
105
 
 
106
        _board[7][0].setUnit(ROOK);
 
107
        _board[7][1].setUnit(KNIGHT);
 
108
        _board[7][2].setUnit(BISHOP);
 
109
        _board[7][3].setUnit(QUEEN);
 
110
        _board[7][4].setUnit(KING);
 
111
        _board[7][5].setUnit(BISHOP);
 
112
        _board[7][6].setUnit(KNIGHT);
 
113
        _board[7][7].setUnit(ROOK);
 
114
 
 
115
        return;
 
116
}
 
117
 
 
118
void 
 
119
Board::print()
 
120
/***************************************************************************
 
121
*       Board::print()
 
122
*       
 
123
*       - Prints the board to the console.  This is a throw back to the early
 
124
*   development days of Brutal Chess when it was all still text based.  
 
125
*   We're keeping this around in case we want to add support later for
 
126
*   playing over a network with the text based version vs. the graphical
 
127
*   version.
 
128
***************************************************************************/
 
129
{
 
130
        // A matrix that we'll fill with characters to visually represent the
 
131
        // current state of the chess board.
 
132
    char printerboard[25][25];
 
133
 
 
134
        // Setting the edges of the squares.
 
135
    for(int i = 0; i < 25; i++) {
 
136
        for(int j = 0; j < 25; j++) {
 
137
            if(i%3 == 0)
 
138
                printerboard[i][j] = '-';
 
139
            else
 
140
                printerboard[i][j] = '|';
 
141
        }
 
142
    }
 
143
//---
 
144
    for(int i = 1; i < 25; i += 6) {
 
145
        for(int j = 2; j < 25; j += 6)
 
146
            printerboard[i][j] = '-';
 
147
    }
 
148
    for(int i = 2; i < 25; i += 6) {
 
149
        for(int j = 1; j < 25; j += 6)
 
150
            printerboard[i][j] = '-';
 
151
    }
 
152
    for(int i = 4; i < 25; i += 6) {
 
153
        for(int j = 5; j < 25; j += 6)
 
154
            printerboard[i][j] = '-';
 
155
    }
 
156
    for(int i = 5; i < 25; i += 6) {
 
157
        for(int j = 4; j < 25; j += 6)
 
158
            printerboard[i][j] = '-';
 
159
    }
 
160
//---
 
161
    for(int i = 4; i < 25; i += 6) {
 
162
        for(int j = 2; j < 25; j += 6)
 
163
            printerboard[i][j] = ' ';
 
164
    }
 
165
    for(int i = 5; i < 25; i += 6) {
 
166
        for(int j = 1; j < 25; j += 6)
 
167
            printerboard[i][j] = ' ';
 
168
    }
 
169
    for(int i = 1; i < 25; i += 6) {
 
170
        for(int j = 5; j < 25; j += 6)
 
171
            printerboard[i][j] = ' ';
 
172
    }
 
173
    for(int i = 2; i < 25; i += 6) {
 
174
        for(int j = 4; j < 25; j += 6)
 
175
            printerboard[i][j] = ' ';
 
176
    }
 
177
 
 
178
        // Setting the piece type for non-empty squares.
 
179
    for(int i = 1; i < 25; i += 3) {
 
180
        for(int j = 1; j < 25; j += 3) {
 
181
            if(_board[i/3][j/3].getUnit() == PAWN)
 
182
                printerboard[i][j] = 'P';
 
183
            if(_board[i/3][j/3].getUnit() == KNIGHT)
 
184
                printerboard[i][j] = 'N';
 
185
            if(_board[i/3][j/3].getUnit() == BISHOP)
 
186
                printerboard[i][j] = 'B';
 
187
            if(_board[i/3][j/3].getUnit() == ROOK)
 
188
                printerboard[i][j] = 'R';
 
189
            if(_board[i/3][j/3].getUnit() == QUEEN)
 
190
                printerboard[i][j] = 'Q';
 
191
            if(_board[i/3][j/3].getUnit() == KING)
 
192
                printerboard[i][j] = 'K';
 
193
            if(_board[i/3][j/3].getUnit() == EMPTY) {
 
194
                if((i+2)%6 != 0) {
 
195
                    if((j+2)%6 != 0)
 
196
                        printerboard[i][j] = '-';
 
197
                    else
 
198
                        printerboard[i][j] = ' ';
 
199
                } else {
 
200
                    if((j+2)%6 !=0)
 
201
                        printerboard[i][j] = ' ';
 
202
                    else
 
203
                        printerboard[i][j] = '-';
 
204
                }
 
205
            }
 
206
        }
 
207
    }
 
208
    
 
209
        // Setting the piece colors.
 
210
    for(int i = 2; i < 25; i += 3) {
 
211
        for(int j = 2; j < 25; j += 3) {
 
212
            if(_board[i/3][j/3].getColor() == BLACK)
 
213
                printerboard[i][j] = 'B';
 
214
            else if(_board[i/3][j/3].getColor() == WHITE)
 
215
                printerboard[i][j] = 'W';
 
216
            else {
 
217
                if((i+1)%6 != 0) {
 
218
                    if((j+1)%6 != 0)
 
219
                        printerboard[i][j] = '-';
 
220
                    else
 
221
                        printerboard[i][j] = ' ';
 
222
                } else {
 
223
                    if((j+1)%6 != 0)
 
224
                        printerboard[i][j] = ' ';
 
225
                    else
 
226
                        printerboard[i][j] = '-';
 
227
                }
 
228
            }
 
229
        }
 
230
    }
 
231
 
 
232
        // Setting up the file indicators.
 
233
    cout << endl;
 
234
        cout << " 0  1  2  3  4  5  6  7" << endl;
 
235
    for(int i = 0; i < 25; i++) {
 
236
        for(int j = 0; j < 25; j++)
 
237
            cout << printerboard[i][j];
 
238
                if ((i+2)%3 == 0)
 
239
                        cout << ((i+2)/3)-1;
 
240
        cout << endl;
 
241
    }
 
242
 
 
243
        return;
 
244
}
 
245
 
 
246
void
 
247
Board::pawnPromotion()
 
248
/***************************************************************************
 
249
*       Board::pawnPromotion
 
250
*
 
251
*       - Looks over board and promotes any pawns that make it to the last rank
 
252
*     a queen. Need to implement a way to choose, however.
 
253
***************************************************************************/
 
254
{
 
255
        for(int i = 0; i < 8; i++) {
 
256
                if ((_board[7][i].getColor() == BLACK) &&
 
257
                    (_board[7][i].getUnit()==PAWN))
 
258
                        _board[7][i].setUnit(QUEEN);
 
259
                if ((_board[0][i].getColor() == WHITE) &&
 
260
                    (_board[0][i].getUnit() == PAWN))
 
261
                        _board[0][i].setUnit(QUEEN);
 
262
        }
 
263
 
 
264
        return;
 
265
}
 
266
 
 
267
void 
 
268
Board::updateBoard(BoardMove move)
 
269
/***************************************************************************
 
270
*       Board::updateBoard
 
271
*
 
272
*       - Takes in a BoardMove, 'move', which has already validated
 
273
*       hopefully, and takes care of moving the pieces, updating movecounts, and
 
274
*       when neccessary, taking pieces.
 
275
***************************************************************************/
 
276
{
 
277
        // Getting Move Coordinates.
 
278
        uint srow = move.getStartx();
 
279
        uint scol = move.getStarty();
 
280
        uint erow = move.getEndx();
 
281
        uint ecol = move.getEndy();
 
282
 
 
283
        move.checkFlags( *this );
 
284
 
 
285
        // Check for En Passant and handle it.
 
286
        if (move.getIsEnPassant()) {
 
287
                move.unsetIsEnPassant();
 
288
                _board[srow][ecol].setUnit(EMPTY);
 
289
                _board[srow][ecol].setColor(BLANK);
 
290
                _board[srow][ecol].setMovecount(0);
 
291
        }
 
292
 
 
293
        // Check for Castling and handle it.
 
294
        if (move.getCastling()) {
 
295
        move.unsetCastling();
 
296
 
 
297
                if ((_board[srow][ecol-2].getUnit() == ROOK) && 
 
298
                        (_board[srow][ecol-2].getMovecount() == 0)) {
 
299
            _board[srow][ecol+1].setUnit(_board[srow][ecol-2].getUnit());
 
300
            _board[srow][ecol+1].setColor(_board[srow][ecol-2].getColor());
 
301
            _board[srow][ecol+1].setMovecount(_board[srow][ecol-2].getMovecount()+1);
 
302
            _board[srow][ecol-2].setUnit(EMPTY);
 
303
            _board[srow][ecol-2].setColor(BLANK);
 
304
            _board[srow][ecol-2].setMovecount(0);
 
305
        } else if((_board[srow][ecol+1].getUnit() == ROOK) && 
 
306
                              (_board[srow][ecol+1].getMovecount() == 0)) {
 
307
            _board[srow][ecol-1].setUnit(_board[srow][ecol+1].getUnit());
 
308
            _board[srow][ecol-1].setColor(_board[srow][ecol+1].getColor());
 
309
            _board[srow][ecol-1].setMovecount(_board[srow][ecol+1].getMovecount()+1);
 
310
            _board[srow][ecol+1].setUnit(EMPTY);
 
311
            _board[srow][ecol+1].setColor(BLANK);
 
312
            _board[srow][ecol+1].setMovecount(0);
 
313
        }
 
314
    }
 
315
 
 
316
        // Move to the current 'end' coordinates.
 
317
        _board[erow][ecol].setUnit(_board[srow][scol].getUnit());
 
318
        _board[erow][ecol].setColor(_board[srow][scol].getColor());
 
319
        _board[erow][ecol].setMovecount(_board[srow][scol].getMovecount()+1);
 
320
        _board[srow][scol].setUnit(EMPTY);
 
321
        _board[srow][scol].setColor(BLANK);
 
322
        _board[srow][scol].setMovecount(0);
 
323
        
 
324
        //Check for any neccessary pawns to promote
 
325
        pawnPromotion();
 
326
        
 
327
        // Do this here, or flags don't get set right
 
328
        // Updating 'last moved piece'
 
329
        // Unseting them all is slower, but safer
 
330
        for( int i = 0; i < BOARDSIZE; i++ )
 
331
                for( int j = 0; j < BOARDSIZE; j++ )
 
332
                        _board[i][j].unsetJustMoved();
 
333
        
 
334
        _board[erow][ecol].setJustMoved();
 
335
        
 
336
        return;
 
337
}
 
338
 
 
339
bool
 
340
Board::inDanger(bool is_white, int row, int col) const
 
341
/***************************************************************************
 
342
*       inDanger
 
343
*       
 
344
*       - Checks to make sure that the legal move the king made is not illegal
 
345
*     by placing himself into check
 
346
****************************************************************************/
 
347
{   
 
348
 
 
349
    //Look up the column for an enemy Rook or Queen
 
350
    if (col != 7) {
 
351
        for (int i = col+1; i < 8; i++) {
 
352
            if (is_white) {
 
353
                if (_board[row][i].getColor() == WHITE)
 
354
                    break;
 
355
                if ((_board[row][i].getColor() == BLACK) && 
 
356
                                    ((_board[row][i].getUnit() == ROOK) || 
 
357
                                     (_board[row][i].getUnit() == QUEEN)))
 
358
                    return true;
 
359
                if (_board[row][i].getColor() == BLACK)
 
360
                    break;
 
361
            } else {
 
362
                if (_board[row][i].getColor() == BLACK)
 
363
                    break;
 
364
                if ((_board[row][i].getColor() == WHITE) && 
 
365
                                        ((_board[row][i].getUnit() == ROOK) || 
 
366
                                         (_board[row][i].getUnit() == QUEEN)))
 
367
                    return true;
 
368
                if(_board[row][i].getColor() == WHITE)
 
369
                    break;
 
370
            }
 
371
        }
 
372
    }
 
373
    //Look down the column for an enemy Rook or Queen
 
374
    if(col != 0) {
 
375
        for(int i = col-1; i >= 0; i--) {
 
376
            if(is_white) {
 
377
                if(_board[row][i].getColor() == WHITE)
 
378
                    break;
 
379
                if(   _board[row][i].getColor() == BLACK
 
380
                   &&(_board[row][i].getUnit() == ROOK
 
381
                   || _board[row][i].getUnit() == QUEEN) )
 
382
                    return true;
 
383
                if(_board[row][i].getColor() == BLACK)
 
384
                    break;
 
385
            }
 
386
            else
 
387
            {
 
388
                if(_board[row][i].getColor() == BLACK)
 
389
                    break;
 
390
                if(   _board[row][i].getColor() == WHITE
 
391
                   &&(_board[row][i].getUnit() == ROOK
 
392
                   || _board[row][i].getUnit() == QUEEN) )
 
393
                    return true;
 
394
                if(_board[row][i].getColor() == WHITE)
 
395
                    break;
 
396
            }
 
397
        }
 
398
    }
 
399
    //Look right across the rows for an enemy Rook or Queen
 
400
    if(row != 7)
 
401
    {
 
402
        for(int i=row+1; i < 8; i++)
 
403
        {
 
404
            if(is_white)
 
405
            {
 
406
                if(_board[i][col].getColor() == WHITE)
 
407
                    break;
 
408
                if(   _board[i][col].getColor() == BLACK
 
409
                   &&(_board[i][col].getUnit() == ROOK
 
410
                   || _board[i][col].getUnit() == QUEEN) )
 
411
                    return true;
 
412
                if(_board[i][col].getColor() == BLACK)
 
413
                    break;
 
414
            }
 
415
            else
 
416
            {
 
417
                if(_board[i][col].getColor() == BLACK)
 
418
                    break;
 
419
                if(   _board[i][col].getColor() == WHITE
 
420
                   &&(_board[i][col].getUnit() == ROOK
 
421
                   || _board[i][col].getUnit() == QUEEN) )
 
422
                    return true;
 
423
                if(_board[i][col].getColor() == WHITE)
 
424
                    break;
 
425
            }
 
426
        }
 
427
    }
 
428
    //Look left across the rows for an enemy Rook or Queen
 
429
    if(row != 0)
 
430
    {
 
431
        for(int i=row-1; i >= 0; i--)
 
432
        {
 
433
            if(is_white)
 
434
            {
 
435
                if(_board[i][col].getColor() == WHITE)
 
436
                    break;
 
437
                if(   _board[i][col].getColor() == BLACK
 
438
                   &&(_board[i][col].getUnit() == ROOK
 
439
                   || _board[i][col].getUnit() == QUEEN) )
 
440
                    return true;
 
441
                if(_board[i][col].getColor() == BLACK)
 
442
                    break;
 
443
            }
 
444
            else
 
445
            {
 
446
                if(_board[i][col].getColor() == BLACK)
 
447
                    break;
 
448
                if(   _board[i][col].getColor() == WHITE
 
449
                   &&(_board[i][col].getUnit() == ROOK
 
450
                   || _board[i][col].getUnit() == QUEEN) )
 
451
                    return true;
 
452
                if(_board[i][col].getColor() == WHITE)
 
453
                    break;
 
454
            }
 
455
        }
 
456
    }
 
457
    
 
458
    //Diagonal
 
459
    if(row != 7 && col != 7)
 
460
    {
 
461
        for(int i = 1; (row+i != 8 && col+i !=8); i++)
 
462
        {
 
463
            if(is_white)
 
464
            {
 
465
                if(_board[row+i][col+i].getColor() == WHITE)
 
466
                    break;
 
467
                if(   _board[row+i][col+i].getColor() == BLACK
 
468
                   &&(_board[row+i][col+i].getUnit() == BISHOP
 
469
                   || _board[row+i][col+i].getUnit() == QUEEN) )
 
470
                    return true;
 
471
                if(_board[row+i][col+i].getColor() == BLACK)
 
472
                    break;
 
473
            }
 
474
            else
 
475
            {
 
476
                if(_board[row+i][col+i].getColor() == BLACK)
 
477
                    break;
 
478
                if(   _board[row+i][col+i].getColor() == WHITE
 
479
                   &&(_board[row+i][col+i].getUnit() == BISHOP
 
480
                   || _board[row+i][col+i].getUnit() == QUEEN) )
 
481
                    return true;
 
482
                if(_board[row+i][col+i].getColor() == WHITE)
 
483
                    break;
 
484
            }
 
485
        }
 
486
    }
 
487
    if(row != 0 && col != 7)
 
488
    {
 
489
        for(int i = 1; (row-i >= 0 && col+i !=8); i++)
 
490
        {
 
491
            if(is_white)
 
492
            {
 
493
                if(_board[row-i][col+i].getColor() == WHITE)
 
494
                    break;
 
495
                if(   _board[row-i][col+i].getColor() == BLACK
 
496
                   &&(_board[row-i][col+i].getUnit() == BISHOP
 
497
                   || _board[row-i][col+i].getUnit() == QUEEN) )
 
498
                    return true;
 
499
                if(_board[row-i][col+i].getColor() == BLACK)
 
500
                    break;
 
501
            }
 
502
            else
 
503
            {
 
504
                if(_board[row-i][col+i].getColor() == BLACK)
 
505
                    break;
 
506
                if(   _board[row-i][col+i].getColor() == WHITE
 
507
                   &&(_board[row-i][col+i].getUnit() == BISHOP
 
508
                   || _board[row-i][col+i].getUnit() == QUEEN) )
 
509
                    return true;
 
510
                if(_board[row-i][col+i].getColor() == WHITE)
 
511
                    break;
 
512
            }
 
513
        }
 
514
    }
 
515
    if(row != 7 && col != 0)
 
516
    {
 
517
        for(int i = 1; (row+i != 8 && col-i >=0); i++)
 
518
        {
 
519
            if(is_white)
 
520
            {
 
521
                if(_board[row+i][col-i].getColor() == WHITE)
 
522
                    break;
 
523
                if(   _board[row+i][col-i].getColor() == BLACK
 
524
                   &&(_board[row+i][col-i].getUnit() == BISHOP
 
525
                   || _board[row+i][col-i].getUnit() == QUEEN) )
 
526
                    return true;
 
527
                if(_board[row+i][col-i].getColor() == BLACK)
 
528
                    break;
 
529
            }
 
530
            else
 
531
            {
 
532
                if(_board[row+i][col-i].getColor() == BLACK)
 
533
                    break;
 
534
                if(   _board[row+i][col-i].getColor() == WHITE
 
535
                   &&(_board[row+i][col-i].getUnit() == BISHOP
 
536
                   || _board[row+i][col-i].getUnit() == QUEEN) )
 
537
                    return true;
 
538
                if(_board[row+i][col-i].getColor() == WHITE)
 
539
                    break;
 
540
            }
 
541
        }
 
542
    }
 
543
    if(row != 0 && col != 0)
 
544
    {
 
545
        for(int i = 1; (row-i >=0 && col-i >=0); i++)
 
546
        {
 
547
            if(is_white)
 
548
            {
 
549
                if(_board[row-i][col-i].getColor() == WHITE)
 
550
                    break;
 
551
                if(   _board[row-i][col-i].getColor() == BLACK
 
552
                   &&(_board[row-i][col-i].getUnit() == BISHOP
 
553
                   || _board[row-i][col-i].getUnit() == QUEEN) )
 
554
                    return true;
 
555
                if(_board[row-i][col-i].getColor() == BLACK)
 
556
                    break;
 
557
            }
 
558
            else
 
559
            {
 
560
                if(_board[row-i][col-i].getColor() == BLACK)
 
561
                    break;
 
562
                if(   _board[row-i][col-i].getColor() == WHITE
 
563
                   &&(_board[row-i][col-i].getUnit() == BISHOP
 
564
                   || _board[row-i][col-i].getUnit() == QUEEN) )
 
565
                    return true;
 
566
                if(_board[row-i][col-i].getColor() == WHITE)
 
567
                    break;
 
568
            }
 
569
        }
 
570
    }
 
571
    
 
572
    //Pawns
 
573
    if(is_white)
 
574
    {
 
575
        if(row != 0 && col != 0)
 
576
        {
 
577
            if(_board[row-1][col-1].getUnit() == PAWN
 
578
               && _board[row-1][col-1].getColor() == BLACK)
 
579
               return true;
 
580
        }
 
581
        if(row != 0 && col != 7)
 
582
        {
 
583
            if(_board[row-1][col+1].getUnit() == PAWN
 
584
               && _board[row-1][col+1].getColor() == BLACK)
 
585
               return true;
 
586
        }
 
587
    }
 
588
    else
 
589
    {
 
590
        if(row != 7 && col != 0)
 
591
        {
 
592
            if(_board[row+1][col-1].getUnit() == PAWN
 
593
               && _board[row+1][col-1].getColor() == WHITE)
 
594
               return true;
 
595
        }
 
596
        if(row != 7 && col != 7)
 
597
        {
 
598
            if(_board[row+1][col+1].getUnit() == PAWN
 
599
               && _board[row+1][col+1].getColor() == WHITE)
 
600
               return true;
 
601
        }
 
602
    }
 
603
        
 
604
        // Checking to see if any Knights are putting the king into check.
 
605
        uint startrow = 0;
 
606
        uint startcol = 0;
 
607
        BoardMove knightOne(startrow, startcol, row+1, col+2);  
 
608
        BoardMove knightTwo(startrow, startcol, row+1, col-2);  
 
609
        BoardMove knightThr(startrow, startcol, row+2, col+1);  
 
610
        BoardMove knightFou(startrow, startcol, row+2, col-1);  
 
611
        BoardMove knightFiv(startrow, startcol, row-1, col+2);  
 
612
        BoardMove knightSix(startrow, startcol, row-1, col-2);  
 
613
        BoardMove knightSev(startrow, startcol, row-2, col+1);  
 
614
        BoardMove knightEig(startrow, startcol, row-2, col-1);  
 
615
        if (is_white)
 
616
        {
 
617
                if (Board::is_in(knightOne))
 
618
                {
 
619
                        if (   _board[row+1][col+2].getUnit() == KNIGHT
 
620
                                && _board[row+1][col+2].getColor() == BLACK)
 
621
                                return true;
 
622
                }       
 
623
                if (Board::is_in(knightTwo))
 
624
                {
 
625
                        if (   _board[row+1][col-2].getUnit() == KNIGHT
 
626
                                && _board[row+1][col-2].getColor() == BLACK)
 
627
                                return true;
 
628
                }               
 
629
                if (Board::is_in(knightThr))
 
630
                {
 
631
                        if (   _board[row+2][col+1].getUnit() == KNIGHT
 
632
                                && _board[row+2][col+1].getColor() == BLACK)
 
633
                                return true;
 
634
                }
 
635
                if (Board::is_in(knightFou))
 
636
                {
 
637
                        if (   _board[row+2][col-1].getUnit() == KNIGHT
 
638
                                && _board[row+2][col-1].getColor() == BLACK)
 
639
                                return true;
 
640
                }
 
641
                if (Board::is_in(knightFiv))
 
642
                {
 
643
                        if (   _board[row-1][col+2].getUnit() == KNIGHT
 
644
                                && _board[row-1][col+2].getColor() == BLACK)
 
645
                                return true;
 
646
                }
 
647
                if (Board::is_in(knightSix))
 
648
                {
 
649
                        if (   _board[row-1][col-2].getUnit() == KNIGHT
 
650
                                && _board[row-1][col-2].getColor() == BLACK)
 
651
                                return true;
 
652
                }
 
653
                if (Board::is_in(knightSev))
 
654
                {
 
655
                        if (   _board[row-2][col+1].getUnit() == KNIGHT
 
656
                                && _board[row-2][col+1].getColor() == BLACK)
 
657
                                return true;
 
658
                }
 
659
                if (Board::is_in(knightEig))
 
660
                {
 
661
                        if (   _board[row-2][col-1].getUnit() == KNIGHT
 
662
                                && _board[row-2][col-1].getColor() == BLACK)
 
663
                                return true;
 
664
                }                       
 
665
        }
 
666
        else
 
667
        {
 
668
                if (Board::is_in(knightOne))
 
669
                {
 
670
                        if (   _board[row+1][col+2].getUnit() == KNIGHT
 
671
                                && _board[row+1][col+2].getColor() == WHITE)
 
672
                                return true;
 
673
                }       
 
674
                if (Board::is_in(knightTwo))
 
675
                {
 
676
                        if (   _board[row+1][col-2].getUnit() == KNIGHT
 
677
                                && _board[row+1][col-2].getColor() == WHITE)
 
678
                                return true;
 
679
                }               
 
680
                if (Board::is_in(knightThr))
 
681
                {
 
682
                        if (   _board[row+2][col+1].getUnit() == KNIGHT
 
683
                                && _board[row+2][col+1].getColor() == WHITE)
 
684
                                return true;
 
685
                }
 
686
                if (Board::is_in(knightFou))
 
687
                {
 
688
                        if (   _board[row+2][col-1].getUnit() == KNIGHT
 
689
                                && _board[row+2][col-1].getColor() == WHITE)
 
690
                                return true;
 
691
                }
 
692
                if (Board::is_in(knightFiv))
 
693
                {
 
694
                        if (   _board[row-1][col+2].getUnit() == KNIGHT
 
695
                                && _board[row-1][col+2].getColor() == WHITE)
 
696
                                return true;
 
697
                }
 
698
                if (Board::is_in(knightSix))
 
699
                {
 
700
                        if (   _board[row-1][col-2].getUnit() == KNIGHT
 
701
                                && _board[row-1][col-2].getColor() == WHITE)
 
702
                                return true;
 
703
                }
 
704
                if (Board::is_in(knightSev))
 
705
                {
 
706
                        if (   _board[row-2][col+1].getUnit() == KNIGHT
 
707
                                && _board[row-2][col+1].getColor() == WHITE)
 
708
                                return true;
 
709
                }
 
710
                if (Board::is_in(knightEig))
 
711
                {
 
712
                        if (   _board[row-2][col-1].getUnit() == KNIGHT
 
713
                                && _board[row-2][col-1].getColor() == WHITE)
 
714
                                return true;
 
715
                }
 
716
        }
 
717
        
 
718
        // Check to make sure a king isn't trying to move next to another king
 
719
        if (is_white)
 
720
        {
 
721
                if (col != 7)
 
722
                {
 
723
                        if (row != 7)
 
724
                        {
 
725
                                if(   _board[row+1][col+1].getUnit() == KING
 
726
                                   && _board[row+1][col+1].getColor() == BLACK)
 
727
                                        return true;
 
728
                        }
 
729
                        if (   _board[row][col+1].getUnit() == KING
 
730
                                && _board[row][col+1].getColor() == BLACK)
 
731
                                return true;
 
732
                        if (row != 0)
 
733
                        {
 
734
                                if(   _board[row-1][col+1].getUnit() == KING
 
735
                                   && _board[row-1][col+1].getColor() == BLACK)
 
736
                                        return true;
 
737
                        }
 
738
                }
 
739
                if (row != 0)
 
740
                {
 
741
                        if(   _board[row-1][col].getUnit() == KING
 
742
                           && _board[row-1][col].getColor() == BLACK)
 
743
                                return true;
 
744
                        if (col != 0)
 
745
                        {
 
746
                                if (   _board[row-1][col-1].getUnit() == KING
 
747
                                        && _board[row-1][col-1].getColor() == BLACK)
 
748
                                        return true;
 
749
                        }
 
750
                }
 
751
                if (col != 0)
 
752
                {
 
753
                        if(   _board[row][col-1].getUnit() == KING
 
754
                           && _board[row][col-1].getColor() == BLACK)
 
755
                                return true;
 
756
                        if (row != 7)
 
757
                        {
 
758
                                if(   _board[row+1][col-1].getUnit() == KING
 
759
                                   && _board[row+1][col-1].getColor() == BLACK)
 
760
                                        return true;
 
761
                        }
 
762
                }
 
763
                if (row != 7)
 
764
                { 
 
765
                        if(   _board[row+1][col].getUnit() == KING
 
766
                           && _board[row+1][col].getColor() == BLACK)
 
767
                                return true;  
 
768
                }
 
769
        }
 
770
        else
 
771
        {
 
772
                if (col != 7)
 
773
                {
 
774
                        if (row != 7)
 
775
                        {
 
776
                                if(   _board[row+1][col+1].getUnit() == KING
 
777
                                   && _board[row+1][col+1].getColor() == WHITE)
 
778
                                        return true;
 
779
                        }
 
780
                        if (   _board[row][col+1].getUnit() == KING
 
781
                                && _board[row][col+1].getColor() == WHITE)
 
782
                                return true;
 
783
                        if (row != 0)
 
784
                        {
 
785
                                if(   _board[row-1][col+1].getUnit() == KING
 
786
                                   && _board[row-1][col+1].getColor() == WHITE)
 
787
                                        return true;
 
788
                        }
 
789
                }
 
790
                if (row != 0)
 
791
                {
 
792
                        if(   _board[row-1][col].getUnit() == KING
 
793
                           && _board[row-1][col].getColor() == WHITE)
 
794
                                return true;
 
795
                        if (col != 0)
 
796
                        {
 
797
                                if (   _board[row-1][col-1].getUnit() == KING
 
798
                                        && _board[row-1][col-1].getColor() == WHITE)
 
799
                                        return true;
 
800
                        }
 
801
                }
 
802
                if (col != 0)
 
803
                {
 
804
                        if(   _board[row][col-1].getUnit() == KING
 
805
                           && _board[row][col-1].getColor() == WHITE)
 
806
                                return true;
 
807
                        if (row != 7)
 
808
                        {
 
809
                                if(   _board[row+1][col-1].getUnit() == KING
 
810
                                   && _board[row+1][col-1].getColor() == WHITE)
 
811
                                        return true;
 
812
                        }
 
813
                }
 
814
                if (row != 7)
 
815
                { 
 
816
                        if(   _board[row+1][col].getUnit() == KING
 
817
                           && _board[row+1][col].getColor() == WHITE)
 
818
                                return true;  
 
819
                }
 
820
        }
 
821
        
 
822
    return false;
 
823
}
 
824
 
 
825
uint
 
826
Board::inDangerCount(bool is_white, int row, int col) const
 
827
/***************************************************************************
 
828
*       inDanger
 
829
*       
 
830
*       - Checks to make sure that the legal move the king made is not illegal
 
831
*     by placing himself into check
 
832
****************************************************************************/
 
833
{   
 
834
        uint count = 0;
 
835
        
 
836
    //Look up the column for an enemy Rook or Queen
 
837
    
 
838
    if(col != 7)
 
839
    {
 
840
        for(int i=col+1; i < 8; i++)
 
841
        {
 
842
            if(is_white)
 
843
            {
 
844
                if(_board[row][i].getColor() == WHITE)
 
845
                    break;
 
846
                if(   _board[row][i].getColor() == BLACK
 
847
                   &&(_board[row][i].getUnit() == ROOK
 
848
                   || _board[row][i].getUnit() == QUEEN) )
 
849
                    count++;
 
850
                if(_board[row][i].getColor() == BLACK)
 
851
                    break;
 
852
            }
 
853
            else
 
854
            {
 
855
                if(_board[row][i].getColor() == BLACK)
 
856
                    break;
 
857
                if(   _board[row][i].getColor() == WHITE
 
858
                   &&(_board[row][i].getUnit() == ROOK
 
859
                   || _board[row][i].getUnit() == QUEEN) )
 
860
                    count++;
 
861
                if(_board[row][i].getColor() == WHITE)
 
862
                    break;
 
863
            }
 
864
        }
 
865
    }
 
866
    //Look down the column for an enemy Rook or Queen
 
867
    if(col != 0)
 
868
    {
 
869
        for(int i=col-1; i >= 0; i--)
 
870
        {
 
871
            if(is_white)
 
872
            {
 
873
                if(_board[row][i].getColor() == WHITE)
 
874
                    break;
 
875
                if(   _board[row][i].getColor() == BLACK
 
876
                   &&(_board[row][i].getUnit() == ROOK
 
877
                   || _board[row][i].getUnit() == QUEEN) )
 
878
                    count++;
 
879
                if(_board[row][i].getColor() == BLACK)
 
880
                    break;
 
881
            }
 
882
            else
 
883
            {
 
884
                if(_board[row][i].getColor() == BLACK)
 
885
                    break;
 
886
                if(   _board[row][i].getColor() == WHITE
 
887
                   &&(_board[row][i].getUnit() == ROOK
 
888
                   || _board[row][i].getUnit() == QUEEN) )
 
889
                    count++;
 
890
                if(_board[row][i].getColor() == WHITE)
 
891
                    break;
 
892
            }
 
893
        }
 
894
    }
 
895
    //Look right across the rows for an enemy Rook or Queen
 
896
    if(row != 7)
 
897
    {
 
898
        for(int i=row+1; i < 8; i++)
 
899
        {
 
900
            if(is_white)
 
901
            {
 
902
                if(_board[i][col].getColor() == WHITE)
 
903
                    break;
 
904
                if(   _board[i][col].getColor() == BLACK
 
905
                   &&(_board[i][col].getUnit() == ROOK
 
906
                   || _board[i][col].getUnit() == QUEEN) )
 
907
                    count++;
 
908
                if(_board[i][col].getColor() == BLACK)
 
909
                    break;
 
910
            }
 
911
            else
 
912
            {
 
913
                if(_board[i][col].getColor() == BLACK)
 
914
                    break;
 
915
                if(   _board[i][col].getColor() == WHITE
 
916
                   &&(_board[i][col].getUnit() == ROOK
 
917
                   || _board[i][col].getUnit() == QUEEN) )
 
918
                    count++;
 
919
                if(_board[i][col].getColor() == WHITE)
 
920
                    break;
 
921
            }
 
922
        }
 
923
    }
 
924
    //Look left across the rows for an enemy Rook or Queen
 
925
    if(row != 0)
 
926
    {
 
927
        for(int i=row-1; i >= 0; i--)
 
928
        {
 
929
            if(is_white)
 
930
            {
 
931
                if(_board[i][col].getColor() == WHITE)
 
932
                    break;
 
933
                if(   _board[i][col].getColor() == BLACK
 
934
                   &&(_board[i][col].getUnit() == ROOK
 
935
                   || _board[i][col].getUnit() == QUEEN) )
 
936
                    count++;
 
937
                if(_board[i][col].getColor() == BLACK)
 
938
                    break;
 
939
            }
 
940
            else
 
941
            {
 
942
                if(_board[i][col].getColor() == BLACK)
 
943
                    break;
 
944
                if(   _board[i][col].getColor() == WHITE
 
945
                   &&(_board[i][col].getUnit() == ROOK
 
946
                   || _board[i][col].getUnit() == QUEEN) )
 
947
                    count++;
 
948
                if(_board[i][col].getColor() == WHITE)
 
949
                    break;
 
950
            }
 
951
        }
 
952
    }
 
953
    
 
954
    //Diagonal
 
955
    if(row != 7 && col != 7)
 
956
    {
 
957
        for(int i = 1; (row+i != 8 && col+i !=8); i++)
 
958
        {
 
959
            if(is_white)
 
960
            {
 
961
                if(_board[row+i][col+i].getColor() == WHITE)
 
962
                    break;
 
963
                if(   _board[row+i][col+i].getColor() == BLACK
 
964
                   &&(_board[row+i][col+i].getUnit() == BISHOP
 
965
                   || _board[row+i][col+i].getUnit() == QUEEN) )
 
966
                    count++;
 
967
                if(_board[row+i][col+i].getColor() == BLACK)
 
968
                    break;
 
969
            }
 
970
            else
 
971
            {
 
972
                if(_board[row+i][col+i].getColor() == BLACK)
 
973
                    break;
 
974
                if(   _board[row+i][col+i].getColor() == WHITE
 
975
                   &&(_board[row+i][col+i].getUnit() == BISHOP
 
976
                   || _board[row+i][col+i].getUnit() == QUEEN) )
 
977
                    count++;
 
978
                if(_board[row+i][col+i].getColor() == WHITE)
 
979
                    break;
 
980
            }
 
981
        }
 
982
    }
 
983
    if(row != 0 && col != 7)
 
984
    {
 
985
        for(int i = 1; (row-i >= 0 && col+i !=8); i++)
 
986
        {
 
987
            if(is_white)
 
988
            {
 
989
                if(_board[row-i][col+i].getColor() == WHITE)
 
990
                    break;
 
991
                if(   _board[row-i][col+i].getColor() == BLACK
 
992
                   &&(_board[row-i][col+i].getUnit() == BISHOP
 
993
                   || _board[row-i][col+i].getUnit() == QUEEN) )
 
994
                    count++;
 
995
                if(_board[row-i][col+i].getColor() == BLACK)
 
996
                    break;
 
997
            }
 
998
            else
 
999
            {
 
1000
                if(_board[row-i][col+i].getColor() == BLACK)
 
1001
                    break;
 
1002
                if(   _board[row-i][col+i].getColor() == WHITE
 
1003
                   &&(_board[row-i][col+i].getUnit() == BISHOP
 
1004
                   || _board[row-i][col+i].getUnit() == QUEEN) )
 
1005
                    count++;
 
1006
                if(_board[row-i][col+i].getColor() == WHITE)
 
1007
                    break;
 
1008
            }
 
1009
        }
 
1010
    }
 
1011
    if(row != 7 && col != 0)
 
1012
    {
 
1013
        for(int i = 1; (row+i != 8 && col-i >=0); i++)
 
1014
        {
 
1015
            if(is_white)
 
1016
            {
 
1017
                if(_board[row+i][col-i].getColor() == WHITE)
 
1018
                    break;
 
1019
                if(   _board[row+i][col-i].getColor() == BLACK
 
1020
                   &&(_board[row+i][col-i].getUnit() == BISHOP
 
1021
                   || _board[row+i][col-i].getUnit() == QUEEN) )
 
1022
                    count++;
 
1023
                if(_board[row+i][col-i].getColor() == BLACK)
 
1024
                    break;
 
1025
            }
 
1026
            else
 
1027
            {
 
1028
                if(_board[row+i][col-i].getColor() == BLACK)
 
1029
                    break;
 
1030
                if(   _board[row+i][col-i].getColor() == WHITE
 
1031
                   &&(_board[row+i][col-i].getUnit() == BISHOP
 
1032
                   || _board[row+i][col-i].getUnit() == QUEEN) )
 
1033
                    count++;
 
1034
                if(_board[row+i][col-i].getColor() == WHITE)
 
1035
                    break;
 
1036
            }
 
1037
        }
 
1038
    }
 
1039
    if(row != 0 && col != 0)
 
1040
    {
 
1041
        for(int i = 1; (row-i >=0 && col-i >=0); i++)
 
1042
        {
 
1043
            if(is_white)
 
1044
            {
 
1045
                if(_board[row-i][col-i].getColor() == WHITE)
 
1046
                    break;
 
1047
                if(   _board[row-i][col-i].getColor() == BLACK
 
1048
                   &&(_board[row-i][col-i].getUnit() == BISHOP
 
1049
                   || _board[row-i][col-i].getUnit() == QUEEN) )
 
1050
                    count++;
 
1051
                if(_board[row-i][col-i].getColor() == BLACK)
 
1052
                    break;
 
1053
            }
 
1054
            else
 
1055
            {
 
1056
                if(_board[row-i][col-i].getColor() == BLACK)
 
1057
                    break;
 
1058
                if(   _board[row-i][col-i].getColor() == WHITE
 
1059
                   &&(_board[row-i][col-i].getUnit() == BISHOP
 
1060
                   || _board[row-i][col-i].getUnit() == QUEEN) )
 
1061
                    count++;
 
1062
                if(_board[row-i][col-i].getColor() == WHITE)
 
1063
                    break;
 
1064
            }
 
1065
        }
 
1066
    }
 
1067
    
 
1068
    //Pawns
 
1069
    if(is_white)
 
1070
    {
 
1071
        if(row != 0 && col != 0)
 
1072
        {
 
1073
            if(_board[row-1][col-1].getUnit() == PAWN
 
1074
               && _board[row-1][col-1].getColor() == BLACK)
 
1075
               count++;
 
1076
        }
 
1077
        if(row != 0 && col != 7)
 
1078
        {
 
1079
            if(_board[row-1][col+1].getUnit() == PAWN
 
1080
               && _board[row-1][col+1].getColor() == BLACK)
 
1081
               count++;
 
1082
        }
 
1083
    }
 
1084
    else
 
1085
    {
 
1086
        if(row != 7 && col != 0)
 
1087
        {
 
1088
            if(_board[row+1][col-1].getUnit() == PAWN
 
1089
               && _board[row+1][col-1].getColor() == WHITE)
 
1090
               count++;
 
1091
        }
 
1092
        if(row != 7 && col != 7)
 
1093
        {
 
1094
            if(_board[row+1][col+1].getUnit() == PAWN
 
1095
               && _board[row+1][col+1].getColor() == WHITE)
 
1096
               count++;
 
1097
        }
 
1098
    }
 
1099
        
 
1100
        // Checking to see if any Knights are putting the king into check.
 
1101
        uint startrow = 0;
 
1102
        uint startcol = 0;
 
1103
        BoardMove knightOne(startrow, startcol, row+1, col+2);  
 
1104
        BoardMove knightTwo(startrow, startcol, row+1, col-2);  
 
1105
        BoardMove knightThr(startrow, startcol, row+2, col+1);  
 
1106
        BoardMove knightFou(startrow, startcol, row+2, col-1);  
 
1107
        BoardMove knightFiv(startrow, startcol, row-1, col+2);  
 
1108
        BoardMove knightSix(startrow, startcol, row-1, col-2);  
 
1109
        BoardMove knightSev(startrow, startcol, row-2, col+1);  
 
1110
        BoardMove knightEig(startrow, startcol, row-2, col-1);  
 
1111
        if (is_white)
 
1112
        {
 
1113
                if (Board::is_in(knightOne))
 
1114
                {
 
1115
                        if (   _board[row+1][col+2].getUnit() == KNIGHT
 
1116
                                && _board[row+1][col+2].getColor() == BLACK)
 
1117
                                count++;
 
1118
                }       
 
1119
                if (Board::is_in(knightTwo))
 
1120
                {
 
1121
                        if (   _board[row+1][col-2].getUnit() == KNIGHT
 
1122
                                && _board[row+1][col-2].getColor() == BLACK)
 
1123
                                count++;
 
1124
                }               
 
1125
                if (Board::is_in(knightThr))
 
1126
                {
 
1127
                        if (   _board[row+2][col+1].getUnit() == KNIGHT
 
1128
                                && _board[row+2][col+1].getColor() == BLACK)
 
1129
                                count++;
 
1130
                }
 
1131
                if (Board::is_in(knightFou))
 
1132
                {
 
1133
                        if (   _board[row+2][col-1].getUnit() == KNIGHT
 
1134
                                && _board[row+2][col-1].getColor() == BLACK)
 
1135
                                count++;
 
1136
                }
 
1137
                if (Board::is_in(knightFiv))
 
1138
                {
 
1139
                        if (   _board[row-1][col+2].getUnit() == KNIGHT
 
1140
                                && _board[row-1][col+2].getColor() == BLACK)
 
1141
                                count++;
 
1142
                }
 
1143
                if (Board::is_in(knightSix))
 
1144
                {
 
1145
                        if (   _board[row-1][col-2].getUnit() == KNIGHT
 
1146
                                && _board[row-1][col-2].getColor() == BLACK)
 
1147
                                count++;
 
1148
                }
 
1149
                if (Board::is_in(knightSev))
 
1150
                {
 
1151
                        if (   _board[row-2][col+1].getUnit() == KNIGHT
 
1152
                                && _board[row-2][col+1].getColor() == BLACK)
 
1153
                                count++;
 
1154
                }
 
1155
                if (Board::is_in(knightEig))
 
1156
                {
 
1157
                        if (   _board[row-2][col-1].getUnit() == KNIGHT
 
1158
                                && _board[row-2][col-1].getColor() == BLACK)
 
1159
                                count++;
 
1160
                }                       
 
1161
        }
 
1162
        else
 
1163
        {
 
1164
                if (Board::is_in(knightOne))
 
1165
                {
 
1166
                        if (   _board[row+1][col+2].getUnit() == KNIGHT
 
1167
                                && _board[row+1][col+2].getColor() == WHITE)
 
1168
                                count++;
 
1169
                }       
 
1170
                if (Board::is_in(knightTwo))
 
1171
                {
 
1172
                        if (   _board[row+1][col-2].getUnit() == KNIGHT
 
1173
                                && _board[row+1][col-2].getColor() == WHITE)
 
1174
                                count++;
 
1175
                }               
 
1176
                if (Board::is_in(knightThr))
 
1177
                {
 
1178
                        if (   _board[row+2][col+1].getUnit() == KNIGHT
 
1179
                                && _board[row+2][col+1].getColor() == WHITE)
 
1180
                                count++;
 
1181
                }
 
1182
                if (Board::is_in(knightFou))
 
1183
                {
 
1184
                        if (   _board[row+2][col-1].getUnit() == KNIGHT
 
1185
                                && _board[row+2][col-1].getColor() == WHITE)
 
1186
                                count++;
 
1187
                }
 
1188
                if (Board::is_in(knightFiv))
 
1189
                {
 
1190
                        if (   _board[row-1][col+2].getUnit() == KNIGHT
 
1191
                                && _board[row-1][col+2].getColor() == WHITE)
 
1192
                                count++;
 
1193
                }
 
1194
                if (Board::is_in(knightSix))
 
1195
                {
 
1196
                        if (   _board[row-1][col-2].getUnit() == KNIGHT
 
1197
                                && _board[row-1][col-2].getColor() == WHITE)
 
1198
                                count++;
 
1199
                }
 
1200
                if (Board::is_in(knightSev))
 
1201
                {
 
1202
                        if (   _board[row-2][col+1].getUnit() == KNIGHT
 
1203
                                && _board[row-2][col+1].getColor() == WHITE)
 
1204
                                count++;
 
1205
                }
 
1206
                if (Board::is_in(knightEig))
 
1207
                {
 
1208
                        if (   _board[row-2][col-1].getUnit() == KNIGHT
 
1209
                                && _board[row-2][col-1].getColor() == WHITE)
 
1210
                                count++;
 
1211
                }
 
1212
        }
 
1213
        
 
1214
        // Check to make sure a king isn't trying to move next to another king
 
1215
        if (is_white)
 
1216
        {
 
1217
                if (col != 7)
 
1218
                {
 
1219
                        if (row != 7)
 
1220
                        {
 
1221
                                if(   _board[row+1][col+1].getUnit() == KING
 
1222
                                   && _board[row+1][col+1].getColor() == BLACK)
 
1223
                                        count++;
 
1224
                        }
 
1225
                        if (   _board[row][col+1].getUnit() == KING
 
1226
                                && _board[row][col+1].getColor() == BLACK)
 
1227
                                count++;
 
1228
                        if (row != 0)
 
1229
                        {
 
1230
                                if(   _board[row-1][col+1].getUnit() == KING
 
1231
                                   && _board[row-1][col+1].getColor() == BLACK)
 
1232
                                        count++;
 
1233
                        }
 
1234
                }
 
1235
                if (row != 0)
 
1236
                {
 
1237
                        if(   _board[row-1][col].getUnit() == KING
 
1238
                           && _board[row-1][col].getColor() == BLACK)
 
1239
                                count++;
 
1240
                        if (col != 0)
 
1241
                        {
 
1242
                                if (   _board[row-1][col-1].getUnit() == KING
 
1243
                                        && _board[row-1][col-1].getColor() == BLACK)
 
1244
                                        count++;
 
1245
                        }
 
1246
                }
 
1247
                if (col != 0)
 
1248
                {
 
1249
                        if(   _board[row][col-1].getUnit() == KING
 
1250
                           && _board[row][col-1].getColor() == BLACK)
 
1251
                                count++;
 
1252
                        if (row != 7)
 
1253
                        {
 
1254
                                if(   _board[row+1][col-1].getUnit() == KING
 
1255
                                   && _board[row+1][col-1].getColor() == BLACK)
 
1256
                                        count++;
 
1257
                        }
 
1258
                }
 
1259
                if (row != 7)
 
1260
                { 
 
1261
                        if(   _board[row+1][col].getUnit() == KING
 
1262
                           && _board[row+1][col].getColor() == BLACK)
 
1263
                                count++;  
 
1264
                }
 
1265
        }
 
1266
        else
 
1267
        {
 
1268
                if (col != 7)
 
1269
                {
 
1270
                        if (row != 7)
 
1271
                        {
 
1272
                                if(   _board[row+1][col+1].getUnit() == KING
 
1273
                                   && _board[row+1][col+1].getColor() == WHITE)
 
1274
                                        count++;
 
1275
                        }
 
1276
                        if (   _board[row][col+1].getUnit() == KING
 
1277
                                && _board[row][col+1].getColor() == WHITE)
 
1278
                                count++;
 
1279
                        if (row != 0)
 
1280
                        {
 
1281
                                if(   _board[row-1][col+1].getUnit() == KING
 
1282
                                   && _board[row-1][col+1].getColor() == WHITE)
 
1283
                                        count++;
 
1284
                        }
 
1285
                }
 
1286
                if (row != 0)
 
1287
                {
 
1288
                        if(   _board[row-1][col].getUnit() == KING
 
1289
                           && _board[row-1][col].getColor() == WHITE)
 
1290
                                count++;
 
1291
                        if (col != 0)
 
1292
                        {
 
1293
                                if (   _board[row-1][col-1].getUnit() == KING
 
1294
                                        && _board[row-1][col-1].getColor() == WHITE)
 
1295
                                        count++;
 
1296
                        }
 
1297
                }
 
1298
                if (col != 0)
 
1299
                {
 
1300
                        if(   _board[row][col-1].getUnit() == KING
 
1301
                           && _board[row][col-1].getColor() == WHITE)
 
1302
                                count++;
 
1303
                        if (row != 7)
 
1304
                        {
 
1305
                                if(   _board[row+1][col-1].getUnit() == KING
 
1306
                                   && _board[row+1][col-1].getColor() == WHITE)
 
1307
                                        count++;
 
1308
                        }
 
1309
                }
 
1310
                if (row != 7)
 
1311
                { 
 
1312
                        if(   _board[row+1][col].getUnit() == KING
 
1313
                           && _board[row+1][col].getColor() == WHITE)
 
1314
                                count++;  
 
1315
                }
 
1316
        }
 
1317
        
 
1318
    return count;
 
1319
}
 
1320
 
 
1321
 
 
1322
bool
 
1323
Board::is_in(BoardMove move) const
 
1324
{
 
1325
    if(    move.getStartx() < 8 && move.getStartx() >=0
 
1326
                && move.getStarty() < 8 && move.getStarty() >=0
 
1327
            && move.getEndx() < 8 && move.getEndy() >= 0
 
1328
                && move.getEndy() < 8 && move.getEndy() >= 0   )
 
1329
                return true;
 
1330
        else
 
1331
                return false;
 
1332
}
 
1333
 
 
1334
// End of file board.cpp