-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.cpp
More file actions
116 lines (113 loc) · 4.15 KB
/
ui.cpp
File metadata and controls
116 lines (113 loc) · 4.15 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
#include "ui.h"
#include<iostream>
#include<cstdlib>
#include<ctime>
#include <string>
#include<vector>
#include "game.h"
#include "element.h"
#include "minmax.h"
using namespace std;
void ui() {
srand(time(NULL));
while (true) {
int number, mode;//mode==type of stucture, number==operation
Game *game;
cout << "KOLKO I KRZYZYK" << endl;
cout << "START [1]" << endl;
cout << "ZAMKNIJ [0]" << endl << endl;
cout << "Wybor: ";
cin >> mode;
cout << endl;
bool start = true;//for closing ui
bool s;
switch (mode) {//making structure
case 1: {
int size = 0, win = 0, depth = 0;
while(size < 3 ) {
cout << "Podaj rozmiar planszy: ";
cin >> size;
if(size < 3) cout << "Podaj liczbe dodatnia, minimum 3"<< endl;
}
while(win < 3) {
cout << "Podaj ilosc znakow w rzedzie do wygranej: ";
cin >> win;
if (win < 3 or win >size) {
cout << "Minimalna liczba to 3, maksymalna to rozmiar planszy" << endl;
win = 0;
}
}
cout << endl << "Podaj glebokosc dzialania algorytmu (0 - auto-dobieranie): ";
cin >> depth;
if (depth < 1) cout << "autodobieranie" << endl;
MinMax minMax(win, depth);
game = new Game(size, win);
int t;
cout << "Wybierz znak ktorym chcesz grac: "<< endl;
cout << "KOLKO [0]"<< endl;
cout << "KRZYZYK [1]"<< endl;
cout << "Wybor: ";
cin >> t;
s = bool(t%2);
cout << endl;
int l=rand()%2;
int x = 0, y = 0;
if(l == 0){
cout << "Ruch komputera" << endl << endl;
game->computerMove(minMax.findBestMove(game->board));
game->printBoard(s);
}
else game->printBoard(s);
while (start == 1) {
while(x <= 0 or x > size and y <= 0 or y > size){
cout << endl<<"Podaj wspolrzedne x: ";
cin >> y;
cout << "Podaj wspolrzedne y: ";
cin >> x;
cout << endl;
if(x <= 0 or x > size or y <= 0 or y > size) {
cout << "Takie pole nie istnieje"<< endl;
x = 0;
y = 0;
}
else if (game->board[x - 1][y - 1] != EMPTY){
cout << "Zajete pole" << endl;
x = 0;
y = 0;
}
}
game->humanMove(x - 1, y - 1);
x = 0;
y = 0;
game->printBoard(s);
if (game->isWin() == 1) {
cout << "WYGRALES" << endl << endl;
start = 0;
break;
} else if (game->isWin() == 2) {
cout << "REMIS" << endl << endl;
start = 0;
break;
}
cout << "Ruch komputera" << endl << endl;
game->computerMove(minMax.findBestMove(game->board));
game->printBoard(s);
if (game->isWin() == 1) {
cout << "PRZEGRALES" << endl << endl;
start = 0;
break;
} else if (game->isWin() == 2) {
cout << "REMIS" << endl << endl;
start = 0;
break;
}
}
break;
}
default: {
cout << "Program zakonczony";
return;
}
}
}
}