Skip to content

Commit

Permalink
milestone one fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierian-Data committed Feb 14, 2018
1 parent 331e63f commit c16e0f9
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 2,176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from IPython.display import clear_output\n",
Expand All @@ -44,7 +46,37 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<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>"
"**TEST Step 1:** run your function on a test version of the board list, and make adjustments as necessary"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" | |\n",
" X | O | X\n",
" | |\n",
"-----------\n",
" | |\n",
" O | X | O\n",
" | |\n",
"-----------\n",
" | |\n",
" X | O | X\n",
" | |\n"
]
}
],
"source": [
"test_board = ['#','X','O','X','O','X','O','X','O','X']\n",
"display_board(test_board)"
]
},
{
Expand All @@ -57,14 +89,16 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def player_input():\n",
" marker = ''\n",
" \n",
" while not (marker == 'X' or marker == 'O'):\n",
" marker = input('Player 1: Do you want to be X or O?').upper()\n",
" marker = input('Player 1: Do you want to be X or O? ').upper()\n",
"\n",
" if marker == 'X':\n",
" return ('X', 'O')\n",
Expand All @@ -76,13 +110,51 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**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.**"
"**TEST Step 2:** run the function to make sure it returns the desired output"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Player 1: Do you want to be X or O? X\n"
]
},
{
"data": {
"text/plain": [
"('X', 'O')"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"player_input()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**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.**"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def place_marker(board, marker, position):\n",
Expand All @@ -93,13 +165,52 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Step 4: Write a function that takes in a board and checks to see if someone has won. **"
"**TEST Step 3:** run the place marker function using test parameters and display the modified board"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" | |\n",
" X | $ | X\n",
" | |\n",
"-----------\n",
" | |\n",
" O | X | O\n",
" | |\n",
"-----------\n",
" | |\n",
" X | O | X\n",
" | |\n"
]
}
],
"source": [
"place_marker(test_board,'$',8)\n",
"display_board(test_board)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Step 4: Write a function that takes in a board and checks to see if someone has won. **"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def win_check(board,mark):\n",
Expand All @@ -118,13 +229,44 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**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.**"
"**TEST Step 4:** run the win_check function against our test_board - it should return True"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"win_check(test_board,'X')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**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.**"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import random\n",
Expand All @@ -145,8 +287,10 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def space_check(board, position):\n",
Expand All @@ -163,8 +307,10 @@
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def full_board_check(board):\n",
Expand All @@ -183,8 +329,10 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"execution_count": 12,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def player_choice(board):\n",
Expand All @@ -205,8 +353,10 @@
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def replay():\n",
Expand All @@ -225,26 +375,28 @@
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" | |\n",
" X | O | X\n",
" | O | \n",
" | |\n",
"-----------\n",
" | |\n",
" O | O | X\n",
" | O | X\n",
" | |\n",
"-----------\n",
" | |\n",
" X | X | O\n",
" X | O | X\n",
" | |\n",
"The game is a draw!\n",
"Do you want to play again? Enter Yes or No: n\n"
"Player 2 has won!\n",
"Do you want to play again? Enter Yes or No: No\n"
]
}
],
Expand All @@ -257,8 +409,13 @@
" player1_marker, player2_marker = player_input()\n",
" turn = choose_first()\n",
" print(turn + ' will go first.')\n",
" play_game = input('Are you ready to play?')\n",
" game_on = True\n",
" \n",
" play_game = input('Are you ready to play? Enter Yes or No.')\n",
" \n",
" if play_game.lower()[0] == 'y':\n",
" game_on = True\n",
" else:\n",
" game_on = False\n",
"\n",
" while game_on:\n",
" if turn == 'Player 1':\n",
Expand Down Expand Up @@ -294,7 +451,7 @@
" else:\n",
" if full_board_check(theBoard):\n",
" display_board(theBoard)\n",
" print('The game is a tie!')\n",
" print('The game is a draw!')\n",
" break\n",
" else:\n",
" turn = 'Player 1'\n",
Expand All @@ -314,8 +471,9 @@
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
Expand All @@ -329,7 +487,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
"version": "3.5.3"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit c16e0f9

Please sign in to comment.