Conversation
jaipurandare
left a comment
There was a problem hiding this comment.
I have put my review comments. I don't know if you want to make all these changes.
| " check_position=True\n", | ||
| " while check_position:\n", | ||
| " try:\n", | ||
| " if player_flag==True:\n", |
There was a problem hiding this comment.
player_flag is a boolean. Not need to compare it to True or False. condition "if payer_flag:" is enough.
| " global player1\n", | ||
| " global player2\n", | ||
| " check_player_input=True\n", | ||
| " while check_player_input: \n", |
There was a problem hiding this comment.
Just a note: This while loop can easily become infinite loop if the user keep entering wrong input. There should be limited number of attempts.
| " length=9\n", | ||
| " winner_found=False\n", | ||
| " result=''\n", | ||
| " while length>0:\n", |
There was a problem hiding this comment.
you can change the while condition as "length>0 and not winner_found". In that case no need to do length=0 after winner is found.
| " print('Unable to understand the input. Please re-enter.')\n", | ||
| "\n", | ||
| "#Save the result of the game in a file\n", | ||
| "def result_file(result):\n", |
There was a problem hiding this comment.
you should name the method based on action they perform. Like "save_result" or "save_result_to_file" or "write_to_file". Its more readable and makes sense about what the function is doing.
| " while play_again_input: \n", | ||
| " replay=input('Would you like to play again? (Yes/No): ')\n", | ||
| " if replay=='Yes':\n", | ||
| " global board\n", |
There was a problem hiding this comment.
All these can be pulled out into a function called "reset_game" or "reset_board".
| " player_select()\n", | ||
| " board_update()\n", | ||
| "\n", | ||
| "play_game_start()" |
There was a problem hiding this comment.
I would write this as follows
def replay_game():
attempts = 0
play_again_invalid_input = True
while play_again_invalid_input and attempts < 3:
replay = input('Would you like to play again? (Yes/No): ')
if replay in ['Yes', 'No']:
play_again_invalid_input = False
else:
print('invalid input. re-enter')
attempts +=1
return replay == 'Yes'
yes = 'Yes'
no = 'No'
replay = True
while replay:
reset_game()
play_game_start()
replay = replay_game()
print('Game stopped as per you request!')
| " print(result)\n", | ||
| " \n", | ||
| " result_file(result) \n", | ||
| " play_again()\n", |
There was a problem hiding this comment.
play_again() should not be called here. It is not responsibility of the board_update function. It can be called at the end of play_game_start function.
Created pull request so I can put comments