-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
97 lines (95 loc) · 1.94 KB
/
main.cpp
File metadata and controls
97 lines (95 loc) · 1.94 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
#include <iostream>
#include "gamestate.hpp"
#include "bruteforce.hpp"
void clear() // ceilingfans
{
#ifndef _WIN32
system("clear");
#else
system("cls");
#endif /* _WIN32 */
}
int main()
{
us moves = 0;
while (moves < 2)
{
clear();
std::cout << "size of set of possible moves (int): ";
std::cin >> moves;
}
us length = 0;
while (length < 1)
{
clear();
std::cout << "length of substrings (int): ";
std::cin >> length;
}
std::string trackcalls;
while (true)
{
clear();
std::cout << "would you like to track number of recursive function calls? (y/n) ";
std::cin >> trackcalls;
if (trackcalls == (std::string) "y")
{
showcalls = true;
break;
}
else if (trackcalls == (std::string) "n")
{
showcalls = false;
break;
}
}
gamestate gs0(moves, length);
std::string userstartstr;
us userno;
while (true)
{
clear();
std::cout << "would you like to start first? (y/n) ";
std::cin >> userstartstr;
if (userstartstr == (std::string) "y")
{
userno = 1;
break;
}
else if (userstartstr == (std::string) "n")
{
userno = 2;
gs0.advance(0);
break;
}
}
bool gamerunning = true;
us move = gs0.maxmove;
clear();
while (gamerunning)
{
std::cout << "current string: " << gs0.getstring() << std::endl;
std::cout << "available moves: " << join(gs0.alllegal()) << std::endl;
std::cout << "your move: ";
std::cin >> move;
while (!gs0.legal(move))
{
clear();
std::cout << "illegal move" << std::endl;
std::cout << gs0.getstring() << std::endl;
std::cout << join(gs0.alllegal()) << std::endl;
std::cout << "your move: ";
std::cin >> move;
}
gs0.advance(move);
clear();
if (gs0.alllegal().size()!=0)
{
move = bruteforce(gs0);
gs0.advance(move);
}
gamerunning = gs0.alllegal().size()!=0;
}
clear();
std::cout << gs0.getstring() << std::endl;
std::cout << "player " << 3-gs0.getplayer() << ((userno==gs0.getplayer())?" (computer)":" (human)") << " wins" << std::endl;
}