-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogic.cpp
More file actions
72 lines (64 loc) · 1.26 KB
/
logic.cpp
File metadata and controls
72 lines (64 loc) · 1.26 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
#include "logic.h"
#include <QDebug> // for dbg
#define SIZE 8
int board[8][8];
QVector<QVector<QVector<int> > > boards;
Logic::Logic()
{
/* Empty constructor */
}
bool Logic::tryQueen(int a, int b)
{
for(int i = 0; i < a; ++i)
{
if(board[i][b])
{
return false;
}
}
for(int i = 1; i <= a && b-i >= 0; ++i)
{
if(board[a-i][b-i])
{
return false;
}
}
for(int i = 1; i <= a && b+i < SIZE; i++)
{
if(board[a-i][b+i])
{
return false;
}
}
return true;
}
void Logic::setQueen(int a)
{
if(a == SIZE)
{
QVector<QVector<int> > temp2;
for(int a = 0; a < SIZE; ++a)
{
QVector<int> temp;
for(int b = 0; b < SIZE; ++b)
{
temp.push_back((board[a][b]) ? 1 : 0);
}
temp2.push_back(temp);
}
boards.push_back(temp2);
}
for(int i = 0; i < SIZE; ++i)
{
if(tryQueen(a, i))
{
board[a][i] = 1;
setQueen(a+1);
board[a][i] = 0;
}
}
}
Logic::~Logic()
{
/* Empty destructor */
}