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
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
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
Step by step
Solved in 4 steps with 1 images