-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathttt.cpp
More file actions
87 lines (65 loc) · 1.62 KB
/
ttt.cpp
File metadata and controls
87 lines (65 loc) · 1.62 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
#include <iostream>
#include <array>
#include<vector>
#include "helper.hpp"
/**
* Author: Naomi Lambert
*
* Main classs responsible for the execution of the main game loop
*/
int main() {
welcome();
// constants to hold the player numbers
int const player1 = 1;
int const player2 = 2;
//variable to hold the final winner
int winner = 0;
//whether or not the end of the game has been reached
bool end_of_game = false;
std::vector<std::string> valid_moves;
set_valid_moves(valid_moves);
std::vector<std::array<int,3> > winning_moves;
set_winning_moves(winning_moves);
std::vector<std::string> board;
for (int i = 0; i <10; i++) {
board.push_back(" ");
}
while (!end_of_game) {
print_board(board);
std::string move_player1;
std::string move_player2;
int move_p1;
while (!is_valid_move(valid_moves, move_player1, move_p1)) {
std::cout << "Player 1: ";
std::cin >> move_player1;
if (move_player1 == "Q") {
exit(0);
}
}
make_move(player1, move_p1, board);
remove_move(move_player1, valid_moves);
print_board(board);
if (is_winning_board(board, winning_moves, winner)) {
end_of_game = true;
break;
}
int move_p2;
while (!is_valid_move(valid_moves, move_player2, move_p2)) {
std::cout << "Player 2: ";
std::cin >> move_player2;
if (move_player2 == "Q") {
exit(0);
}
}
make_move(player2, move_p2, board);
remove_move(move_player2, valid_moves);
print_board(board);
if (is_winning_board(board, winning_moves, winner)) {
end_of_game = true;
break;
}
if (end_of_game) {
std::cout << "The winner is Player " << winner << "!\n";
}
}
}