Question
Using Pythong to make a Tic-tac-toe game in a 2D list where EMPTY = 0 X = 1 O = 2. I'm currently struggling with
Using Pythong to make a Tic-tac-toe game in a 2D list where
EMPTY = 0 X = 1 O = 2.
I'm currently struggling with Part 5.
Part 5: Checking if a player has a win in a diagonal We have a final sub-function to check if a player has a win in any diagonal direction. Create a function named winInDiag (notice the use of a lowercase w. but uppercase I and D). The function will take 2 parameters: 1. a two-dimensional list that holds a representation of the board game-state 2. the piece type of one of the players This function should return True if there are 3 pieces in a row in a forward slash diagonal and a backward slash diagonal. Remember that we have the possibility of diagonals of length 3 and of length 4. You will have to create an implementation that finds 3 in a row in both of these situations. You cant just find the total number of pieces of the same type in the diagonal. In a diagonal of length 4 there may be 3 pieces with an EMPTY or opponent piece in between them which prevent them from being 3 in a row. This function is more complicated than the previous row, and column versions. You will notice that you are changing both your row and column at the same time. For one direction of diagonal the row/columns will increase/decrease in the same direction. For the other direction when row goes up the column will go down and vice versa. There are a few of ways of doing this function including checking specific indices with a number of if-statements, or through a loop implementation. Either is a valid solution. Be aware, that these functions are asking about a specific piece type. Returning True for 3 in a row for another piece type or not in a diagonal is a wrong implementation and my tests will fail.
Thanks a lot for helping out!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started