Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The problem You are probably familiar with the game of Toughts and Crosses ( also known as Tlo - Tso - Toe, see the Wikipedia

The problem
You are probably familiar with the game of Toughts and Crosses" (also known as Tlo-Tso-Toe", see the Wikipedia Page for detalis and referencee), In which two players mark the originaly blank cello on a 3-by-3 grid. One playec, who marks the fleid with a crose, 'x', otarts first. Every "cross move" is followed by another pleyer who marke any of the remaining empty field with a nought, '0'. The winner is the one who firat puta their aymbol on a column, or a row ar one of the dlagonala. If nobody is able to achleve such a "line-up" when the last empty fleid is marked, the game is a draw. The game ian't particular difficult from the Game Theory point of view. There is an algorithm ("sirategn) to always lead the game to a draw for the "noughts" player, who is formally disadvantaged by starting second. This is a futile game.
In this homework, your goal will be to simply determine what is the outcome given the state of the game. The game is described by a 33 "grid" which is a nested list of lists, where all inner list elements values are either 1,-1 or 0. These values represent the cells with nought, or cross, or an unmarked cell, respectively. You should write an implementation of the function ttt_check (game) Which will return a string with one of the possible values: Crosses. Noughts, or Draw. We will assume, that the game state is the result of playing the game without violation of its rules.
What you need to know to implement the ttt_check function is explained in the lectures of Week 15. Namely, knowledge of these language features is useful to construct your solution.
how to check variables of int type for their value
how to program conditional branches, the if-control flow
how to define a function
how to defline a function which retums a value
how to index a list (extract a value of list element given its index)
how to sum a list elements
how to slice a list
The function which will check the game outcome is called ttt_check (game), where the parameter game is a 3-element long list of 3-element lists (nested list 3.3). which describes the state of game as explained above (the first element-list describes the state of first row, and so on). The function prototype is included in the file noughts_and_crosses. py. The "prototype" here means that there is a declaration of the function t.t_ check (gane), but its body is incomplete - it contains a statement pass (a "do nothing" statement in Python), which must be replaced with the specified implementation. The program file noughts_and_crosses. py aiso contains a test function test_ttt_check (this one is complete and must not be modified), which can be used to verify your solution (once you completed it).
Remember, that even if the test function says that tests are passed, this does not guarantee the functional correctness. The testing can only reveal errors, it cannot prove the program correctness.
We will test your submission with other tests, not just the one given in the noughts_and_crosses.py file.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions