Try your skills getting four in a row on the 5x5 grid for an extra challenge. Your goal is to get three in a row before your opponent does. On your turn, click anywhere on the grid to place an X in that square. Marker = input('Player1: Choose X or O: ').You are X’s and your opponent is O’s. I totally do not understand why you basically print your board upside down but I left that as is. I also added a check on user input to make sure that what the user enters is a number and it does not crash if not. You need to check every position, not just the last one. You also are not properly checking for when a player wins, which is why you are having that weird top row behavior. The reason the turn was not going properly to "Player 1" is because you had a space missing in the check for that player. I want the game to go back and forth between each player with the correct markers assigned to them and I cannot figure out why this isn't happening as it looks correct to me. Place_marker(the_board,player2_marker,position) If full_board_check(the_board): # Check for tie Place_marker(the_board,player1_marker,position) Play_game = input('Ready to play? y or n: ') Player1_marker,player2_marker = player_input() ![]() # Game Setup (Board, Players, Player turns) # Need to break out of the while loop on replay() # While loop needed to keep running the game Position = int(input('Choose a position: (1-9): '))ĭef replay(): # Asks if the players want to play againĬhoice = input("Play again? Enter Yes or No: ") While position not in or not space_check(board, position): If space_check(board,i): # If there is free space, board is NOT fullĭef player_choice(board): # Asks for the player's next move choice (board and board and board = mark))ĭef choose_first(): # Randomize who goes firstĭef space_check(board, position): # Check to see if a space on the board is still availableĭef full_board_check(board): # Checks to see if board is full resulting in a draw (board and board and board = mark) or # Diagonals (board and board and board = mark) or # Columns Return ((board and board and board = mark) or # Rows Marker = input('Player1: Choose X or O: ').upper()ĭef place_marker(board, marker, position): # Allows player to place their marker at specific board indexĭef win_check(board, mark): # Check all rows, columns, diagonals for sharing the same marker to check for a winner ![]() Print(board + '|' + board + '|' + board)ĭef player_input(): # Player assignment - use while loop to keep asking until a valid character is entered I have tried to debug but the code is syntactically valid so I cannot pinpoint the logical issues with it. Additionally, the player that does move, whenever they choose a spot on the top row (indexes 7-9), it is an automatic win. It randomly assigns which player will go first, which it's supposed to, but that player's marker is not assigned correctly and the other player never gets to move. I have followed the steps exactly but I think the game was written specifically for a Jupyter notebook because it is not working properly for me in a real python interpreter (I wrote out all the code in VS code). I did a code-along for a tic-tac-toe game written in python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |