Write a class called AddThreeGame that allows two players to play a game in which they alternately choose numbers from 1- 9. They may not choose a number that has already been selected by either player. If at any point exactly three of the player's numbers sum to exactly 15, then that player has won. If all numbers from 1-9 are chosen, but neither player has won, then the game ends in a draw. Player "first" has the first turn. The class will need private data members for: 1. keeping track of which numbers have been chosen, and by whom 2. the current state, which holds one of the four following values: "FIRST_WON", "SECOND_WON", "DRAW", or "UNFINISHED" 3. keeping track of whose turn it is Your AddThreeGame class must include the following methods: • An init method that takes no parameters and initializes all data members. A get method named get_current_state, which returns the current state. • A method named make_move that takes two parameters - a string designating the player making the move, either "first" or "second", and an integer giving their number choice (in that order). If it is not that player's turn, or if the integer is not in the correct range, or if that integer has already been chosen, or if the game has already been won or drawn, make_move should return False. You can assume the user chooses an integer, but if it's outside the range 1-9, make_move should return False. Otherwise, it should record the move, update the current state if the move caused a win or draw, update which player's turn it is, and return True.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

In Python

For example, your class could be used as follows:
game = AddThreeGame()
game.make_move("first",
game.make_move("second", 5)
2)
game.make_move("first", 7)
state = game.get_current_state()
result
%3D
Transcribed Image Text:For example, your class could be used as follows: game = AddThreeGame() game.make_move("first", game.make_move("second", 5) 2) game.make_move("first", 7) state = game.get_current_state() result %3D
Write a class called AddThreeGame that allows two players to play a game in which they alternately choose numbers from 1-
9. They may not choose a number that has already been selected by either player. If at any point exactly three of the player's
numbers sum to exactly 15, then that player has won. If all numbers from 1-9 are chosen, but neither player has won, then the
game ends in a draw. Player "first" has the first turn.
The class will need private data members for:
1. keeping track of which numbers have been chosen, and by whom
2. the current state, which holds one of the four following values: "FIRST_WON", "SECOND_WON", "DRAW", or
"UNFINISHED"
3. keeping track of whose turn it is
Your AddThreeGame class must include the following methods:
An init method that takes no parameters and initializes all data members.
A get method named get_current_state, which returns the current state.
A method named make_move that takes two parameters - a string designating the player making the move, either "first"
or "second", and an integer giving their number choice (in that order). If it is not that player's turn, or if the integer is not in
the correct range, or if that integer has already been chosen, or if the game has already been won or drawn, make_move
should return False. You can assume the user chooses an integer, but if it's outside the range 1-9, make_move should
return False. Otherwise, it should record the move, update the current state if the move caused a win or draw, update
which player's turn it is, and return True.
Transcribed Image Text:Write a class called AddThreeGame that allows two players to play a game in which they alternately choose numbers from 1- 9. They may not choose a number that has already been selected by either player. If at any point exactly three of the player's numbers sum to exactly 15, then that player has won. If all numbers from 1-9 are chosen, but neither player has won, then the game ends in a draw. Player "first" has the first turn. The class will need private data members for: 1. keeping track of which numbers have been chosen, and by whom 2. the current state, which holds one of the four following values: "FIRST_WON", "SECOND_WON", "DRAW", or "UNFINISHED" 3. keeping track of whose turn it is Your AddThreeGame class must include the following methods: An init method that takes no parameters and initializes all data members. A get method named get_current_state, which returns the current state. A method named make_move that takes two parameters - a string designating the player making the move, either "first" or "second", and an integer giving their number choice (in that order). If it is not that player's turn, or if the integer is not in the correct range, or if that integer has already been chosen, or if the game has already been won or drawn, make_move should return False. You can assume the user chooses an integer, but if it's outside the range 1-9, make_move should return False. Otherwise, it should record the move, update the current state if the move caused a win or draw, update which player's turn it is, and return True.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY