/
input.h
56 lines (47 loc) · 1.04 KB
/
input.h
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
#ifndef INPUT_H
#define INPUT_H
#include <bits/stdc++.h>
#include <stdlib.h>
#include "board.h"
using namespace std;
vector<string> tokenize(string input){
vector<string> ret;
string temp = "";
for(int i = 0; i <= input.length(); i++){
if(i == input.length() - 1){
temp += input[i];
}
if(input[i] == ' ' || i == input.length() - 1){
ret.push_back(temp);
temp = "";
}else{
temp += input[i];
}
}
return ret;
}
string pause(bool isPlayer1) {
cin.clear();
cout << flush;
string command;
getline(cin, command);
vector<string> commands = tokenize(command);
if(command == "exit"){
cout << "Exiting...\n";
exit(0);
}else if(command == "moves"){
cout << moveLog << "\n";
}
if(commands[0] == "preview" && commands.size() == 2 && commands[1].length() == 2){
PrintPreview(commands[1]);
}
command.erase(remove(command.begin(), command.end(), ' '), command.end());
if(checkMove(command, isPlayer1)){
return command;
}else{
return pause(isPlayer1);
}
system("clear");
return command;
}
#endif