-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.cpp
More file actions
67 lines (57 loc) · 1.41 KB
/
game.cpp
File metadata and controls
67 lines (57 loc) · 1.41 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
#include <cstdio>
#include <iostream>
#include <stdexcept>
#include <vector>
#include "mefisto.h"
#include "mastermind.h"
#include "readint.h"
using namespace std;
/***
* Funkce, která načte ze vstupu číslo
* (opakuje pokusy dokud neuspěje)
* @return - načtené číslo
*/
int reader() {
int n;
int check = 0;
while (!check) {
check = 1;
try {
n = read_int(0);
}
catch (runtime_error e) {
cout << e.what();
check = 0;
}
}
return n;
}
int main() {
int pegs, colors, mef_ai;
// Načítání parametrů hry
cout << "Zadejte počet barev: ";
colors = reader();
cout << "Zadejte počet kolíků: ";
pegs = reader();
cout << "Vyberte si AI proti kterému chcete hrát:\n";
cout << "0 - Náhodný (obvyklá hra)\n";
cout << "1 - MinMax (nevhodný pro velké hry)\n";
cout << "2 - Omezený MinMax\n";
do {
cout << "Zadejte identifikační číslo příslušného AI: ";
mef_ai = reader();
} while (mef_ai > 2);
Mefisto mefisto(mef_ai, colors, pegs);
Mastermind mastermind(colors, pegs);
int turns = 0;
vector<int> packet(pegs); // Paměť, ve které si Mastermind a Mefisto předávají data
while (!mefisto.is_correct()) {
// Smyčka komunikace mezi Mastermindem a Mefistem dokud se nevyhraje hra
mastermind.get_query(packet);
mefisto.get_reply(packet);
mastermind.send_reply(packet);
++turns;
}
cout << "Vyhráli jste! Počet tahů: " << turns << std::endl;
return 0;
}