-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboard.cpp
More file actions
674 lines (637 loc) · 22.9 KB
/
board.cpp
File metadata and controls
674 lines (637 loc) · 22.9 KB
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#include "board.h"
#include "ui_board.h"
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <QRandomGenerator>
#include <QDateTime>
#include <QMovie>
#include <QDebug>
#include <QMessageBox>
#include <QAbstractButton>
#include <QHBoxLayout>
#include "constants.h"
/**
* constructor
*
* @param plyr Player that will start the game
*/
Board::Board(Player* plyr, QWidget *parent) :
QDialog(parent),
currentPlayer(plyr),
ui(new Ui::Board)
{
ui->setupUi(this);
this->player = currentPlayer->getColor();
fields = new field[SIZE];
whiteBeat = blackBeat = false;
active = prevActive = -1;
white = black = 12;
if(player == Color::WHITE)
{
for(int i = 0; i < SIZE; ++i)
{
int row = i/static_cast<int>(sqrt(SIZE));
int column = i%static_cast<int>(sqrt(SIZE));
ui->gridChBoard->addWidget(fields[i].getCheckerbutton(), row, column);
fields[i].setCoordinate(i);
fields[i].getCheckerbutton()->indexChange(i);
modelBoard(i);
connect(fields[i].getCheckerbutton(), SIGNAL(clicked(int)), this, SLOT(isClicked(int)));
}
}
else
{
for(int i = SIZE-1; i >= 0; --i)
{
int row = static_cast<int>(sqrt(SIZE))-1-i/static_cast<int>(sqrt(SIZE));
int column = static_cast<int>(sqrt(SIZE))-1-i%static_cast<int>(sqrt(SIZE));
ui->gridChBoard->addWidget(fields[i].getCheckerbutton(), row, column);
fields[i].setCoordinate(i);
fields[i].getCheckerbutton()->indexChange(i);
modelBoard(i);
connect(fields[i].getCheckerbutton(), SIGNAL(clicked(int)), this, SLOT(isClicked(int)));
}
}
correctBoard();
}
/*!
* @brief copy constructor
*/
Board::Board(const Board& obj)
{
white = obj.white;
black = obj.black;
fields = new field[SIZE];
for(int i = 0; i < SIZE; ++i)
{
fields[i] = obj.fields[i];
}
active = obj.active;
prevActive = obj.prevActive;
whiteBeat = obj.whiteBeat;
blackBeat = obj.blackBeat;
whiteMove = obj.whiteMove;
blackMove = obj.blackMove;
whiteBeats = obj.whiteBeats;
blackBeats = obj.blackBeats;
player = obj.player;
isActive = obj.isActive;
currentPlayer = obj.currentPlayer;
}
/**
* @brief checks if the field is black
* @param i Index of the field
* @return true if field color is black, false if white
*/
bool Board::isBlackField(int i)
{
if((i%2 + i/static_cast<int>(sqrt(SIZE)))%2 == 0) return false;
return true;
}
/**
* @brief prepares board before the beginning of the game
sets appropriate figure on the field
* @param i Index of the field
*/
void Board::modelBoard(int i)
{
if(isBlackField(i))
{
fields[i].setColor((Color::BLACK)); //field is black
if(i < static_cast<int>(sqrt(SIZE))*3)
{
//black figures
Figure* figure = new Figure(Color::BLACK);
fields[i].setFigure(figure);
}
else if(i >= SIZE-static_cast<int>(sqrt(SIZE))*3)
{
//white figures
Figure* figure = new Figure(Color::WHITE);
fields[i].setFigure(figure);
}
}
fields[i].setPicture();
}
/**
* @brief Slot that is called when field is clicked on
* @param i Index of the field that was clicked
*/
void Board::isClicked(int i)
{
prevActive = active;
active = i;
//if player`s firt click was on empty field - do nothing
if(prevActive == -1 && (!fields[active].getFigure()||fields[active].getFigure()->getColor() != currentPlayer->getColor()))
return;
//if player`s figure was chosen and it was either first move or previous chosen field was empty
//mark chosen field and all possible moves
if((prevActive==-1 || !fields[prevActive].getFigure()) && fields[active].getFigure()
&& player == fields[active].getFigure()->getColor())
{
markField(active);
}
//if players figure was chosen and previous chosen field contained opponents figure
//mark chosen field and all possible moves
else if(fields[prevActive].getFigure()&&fields[prevActive].getFigure()->getColor() != player &&
fields[active].getFigure() && player == fields[active].getFigure()->getColor())
{
markField(active);
}
//if previous figure was player`s figure
else if(fields[prevActive].getFigure()&&fields[prevActive].getFigure()->getColor() == player)
{
deleteMark(prevActive);
//if chosen field is black and empty
if(!fields[active].getFigure() && isBlackField(active) && fields[prevActive].canMoveTo(active))
{
//move
move(prevActive, active);
}
else if(fields[active].getFigure() && fields[active].getFigure()->getColor() == player)
{
markField(active);
}
}
}
/**
* @brief Returns all the fields where a figure from the field i can move on
* @param i Index of the field for which possible moves are counted
* It is guaranteed that fieled i has a figure on it
* @return QVector<int> result of all possible moves
*/
QVector<int> Board::neighborFieldsToMove(int i)
{
QVector<int> result;
if(!fields[i].getFigure()) return result;
//if target field is black and free of figures and target field index is on the checker board and
//figure on given field is either king(can move in all directions or have certain color)
if(i-static_cast<int>(sqrt(SIZE))-1 >= 0 && isBlackField(i-static_cast<int>(sqrt(SIZE))-1)
&& !fields[i-static_cast<int>(sqrt(SIZE))-1].getFigure()
&&(fields[i].getFigure()->isKing()||fields[i].getFigure()->getColor() == Color::WHITE))
{
result.push_back(i-static_cast<int>(sqrt(SIZE))-1);
}
if(i+static_cast<int>(sqrt(SIZE))+1 < SIZE && isBlackField(i+static_cast<int>(sqrt(SIZE))+1)
&& !fields[i+static_cast<int>(sqrt(SIZE))+1].getFigure()
&&(fields[i].getFigure()->isKing()||fields[i].getFigure()->getColor() == Color::BLACK))
{
result.push_back(i+static_cast<int>(sqrt(SIZE))+1);
}
if(i-static_cast<int>(sqrt(SIZE))+1 >= 0 && isBlackField(i-static_cast<int>(sqrt(SIZE))+1)
&& !fields[i-static_cast<int>(sqrt(SIZE))+1].getFigure()
&&(fields[i].getFigure()->isKing()||fields[i].getFigure()->getColor() == Color::WHITE))
{
result.push_back(i-static_cast<int>(sqrt(SIZE))+1);
}
if(i+static_cast<int>(sqrt(SIZE))-1 < SIZE && isBlackField(i+static_cast<int>(sqrt(SIZE))-1)
&& !fields[i+static_cast<int>(sqrt(SIZE))-1].getFigure()
&&(fields[i].getFigure()->isKing()||fields[i].getFigure()->getColor() == Color::BLACK))
{
result.push_back(i+static_cast<int>(sqrt(SIZE))-1);
}
return result;
}
/**
* @brief Returns all the fields where a figure from the field i can beat on
* @param i Index of the field for which possible beats are counted
* It is guaranteed that fieled i has a figure on it
* @return QVector<int> result of all possible beats
*/
QVector<int> Board::neighborFieldsToBeat(int i)
{
QVector<int> result;
if(!fields[i].getFigure()) return result;
//if target field and via field indexes are on the checker board
//and target field is black and target field is free from other figures and
//via field has figure which color differs from given field figure
//and given figure is either king or can move in that diection
if(i-static_cast<int>(sqrt(SIZE))-1>=0 && i-2*static_cast<int>(sqrt(SIZE))-2>=0
&& isBlackField(i-static_cast<int>(sqrt(SIZE))*2-2) && !fields[i-2*static_cast<int>(sqrt(SIZE))-2].getFigure()
&& fields[i-static_cast<int>(sqrt(SIZE))-1].getFigure()
&& fields[i].getFigure()->getColor() != fields[i-static_cast<int>(sqrt(SIZE))-1].getFigure()->getColor()
&& (fields[i].getFigure()->isKing()||fields[i].getFigure()->getColor() == Color::WHITE))
{
result.push_back(i-2*static_cast<int>(sqrt(SIZE))-2);
}
if(i-static_cast<int>(sqrt(SIZE))+1>=0 && i-2*static_cast<int>(sqrt(SIZE))+2>=0
&& isBlackField(i-2*static_cast<int>(sqrt(SIZE))+2) && !fields[i-static_cast<int>(sqrt(SIZE))*2+2].getFigure()
&& fields[i-static_cast<int>(sqrt(SIZE))+1].getFigure()
&& fields[i].getFigure()->getColor() != fields[i-static_cast<int>(sqrt(SIZE))+1].getFigure()->getColor()
&& (fields[i].getFigure()->isKing()||fields[i].getFigure()->getColor() == Color::WHITE))
{
result.push_back(i-static_cast<int>(sqrt(SIZE))*2+2);
}
if(i+static_cast<int>(sqrt(SIZE))+1<SIZE && i+2*static_cast<int>(sqrt(SIZE))+2<SIZE
&& isBlackField(i+2*static_cast<int>(sqrt(SIZE))+2) && !fields[i+2*static_cast<int>(sqrt(SIZE))+2].getFigure()
&& fields[i+static_cast<int>(sqrt(SIZE))+1].getFigure()
&& fields[i].getFigure()->getColor() != fields[i+static_cast<int>(sqrt(SIZE))+1].getFigure()->getColor()
&& (fields[i].getFigure()->isKing()||fields[i].getFigure()->getColor() == Color::BLACK))
{
result.push_back(i+2*static_cast<int>(sqrt(SIZE))+2);
}
if(i+static_cast<int>(sqrt(SIZE))-1<SIZE && i+2*static_cast<int>(sqrt(SIZE))-2<SIZE
&& isBlackField(i+2*static_cast<int>(sqrt(SIZE))-2) && !fields[i+2*static_cast<int>(sqrt(SIZE))-2].getFigure()
&& fields[i+static_cast<int>(sqrt(SIZE))-1].getFigure()
&& fields[i].getFigure()->getColor() != fields[i+static_cast<int>(sqrt(SIZE))-1].getFigure()->getColor()
&& (fields[i].getFigure()->isKing()||fields[i].getFigure()->getColor() == Color::BLACK))
{
result.push_back(i+2*static_cast<int>(sqrt(SIZE))-2);
}
return result;
}
/**
* @brief Highlight the given field and all possible beats or moves from this field
* @param i Field which is needed to be marked
*/
void Board::markField(int i)
{
fields[i].markField();
//mark all fields that this figure can beat
if(!fields[i].beats.empty())
{
for(int j = 0; j < fields[i].beats.size(); ++j)
{
fields[fields[i].beats[j]].markField();
}
fields[i].moves.clear();
return;
}
//do nothing if player needs to beat but this figure cannot beat
if(whiteBeat && fields[i].getFigure()->getColor() == Color::WHITE)
{
fields[i].moves.clear();
return;
}
if(blackBeat && fields[i].getFigure()->getColor() == Color::BLACK)
{
fields[i].moves.clear();
return;
}
//mark all fields where figure can move
for(int j = 0; j < fields[i].moves.size(); ++j)
{
fields[fields[i].moves[j]].markField();
}
}
/**
* @brief Deletes mark from the given field and all possible beats or moves from this field
* @param i Field to delete its mark
*/
void Board::deleteMark(int i)
{
fields[i].unmarkField();
//unmark all fields that this figure can beat
if(!fields[i].beats.empty())
{
for(int j = 0; j < fields[i].beats.size(); ++j)
{
fields[fields[i].beats[j]].unmarkField();
}
}
//do nothing if player needs to beat but this figure cannot beat
if((whiteBeat && fields[i].getFigure()->getColor() == Color::WHITE)
|| (blackBeat&&fields[i].getFigure()->getColor()==Color::BLACK)) return;
//unmark all fields where figure can move
for(int j = 0; j < fields[i].moves.size(); ++j)
{
fields[fields[i].moves[j]].unmarkField();
}
}
/**
* @brief This function is called after every change on the board
* It updates values for each field on the board
*/
void Board::correctBoard()
{
whiteBeat = blackBeat = false;
whiteMove.clear();
blackMove.clear();
whiteBeats.clear();
blackBeats.clear();
/*figure need to continue to beat
it has possible beat moves and it`s previous move was beat
*/
if(active != -1 && !neighborFieldsToBeat(active).empty() && fields[active].getFigure()->getBeat())
{
currentPlayer->setCanMove(true);/*need to move again*/
if(fields[active].getFigure()->getColor() == Color::BLACK)
{
blackBeat = true; //set that black player have to beat
blackBeats.push_back(active); //set field that have to be beaten
}
else
{
whiteBeat = true; //set that white player have to beat
whiteBeats.push_back(active); //set field that have to be beaten
}
for(int i = 0; i < SIZE; ++i)
{
if(fields[i].getFigure())
{
fields[i].moves.clear();
fields[i].beats.clear();
fields[i].setBeat(false);
}
}
fields[active].setBeat(true);
fields[active].beats = neighborFieldsToBeat(active);
fields[active].moves.clear();
active = prevActive = -1;
return;
}
active = prevActive = -1;
/*for each field update its values*/
for(int i = 0; i < SIZE; ++i)
{
fields[i].setBeat(false);
fields[i].beats.clear();
fields[i].moves.clear();
if(fields[i].getFigure())
{
fields[i].getFigure()->setBeat(false);
fields[i].beats = neighborFieldsToBeat(i);//sets fields that must to be beat
if(!fields[i].beats.empty()) //if figure on this field must beat
{
fields[i].setBeat(true);
if(fields[i].getFigure()->getColor() == Color::WHITE)
{
whiteBeat = true;
whiteBeats.push_back(i);
}
else
{
blackBeat = true;
blackBeats.push_back(i);
}
}
fields[i].moves = neighborFieldsToMove(i);//sets all possible moves
//if figure has possible moves
//add figure to the possible moves on the board
if(!fields[i].moves.empty())
{
if(fields[i].getFigure()->getColor() == Color::WHITE)
{
whiteMove.push_back(i);
}
else
{
blackMove.push_back(i);
}
}
}
fields[i].setPicture();
}
if(whiteBeat) whiteMove.clear();
if(blackBeat) blackMove.clear();
gameEnd();// check if the game is not over
if(currentPlayer)currentPlayer->setCanMove(false);/*it is next player`s turn to move*/
}
/**
* @brief Counts the index of the field that must be beaten if figure moves from field with index 'from'
* to the field with index 'to'
* @param from Index of the field where figure starts its move
* @param to Index of the field where figure ends its move
* @return index of the field that must be beaten
* or -1 if it was not a beat move
*/
int Board::fieldToBeat(int from, int to)
{
int beat = -1;
if(to-from == -(2*static_cast<int>(sqrt(SIZE))+2)) beat = from-static_cast<int>(sqrt(SIZE))-1;
else if(to-from == -(2*static_cast<int>(sqrt(SIZE))-2)) beat = from-static_cast<int>(sqrt(SIZE))+1;
else if(to-from == 2*static_cast<int>(sqrt(SIZE))-2) beat = from+static_cast<int>(sqrt(SIZE))-1;
else if(to-from == 2*static_cast<int>(sqrt(SIZE))+2) beat = from+static_cast<int>(sqrt(SIZE))+1;
return beat;
}
/**
* @brief Move figures from the field with index from to the field with index to
* and updates their pictures
* @param from Index of the field where figure starts its move
* @param to Index of the field where figure ends its move
*/
void Board::move(int from, int to)
{
active = to;
prevActive = from;
// figure must beat
if(fields[from].getBeat())
{
fields[from].getFigure()->setBeat(true);
//calculate what field must be beaten
int beatField = fieldToBeat(from, to);
//decrease number of figures
if(fields[beatField].getFigure()->getColor() == Color::BLACK)
{
black--;
ui->blackNuber->setText("Black: "+QString::number(black));
}
else
{
white--;
ui->whiteNumber->setText("White: "+QString::number(white));
}
delete fields[beatField].getFigure();
fields[beatField].setFigure(nullptr);
fields[beatField].setPicture();
}
else {
fields[from].getFigure()->setBeat(false);
}
fields[to].setFigure(fields[from].getFigure());
fields[from].setFigure(nullptr);
/*set figure to be a king if it reached the line*/
if(fields[to].getFigure() && ((fields[to].getFigure()->getColor() == Color::BLACK && to/static_cast<int>(sqrt(SIZE)) == static_cast<int>(sqrt(SIZE))-1)
||(fields[to].getFigure()->getColor() == Color::WHITE && to/static_cast<int>(sqrt(SIZE)) == 0)))
{
fields[to].getFigure()->becomeKing();
}
fields[from].setPicture();
fields[to].setPicture();
correctBoard();
/*emit signal to inform that another player can move*/
if(!currentPlayer->isBot()) emit(moved(currentPlayer));
}
/**
* @brief Opposite to the function move()
* removes the figure from the field with index to and puts it on the field with index from
* @param from Index of the field where figure starts its move
* @param to Index of the field where figure ends its move
* @param wasKing Is true if the figure on the field with index to was a king before this move
* @param king True if the figure on the field with index to is a king
* @param hadBeat True if during the previous move figure had to beat
*/
void Board::undoMove(int from, int to, bool wasKing, bool king, bool hadBeat)
{
active = to;
prevActive = from;
int beatField = fieldToBeat(from, to);
if(beatField != -1)
{
Figure *figure = nullptr;
if(fields[to].getFigure()->getColor() == Color::WHITE)
{
black++;
ui->blackNuber->setText("Black: "+QString::number(black));
figure = new Figure(Color::BLACK);
}
else
{
white++;
ui->whiteNumber->setText("White: "+QString::number(white));
figure = new Figure(Color::WHITE);
}
figure->setKing(king);
figure->setBeat(false);
fields[beatField].setFigure(figure);
fields[beatField].setPicture();
}
//wasKing - переменная которая показывает была ли фигура которая сейчас стоит на поле to ранее дамкой,
//если же была то при отмене хода она и должна остаться дамкой
/*set figure to be a king if it reached the line*/
if(fields[to].getFigure() && ((fields[to].getFigure()->getColor() == Color::BLACK && to/static_cast<int>(sqrt(SIZE)) == static_cast<int>(sqrt(SIZE))-1)
||(fields[to].getFigure()->getColor() == Color::WHITE && to/static_cast<int>(sqrt(SIZE)) == 0)) && !wasKing)
{
fields[to].getFigure()->removeKing();
}
fields[from].setFigure(fields[to].getFigure());
fields[to].setFigure(nullptr);
fields[from].getFigure()->setBeat(hadBeat);
fields[from].setPicture();
fields[to].setPicture();
active = from;
correctBoard();
}
/**
* @brief Sets if the fields will react on the mouse click
* @param active True if fields should react on the mouse click
*/
void Board::setActivity(bool active)
{
isActive = active;
for(int i = 0; i < SIZE; ++i)
{
fields[i].setActive(active);
}
}
/**
* @brief Indicates that the game is over
*/
void Board::gameEnd()
{
Color color = currentPlayer->getColor();
/*black player finished his moves and white player does not have any possible moves*/
if(color == Color::BLACK)
{
if(whiteMove.empty() && whiteBeats.empty()) emit end();
}
/*white player finished his moves and black player does not have any possible moves*/
else
{
if(blackMove.empty() && blackBeats.empty()) emit end();
}
}
/**
* @brief Evaluates the current state of the board
* Is used in Minimax algorithm
* @param maximizer Color of the player who wants to maximize score
* @return int score that is the evaluation of the board`s state
*/
int Board::evaluateBoard(Color maximizer)
{
int score = 0;
for(int i = 0; i < SIZE; ++i)
{
/*evaluating a score based on the field itself*/
if(!fields[i].getFigure()) score += 0;
else if(fields[i].getFigure()->getColor() == maximizer && fields[i].getFigure()->isKing())
{
score += 20;
}
else if(fields[i].getFigure()->getColor() != maximizer && fields[i].getFigure()->isKing())
{
score += -20;
}
else if(fields[i].getFigure()->getColor() == maximizer)
{
score += 10;
}
else if(fields[i].getFigure()->getColor() != maximizer)
{
score += -10;
}
/*evaluating a score based on the figures position*/
if(i % static_cast<int>(sqrt(SIZE)) == 0
||i % static_cast<int>(sqrt(SIZE)) == static_cast<int>(sqrt(SIZE))-1
|| i < static_cast<int>(sqrt(SIZE))
|| i >= SIZE-static_cast<int>(sqrt(SIZE)))
{
if(fields[i].getFigure() && fields[i].getFigure()->getColor() == maximizer)
{
score += 4;
}
else if(fields[i].getFigure() && fields[i].getFigure()->getColor() != maximizer)
{
score += -4;
}
}
}
/*there are no possible moves*/
if(maximizer == Color::WHITE && whiteMove.empty() && whiteBeats.empty() && currentPlayer->getColor()==maximizer)
{
score += -100;
}
else if(maximizer == Color::BLACK && whiteMove.empty() && whiteBeats.empty() && currentPlayer->getColor() != maximizer)
{
score += 100;
}
else if(maximizer == Color::WHITE && blackMove.empty() && blackBeats.empty() && currentPlayer->getColor()!=maximizer)
{
score += 100;
}
else if(maximizer == Color::BLACK && blackMove.empty() && blackBeats.empty() && currentPlayer->getColor()==maximizer)
{
score += -100;
}
/*pieces that are threatened by current player*/
if(maximizer == Color::BLACK)
{
int beats = 0;
for(int j = 0; j < blackBeats.size(); ++j)
{
beats += fields[blackBeats[j]].beats.size();
}
score += 10*beats;
beats = 0;
for(int j = 0; j < whiteBeats.size(); ++j)
{
beats += fields[whiteBeats[j]].beats.size();
}
score += -10*beats;
}
else
{
int beats = 0;
for(int j = 0; j < whiteBeats.size(); ++j)
{
beats += fields[whiteBeats[j]].beats.size();
}
score += 10*beats;
beats = 0;
for(int j = 0; j < blackBeats.size(); ++j)
{
beats += fields[blackBeats[j]].beats.size();
}
score += -10*beats;
}
return score;
}
/**
* @brief destructor
*/
Board::~Board()
{
delete [] fields;
}