Tic Tac Toe: You will be given a series of moves in a Tic Tac Toe...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Tic Tac Toe: You will be given a series of moves in a Tic Tac Toe (or Xs and Os) game. You have to figure out who the winner of the game is. Assume that the first move of the game is made by the player having X. Then the moves alternate between O and X. If X wins the game, print X (uppercase letter X). If O wins the game, print O (uppercase letter O). If it's a tie, print T (uppercase letter T). Each move is represented by two numbers r and c. They denote the coordinates of the square where the player has placed his/her marker (X or O). (1, 1) represents the top left corner and (3, 3) represents the bottom right corner. You have to take input continuously and stop as soon as someone wins. The winner might be determined in less than 9 moves but to guarantee a tie, you must take input 9 times. Sample Input 1: 11 12 21 22 31 X Sample Output 1: Sample Input 2: 13 11 22 31 21 23 32 12 33 Sample Output 2: Τ Hint 1: Notice that the coordinates given to you are starting from 1 but in arrays, we use 0 based indexing. Hint 2: Make a 2D array to store the state of the game. Create a function that takes the state as an argument and returns if the winner can be determined. Take input in the main function, change the state depending on input and call the function until a winner is obtained or all the 9 moves have been played. Tic Tac Toe: You will be given a series of moves in a Tic Tac Toe (or Xs and Os) game. You have to figure out who the winner of the game is. Assume that the first move of the game is made by the player having X. Then the moves alternate between O and X. If X wins the game, print X (uppercase letter X). If O wins the game, print O (uppercase letter O). If it's a tie, print T (uppercase letter T). Each move is represented by two numbers r and c. They denote the coordinates of the square where the player has placed his/her marker (X or O). (1, 1) represents the top left corner and (3, 3) represents the bottom right corner. You have to take input continuously and stop as soon as someone wins. The winner might be determined in less than 9 moves but to guarantee a tie, you must take input 9 times. Sample Input 1: 11 12 21 22 31 X Sample Output 1: Sample Input 2: 13 11 22 31 21 23 32 12 33 Sample Output 2: Τ Hint 1: Notice that the coordinates given to you are starting from 1 but in arrays, we use 0 based indexing. Hint 2: Make a 2D array to store the state of the game. Create a function that takes the state as an argument and returns if the winner can be determined. Take input in the main function, change the state depending on input and call the function until a winner is obtained or all the 9 moves have been played.
Expert Answer:
Answer rating: 100% (QA)
Heres a Python solution to determine the winner of a Tic Tac Toe game based on the provide... View the full answer
Related Book For
Organizational Behavior
ISBN: 9780134729329
18th Edition
Authors: Stephen RobbinsTimothy JudgeTimothy Judge, Timothy Judge
Posted Date:
Students also viewed these programming questions
-
Developments in Technology Light is incident from air on the end face of a multimode optical fibre at angle of incidence as shown below. n n 1 2 The refractive indices of the core and cladding are...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Part C A 100.0 ? and a 150.0 ? resistor, both ratedat 2.00 W, are connected in series across a variable potentialdifference. What is the greatest this potential difference can bewithout overheating...
-
After his first business trip to a major city, Herman is alarmed when he reviews his credit card receipts. Both the hotel bill and the car rental charge are in excess of the price he was quoted. Was...
-
Given these results, comment on the direction of the difference between the population means: M 1 = 72, M 2 = 73, t(26) = 2.08, p < .05.
-
XCBob, Inc. is an online motorcycle and ATV parts business from the owners home. XCBob entered into oral agreements with the defendant, Ed Tucker Distributers, for purchases of various materials to...
-
The stockholders equity accounts of Karp Company at January 1, 2014, are as follows. Preferred Stock, 6%, $50 par ................$600,000 Common Stock , $5 par .................... 800,000 Paid-in...
-
There are four types of relational models: communal sharing, authority ranking, equality matching, and market pricing. Which relational models do you use in your interpersonal interactions? Is one...
-
Distinguish the characteristics of public versus private sources of financing long-term care services in the U.S. Describe the percentage of shares of spending on long-term care for the elderly
-
PhilaFarm just purchased equipment for $430,000. Use the MACRS rates for an equipment classified as a 3-year class asset to find: The equipment's annual depreciation. The annual tax shield associated...
-
3. Let x(u,v) = ((R+r cos u) cos v, (R+r cos u) sin v, r sin u) be the usual parametrization of a torus. Determine whether the v-parameter curve, u = 0, of x is principal, asymptotic and geodesic....
-
Activities in the Weekly Planning basket are to be a.With max. 10% constraints b.With no constraints c.Constraints do not matter d.With max. 50% constraints
-
In the Business & Sustainability perspective, please briefly describe each of the sections below: Operations and Supply Chain Define Product Life Cycle and Product Life Cycle Assessment? How are the...
-
Which of these is true about the backward-bending supply curve of labor theory? a. Labor supply has an inverse relationship with wages, at least at low wage levels O b. At low wage levels the income...
-
What is a bovine genomic selection breeding programme and what are its advantages to the cattle breeding industry over traditional breeding strategies?
-
What types of inventory issues Starbucks might reflect upon at the end of each year? The mission of Starbucks is to inspire and nurture the human spiritone person, one cup, and one neighborhood at a...
-
Employees at many successful companies start the day by checking the economic forecast. Patagonias Ventura, California, employees start the day by checking the surf forecast. The outdoor clothing...
-
The sound of Matt and Peters arguing is familiar to everyone in the office by now. In an effort to make the best use of space and ensure a free flow of discussion and ideas, the founder of Markay...
-
We have noted throughout the text that honesty is generally the best policy in managing OB. But that doesnt mean honest dealing is always the rule in business. Studies have found, in fact, that whole...
-
In recent years, Keflavik Paper Company has been having problems with its project management process. Several commercial projects, for example, have come in late and well over budget, and product...
-
Your firm has the opportunity to invest $75,000 in a new project opportunity but due to cash flow concerns, your boss wants to know when you can pay back the original investment. Using the discounted...
-
Pracht, a popular cosmetics company in Germany, has been performing favorably and growing at a constant rate, with profits exceeding $900,000 in the last financial year. The company now wants to...
Study smarter with the SolutionInn App