def make_grid (w: int, h: int, player_coord: Tuple lint, int], gold_coord: Tuple[int, int]) -> List (List [str]]: Given two integers width w and height h, create a list of lists to represent a grid of the given width and height. The coordinates for the player and the gold is also given as two two-element tuples. For each tuple, the first element has the x-coordinate and the second element has the y-coordinate. The player and the gold should be included in the grid in the positions specified by these tuples. The player is represented with the string '(x)' The gold is represented with the string ' (o) All other spaces are represented with the string ')' Return this list. >>> make_grid(2, 3, (0, 0), (1, 2)) [[" (x)',)'1, I'O','O'1, I'O', ' (0)'11

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
def update_grid(grid: List [List [str]], w: int, h: int, px: int, py: int,
dx: int, dy: int) -> Optional [Tuple [int, int]]:
Given the player's current position as px and py,
and the directional changes in dx
and dy, update the given grid to change the player's
x-coordinate by dx, and their y-coordinate by dy.
More information:
Use the given w and h (representing the grid's width
and height) to figure out whether or not the move is valid.
If the move is not valid (that is, if it is outside
of the grid's boundaries), then NO change occurs to the grid.
The grid stays the same, and nothing is returned.
If the move IS possible, then the grid is updated
by adding dx to the player's x-coordinate,
and adding dy to the player's y-coordinate.
The new position in the grid is changed to the player
icon ' (x)', and the old position the player used to be in
is changed to an empty space 'O'. The new x- and y coordinates
of the player is returned as a tuple.
This function does NOT create or return a new grid.
It modifies the "grid" 1ist that is passed into it directly.
>>> L = [[' (x)''Q'1, IO', (0)'1, lO', 'O'1]
>>> update_grid (L, 2, 3, 0, 0, 1, 0)
(1, 0)
>>> L
[[O', '(x)'1, ĽO', '(0)'1, IO', 'O'1]
[l' (x)', 'O'1, [O', '(0)'1, I'O', 'O'1]
>>> L =
(0, 1)
>>> L
[[O', 'O'1, I' (x)', ' (o)'1, IO', 'O'1]
[[' (x)', 'O'], I'O', '(0)'], IO', 'O']]
>>> L =
>>> print (update_grid (L, 2, 3, 0, 0, -1, 0))
None
>>> L
[[' (x)', ')'1, Ľ'O', '(0)'1, IO', 'O'1]
Transcribed Image Text:def update_grid(grid: List [List [str]], w: int, h: int, px: int, py: int, dx: int, dy: int) -> Optional [Tuple [int, int]]: Given the player's current position as px and py, and the directional changes in dx and dy, update the given grid to change the player's x-coordinate by dx, and their y-coordinate by dy. More information: Use the given w and h (representing the grid's width and height) to figure out whether or not the move is valid. If the move is not valid (that is, if it is outside of the grid's boundaries), then NO change occurs to the grid. The grid stays the same, and nothing is returned. If the move IS possible, then the grid is updated by adding dx to the player's x-coordinate, and adding dy to the player's y-coordinate. The new position in the grid is changed to the player icon ' (x)', and the old position the player used to be in is changed to an empty space 'O'. The new x- and y coordinates of the player is returned as a tuple. This function does NOT create or return a new grid. It modifies the "grid" 1ist that is passed into it directly. >>> L = [[' (x)''Q'1, IO', (0)'1, lO', 'O'1] >>> update_grid (L, 2, 3, 0, 0, 1, 0) (1, 0) >>> L [[O', '(x)'1, ĽO', '(0)'1, IO', 'O'1] [l' (x)', 'O'1, [O', '(0)'1, I'O', 'O'1] >>> L = (0, 1) >>> L [[O', 'O'1, I' (x)', ' (o)'1, IO', 'O'1] [[' (x)', 'O'], I'O', '(0)'], IO', 'O']] >>> L = >>> print (update_grid (L, 2, 3, 0, 0, -1, 0)) None >>> L [[' (x)', ')'1, Ľ'O', '(0)'1, IO', 'O'1]
def make_grid (w: int, h: int, player_coord: Tuple [int, int],
gold coord: Tuple [int, int]) -> List [List[str]]:
Given two integers width w and height h, create a list
of lists to represent a grid of the given width and height.
The coordinates for the player and the gold
is also given as two two-element tuples. For each tuple,
the first element has the x-coordinate and the
second element has the y-coordinate. The player
and the gold should be included in the grid in
the positions specified by these tuples.
The player is represented with the string ' (x)'
The gold is represented with the string' (0)
All other spaces are represented with the string '()'
Return this list.
>>> make_grid (2, 3, (0, 0), (1, 2))
[[' (x)',
(o)' ]]
Transcribed Image Text:def make_grid (w: int, h: int, player_coord: Tuple [int, int], gold coord: Tuple [int, int]) -> List [List[str]]: Given two integers width w and height h, create a list of lists to represent a grid of the given width and height. The coordinates for the player and the gold is also given as two two-element tuples. For each tuple, the first element has the x-coordinate and the second element has the y-coordinate. The player and the gold should be included in the grid in the positions specified by these tuples. The player is represented with the string ' (x)' The gold is represented with the string' (0) All other spaces are represented with the string '()' Return this list. >>> make_grid (2, 3, (0, 0), (1, 2)) [[' (x)', (o)' ]]
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
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