Skip to content

Commit c16e0f9

Browse files
committed
milestone one fixed
1 parent 331e63f commit c16e0f9

11 files changed

+529
-2176
lines changed

04-Milestone Project - 1/.ipynb_checkpoints/03-Milestone Project 1 - Complete Walkthrough Solution-checkpoint.ipynb

Lines changed: 188 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
},
1919
{
2020
"cell_type": "code",
21-
"execution_count": 2,
22-
"metadata": {},
21+
"execution_count": 1,
22+
"metadata": {
23+
"collapsed": true
24+
},
2325
"outputs": [],
2426
"source": [
2527
"from IPython.display import clear_output\n",
@@ -44,7 +46,37 @@
4446
"cell_type": "markdown",
4547
"metadata": {},
4648
"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)"
4880
]
4981
},
5082
{
@@ -57,14 +89,16 @@
5789
{
5890
"cell_type": "code",
5991
"execution_count": 3,
60-
"metadata": {},
92+
"metadata": {
93+
"collapsed": true
94+
},
6195
"outputs": [],
6296
"source": [
6397
"def player_input():\n",
6498
" marker = ''\n",
6599
" \n",
66100
" 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",
68102
"\n",
69103
" if marker == 'X':\n",
70104
" return ('X', 'O')\n",
@@ -76,13 +110,51 @@
76110
"cell_type": "markdown",
77111
"metadata": {},
78112
"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"
80114
]
81115
},
82116
{
83117
"cell_type": "code",
84118
"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",
85147
"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+
},
86158
"outputs": [],
87159
"source": [
88160
"def place_marker(board, marker, position):\n",
@@ -93,13 +165,52 @@
93165
"cell_type": "markdown",
94166
"metadata": {},
95167
"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"
97169
]
98170
},
99171
{
100172
"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",
102203
"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+
},
103214
"outputs": [],
104215
"source": [
105216
"def win_check(board,mark):\n",
@@ -118,13 +229,44 @@
118229
"cell_type": "markdown",
119230
"metadata": {},
120231
"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"
122233
]
123234
},
124235
{
125236
"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",
127259
"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+
},
128270
"outputs": [],
129271
"source": [
130272
"import random\n",
@@ -145,8 +287,10 @@
145287
},
146288
{
147289
"cell_type": "code",
148-
"execution_count": 7,
149-
"metadata": {},
290+
"execution_count": 10,
291+
"metadata": {
292+
"collapsed": true
293+
},
150294
"outputs": [],
151295
"source": [
152296
"def space_check(board, position):\n",
@@ -163,8 +307,10 @@
163307
},
164308
{
165309
"cell_type": "code",
166-
"execution_count": 8,
167-
"metadata": {},
310+
"execution_count": 11,
311+
"metadata": {
312+
"collapsed": true
313+
},
168314
"outputs": [],
169315
"source": [
170316
"def full_board_check(board):\n",
@@ -183,8 +329,10 @@
183329
},
184330
{
185331
"cell_type": "code",
186-
"execution_count": 9,
187-
"metadata": {},
332+
"execution_count": 12,
333+
"metadata": {
334+
"collapsed": true
335+
},
188336
"outputs": [],
189337
"source": [
190338
"def player_choice(board):\n",
@@ -205,8 +353,10 @@
205353
},
206354
{
207355
"cell_type": "code",
208-
"execution_count": 10,
209-
"metadata": {},
356+
"execution_count": 13,
357+
"metadata": {
358+
"collapsed": true
359+
},
210360
"outputs": [],
211361
"source": [
212362
"def replay():\n",
@@ -225,26 +375,28 @@
225375
},
226376
{
227377
"cell_type": "code",
228-
"execution_count": 11,
229-
"metadata": {},
378+
"execution_count": 16,
379+
"metadata": {
380+
"collapsed": false
381+
},
230382
"outputs": [
231383
{
232384
"name": "stdout",
233385
"output_type": "stream",
234386
"text": [
235387
" | |\n",
236-
" X | O | X\n",
388+
" | O | \n",
237389
" | |\n",
238390
"-----------\n",
239391
" | |\n",
240-
" O | O | X\n",
392+
" | O | X\n",
241393
" | |\n",
242394
"-----------\n",
243395
" | |\n",
244-
" X | X | O\n",
396+
" X | O | X\n",
245397
" | |\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"
248400
]
249401
}
250402
],
@@ -257,8 +409,13 @@
257409
" player1_marker, player2_marker = player_input()\n",
258410
" turn = choose_first()\n",
259411
" 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",
262419
"\n",
263420
" while game_on:\n",
264421
" if turn == 'Player 1':\n",
@@ -294,7 +451,7 @@
294451
" else:\n",
295452
" if full_board_check(theBoard):\n",
296453
" display_board(theBoard)\n",
297-
" print('The game is a tie!')\n",
454+
" print('The game is a draw!')\n",
298455
" break\n",
299456
" else:\n",
300457
" turn = 'Player 1'\n",
@@ -314,8 +471,9 @@
314471
}
315472
],
316473
"metadata": {
474+
"anaconda-cloud": {},
317475
"kernelspec": {
318-
"display_name": "Python 3",
476+
"display_name": "Python [default]",
319477
"language": "python",
320478
"name": "python3"
321479
},
@@ -329,7 +487,7 @@
329487
"name": "python",
330488
"nbconvert_exporter": "python",
331489
"pygments_lexer": "ipython3",
332-
"version": "3.6.2"
490+
"version": "3.5.3"
333491
}
334492
},
335493
"nbformat": 4,

0 commit comments

Comments
 (0)