forked from kbuffardi/ConnectX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectX.cpp.gcov~
209 lines (209 loc) · 6.92 KB
/
ConnectX.cpp.gcov~
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
-: 0:Source:ConnectX.cpp
-: 0:Graph:ConnectX.gcno
-: 0:Data:ConnectX.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:#include "ConnectX.h"
-: 2:#include <iostream>
-: 3:
-: 4:// constructor provides customized dimensions and number of
-: 5:// sequential pieces (x) it takes to win the game
function _ZN8ConnectXC2Eiii called 19 returned 100% blocks executed 100%
19: 6:ConnectX::ConnectX(int wide, int high, int x)
call 0 returned 100%
-: 7:{
-: 8: //invalid input resets everything to default settings
19: 9: if( wide <= 0 || high <= 0 || x <= 0)
branch 0 taken 89% (fallthrough)
branch 1 taken 11%
branch 2 taken 94% (fallthrough)
branch 3 taken 6%
branch 4 taken 6% (fallthrough)
branch 5 taken 94%
-: 10: {
4: 11: wide=DEFAULT_WIDTH;
4: 12: high=DEFAULT_HEIGHT;
4: 13: x=DEFAULT_TO_WIN;
-: 14: }
-: 15:
19: 16: board.resize(high);
call 0 returned 100%
127: 17: for(int i=0; i<high; i++)
branch 0 taken 85% (fallthrough)
branch 1 taken 15%
-: 18: {
108: 19: board[i].resize(wide);
call 0 returned 100%
call 1 returned 100%
852: 20: for(int j=0; j<wide; j++)
branch 0 taken 87% (fallthrough)
branch 1 taken 13%
-: 21: {
744: 22: board[i][j] = EMPTY;
call 0 returned 100%
call 1 returned 100%
-: 23: }
-: 24: }
19: 25: width = wide;
19: 26: height = high;
19: 27: toWin = x;
19: 28: turn = BLACK;
19: 29:}
-: 30:
-: 31:// changes turn to reflect whose turn it is
function _ZN8ConnectX10toggleTurnEv called 27 returned 100% blocks executed 100%
27: 32:void ConnectX::toggleTurn()
-: 33:{
27: 34: if(turn == WHITE)
branch 0 taken 22% (fallthrough)
branch 1 taken 78%
-: 35: {
6: 36: turn = BLACK;
-: 37: }
-: 38: else
21: 39: turn = WHITE;
27: 40:}
-: 41:
-: 42:// returns whether or not the provided location is a valid
-: 43:// space in the board
function _ZN8ConnectX8inBoundsEii called 93 returned 100% blocks executed 100%
93: 44:bool ConnectX::inBounds(int w, int h)
-: 45:{
-: 46: bool inside;
93: 47: if( w>=width || w<0 )
branch 0 taken 86% (fallthrough)
branch 1 taken 14%
branch 2 taken 3% (fallthrough)
branch 3 taken 98%
15: 48: inside = false;
-: 49: else
78: 50: inside = true;
-: 51:
93: 52: if( h<0 || h>=height )
branch 0 taken 98% (fallthrough)
branch 1 taken 2%
branch 2 taken 3% (fallthrough)
branch 3 taken 97%
5: 53: inside = false;
-: 54: else
88: 55: inside = true;
-: 56:
93: 57: return inside;
-: 58:}
-: 59:
-: 60:// Prints out the board to the command line, showing both
-: 61:// empty places and where each player has placed pieces
function _ZN8ConnectX9showBoardEv called 1 returned 100% blocks executed 100%
1: 62:void ConnectX::showBoard()
-: 63:{
1: 64: std::cout<<" ";
call 0 returned 100%
3: 65: for(int w = 0; w < width; w++)
branch 0 taken 67% (fallthrough)
branch 1 taken 33%
-: 66: {
2: 67: std::cout<<"["<<w<<"]";
call 0 returned 100%
call 1 returned 100%
call 2 returned 100%
-: 68: }
1: 69: std::cout<<std::endl;
call 0 returned 100%
3: 70: for(int h = 0; h < height; h++)
branch 0 taken 67% (fallthrough)
branch 1 taken 33%
-: 71: {
2: 72: std::cout<<"["<<h<<"]";
call 0 returned 100%
call 1 returned 100%
call 2 returned 100%
6: 73: for(int w = 0; w < width; w++)
branch 0 taken 67% (fallthrough)
branch 1 taken 33%
-: 74: {
-: 75: char place;
4: 76: Piece val = at(w,h);
call 0 returned 100%
4: 77: if(val == BLACK)
branch 0 taken 25% (fallthrough)
branch 1 taken 75%
1: 78: place = 'B';
3: 79: else if( val == WHITE )
branch 0 taken 33% (fallthrough)
branch 1 taken 67%
1: 80: place = 'W';
-: 81: else
2: 82: place = ' ';
4: 83: std::cout<<"["<<place<<"]";
call 0 returned 100%
call 1 returned 100%
call 2 returned 100%
-: 84: }
2: 85: std::cout<<std::endl;
call 0 returned 100%
-: 86: }
1: 87:}
-: 88:
-: 89:// Returns whose turn it is (BLACK or WHITE)
function _ZN8ConnectX9whoseTurnEv called 0 returned 0% blocks executed 0%
#####: 90:Piece ConnectX::whoseTurn()
-: 91:{
#####: 92: return turn;
-: 93:}
-: 94:
-: 95:// Retrieves the value at a provided (w,h) location in the board or returns
-: 96:// INVALID if the provided location is not within the board
function _ZN8ConnectX2atEii called 69 returned 100% blocks executed 100%
69: 97:Piece ConnectX::at(int w, int h)
-: 98:{
69: 99: if( inBounds(w,h) )
call 0 returned 100%
branch 1 taken 93% (fallthrough)
branch 2 taken 7%
-: 100: {
64: 101: return board[h][w];
call 0 returned 100%
call 1 returned 100%
-: 102: }
-: 103: else
5: 104: return INVALID;
-: 105:}
-: 106:
-: 107:// Puts the current player's piece in a vertical column, where the piece falls
-: 108:// to the lowest empty position available in the board. Placing a piece in a
-: 109:// "bad" column (such as a column that doesn't exist or is already full of
-: 110:// pieces) results in the player just losing their turn
function _ZN8ConnectX10placePieceEi called 27 returned 100% blocks executed 100%
27: 111:void ConnectX::placePiece(int column)
-: 112:{
41: 113: for(int i=height-1; i>=0; i--)
branch 0 taken 93% (fallthrough)
branch 1 taken 7%
-: 114: {
38: 115: if( at(column,i) == EMPTY && inBounds(column,i) )
call 0 returned 100%
branch 1 taken 63% (fallthrough)
branch 2 taken 37%
call 3 returned 100%
branch 4 taken 100% (fallthrough)
branch 5 taken 0%
branch 6 taken 63% (fallthrough)
branch 7 taken 37%
-: 116: {
24: 117: board[i][column] = turn;
call 0 returned 100%
call 1 returned 100%
24: 118: break;
-: 119: }
-: 120: }
-: 121:
27: 122: toggleTurn();
call 0 returned 100%
function _GLOBAL__sub_I__ZN8ConnectXC2Eiii called 1 returned 100% blocks executed 100%
function _Z41__static_initialization_and_destruction_0ii called 1 returned 100% blocks executed 100%
30: 123:}
call 0 returned 100%
branch 1 taken 100% (fallthrough)
branch 2 taken 0%
branch 3 taken 100% (fallthrough)
branch 4 taken 0%