Notebook For The Milestone Project 1
Notebook For The Milestone Project 1
def display_board(board):
clear_output()
print('Here is the current board')
print(' | | ')
print(' '+board[1]+' | '+board[2]+' | '+board[3]+' ')
print(' | | ')
print('-----------')
print(' | | ')
print(' '+board[4]+' | '+board[5]+' | '+board[6]+' ')
print(' | | ')
print('-----------')
print(' | | ')
print(' '+board[7]+' | '+board[8]+' | '+board[9]+' ')
print(' | | ')
def player_input():
marker = ''
if marker == 'X':
return ('X', 'O')
else:
return ('O', 'X')
def win_check(board,mark):
import random
def choose_first():
if random.randint(0, 1) == 0:
return 'Player 2'
else:
return 'Player 1'
def player_choice(board):
position = 0
return position
def replay():
aswer= ' '
while not (aswer =='Yes' or aswer == 'No'):
aswer=input('Please insert Yes if you want to play else insert No')
if aswer=='yes':
return True
else:
pass
def full_tic_tac_toe_game():#1
print('Welcome to Tic Tac Toe!')#2
#3
theboard=['#','1','2','3','4','5','6','7','8','9']#4
#5
while True:#6
display_board(theboard)#7
whos_turn=choose_first()#8
print(whos_turn+' will go first')#9
want_to_play=' '#10
while want_to_play =='Yes' or want_to_play == 'No':#11
want_to_play = input('Are you ready?')#12
if want_to_play=='yes':#13
game_on=True#14
else:#15
game_on=False#16
#17
while game_on:#18
if whos_turn == 'player_1':#19
display_board(theboard)#20
player_choice(theboard)#21
place_marker(theboard,player1_marker, position)#22
#23
if win_check(theBoard, player1_marker):#24
display_board(theboard)#25
print('Congratulations! Player_1 you have won the game!')#26
game_on = False#27
else:#28
if full_board_check(theboard):#29
display_board(theboard)#30
print('No one has won the game because it is a draw!')#31
break#32
else:#33
turn = 'Player 2'#34
#35
else:#36
#37
display_board(theboard)#38
position = player_choice(thboard)#39
place_marker(theboard, player2_marker, position)#39
#40
if win_check(theboard, player2_marker):#41
display_board(theboard)#42
print('Congratulations! Player_2 you have won the game!')#43
game_on = False#44
else:#45
if full_board_check(theboard):#46
display_board(theboard)#47
print('No one has won the game because it is a draw!')#48
break#49
else:#50
turn = 'Player 1'#51
#52
if replay == True:#53
full_tic_tac_toe_game()#54
else:#55
pass#56