Python编程语言调试、辅导program、Python程序设计讲解 辅导Python编程|讲解留学生Processing
- 首页 >> Python编程 Students:
This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns
about this content to your instructor. If you have any technical issues with the zyLab submission
system, use the Trouble with lab button at the bottom of the lab.
12.16 2048: ZyProject2: Fall 2020
This lab will be available until November 17th, 3:59 PM
[ N|Solid](2048 Simulation)
Lab Exam Instructions
You are to complete this assignment on your own before Saturday (14 Nov.) at 11:59 pm.
Submission on Sunday(11/15) will incur a 10% penalty, and 20% on Monday(11/16).
It is an open book project, and therefore you may reference notes, but you may not
reference each other, or any other individual. Otherwise, it is just like a normal lab
assignment: you may use PythonTutor, and you may submit as many times as you need.
MOSS: A Word on Plagiarism Detection
Please keep in mind that as computer science instructors, we care about academic
dishonesty just as strongly as our peers in other elds
of study. Unlike our peers, however,
our eld
of expertise and the nature of the material allows us to create tools that enhance
our detection of plagiarism. I'm sure you have heard of similar tools, such as TurnItIn.com,
and other plagiarism detection systems for essays. Since our eld
is more mathematical,
however, we are capable of considering not only the actual text written on the screen but
the overall ow
and intent of the program, and mathematically compare it to that of
another to determine the level of similarity between the two. Therefore, I highly suggest
that you do not "collaborate" with anyone else, as we will be able to detect it. If we catch
you cheating, you will receive an automatic zero in the class, and your case will be sent to
the Oce
of Academic Integrity & Student Conduct. With that being said, let's all take a
deep breath and try to have some fun!
Reading in CS?
If you decided to join computer science to try to avoid reading, you'll nd
that your
assumption about the eld
was terribly wrong. Not only do our assignment specications
have to be incredibly specic
and in-depth instructions, but being able to integrate our
work with that of others or vice-versa requires us to constantly read and check the
documentation of the code we're integrating (in)to. Therefore, you shouldn't shy away
from the reading required in the CS eld,
as building that habit now will only lead to your
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 2/15
downfall later. To encourage you to carefully read this assignment, we may have hidden
some useful information throughout the writeup.
Preamble
At this point in the course, you have enough knowledge about Python to do more than you
might rst
expect. Many simple games, for example, can be written with your
understanding of programming. So let's do it! Let's create the game 2048!
Concepts being tested
Data Structures
Nested Lists
Dictionaries
Potentially Sets
Branching
Loops
Nested Loops
Functions Basics
Critical thinking, planning, & organization
The Game
If you're not familiar with the game, try your hand at it here. The game has 4 controls:
w - move the board up
s - move the board down
a - move the board left
d - move the board right
Moving the board will slide the pieces towards the chosen direction, combining pieces
with the same number if they slide into each other. Sliding this board down, for example:
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 2 ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 2 ││ │
╰────╯╰────╯╰────╯╰────╯
results in this board:
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 3/15
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 4 ││ │
╰────╯╰────╯╰────╯╰────╯
The two 2's combine to form one 4. The game then randomly places another piece on the
board, which is the 2 in the upper left of the second board. The goal of the game is to
create a piece of the value 2048, in which case the player wins, and the game is over. The
game may also terminate if there are no more empty spaces for the game to place a new
piece in, and there are no more moves for the user to take, resulting in a loss for the player.
Our program will have one more input:
q - Terminates the program with the message: "Goodbye"
The Program
To help alleviate some of the pressure of creating a slightly larger program, we will provide
you with:
base code
utility functions
a strategy guide
Doing so will not only assist you in developing your program but has also created a way
for us to automatically test your program without human intervention, meaning you can
get instant feedback on your program as usual.
All the code you will write will be contained within the main.py module. The utilities.py
module provides a few helper functions to assist in writing the program. If you are
comfortable in doing so, you may write as many helper functions as you nd
necessary,
but your program must only execute when the function main() is called with the starting
board, as seen at the bottom of main.py template. The only other restriction is that your
program must use the place_random() function provided in the utilities module to
generate a new piece. Otherwise, you may throw out the base code or strategy guide and
go your own path.
DEV_MODE
The base code allows you to control the placement of the random pieces through input.
By setting the variable "DEV_MODE" to True, the program will prompt the user for column,
row coordinates and a value which it will then use to place the next piece (you must code
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 4/15
the placement of this piece, but the input prompt is provided). Include this code in the
game loop to control the placement of all pieces instead of relying on the random
function. This functionality is optional, but is a good starting ground for familiarizing
yourself with the game board data structure.
Flow of the Program
Most games follow a rather simple ow
of events. They rst
initialize key variables that
keep track of important aspects of the game, such as clearing the board, deciding who's
turn it is, resetting the score, etc. Then the game enters the game loop, which is a series of
events and responses that repeat until the game is over, at which point the program
breaks out of the loop. Depending on how the program is written, a third section may exist
where the program handles termination of the game, such as writing end scores or
corresponding win or loss messages.
"Single-Player" Computer Games
Although this game is technically played by only one person, the game isn't actually a
single-player game. From a coding perspective, there are two players involved: the human
who controls the moves, and the computer who places random pieces on the board. This
affects how you write the logic of the game, since you must keep track of whose turn it is.
The computer's turn is fairly simple: place a piece on the board and end the turn. The
player's turn, on the other hand, is harder to track. We must consider and properly handle
instances were the player does not act as we expect them to:
When the player inputs an invalid character "b", we must re-prompt them for input
until we receive a valid character (wasdq)
When the player inputs a valid move, we must verify that at least one piece on the
board moved. Otherwise, the player is allowed to input another move. We must
repeat this until the player inputs a move that affects the board.
Since these are two separate conditions, you should treat them as such. Don't try to solve
both checks with one solution.
Initializing Data
A game of 2048 can be tracked using 4 pieces of information:
The game board
A 2-dimensional list of integers representing the cells of the board.
Our board will be limited to a 4x4 eld.
Empty cells will be represented as 0's, and all other numbers represent
themselves.
The board data structure can be indexed by [row][column].
Index [0][0] is the top left of the board, [0][3] is top right, and [3][0] is the bottom
left.
Whose turn it is
Computer v. user
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 5/15
Useful in determining if a new piece should be added, as well as when to check
if the game is lost or won.
If the game has been won
Although your program may realize that the game has been won, it may not be
able to take action right away, and therefore, a tracker variable can be helpful
to signal the program to take action at a later time.
User input
Game-Ending Moves
Take a moment to consider how the game can end. Can a game of 2048 ever be lost on
the user's turn? Since the user cannot add more pieces to the board, the answer is no.
Therefore, the game can only be lost during the computer's turn. What about winning? Can
the game ever be won on the computer's turn? For similar reasons, no. Therefore, we only
need to check if the game has been won or lost after each respective turn.
Game Loop
A round of 2048 can be broken up into the following actions:
Computer's turn
Place a new piece on the board
Check if the game is lost and act accordingly
Print the Updated Board
Remember to use the utilities.py module
User's turn
1. Take input
2. Validate input, return to step 1 of the User's turn if the input is invalid
3. Quit the program if appropriate
4. Update the board
If the board hasn't changed, return to step 1 of the User's turn
5. Check if the game is won and act accordingly
Note: when you open a game of 2048, the board is already lled
with 2 pieces before the
player takes their turn.
Algorithms
User Moves The heart of this program is being able to manipulate the cells of the game
board to create the player moves. There are many different ways to approach this, but all
of them will require you to dig deep and apply many different concepts. You might, for
example, need to apply concepts such as reversing a list, list concatenation, or list/set
membership (the "in" operator).
Advise:
The obvious algorithm would involve moving pieces space by space across the
board until no more empty spaces remain in an applied direction.
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 6/15
This approach may be simpler to think of, but implementing it leaves a lot of
room for error.
A less obvious approach would be to delete unnecessary information from the board
and add it back in after combining pieces.
Shifting the row [0, 2, 0, 4] left or right results in [2, 4, …] or […, 2, 4]. What
information is important here? What can you ignore?
Most solutions will involve nested loops.
You should break the problem of updating the board down into the smaller
problem of updating a single row or column, and then repeating the process
for all rows or columns.
Examples:
Regardless of the specic
choice - 'w', 'a', 's', or 'd' - all user moves boil down to the same
algorithm, just applied in different directions. Let's take a look at the 'a' (shift left) move indepth,
which you can then apply to the remaining moves. Given the following board and
the instruction 'a':
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 4 ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ 2 ││ 4 ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ 2 ││ 4 ││ │
╰────╯╰────╯╰────╯╰────╯
the resulting board would look like:
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ 4 ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ 4 ││ ││ │
╰────╯╰────╯╰────╯╰────╯
Since each row is independent of its neighbors (hint), we can analyze them one at a time.
Viewing it in its list form, the rst
list undergoes this transformation:
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 7/15
[0, 4, 0, 0] -> [4, 0, 0, 0]
The second row:
[0, 2, 4, 0] -> [2, 4, 0, 0]
Things to note
What moves? The 2 and the 4, or the 0's?
[8, 0, 0, 0] -> [8, 0, 0, 0]
Why does the algorithm not move the 8?
[2, 2, 4, 0] -> [4, 4, 0, 0]
Does the number of 0's change? By how many? How can you calculate this?
How did the game know not to combine the two 4's?
Is there a way to track which pieces/cells were already used in a combine
move?
additional cases to consider:
[2, 2, 2, 0] -> [4, 2, 0, 0]
Why is it not [2, 4, 0, 0]?
Once you can handle a single row, is there a way to repeat the same process for the
remaining 3 rows?
If you can achieve an algorithm for 'a', then you can apply it to 'd' (shift right) as well by
reversing the direction of indices:
[2, 2, 4, 0] -> [0, 0, 4, 4]
Similarly, swapping the column and row coordinates, you can solve the vertical moves as
well
[0] [0]
[2] -> [0]
[2] [4]
[4] [4]
Suggestion
Try solving a row by hand (pen & paper), taking one step at a time. Note any logic you use
in deciding the next move. Things like "I can't move this piece over because ____", "It would
be easier to remove ____ than to move each piece over multiple times", or "I can't combine
this piece because ____". Then, convert the process into code.
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 8/15
Game Over
The other algorithm you will need to implement is the game-over detection system.
Let's consider the following board:
╭────╮╭────╮╭────╮╭────╮
│ ││ 2 ││ 8 ││ 4 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ 16 ││ 4 ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││128 ││ 16 ││ 8 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ 8 ││ 4 ││ 2 │
╰────╯╰────╯╰────╯╰────╯
What's the rst
thing you check to tell if the game is over? Immediately, you know the
game has not ended because there is at least one empty space for a new piece to be
generated in.
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ 2 ││ 8 ││ 4 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ 16 ││ 4 ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││128 ││ 16 ││ 8 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ 8 ││ 4 ││ 2 │
╰────╯╰────╯╰────╯╰────╯
This second board is lled
with pieces; no empty cells remain. To decide if the game is
lost, you must identify any valid user moves. Again, try your hand at doing this manually,
and then convert the process into code.
Hint: Attempting to apply each user move to determine if the game is over may work, but
requires more effort. Can you nd
a way to determine if the game is over by visiting each
cell only once (looping over the board only once)?
Sample Game
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 9/15
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
a
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 4 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ ││ ││ │
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 10/15
╰────╯╰────╯╰────╯╰────╯
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ ││ ││ 4 │
╰────╯╰────╯╰────╯╰────╯
wasd # note this input is invalid, and therefore the program
does not act upon it
wa # here it rejects the input again, only proceeding when the
input is valid
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ ││ ││ 4 │
╰────╯╰────╯╰────╯╰────╯
d
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 8 ││ 4 │
╰────╯╰────╯╰────╯╰────╯
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 2 ││ │
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 11/15
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 4 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ 8 ││ 4 │
╰────╯╰────╯╰────╯╰────╯
w
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ 2 ││ 8 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 8 ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
q
Goodbye
Updates
Return the game_board. The template and tests have been updated to reect
this. If you
already have code, just add "return game_board" to the end of your code.
You may assume that place_board will always return a valid space, you should not verify
that the space is available.
You should call place_random only once per piece.
Due to an issue with the test cases, only submissions after Nov. 11th 2:45 will be
considered for your nal
score. If you have already completed the lab, please re-submit.
260354.1651872
LAB
ACTIVITY
12.16.1: 2048: ZyProject2: Fall 2020 2 / 53
Downloadable les
main.py utilities.py Download
Current le:
main.py Load default template...
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 12/15
from utilities import place_random, print_board
DEV_MODE = False
def main(game_board: [[int, ], ]) -> [[int, ], ]:
"""
2048 main function, runs a game of 2048 in the console.
Uses the following keys:
w - shift up
a - shift left
s - shift down
d - shift right
q - ends the game and returns control of the console
:param game_board: a 4x4 2D list of integers representing a game of 2048
:return: returns the ending game board
"""
# Initialize board's first cell
p = place_random(game_board)
game_board[p['row']][p['column']] = p['value']
# Initialize game state trackers
# Game Loop
while True:
# TODO: Reset user input variable
user_input = input()
# TODO: Take computer's turn
# place a random piece on the board
L = place_random(game_board)
# check to see if the game is over using the game_over function
if game_over() is True:
print_board(game_board)
break
# TODO: Show updated board using the print_board function
print_board(game_board)
# TODO: Take user's turn
# Take input until the user's move is a valid key
# if the user quits the game, print Goodbye and stop the Game Loop
if user_input == 'a':
for i in range(len(game_board[][])):
# Execute the user's move
# Check if the user wins
if game_over() is True:
print_board(game_board)
return game_board
def game_over(game_board: [[int, ], ]) -> bool:
"""
Query the provided board's game state.
:param game_board: a 4x4 2D list of integers representing a game of 2048
:return: Boolean indicating if the game is over (True) or not (False)
"""
# TODO: Loop over the board and determine if the game is over
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 13/15
When done developing your program, press the
Submit for grading button below. This will
submit your program for auto-grading.
Signature of your work
11/11.. W- R---|2--------|2-------- F----------|2-|2|1
|1|1|1|1|1|1|1|1|2|2|2|2|2-|2|2|2|2|2|0 S|0|0|0|0|0|0
|0|0--|0|0|0 ..11/14
Latest submission - 12:35 PM on 11/14/20 Total score: 0 / 53
1: Validate_Variables 0 / 1
Validates required variables & functions are present in main le.
2: q_termination 0 / 1
Veries
the program terminates when q is given as the rst
input.
3: initialize_board 0 / 1
Veries
the game correctly initializes the board and immediately terminates
the program
4: validate_game_over 0 / 4
Verify the game_over function correctly identies
a full lost board vs. an
semi-empty, non-lost board
5: validate_game_over__full_but_valid_moves_remaining 0 / 4
Develop mode Submit mode
Submit for grading
What is this?
Only show failing tests Download this submission
return False # TODO: Don't always return false
if __name__ == "__main__":
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 14/15
Verify the game_over function correctly identies
a full board that has valid
moves left vs. one that does not.
6: a_move__non_combining__no_action 0 / 1
Veries
non_combining features of the "a" move where no action is expected:
empty row, non-moving single piece, two non-moving pieces, and a full row.
7: a_move__non_combining__action 0 / 1
Veries
non_combining features of the "a" move where action is required:
single moving piece, two moving pieces.
8: a_move__combining_0 0 / 2
Veries
combining features of the "a" move: two combining pieces, two
combining pieces and additional non-combining pieces.
9: a_move__combining_1 0 / 2
Veries
combining features of the "a" move: two combining pieces and
additional non-combining pieces, two pairs of combining pieces, a row of all
the same pieces.
10: a_move__combining_2 0 / 2
Veries
combining features of the "a" move: two combining pieces and a
piece of the same new value, three pieces of the same value.
11: d_move 0 / 8
Veries
the functionality of the "d" move.
12: s_move 0 / 10
Veries
the functionality of the "s" move.
13: w_move 0 / 10
Veries
the functionality of the "w" move.
14: win_detection 0 / 2
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 15/15
Veries
that the game can successfully detect a won board and terminates
without taking further input. (Requires basic "a"-move functionality).
15: mock_game 0 / 4
Simulates part of a game of 2048. Moves: dsasdsasddsaaa
5 previous submissions
11:19 AM on 11/14/20 0 / 53
10:37 AM on 11/14/20 0 / 53
2:04 AM on 11/14/20 0 / 53
1:56 AM on 11/14/20 0 / 53
12:57 AM on 11/14/20 0 / 53
Trouble with lab?
This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns
about this content to your instructor. If you have any technical issues with the zyLab submission
system, use the Trouble with lab button at the bottom of the lab.
12.16 2048: ZyProject2: Fall 2020
This lab will be available until November 17th, 3:59 PM
[ N|Solid](2048 Simulation)
Lab Exam Instructions
You are to complete this assignment on your own before Saturday (14 Nov.) at 11:59 pm.
Submission on Sunday(11/15) will incur a 10% penalty, and 20% on Monday(11/16).
It is an open book project, and therefore you may reference notes, but you may not
reference each other, or any other individual. Otherwise, it is just like a normal lab
assignment: you may use PythonTutor, and you may submit as many times as you need.
MOSS: A Word on Plagiarism Detection
Please keep in mind that as computer science instructors, we care about academic
dishonesty just as strongly as our peers in other elds
of study. Unlike our peers, however,
our eld
of expertise and the nature of the material allows us to create tools that enhance
our detection of plagiarism. I'm sure you have heard of similar tools, such as TurnItIn.com,
and other plagiarism detection systems for essays. Since our eld
is more mathematical,
however, we are capable of considering not only the actual text written on the screen but
the overall ow
and intent of the program, and mathematically compare it to that of
another to determine the level of similarity between the two. Therefore, I highly suggest
that you do not "collaborate" with anyone else, as we will be able to detect it. If we catch
you cheating, you will receive an automatic zero in the class, and your case will be sent to
the Oce
of Academic Integrity & Student Conduct. With that being said, let's all take a
deep breath and try to have some fun!
Reading in CS?
If you decided to join computer science to try to avoid reading, you'll nd
that your
assumption about the eld
was terribly wrong. Not only do our assignment specications
have to be incredibly specic
and in-depth instructions, but being able to integrate our
work with that of others or vice-versa requires us to constantly read and check the
documentation of the code we're integrating (in)to. Therefore, you shouldn't shy away
from the reading required in the CS eld,
as building that habit now will only lead to your
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 2/15
downfall later. To encourage you to carefully read this assignment, we may have hidden
some useful information throughout the writeup.
Preamble
At this point in the course, you have enough knowledge about Python to do more than you
might rst
expect. Many simple games, for example, can be written with your
understanding of programming. So let's do it! Let's create the game 2048!
Concepts being tested
Data Structures
Nested Lists
Dictionaries
Potentially Sets
Branching
Loops
Nested Loops
Functions Basics
Critical thinking, planning, & organization
The Game
If you're not familiar with the game, try your hand at it here. The game has 4 controls:
w - move the board up
s - move the board down
a - move the board left
d - move the board right
Moving the board will slide the pieces towards the chosen direction, combining pieces
with the same number if they slide into each other. Sliding this board down, for example:
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 2 ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 2 ││ │
╰────╯╰────╯╰────╯╰────╯
results in this board:
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 3/15
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 4 ││ │
╰────╯╰────╯╰────╯╰────╯
The two 2's combine to form one 4. The game then randomly places another piece on the
board, which is the 2 in the upper left of the second board. The goal of the game is to
create a piece of the value 2048, in which case the player wins, and the game is over. The
game may also terminate if there are no more empty spaces for the game to place a new
piece in, and there are no more moves for the user to take, resulting in a loss for the player.
Our program will have one more input:
q - Terminates the program with the message: "Goodbye"
The Program
To help alleviate some of the pressure of creating a slightly larger program, we will provide
you with:
base code
utility functions
a strategy guide
Doing so will not only assist you in developing your program but has also created a way
for us to automatically test your program without human intervention, meaning you can
get instant feedback on your program as usual.
All the code you will write will be contained within the main.py module. The utilities.py
module provides a few helper functions to assist in writing the program. If you are
comfortable in doing so, you may write as many helper functions as you nd
necessary,
but your program must only execute when the function main() is called with the starting
board, as seen at the bottom of main.py template. The only other restriction is that your
program must use the place_random() function provided in the utilities module to
generate a new piece. Otherwise, you may throw out the base code or strategy guide and
go your own path.
DEV_MODE
The base code allows you to control the placement of the random pieces through input.
By setting the variable "DEV_MODE" to True, the program will prompt the user for column,
row coordinates and a value which it will then use to place the next piece (you must code
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 4/15
the placement of this piece, but the input prompt is provided). Include this code in the
game loop to control the placement of all pieces instead of relying on the random
function. This functionality is optional, but is a good starting ground for familiarizing
yourself with the game board data structure.
Flow of the Program
Most games follow a rather simple ow
of events. They rst
initialize key variables that
keep track of important aspects of the game, such as clearing the board, deciding who's
turn it is, resetting the score, etc. Then the game enters the game loop, which is a series of
events and responses that repeat until the game is over, at which point the program
breaks out of the loop. Depending on how the program is written, a third section may exist
where the program handles termination of the game, such as writing end scores or
corresponding win or loss messages.
"Single-Player" Computer Games
Although this game is technically played by only one person, the game isn't actually a
single-player game. From a coding perspective, there are two players involved: the human
who controls the moves, and the computer who places random pieces on the board. This
affects how you write the logic of the game, since you must keep track of whose turn it is.
The computer's turn is fairly simple: place a piece on the board and end the turn. The
player's turn, on the other hand, is harder to track. We must consider and properly handle
instances were the player does not act as we expect them to:
When the player inputs an invalid character "b", we must re-prompt them for input
until we receive a valid character (wasdq)
When the player inputs a valid move, we must verify that at least one piece on the
board moved. Otherwise, the player is allowed to input another move. We must
repeat this until the player inputs a move that affects the board.
Since these are two separate conditions, you should treat them as such. Don't try to solve
both checks with one solution.
Initializing Data
A game of 2048 can be tracked using 4 pieces of information:
The game board
A 2-dimensional list of integers representing the cells of the board.
Our board will be limited to a 4x4 eld.
Empty cells will be represented as 0's, and all other numbers represent
themselves.
The board data structure can be indexed by [row][column].
Index [0][0] is the top left of the board, [0][3] is top right, and [3][0] is the bottom
left.
Whose turn it is
Computer v. user
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 5/15
Useful in determining if a new piece should be added, as well as when to check
if the game is lost or won.
If the game has been won
Although your program may realize that the game has been won, it may not be
able to take action right away, and therefore, a tracker variable can be helpful
to signal the program to take action at a later time.
User input
Game-Ending Moves
Take a moment to consider how the game can end. Can a game of 2048 ever be lost on
the user's turn? Since the user cannot add more pieces to the board, the answer is no.
Therefore, the game can only be lost during the computer's turn. What about winning? Can
the game ever be won on the computer's turn? For similar reasons, no. Therefore, we only
need to check if the game has been won or lost after each respective turn.
Game Loop
A round of 2048 can be broken up into the following actions:
Computer's turn
Place a new piece on the board
Check if the game is lost and act accordingly
Print the Updated Board
Remember to use the utilities.py module
User's turn
1. Take input
2. Validate input, return to step 1 of the User's turn if the input is invalid
3. Quit the program if appropriate
4. Update the board
If the board hasn't changed, return to step 1 of the User's turn
5. Check if the game is won and act accordingly
Note: when you open a game of 2048, the board is already lled
with 2 pieces before the
player takes their turn.
Algorithms
User Moves The heart of this program is being able to manipulate the cells of the game
board to create the player moves. There are many different ways to approach this, but all
of them will require you to dig deep and apply many different concepts. You might, for
example, need to apply concepts such as reversing a list, list concatenation, or list/set
membership (the "in" operator).
Advise:
The obvious algorithm would involve moving pieces space by space across the
board until no more empty spaces remain in an applied direction.
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 6/15
This approach may be simpler to think of, but implementing it leaves a lot of
room for error.
A less obvious approach would be to delete unnecessary information from the board
and add it back in after combining pieces.
Shifting the row [0, 2, 0, 4] left or right results in [2, 4, …] or […, 2, 4]. What
information is important here? What can you ignore?
Most solutions will involve nested loops.
You should break the problem of updating the board down into the smaller
problem of updating a single row or column, and then repeating the process
for all rows or columns.
Examples:
Regardless of the specic
choice - 'w', 'a', 's', or 'd' - all user moves boil down to the same
algorithm, just applied in different directions. Let's take a look at the 'a' (shift left) move indepth,
which you can then apply to the remaining moves. Given the following board and
the instruction 'a':
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 4 ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ 2 ││ 4 ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ 2 ││ 4 ││ │
╰────╯╰────╯╰────╯╰────╯
the resulting board would look like:
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ 4 ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ 4 ││ ││ │
╰────╯╰────╯╰────╯╰────╯
Since each row is independent of its neighbors (hint), we can analyze them one at a time.
Viewing it in its list form, the rst
list undergoes this transformation:
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 7/15
[0, 4, 0, 0] -> [4, 0, 0, 0]
The second row:
[0, 2, 4, 0] -> [2, 4, 0, 0]
Things to note
What moves? The 2 and the 4, or the 0's?
[8, 0, 0, 0] -> [8, 0, 0, 0]
Why does the algorithm not move the 8?
[2, 2, 4, 0] -> [4, 4, 0, 0]
Does the number of 0's change? By how many? How can you calculate this?
How did the game know not to combine the two 4's?
Is there a way to track which pieces/cells were already used in a combine
move?
additional cases to consider:
[2, 2, 2, 0] -> [4, 2, 0, 0]
Why is it not [2, 4, 0, 0]?
Once you can handle a single row, is there a way to repeat the same process for the
remaining 3 rows?
If you can achieve an algorithm for 'a', then you can apply it to 'd' (shift right) as well by
reversing the direction of indices:
[2, 2, 4, 0] -> [0, 0, 4, 4]
Similarly, swapping the column and row coordinates, you can solve the vertical moves as
well
[0] [0]
[2] -> [0]
[2] [4]
[4] [4]
Suggestion
Try solving a row by hand (pen & paper), taking one step at a time. Note any logic you use
in deciding the next move. Things like "I can't move this piece over because ____", "It would
be easier to remove ____ than to move each piece over multiple times", or "I can't combine
this piece because ____". Then, convert the process into code.
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 8/15
Game Over
The other algorithm you will need to implement is the game-over detection system.
Let's consider the following board:
╭────╮╭────╮╭────╮╭────╮
│ ││ 2 ││ 8 ││ 4 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ 16 ││ 4 ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││128 ││ 16 ││ 8 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ 8 ││ 4 ││ 2 │
╰────╯╰────╯╰────╯╰────╯
What's the rst
thing you check to tell if the game is over? Immediately, you know the
game has not ended because there is at least one empty space for a new piece to be
generated in.
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ 2 ││ 8 ││ 4 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ 16 ││ 4 ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││128 ││ 16 ││ 8 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ 8 ││ 4 ││ 2 │
╰────╯╰────╯╰────╯╰────╯
This second board is lled
with pieces; no empty cells remain. To decide if the game is
lost, you must identify any valid user moves. Again, try your hand at doing this manually,
and then convert the process into code.
Hint: Attempting to apply each user move to determine if the game is over may work, but
requires more effort. Can you nd
a way to determine if the game is over by visiting each
cell only once (looping over the board only once)?
Sample Game
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 9/15
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
a
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 4 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 4 ││ ││ ││ │
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 10/15
╰────╯╰────╯╰────╯╰────╯
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ ││ ││ 4 │
╰────╯╰────╯╰────╯╰────╯
wasd # note this input is invalid, and therefore the program
does not act upon it
wa # here it rejects the input again, only proceeding when the
input is valid
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 8 ││ ││ ││ 4 │
╰────╯╰────╯╰────╯╰────╯
d
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 8 ││ 4 │
╰────╯╰────╯╰────╯╰────╯
s
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 2 ││ │
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 11/15
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 4 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ 8 ││ 4 │
╰────╯╰────╯╰────╯╰────╯
w
╭────╮╭────╮╭────╮╭────╮
│ 2 ││ ││ 2 ││ 8 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ 8 ││ │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ 2 │
╰────╯╰────╯╰────╯╰────╯
╭────╮╭────╮╭────╮╭────╮
│ ││ ││ ││ │
╰────╯╰────╯╰────╯╰────╯
q
Goodbye
Updates
Return the game_board. The template and tests have been updated to reect
this. If you
already have code, just add "return game_board" to the end of your code.
You may assume that place_board will always return a valid space, you should not verify
that the space is available.
You should call place_random only once per piece.
Due to an issue with the test cases, only submissions after Nov. 11th 2:45 will be
considered for your nal
score. If you have already completed the lab, please re-submit.
260354.1651872
LAB
ACTIVITY
12.16.1: 2048: ZyProject2: Fall 2020 2 / 53
Downloadable les
main.py utilities.py Download
Current le:
main.py Load default template...
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 12/15
from utilities import place_random, print_board
DEV_MODE = False
def main(game_board: [[int, ], ]) -> [[int, ], ]:
"""
2048 main function, runs a game of 2048 in the console.
Uses the following keys:
w - shift up
a - shift left
s - shift down
d - shift right
q - ends the game and returns control of the console
:param game_board: a 4x4 2D list of integers representing a game of 2048
:return: returns the ending game board
"""
# Initialize board's first cell
p = place_random(game_board)
game_board[p['row']][p['column']] = p['value']
# Initialize game state trackers
# Game Loop
while True:
# TODO: Reset user input variable
user_input = input()
# TODO: Take computer's turn
# place a random piece on the board
L = place_random(game_board)
# check to see if the game is over using the game_over function
if game_over() is True:
print_board(game_board)
break
# TODO: Show updated board using the print_board function
print_board(game_board)
# TODO: Take user's turn
# Take input until the user's move is a valid key
# if the user quits the game, print Goodbye and stop the Game Loop
if user_input == 'a':
for i in range(len(game_board[][])):
# Execute the user's move
# Check if the user wins
if game_over() is True:
print_board(game_board)
return game_board
def game_over(game_board: [[int, ], ]) -> bool:
"""
Query the provided board's game state.
:param game_board: a 4x4 2D list of integers representing a game of 2048
:return: Boolean indicating if the game is over (True) or not (False)
"""
# TODO: Loop over the board and determine if the game is over
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 13/15
When done developing your program, press the
Submit for grading button below. This will
submit your program for auto-grading.
Signature of your work
11/11.. W- R---|2--------|2-------- F----------|2-|2|1
|1|1|1|1|1|1|1|1|2|2|2|2|2-|2|2|2|2|2|0 S|0|0|0|0|0|0
|0|0--|0|0|0 ..11/14
Latest submission - 12:35 PM on 11/14/20 Total score: 0 / 53
1: Validate_Variables 0 / 1
Validates required variables & functions are present in main le.
2: q_termination 0 / 1
Veries
the program terminates when q is given as the rst
input.
3: initialize_board 0 / 1
Veries
the game correctly initializes the board and immediately terminates
the program
4: validate_game_over 0 / 4
Verify the game_over function correctly identies
a full lost board vs. an
semi-empty, non-lost board
5: validate_game_over__full_but_valid_moves_remaining 0 / 4
Develop mode Submit mode
Submit for grading
What is this?
Only show failing tests Download this submission
return False # TODO: Don't always return false
if __name__ == "__main__":
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 14/15
Verify the game_over function correctly identies
a full board that has valid
moves left vs. one that does not.
6: a_move__non_combining__no_action 0 / 1
Veries
non_combining features of the "a" move where no action is expected:
empty row, non-moving single piece, two non-moving pieces, and a full row.
7: a_move__non_combining__action 0 / 1
Veries
non_combining features of the "a" move where action is required:
single moving piece, two moving pieces.
8: a_move__combining_0 0 / 2
Veries
combining features of the "a" move: two combining pieces, two
combining pieces and additional non-combining pieces.
9: a_move__combining_1 0 / 2
Veries
combining features of the "a" move: two combining pieces and
additional non-combining pieces, two pairs of combining pieces, a row of all
the same pieces.
10: a_move__combining_2 0 / 2
Veries
combining features of the "a" move: two combining pieces and a
piece of the same new value, three pieces of the same value.
11: d_move 0 / 8
Veries
the functionality of the "d" move.
12: s_move 0 / 10
Veries
the functionality of the "s" move.
13: w_move 0 / 10
Veries
the functionality of the "w" move.
14: win_detection 0 / 2
2020/11/14 12.16. 2048: ZyProject2: Fall 2020
https://learn.zybooks.com/zybook/UCIICSCI31Fall2020/chapter/12/section/16?content_resource_id=51678412 15/15
Veries
that the game can successfully detect a won board and terminates
without taking further input. (Requires basic "a"-move functionality).
15: mock_game 0 / 4
Simulates part of a game of 2048. Moves: dsasdsasddsaaa
5 previous submissions
11:19 AM on 11/14/20 0 / 53
10:37 AM on 11/14/20 0 / 53
2:04 AM on 11/14/20 0 / 53
1:56 AM on 11/14/20 0 / 53
12:57 AM on 11/14/20 0 / 53
Trouble with lab?