Prog 5: 1024 And More

(4/7 changes shown in blue.  4/14 scoring info shown in red)

Write a C++ program to play a text-based version of the game of 1024, which is the same idea as the game of 2048, which itself is a copy of the (better) game of threes.  (I recommend you buy threes, BTW.  See this letter from its makers.).  When the program starts it should ask you what size board you would like (>= 4), should create that size board, then proceed with the game.  The goal for a 4x4 board is 1024.  Each additional increment in board size doubles the goal value.  Running this program should look like:

Dale Reed

UIC CS 141, Spring 2014

Welcome to 1024 and More.

This program is based off of Gabriele Cirulli's game online at

    bit.ly/great2048

For each move enter a direction as a letter key, as follows:

    W

  A S D

where A=left,W=up, D=right and S=down.

After a move, when two identical valued tiles come together they

join to become a new single tile with the value of the sum of the

two originals. This value gets added to the score.  On each move

one new randomly chosen value of 2 or 4 is placed in a random open

square.  User input of x exits the game.

Enter the size board you want, between 4 and 12: 4

Game ends when you reach 1024. 

Score: 0

   .   .   .   .

   2   .   .   .

   .   .   2   .

   .   .   .   .

1. Your move: a

Score: 0

   .   .   4   .

   2   .   .   .

   2   .   .   .

   .   .   .   .

2. Your move: s

Score: 4

   .   .   .   .

   .   .   .   .

   .   2   .   .

   4   .   4   .

3. Your move: 

.

.

.

Alternatively running the program where the board size is 5 would look like:

Dale Reed

UIC CS 141, Spring 2014

Welcome to 1024 and More.

This program is based off of Gabriele Cirulli's game online at

    bit.ly/great2048

For each move enter a direction as a letter key, as follows:

    W

  A S D

where A=left,W=up, D=right and S=down.

After a move, when two identical valued tiles come together they 

join to become a new single tile with the value of the sum of the 

two originals. This value gets added to the score.  On each move 

one new randomly chosen value of 2 or 4 is placed in a random open 

square.  User input of x exits the game.

Enter the size board you want, between 4 and 12: 5

Game ends when you reach 2048. 

Score: 0

   .   .   .   .   . 

   .   .   .   .   .

   .   2   .   .   2

   .   .   .   .   .

   .   .   .   .   .

1. Your move: d

Score: 4

   .   .   .   .   .

   .   .   2   .   .

   .   .   .   .   4

   .   .   .   .   .

   .   .   .   .   .

2. Your move: 

.

.

.

For each move all squares on the board move in the selected direction.  After each move any squares that have been combined get added to the score. Reaching some board tile that has the value 1024 ends the game. When moving left, start looking for pairs from the left.  When moving right, start looking for pairs from the right.  When moving down, start looking for pairs from the bottom.  When moving up, start looking for pairs from the top.

Additionally your program must handle input of 'p' to place a value at a particular board position.  The input:

   p 3 1024

would place the value 1024 at index position 3, where we consider the board to be stored as a one-dimensional array.

You should clear the screen between moves.  On windows this would be system("cls") and on UNIX it would by system("clear");   The version you turn in must run on the CS Department UNIX machines.

Scoring (of the 55 points for execution):

10  Allows making moves in all 4 directions and slides pieces correctly

10  Allows placing piece on the board manually  (and don't add a random piece in this case)

  5  Max size changes proportionately with board size change (4:1024, 5:2048 etc.)

  5  Allows creating different size boards

10  Combines pieces appropriately (  left slide of 2 2 4 becomes 4 4 and not 8)

  5  Only places random piece when a move is made resulting in pieces on the board moving

10  Detects end of game

Extra Credit (up to 10 points): 

For extra credit points have user input of i (upper or lower-case) starts up the "AI" (Artificial Intelligence) which does a multiple move look-ahead to select the current best move, and repeatedly does this automatically for 10 moves (or until game ends), pausing long enough between moves to allow us humans to see which move was made.  To pause, use system("sleep 1"); in UNIX to make the computer sleep for 1 second. 

(For your information see this example of an AI that plays this game, or this example that does the opposite and chooses the worst place for each newly placed tile.  And if these are all too easy for you, try NumberWhang)