Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This problem is about the game Tic-Tac-Toe (= noughts and crosses = Xs and Os). We represent a 3 x 3 board of the game

image text in transcribed

This problem is about the game Tic-Tac-Toe (= noughts and crosses = Xs and Os). We represent a 3 x 3 board of the game by a list of lists board whose entries correspond to positions according to the following table: board[@][0] board[@][1] board[@][2] board[1][@] board[1][1] board[1][2] board[2][0] board[2][1] board[2][2] Here, each entry board[i][j] is one of the characters 'X', 'O' (that's a capital letter O, not the number zero!), or '' (space), where the latter corresponds to an empty cell. Each such board determines an outcome according to the following rules: If the board contains a horizontal, vertical, or diagonal line of three Xs, but not of three Os, then X wins. If the board contains a horizontal, vertical, or diagonal line of three Os, but not of three Xs, then O wins. If the board contains at least one such line of Xs and one such line of Os, then the board corresponds to a draw. Otherwise, the board does not determine a winner. Task. Write a function tictactoe which takes as input a list of lists board as above and returns a string which indicates whether board corresponds to X winning, O winning, a draw, or neither player winning. The possible return values of tictactoe should be the following strings: 'X wins' "O wins' 'draw' 'no winner! Your function should handle all 3 x 3 boards comprised of the characters 'X', '0', and not merely those that actually arise when the game is played. For example, tictactoe should identify X as the winner of the following configuration, even though this cannot actually arise based on the usual rules of the game (why is that?): Oxx

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Briefly describe four guides to ethical decision-making

Answered: 1 week ago

Question

To solve p + 3q = 5z + tan( y - 3x)

Answered: 1 week ago

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago

Question

=+3 In what ways can an MNE improve or change its approach to IHRM?

Answered: 1 week ago