|
18 | 18 | },
|
19 | 19 | {
|
20 | 20 | "cell_type": "code",
|
21 |
| - "execution_count": 2, |
22 |
| - "metadata": {}, |
| 21 | + "execution_count": 1, |
| 22 | + "metadata": { |
| 23 | + "collapsed": true |
| 24 | + }, |
23 | 25 | "outputs": [],
|
24 | 26 | "source": [
|
25 | 27 | "from IPython.display import clear_output\n",
|
|
44 | 46 | "cell_type": "markdown",
|
45 | 47 | "metadata": {},
|
46 | 48 | "source": [
|
47 |
| - "<font color='red'>Note that we're only *defining* a function to display the board. We create the board and run this function much later in our code!</font>" |
| 49 | + "**TEST Step 1:** run your function on a test version of the board list, and make adjustments as necessary" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": 2, |
| 55 | + "metadata": { |
| 56 | + "collapsed": false |
| 57 | + }, |
| 58 | + "outputs": [ |
| 59 | + { |
| 60 | + "name": "stdout", |
| 61 | + "output_type": "stream", |
| 62 | + "text": [ |
| 63 | + " | |\n", |
| 64 | + " X | O | X\n", |
| 65 | + " | |\n", |
| 66 | + "-----------\n", |
| 67 | + " | |\n", |
| 68 | + " O | X | O\n", |
| 69 | + " | |\n", |
| 70 | + "-----------\n", |
| 71 | + " | |\n", |
| 72 | + " X | O | X\n", |
| 73 | + " | |\n" |
| 74 | + ] |
| 75 | + } |
| 76 | + ], |
| 77 | + "source": [ |
| 78 | + "test_board = ['#','X','O','X','O','X','O','X','O','X']\n", |
| 79 | + "display_board(test_board)" |
48 | 80 | ]
|
49 | 81 | },
|
50 | 82 | {
|
|
57 | 89 | {
|
58 | 90 | "cell_type": "code",
|
59 | 91 | "execution_count": 3,
|
60 |
| - "metadata": {}, |
| 92 | + "metadata": { |
| 93 | + "collapsed": true |
| 94 | + }, |
61 | 95 | "outputs": [],
|
62 | 96 | "source": [
|
63 | 97 | "def player_input():\n",
|
64 | 98 | " marker = ''\n",
|
65 | 99 | " \n",
|
66 | 100 | " while not (marker == 'X' or marker == 'O'):\n",
|
67 |
| - " marker = input('Player 1: Do you want to be X or O?').upper()\n", |
| 101 | + " marker = input('Player 1: Do you want to be X or O? ').upper()\n", |
68 | 102 | "\n",
|
69 | 103 | " if marker == 'X':\n",
|
70 | 104 | " return ('X', 'O')\n",
|
|
76 | 110 | "cell_type": "markdown",
|
77 | 111 | "metadata": {},
|
78 | 112 | "source": [
|
79 |
| - "**Step 3: Write a function that takes in the board list object, a marker ('X' or 'O'), and a desired position (number 1-9) and assigns it to the board.**" |
| 113 | + "**TEST Step 2:** run the function to make sure it returns the desired output" |
80 | 114 | ]
|
81 | 115 | },
|
82 | 116 | {
|
83 | 117 | "cell_type": "code",
|
84 | 118 | "execution_count": 4,
|
| 119 | + "metadata": { |
| 120 | + "collapsed": false |
| 121 | + }, |
| 122 | + "outputs": [ |
| 123 | + { |
| 124 | + "name": "stdout", |
| 125 | + "output_type": "stream", |
| 126 | + "text": [ |
| 127 | + "Player 1: Do you want to be X or O? X\n" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "data": { |
| 132 | + "text/plain": [ |
| 133 | + "('X', 'O')" |
| 134 | + ] |
| 135 | + }, |
| 136 | + "execution_count": 4, |
| 137 | + "metadata": {}, |
| 138 | + "output_type": "execute_result" |
| 139 | + } |
| 140 | + ], |
| 141 | + "source": [ |
| 142 | + "player_input()" |
| 143 | + ] |
| 144 | + }, |
| 145 | + { |
| 146 | + "cell_type": "markdown", |
85 | 147 | "metadata": {},
|
| 148 | + "source": [ |
| 149 | + "**Step 3: Write a function that takes in the board list object, a marker ('X' or 'O'), and a desired position (number 1-9) and assigns it to the board.**" |
| 150 | + ] |
| 151 | + }, |
| 152 | + { |
| 153 | + "cell_type": "code", |
| 154 | + "execution_count": 5, |
| 155 | + "metadata": { |
| 156 | + "collapsed": true |
| 157 | + }, |
86 | 158 | "outputs": [],
|
87 | 159 | "source": [
|
88 | 160 | "def place_marker(board, marker, position):\n",
|
|
93 | 165 | "cell_type": "markdown",
|
94 | 166 | "metadata": {},
|
95 | 167 | "source": [
|
96 |
| - "**Step 4: Write a function that takes in a board and checks to see if someone has won. **" |
| 168 | + "**TEST Step 3:** run the place marker function using test parameters and display the modified board" |
97 | 169 | ]
|
98 | 170 | },
|
99 | 171 | {
|
100 | 172 | "cell_type": "code",
|
101 |
| - "execution_count": 5, |
| 173 | + "execution_count": 6, |
| 174 | + "metadata": { |
| 175 | + "collapsed": false |
| 176 | + }, |
| 177 | + "outputs": [ |
| 178 | + { |
| 179 | + "name": "stdout", |
| 180 | + "output_type": "stream", |
| 181 | + "text": [ |
| 182 | + " | |\n", |
| 183 | + " X | $ | X\n", |
| 184 | + " | |\n", |
| 185 | + "-----------\n", |
| 186 | + " | |\n", |
| 187 | + " O | X | O\n", |
| 188 | + " | |\n", |
| 189 | + "-----------\n", |
| 190 | + " | |\n", |
| 191 | + " X | O | X\n", |
| 192 | + " | |\n" |
| 193 | + ] |
| 194 | + } |
| 195 | + ], |
| 196 | + "source": [ |
| 197 | + "place_marker(test_board,'$',8)\n", |
| 198 | + "display_board(test_board)" |
| 199 | + ] |
| 200 | + }, |
| 201 | + { |
| 202 | + "cell_type": "markdown", |
102 | 203 | "metadata": {},
|
| 204 | + "source": [ |
| 205 | + "**Step 4: Write a function that takes in a board and checks to see if someone has won. **" |
| 206 | + ] |
| 207 | + }, |
| 208 | + { |
| 209 | + "cell_type": "code", |
| 210 | + "execution_count": 7, |
| 211 | + "metadata": { |
| 212 | + "collapsed": true |
| 213 | + }, |
103 | 214 | "outputs": [],
|
104 | 215 | "source": [
|
105 | 216 | "def win_check(board,mark):\n",
|
|
118 | 229 | "cell_type": "markdown",
|
119 | 230 | "metadata": {},
|
120 | 231 | "source": [
|
121 |
| - "**Step 5: Write a function that uses the random module to randomly decide which player goes first. You may want to lookup random.randint() Return a string of which player went first.**" |
| 232 | + "**TEST Step 4:** run the win_check function against our test_board - it should return True" |
122 | 233 | ]
|
123 | 234 | },
|
124 | 235 | {
|
125 | 236 | "cell_type": "code",
|
126 |
| - "execution_count": 6, |
| 237 | + "execution_count": 8, |
| 238 | + "metadata": { |
| 239 | + "collapsed": false |
| 240 | + }, |
| 241 | + "outputs": [ |
| 242 | + { |
| 243 | + "data": { |
| 244 | + "text/plain": [ |
| 245 | + "True" |
| 246 | + ] |
| 247 | + }, |
| 248 | + "execution_count": 8, |
| 249 | + "metadata": {}, |
| 250 | + "output_type": "execute_result" |
| 251 | + } |
| 252 | + ], |
| 253 | + "source": [ |
| 254 | + "win_check(test_board,'X')" |
| 255 | + ] |
| 256 | + }, |
| 257 | + { |
| 258 | + "cell_type": "markdown", |
127 | 259 | "metadata": {},
|
| 260 | + "source": [ |
| 261 | + "**Step 5: Write a function that uses the random module to randomly decide which player goes first. You may want to lookup random.randint() Return a string of which player went first.**" |
| 262 | + ] |
| 263 | + }, |
| 264 | + { |
| 265 | + "cell_type": "code", |
| 266 | + "execution_count": 9, |
| 267 | + "metadata": { |
| 268 | + "collapsed": true |
| 269 | + }, |
128 | 270 | "outputs": [],
|
129 | 271 | "source": [
|
130 | 272 | "import random\n",
|
|
145 | 287 | },
|
146 | 288 | {
|
147 | 289 | "cell_type": "code",
|
148 |
| - "execution_count": 7, |
149 |
| - "metadata": {}, |
| 290 | + "execution_count": 10, |
| 291 | + "metadata": { |
| 292 | + "collapsed": true |
| 293 | + }, |
150 | 294 | "outputs": [],
|
151 | 295 | "source": [
|
152 | 296 | "def space_check(board, position):\n",
|
|
163 | 307 | },
|
164 | 308 | {
|
165 | 309 | "cell_type": "code",
|
166 |
| - "execution_count": 8, |
167 |
| - "metadata": {}, |
| 310 | + "execution_count": 11, |
| 311 | + "metadata": { |
| 312 | + "collapsed": true |
| 313 | + }, |
168 | 314 | "outputs": [],
|
169 | 315 | "source": [
|
170 | 316 | "def full_board_check(board):\n",
|
|
183 | 329 | },
|
184 | 330 | {
|
185 | 331 | "cell_type": "code",
|
186 |
| - "execution_count": 9, |
187 |
| - "metadata": {}, |
| 332 | + "execution_count": 12, |
| 333 | + "metadata": { |
| 334 | + "collapsed": true |
| 335 | + }, |
188 | 336 | "outputs": [],
|
189 | 337 | "source": [
|
190 | 338 | "def player_choice(board):\n",
|
|
205 | 353 | },
|
206 | 354 | {
|
207 | 355 | "cell_type": "code",
|
208 |
| - "execution_count": 10, |
209 |
| - "metadata": {}, |
| 356 | + "execution_count": 13, |
| 357 | + "metadata": { |
| 358 | + "collapsed": true |
| 359 | + }, |
210 | 360 | "outputs": [],
|
211 | 361 | "source": [
|
212 | 362 | "def replay():\n",
|
|
225 | 375 | },
|
226 | 376 | {
|
227 | 377 | "cell_type": "code",
|
228 |
| - "execution_count": 11, |
229 |
| - "metadata": {}, |
| 378 | + "execution_count": 16, |
| 379 | + "metadata": { |
| 380 | + "collapsed": false |
| 381 | + }, |
230 | 382 | "outputs": [
|
231 | 383 | {
|
232 | 384 | "name": "stdout",
|
233 | 385 | "output_type": "stream",
|
234 | 386 | "text": [
|
235 | 387 | " | |\n",
|
236 |
| - " X | O | X\n", |
| 388 | + " | O | \n", |
237 | 389 | " | |\n",
|
238 | 390 | "-----------\n",
|
239 | 391 | " | |\n",
|
240 |
| - " O | O | X\n", |
| 392 | + " | O | X\n", |
241 | 393 | " | |\n",
|
242 | 394 | "-----------\n",
|
243 | 395 | " | |\n",
|
244 |
| - " X | X | O\n", |
| 396 | + " X | O | X\n", |
245 | 397 | " | |\n",
|
246 |
| - "The game is a draw!\n", |
247 |
| - "Do you want to play again? Enter Yes or No: n\n" |
| 398 | + "Player 2 has won!\n", |
| 399 | + "Do you want to play again? Enter Yes or No: No\n" |
248 | 400 | ]
|
249 | 401 | }
|
250 | 402 | ],
|
|
257 | 409 | " player1_marker, player2_marker = player_input()\n",
|
258 | 410 | " turn = choose_first()\n",
|
259 | 411 | " print(turn + ' will go first.')\n",
|
260 |
| - " play_game = input('Are you ready to play?')\n", |
261 |
| - " game_on = True\n", |
| 412 | + " \n", |
| 413 | + " play_game = input('Are you ready to play? Enter Yes or No.')\n", |
| 414 | + " \n", |
| 415 | + " if play_game.lower()[0] == 'y':\n", |
| 416 | + " game_on = True\n", |
| 417 | + " else:\n", |
| 418 | + " game_on = False\n", |
262 | 419 | "\n",
|
263 | 420 | " while game_on:\n",
|
264 | 421 | " if turn == 'Player 1':\n",
|
|
294 | 451 | " else:\n",
|
295 | 452 | " if full_board_check(theBoard):\n",
|
296 | 453 | " display_board(theBoard)\n",
|
297 |
| - " print('The game is a tie!')\n", |
| 454 | + " print('The game is a draw!')\n", |
298 | 455 | " break\n",
|
299 | 456 | " else:\n",
|
300 | 457 | " turn = 'Player 1'\n",
|
|
314 | 471 | }
|
315 | 472 | ],
|
316 | 473 | "metadata": {
|
| 474 | + "anaconda-cloud": {}, |
317 | 475 | "kernelspec": {
|
318 |
| - "display_name": "Python 3", |
| 476 | + "display_name": "Python [default]", |
319 | 477 | "language": "python",
|
320 | 478 | "name": "python3"
|
321 | 479 | },
|
|
329 | 487 | "name": "python",
|
330 | 488 | "nbconvert_exporter": "python",
|
331 | 489 | "pygments_lexer": "ipython3",
|
332 |
| - "version": "3.6.2" |
| 490 | + "version": "3.5.3" |
333 | 491 | }
|
334 | 492 | },
|
335 | 493 | "nbformat": 4,
|
|
0 commit comments