Answered step by step
Verified Expert Solution
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 TloTsoToe", see the Wikipedia Page for detalis and referencee In which two players mark the originaly blank cello on a grid. One playec, who marks the fleid with a crose, otarts first. Every "cross move" is followed by another pleyer who marke any of the remaining empty field with a nought, 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 "lineup 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 "grid" which is a nested list of lists, where all inner list elements values are either or These values represent the cells with nought, or cross, or an unmarked cell, respectively. You should write an implementation of the function 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 check function is explained in the lectures of Week 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 ifcontrol 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 tttcheck game where the parameter game is a element long list of element lists nested list which describes the state of game as explained above the first elementlist describes the state of first row, and so on The function prototype is included in the file noughtsandcrosses. py The "prototype" here means that there is a declaration of the function 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 noughtsandcrosses. py aiso contains a test function testtttcheck 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 noughtsandcrosses.py file.
The problem
You are probably familiar with the game of Toughts and Crosses" also known as TloTsoToe", see the Wikipedia Page for detalis and referencee In which two players mark the originaly blank cello on a grid. One playec, who marks the fleid with a crose, otarts first. Every "cross move" is followed by another pleyer who marke any of the remaining empty field with a nought, 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 "lineup 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 "grid" which is a nested list of lists, where all inner list elements values are either or These values represent the cells with nought, or cross, or an unmarked cell, respectively. You should write an implementation of the function 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 check function is explained in the lectures of Week 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 ifcontrol 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 tttcheck game where the parameter game is a element long list of element lists nested list which describes the state of game as explained above the first elementlist describes the state of first row, and so on The function prototype is included in the file noughtsandcrosses. py The "prototype" here means that there is a declaration of the function 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 noughtsandcrosses. py aiso contains a test function testtttcheck 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 noughtsandcrosses.py file.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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