-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchessboard.h
80 lines (63 loc) · 2.34 KB
/
chessboard.h
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
#ifndef CHESSBOARD_H
#define CHESSBOARD_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QMenuBar>
#include <QLabel>
#include "utils.h"
#include "queen.h"
class ChessBoard : public QGraphicsView {
Q_OBJECT
public:
explicit ChessBoard(QWidget *parent = nullptr);
void setBoardSize(int size);
void drawBoard();
void addQueen(int row, int col);
bool checkConflicts();
void solvePuzzle();
void resetGame();
void clearQueens();
signals:
void queenMoved(); // Emitted whenever a queen is moved
private slots:
void performHintMove(int fromRow, int fromCol, int toRow, int toCol);
private:
QGraphicsScene *scene;
int boardSize; // Dynamic board size
bool boardNeedsRedraw; // flag to only redraw squares if necessary
QList<Queen *> queens;
void onQueenDropped(int row, int col);
bool isQueenAt(int row, int col);
void removeQueen(int row, int col);
struct Hint {
int fromRow;
int fromCol;
int toRow;
int toCol;
QColor color;
QString description;
};
void showHint(); // Show a hint "sound system" ye ! !!
int calculateConflicts();
int calculateConflictsAt(int row, int col);
bool suggestLeastConflictMove(QList<ChessBoard::Hint>& hints);
bool suggestConflictBreaker(QList<ChessBoard::Hint>& hints);
Queen* findQueenWithMostConflicts();
int calculateConflictsForQueen(Queen* targetQueen);
bool suggestRandomMove(QList<ChessBoard::Hint>& hints);
bool canCreateFutureSafeMove(Queen *movedQueen);
bool suggestFutureSafeMove(QList<ChessBoard::Hint>& hints);
QPair<int, int> findSafeMoveForQueen(Queen *queen);
bool isBlocking(Queen *queen);
bool isSquareSafe(Queen *ignoreQueen, int row, int col);
std::vector<std::pair<int, int>> findSolution();
bool solveBacktrack(std::vector<int>& board, int row, std::vector<std::pair<int, int>>& solution);
bool isSafe(const std::vector<int>& board, int row, int col);
void highlightSquare(int row, int col, QColor color); // Helper function to highlight a square
void resetChronometer();
void updateChronometer();
QTimer *chronometerTimer; // Timer for the chronometer
QLabel *chronometerLabel; // Label to display the chronometer
int elapsedSeconds; // Keeps track of elapsed time
};
#endif // CHESSBOARD_H