you please help me with this code because I am struggling, I added my code in the photo: question that I need help with: you will develop an AI for a game in which two players take turns placing 1 x 2 dominoes on a rectangular grid. One player must always place his dominoes vertically, and the other must always place his dominoes horizontally. The last player who successfully places a domino on the board wins. an infrastructure that is compatible with the provided GUI has been suggested. However, only the search method will be tested, so you are free to choose a different approach if you find it more convenient to do so. The representation used for this puzzle is a two-dimensional list of Boolean values, where True corresponds to a filled square and False corresponds to an empty square. tasks: In the DominoesGame class, write a method is_legal_move(self, row, col, vertical) that returns a Boolean value indicating whether the given move can be played on the current board. A legal move must place a domino fully within bounds, and may not cover squares which have already been filled. If the vertical parameter is True , then the current player intends to place a domino on squares (row, col) and (row + 1, col) . If the vertical parameter is False , then the current player intends to place a domino on squares (row, col) and (row, col + 1) . This convention will be followed throughout the rest of the section. >>> b = [[False, False], [False, False]] >>> g = DominoesGame(b) >>> g.is_legal_move(0, 0, True) True >>> g.is_legal_move(0, 0, False) True >>> b = [[True, False], [True, False]] >>> g = DominoesGame(b) >>> g.is_legal_move(0, 0, False) False >>> g.is_legal_move(0, 1, True) True >>> g.is_legal_move(1, 1, True) False In the DominoesGame class, write a method legal_moves(self, vertical) which yields the legal moves available to the current player as (row, column) tuples. The moves should be generated in row-major order (i.e. iterating through the rows from top to bottom, and within rows from left to right), starting from the top-left corner of the board. >>> g = create_dominoes_game(3, 3) >>> list(g.legal_moves(True)) [(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)] >>> list(g.legal_moves(False)) >>> b = [[True, False], [True, False]] >>> g = DominoesGame(b) >>> list(g.legal_moves(True)) [(0, 1)] [(0, 0), (0, 1), (1, 0), (1, 1), (2, 0), (2, 1)] >>> list(g.legal_moves(False)) [] In the DominoesGame class, write a method perform_move(self, row, col, vertical) which fills the squares covered by a domino placed at the given location in the specified orientation. >>> g = create_dominoes_game(3, 3) >>> g.perform_move(0, 1, True) >>> g.get_board() [[False, True, False], [False, True, False], [False, False, False]] >>> g = create_dominoes_game(3, 3) >>> g.perform_move(1, 0, False) >>> g.get_board() [[False, False, False], [True, True, False], [False, False, False]] In the DominoesGame class, write a method game_over(self, vertical) that returns whether the current player is unable to place any dominoes. >>> b = [[False, False], [False, False]] >>> g = DominoesGame(b) >>> g.game_over(True) False >>> g.game_over(False) False >>> b = [[True, False], [True, False]] >>> g = DominoesGame(b) >>> g.game_over(True) False >>> g.game_over(False) True

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

you please help me with this code because I am struggling, I added my code in the photo:

question that I need help with:
you will develop an AI for a game in which two players take turns placing 1 x 2 dominoes on a rectangular grid. One player must always place his dominoes vertically, and the other must always place his dominoes horizontally. The last player who successfully places a domino on the board wins.

an infrastructure that is compatible with the provided GUI has been suggested. However, only the search method will be tested, so you are free to choose a different approach if you find it more convenient to do so.

The representation used for this puzzle is a two-dimensional list of Boolean values, where True corresponds to a filled square and False corresponds to an empty square.

tasks:

In the DominoesGame class, write a method is_legal_move(self, row, col, vertical) that returns a Boolean value indicating whether the given move can be played on the current board. A legal move must place a domino fully within bounds, and may not cover squares which have already been filled.


If the vertical parameter is True , then the current player intends to place a domino on squares (row, col) and (row + 1, col) . If the vertical parameter is False , then the current player
intends to place a domino on squares (row, col) and (row, col + 1) . This convention will be followed throughout the rest of the section.

>>> b = [[False, False], [False, False]]
>>> g = DominoesGame(b)
>>> g.is_legal_move(0, 0, True)
True
>>> g.is_legal_move(0, 0, False)
True
>>> b = [[True, False], [True, False]]
>>> g = DominoesGame(b)
>>> g.is_legal_move(0, 0, False)
False
>>> g.is_legal_move(0, 1, True)
True
>>> g.is_legal_move(1, 1, True)
False

In the DominoesGame class, write a method legal_moves(self, vertical) which yields the legal moves available to the current player as (row, column) tuples. The moves should be generated in row-major order (i.e. iterating through the rows from top to bottom, and within rows from left to right), starting from the top-left corner of the board.

>>> g = create_dominoes_game(3, 3)
>>> list(g.legal_moves(True))
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1),
(1, 2)]
>>> list(g.legal_moves(False))
>>> b = [[True, False], [True, False]]
>>> g = DominoesGame(b)
>>> list(g.legal_moves(True))
[(0, 1)]
[(0, 0), (0, 1), (1, 0), (1, 1), (2, 0),
(2, 1)]
>>> list(g.legal_moves(False))
[]

In the DominoesGame class, write a method perform_move(self, row, col, vertical) which fills the squares covered by a domino placed at the given location in the specified orientation.

>>> g = create_dominoes_game(3, 3)
>>> g.perform_move(0, 1, True)
>>> g.get_board()
[[False, True, False],
[False, True, False],
[False, False, False]]
>>> g = create_dominoes_game(3, 3)
>>> g.perform_move(1, 0, False)
>>> g.get_board()
[[False, False, False],
[True, True, False],
[False, False, False]]

In the DominoesGame class, write a method game_over(self, vertical) that returns whether the current player is unable to place any dominoes.

>>> b = [[False, False], [False, False]]
>>> g = DominoesGame(b)
>>> g.game_over(True)
False
>>> g.game_over(False)
False
>>> b = [[True, False], [True, False]]
>>> g = DominoesGame(b)
>>> g.game_over(True)
False
>>> g.game_over(False)
True

# MY CODE
5 usages
class DominoesGame:
def __init__(self, board):
self.board = board
14 usages (8 dynamic)
def get_board (self):
return self.board
2 usages
def reset (self):
rows = len(self.board)
cols=
len (self.board [0]]]
self.board = [[False] cols for in range (rows)]
-
2 usages
def create_dominoes_game (rows, cols):
return DominoesGame([[False] * cols for in range (rows)])
# Testing the implementation
if __name__ == "__main__":
-
# Test case 1
b = [[False, False], [False, False]]
g= DominoesGame (b)
print(g.get_board ()) # Output: [[False, False], [False, False]]
# Test case 2
b = [[True, False], [True, False]]
g = DominoesGame (b)
print(g.get_board()) # Output: [[True, False], [True, False]]
Transcribed Image Text:# MY CODE 5 usages class DominoesGame: def __init__(self, board): self.board = board 14 usages (8 dynamic) def get_board (self): return self.board 2 usages def reset (self): rows = len(self.board) cols= len (self.board [0]]] self.board = [[False] cols for in range (rows)] - 2 usages def create_dominoes_game (rows, cols): return DominoesGame([[False] * cols for in range (rows)]) # Testing the implementation if __name__ == "__main__": - # Test case 1 b = [[False, False], [False, False]] g= DominoesGame (b) print(g.get_board ()) # Output: [[False, False], [False, False]] # Test case 2 b = [[True, False], [True, False]] g = DominoesGame (b) print(g.get_board()) # Output: [[True, False], [True, False]]
# Test case 2
b = [[True, False], [True, False]]
g = Dominoes Game (b)
print(g.get_board()) # Output: [[True, False], [True, False]]
# Test case 3
g = create_dominoes_game (2, 2)
print(g.get_board()) # Output: [[False, False], [False, False]]
# Test case 4
g = create_dominoes_game (2, 3)
print(g.get_board ()) # Output: [[False, False, False], [False, False, False]]
# Test case 5
b = [[False, False], [False, False]]
g = DominoesGame (b)
g.reset()
print(g.get_board()) # Output: [[False, False], [False, False]]
# Test case 6
b = [[True, False], [True, False]]
g = DominoesGame (b)
g.reset()
print(g.get_board()) # Output: [[False, False], [False, False]]
Transcribed Image Text:# Test case 2 b = [[True, False], [True, False]] g = Dominoes Game (b) print(g.get_board()) # Output: [[True, False], [True, False]] # Test case 3 g = create_dominoes_game (2, 2) print(g.get_board()) # Output: [[False, False], [False, False]] # Test case 4 g = create_dominoes_game (2, 3) print(g.get_board ()) # Output: [[False, False, False], [False, False, False]] # Test case 5 b = [[False, False], [False, False]] g = DominoesGame (b) g.reset() print(g.get_board()) # Output: [[False, False], [False, False]] # Test case 6 b = [[True, False], [True, False]] g = DominoesGame (b) g.reset() print(g.get_board()) # Output: [[False, False], [False, False]]
Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education