代写C++代码 代做C++程序 C++辅导 C++教学

C++网络家教 远程写代码 在线Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

2048 is a recent online computer game. Play takes place on a 4x4 board of squares on which a
sequence of tiles appears, each holding a number. Players move tiles around by sliding rows and
columns, with the aim of combining identical tiles to make higher numbers. The player's score is
determined largely by the tiles on the final board.
You can play 2048 online to get familiar with the game. In this project you will construct a computer
player for a simplified version of 2048, and also an interface for a human player.
The rules of 2048
Tiles
2048 is played on a 4x4 grid of squares. Each square is either empty, or it holds a tile holding a number
in {2, 4, 8, 16, 32, 64, ...}, i.e. a power of two. At the start of the game the board holds between one and
sixteen 2­tiles.
Moves
The player makes a sequence of moves, each of which is Left, Right, Up, or Down. The description below
is for Up moves ­ probably you can translate for the other three possibilities, otherwise they are described
here.
An Up move causes all columns on the board to attempt to slide upwards.
If no column can legally slide, nothing happens.
Otherwise all legal slides are implemented, and then a new 2­tile appears in the leftmost empty
square of the bottom row.
Testing slides
A column's attempt to slide upwards is deemed legal if either or both of the following apply.
A non­empty square in that column has an empty square above it.
Two adjacent squares in that column hold identical tiles.
A column cannot slide upwards if it has X tiles at the top with no adjacent identical tiles, and 4­X empty
squares at the bottom.
Implementing slides
When a slide is implemented, the following occurs.
U S E F U L L I N K S
Unit outline
Unit timetable 2016
help1001
csentry
cssubmit
csmarks
Compulsory online modules
26/05/2016 CITS1001: Project 2
http://teaching.csse.uwa.edu.au/units/CITS1001/projects/project2/ 2/5
All squares slide to the top of the column, then
where there are two adjacent squares holding identical tiles K, those tiles combine into a single tile 2K
on the higher square, and all lower tiles slide up again. A tile can participate in only one combination
in a given move.
Examples
The following examples should help.
Illegal slide Illegal slide No combinations, only
sliding
No combinations, only
sliding
One combination One combination
Two combinations Combination is not recursive Combination is not recursive
Game over
The game is over when no more successful (i.e. legal) moves are possible.
Scoring
Each successful move gets one point, and each unsuccessful move loses one point ­ so the score can go
up or down as the game proceeds.
Representations
Squares
Each square on the board is represented by an object belonging to the class Square. The class records
what value the square currently holds, with 0 representing an empty square; it also provides methods to
interrogate this value, and to set or modify it safely. You are required to write the constructor for Square,
and one public method.
public void setSquare(int x) throws Exception
sets the square to the value x if it is 0 or a legal tile value, otherwise it throws a checked exception with
a suitable error message.
public Square(int x)
creates the square with the value x if it is 0 or a legal tile value, otherwise it creates an empty square.
The game state
The state of the game as it progresses is represented by an object belonging to the class GameState.
This records the current state of the board, and the current score. You are required to write two
constructors for GameState, and the following public methods.
public GameState(String file) throws Exception
sets up the board according to the contents of the file file, e.g. B1.txt. You may assume that the file
format is exactly the same as in the example. If all squares are set to empty, the constructor throws a
checked exception with a suitable error message.
public GameState(double p) throws Exception
sets up the board with each square independently set to either 2 (with probability p) or empty. If all
26/05/2016 CITS1001: Project 2
http://teaching.csse.uwa.edu.au/units/CITS1001/projects/project2/ 3/5
squares are set to empty, the constructor throws a checked exception with a suitable error message.
public boolean forward(Square[] row)
attempts to slide row towards the front of the array, in the manner described above. Based on the nine
pictured examples, it would do the following.
{0,0,0,0} is unchanged
{2,8,4,0} is unchanged
{0,2,0,4} turns into {2,4,0,0}
{4,2,0,4} turns into {4,2,4,0}
{2,2,0,0} turns into {4,0,0,0}
{0,2,0,2} turns into {4,0,0,0}
{2,2,4,4} turns into {4,8,0,0}
{2,0,2,4} turns into {4,4,0,0}
{2,2,2,2} turns into {4,4,0,0}
If the method makes any changes to row, it returns true; otherwise it returns false.
public void left()
attempts a Left move. Remember to include the placement of the new tile, if appropriate, and
remember to update the score.
public void clockwise()
rotates the board 90 degrees clockwise, e.g. it would turn {{2,4,8,16},{32,0,0,0},{64,0,0,0},{128,0,0,0}}
into {{128,64,32,2},{0,0,0,4},{0,0,0,8},{0,0,0,16}}. In pictures:
public void anticlockwise()
rotates the board 90 degrees anti­clockwise, e.g. it would turn {{128,64,32,2},{0,0,0,4},{0,0,0,8},
{0,0,0,16}} into {{2,4,8,16},{32,0,0,0},{64,0,0,0},{128,0,0,0}}. (It does the inverse of clockwise.)
public void right()
attempts a Right move.
public void up()
attempts an Up move.
public void down()
attempts a Down move.
public boolean gameOver()
returns true iff there are no legal moves available on the current board.
The game
The class Play2048 defines the code for actually playing 2048. You are required to write three
constructors for 2048, and one public method.
public Play2048(String file)
sets up a game using the file file, and displays the initial board.
public Play2048(double p)
sets up a game using the probability p, and displays the initial board.
public Play2048()
sets up a game using the probability 0.3, and displays the initial board.
public void play2048()
makes the computer play a game of 2048, with each (attempted) move chosen uniformly randomly.
Display the score as you go along, and display a "Game Over" message when no legal moves are
available.
It will almost certainly help you to split up some of these methods, i.e. to write private helper methods.
Tasks
The software architecture you will use for 2048 thus comprises five classes.
Play2048
GameState
Square
SimpleCanvas ­ note that this version is slightly simplified from previous versions
FileIO
26/05/2016 CITS1001: Project 2
http://teaching.csse.uwa.edu.au/units/CITS1001/projects/project2/ 4/5
Each link above gives you a skeleton of the required class, including instance variables, constructors,
and methods. You are required to complete the methods and constructors whose bodies are marked with
the comment TODO, in Play2048.java, GameState.java, and Square.java. Make sure you understand the
connections between the classes, and where each method fits into the scheme described above.
I suggest you tackle these tasks in roughly the order above, although it may be helpful to write a
constructor for Play2048 and a board display method early, to make testing easier. Here are some tips. If
I add to this list, I will update the document version number.
The move description on the main page is for an Up move; whereas the first move you are likely to
implement is a Left move. Make sure that this discrepancy doesn't cause you any problems!
When performing moves, you need to update the existing board. Creating new array(s) will not make
the tester happy.
You may add instance variables to Play2048, although make sure that the information being stored
really needs an instance variable. Do not add instance variables to the other classes.
Avoid repetitious code! There is much less work here than it may appear...
Submission
Submit your three completed files Play2048.java, GameState.java, and Square.java via cssubmit. Only
one submission per team is required, but make sure that all names are clearly marked on every
submitted class.
Your file names, class names, and method names and signatures must match the specifications
exactly. The marking process is partly automated and any deviation in the names or signatures will
cause problems, which will be penalised.
Assessment
Your submission will be assessed on
completeness: how many of the methods you have written;
correctness: whether your methods implement the specifications exactly;
clarity: whether your code is clear to read and well­constructed;
display: how attractive your 2048 display is.
You can (theoretically) get 100% in this project by implementing completely
all game mechanics, and
a computer player that selects a random move to attempt at each turn, and
a basic screen display using SimpleCanvas that shows the progression of a game (something like the
example boards above).
However, if you lose marks in the basic phase of the project, you can regain some of those marks by
going further with some aspects of the game. Suggestions would include
implementing a version of 2048 that works for arbitrary (user­defined) board­sizes;
implementing a more­intelligent computer player for 2048;
implementing a fancier interface for 2048, that allows humans to play the game.
If you extend your program in an attempt to get bonus marks, please make that clear in your submitted
files. Note that it is not possible to get more than 100% of the project mark.
Testing
Testing classes are provided for you to validate your program before submission.
SquareTest
GameStateTest
B1.txt
Note however that the correctness of your program is your responsibility. The testing classes are
(intentionally) quite brief, and a program that passes all of the tests is not guaranteed to be free of errors.
"Testing shows the presence, not the absence, of bugs." ­­ E.W. Dijkstra
Feel free to augment the testing classes with more tests of your own.
26/05/2016 CITS1001: Project 2
http://teaching.csse.uwa.edu.au/units/CITS1001/projects/project2/ 5/5
Prizes
There are two prizes** available for Project 2:
a prize for the best performing 2048 computer player;
a prize for the most attractive 2048 human player interface.
If you believe your submission is worthy of consideration for a prize, email lyndon.while@uwa.edu.au
with a brief description of what you have achieved. We will download your actual submission from
cssubmit in the usual way. You can apply for both prizes, but normally the prizes will be awarded to
different groups.
**All prizes are awarded or not solely at Lyndon's discretion. Late submissions will not be eligible for
prizes.

相关推荐