-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
74 lines (68 loc) · 2.13 KB
/
main.cpp
File metadata and controls
74 lines (68 loc) · 2.13 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
#include <iostream>
#include "board.h"
#include "ai.h"
int main() {
int size, winLength, depth;
std::cout << "Podaj rozmiar planszy: ";
std::cin >> size;
if(size <= 1)
{
std::cout << "Za maly rozmiar tablicy";
return 1;
}
std::cout << "Podaj wymagana ilosc znakow w jednym ciagu aby wygrac: ";
std::cin >> winLength;
if (winLength > size || winLength < 0) {
std::cerr << "Wymagana ilosc znaków nie moze byc wieksza niz rozmiar planszy" << std::endl;
return 1;
}
std::cout << "Podaj glebokosc ai";
std::cin >> depth;
if(depth <= 0)
{
std::cout << "Za niska glebokoc" << std::endl;
return 1;
}
Board board(size, winLength);
AI ai('O', 'X', depth); // AI- O, Człowiek - X
char currentPlayer = 'X';
while (true) {
board.display();
if (currentPlayer == 'X') {
int row, col;
std::cout << "Gracz " << currentPlayer << ", podaj wiersz i kolumne: ";
std::cin >> row >> col;
if (board.makeMove(row, col, currentPlayer)) {
char winner = board.checkWin();
if (winner != ' ') {
board.display();
std::cout << "Gracz " << winner << " wygrywa!" << std::endl;
break;
}
if (board.isFull()) {
board.display();
std::cout << "Remis!" << std::endl;
break;
}
currentPlayer = 'O';
} else {
std::cout << "Nieprawidlowy ruch, sprobuj ponownie." << std::endl;
}
} else {
ai.makeMove(board);
char winner = board.checkWin();
if (winner != ' ') {
board.display();
std::cout << "Gracz " << winner << " wygrywa!" << std::endl;
break;
}
if (board.isFull()) {
board.display();
std::cout << "Remis!" << std::endl;
break;
}
currentPlayer = 'X';
}
}
return 0;
}