Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Representing the game board A game board can be thought of as a table with rows (see the constant N_ROWS) and columns (N_COLUMNS). The size

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Representing the game board

A game board can be thought of as a table with rows (see the constant N_ROWS) and columns (N_COLUMNS). The size of a game board does not change during the course of a game. For example, here is an empty game board with 4 rows and 5 columns:

1 2 3 4 5

1 # | # | # | # | #

2 # | # | # | # | #

3 # | # | # | # | #

4 # | # | # | # | #

A location in the game board can be described by indicating the row and then the column. For example, using the empty

The Slide Game The Slide Game is a two player game played on a two-dimensional game board. The game board has a number of rows and columns specified at the beginning of the game and starts off filled with black squares. The following image is an example of a game board with 4 rows and 5 columns: Each player has an infinite number of squares in one colour 'e.g. one player has red squares; the other player has yellow squaresl. There are two mowes that a player can make to pet their squares onto the game board: 1. Slide Right 2. Slide Left The first plaver to place (un_merri of their squares in a straight line wins the game. Here., man_mou is a number like 3 . The 'straight line: tan be a horizuntal, vertical, or diagonal line of squares on the game board. Slide Right The "Slide Right" move allows a player to slide one of their squares onto the game board. The player must indicate which row they would like to slide their square onto. Because the size of the game board is fixed, the right-most souare in the pame board will 'fall off' to make room for the player's own souare. Slide Left The "Slide Left' move allows a player to slide one of their squares onto the pame board. The player must indicate which row they would like to slide their spuare onto. Eecause the size of the game hoard is fxecd, the left-most square in the game hoard will "fall off" to make room tor the player's cwn square. Winning the game The cobjective of the game is to be the first plaper to connect squares in a rowv either horizontally (or simply' "atross"), vertically (nr simply "down"), or diagonally. Diagonal lines come in two orientations: downward to the right and downward to the left. Assuming ma.ma: i is 3 . here are some examples of where squares should be placed in order to win the zame: The Slide Game in Python Constants are special variables whose values should not change once assigned -- you saw constants in the Week 2 Prepare module. A different naming convention (uppercase pothole) is used for constants, so that programmers know to not change their values. For example, in the starter code, the constant is assigned the value at the beginning of the module and the value of should never change in your code. When writing your code, if you need to use a black square, you should use . The same applies for the other constant values. Using constants simplifies code modifications and improves readability and changeability. For example, if we later decide to use a different character to represent a black square, we would only have to make a change in one place (the assignment statement), rather than throughout the program. This also makes our code more readable - whether we use or any other character to represent a black square, we write our code using the constant so it is clear to the reader what we mean. Representing the game board A game board can be thought of as a table with rows (see the constant . The size of a game board does not change during the course of a game. For example, here is an empty game board with 4 rows and 5 columns: 123451#####2#####3#####4##### A location in the game board can be described by indicating the row and then the column. For example, using the empty game board above, (1, 1) indicates the location at the top-left of the game board. And (4,5) indicates the bottom-right of the game board. We will use strings (i.e., the type) to represent the squares on a game board: - The black squares will be: - The red squares will be: 1. - The yellow squares will be: We have not yet studied how to store 2-dimensional information in Python programs, so we will need a different way to represent our game board. The approach that we will take for this assignment is to store the rows one after another, starting with the first row. - Using our empty (all black squares) game board example, this is: - Using a slightly more interesting example: 123451RHHH#2#HH#Y3RH#H#4YH#HH Would be represented as Accessing a square in the game board We have used row and column indices to describe the position of each square in the grid representation of a game board. But each character in a Python X... is in a position that is described by a single index. How is the Python program going to translate between row and column indices and str indices? To answer this question, we will have to determine a fonmula! Consider the following concrete example: 123451A|B|C|D|E2FGH1J3KLMNO4PQRST Which, as a string, is: bet us use the table helow to derive a formula that calculates the index based an: the location ii.e., row and columing and game board size (i.e., hi Rods, and/or A cocu4is j. From the table above, we see that the character in the square with position (2,1)( i.e., the square at row 2 and column 1) has index 5 . The ather squares in that row have indices 6,7,8 and 9 . We conclude that when moving one square across a row, the index increases by 1. The squares in column 3 have indices 2,7,12 and 17 . Moving one square down a calumn increases the index by 5 , which is the number af columns of the game board. We conclude that when moving one square down a column, the index increases by the game board's number of columns. Let us now introduce variables that will allow us to express the formula explicitly, Let a variable named grid representation of a game board. From what we have seen, we can conclude that and is, col, and ine following, formula vill cornpute The minus 1 's are necded for the arithmetic to work out. This is because we chose to index our rows and columns startine at 1 las a thoueht exercise, what would the formula be if we chose to index the rows and columns starting at O?]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

ISBN: 1844804526, 978-1844804528

Students also viewed these Databases questions

Question

=+26.14. 1 Show that y has no point masses if 2(t) is integrable.

Answered: 1 week ago

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago