Answer To: This is the second part of the assignment, and i will attach all the required files.
Pratik answered on Apr 18 2021
2048 2/AiMain2048.class
public synchronized class AiMain2048 {
public void AiMain2048();
public static void main(String[]);
}
2048 2/Main2048.class
public synchronized class Main2048 {
public void Main2048();
public static void main(String[]);
static void ();
}
2048 2/TwoThousandFourtyEight.class
synchronized class TwoThousandFourtyEight implements TwoThousandFourtyEightInt {
int rows;
int cols;
int[][] Board;
void TwoThousandFourtyEight(int, int);
void TwoThousandFourtyEight(int[][]);
public int[][] getBoard();
public int getHighestTile();
public int cal_score(int);
public int getScore();
public void printBoard();
public TwoThousandFourtyEight copy();
public boolean up();
public boolean down();
public boolean left();
public boolean right();
}
2048 2/TwoThousandFourtyEightInt.class
public abstract interface TwoThousandFourtyEightInt {
public abstract int getScore();
public abstract int[][] getBoard();
public abstract int getHighestTile();
public abstract void printBoard();
public abstract TwoThousandFourtyEight copy();
}
2048 2/OneDimensional.java
2048 2/OneDimensional.java
public interface OneDimensional {
public boolean identicalRows(int[] row1, int[] row2);
public boolean validateValue(int val, int maxPowerOfTwo);
public boolean validateRow(int[] row);
public boolean moveLeft(int[] row);
public boolean combineLeft(int[] row);
}
2048 2/OneDimensional2048.java
2048 2/OneDimensional2048.java
public class OneDimensional2048 implements OneDimensional
{
// Fill-in methods to implement the OneDimensional interface
public boolean identicalRows(int[] row1, int[] row2)
{
if(row1.length!=row2.length)
return false;
for(int i = 0; i < row1.length; ++i)
{
if(row1[i]!=row2[i])
return false;
}
//This return is a default
return true;
}
public boolean validateValue(int val, int maxPowerOfTwo)
{
if (val == 0)
return true;
if(val<2||val>maxPowerOfTwo)
return false;
while (val != 1)
{
if (val % 2 != 0)
return false;
val = val / 2;
}
return true;
}
public boolean validateRow(int[] row)
{
int max=2048;
for(int i = 0; i < row.length; ++i)
{
if(validateValue(row[i],max)==false)
return false;
}
//This return is a default
return true;
}
public boolean moveLeft(int[] row)
{
if(validateRow(row)==false)
return false;
int i,j;
i=0;
j=0;
while(j {
if(row[j]!=0)
{ row[i]=row[j];
if(i!=j)
row[j]=0;
i++;
}
j++;
}
//This return is a default, write your code here
return true;
}
public boolean combineLeft(int[] row)
{
if(moveLeft(row)==false)
return false;
for(int i = 0; i < row.length-1; ++i)
{
if(row[i]==row[i+1])
{
row[i]+=row[i+1];
row[i+1]=0;
}
}
if(moveLeft(row)==false)
return false;
//This return is a default, write your code here
return true;
}
public static void main(String[] argc)
{
int[] row;
// These asserts have no message as output but will cause exeptions and highlight the line.
// feel free to add messages to help you debug.
OneDimensional2048 d =new OneDimensional2048();
assert(!d.validateValue(8, 4));
assert(d.validateValue(8, 8));
assert(d.validateValue(8, 16));
assert(d.validateValue(0, 16));
assert(d.validateValue(2, 2048));
assert(!d.validateValue(7, 2048));
assert(!d.validateValue(1023, 2048));
assert(!d.validateValue(1025, 2048));
assert(d.validateRow(new int[]{2, 2, 2, 2}));
assert(d.validateRow(new int[]{0, 2, 4, 0, 32}));
assert(!d.validateRow(new int[]{2, 2, 0, 3, 4, 0}));
assert(d.validateRow(new int[]{}));
assert(!d.validateRow(new int[]{8, 2, 64, 32, 30}));
row = new int[]{0,0,4,0,0};
assert(d.moveLeft(row) && d.identicalRows(new int[]{4,0,0,0,0}, row));
row = new int[]{0,0,4,0,0};
assert(d.moveLeft(row) && !d.identicalRows(new int[]{4,0,0,0,0,0}, row));
row = new int[]{2,0,4,0,0,16};
assert(d.moveLeft(row) && d.identicalRows(new int[]{2,4,16,0,0,0}, row));
row = new int[]{0,0,0};
assert(d.moveLeft(row) && d.identicalRows(new int[]{0,0,0}, row));
assert(!d.moveLeft(new int[]{2,0,31}));
row = new int[]{4,16,2048};
assert(d.moveLeft(row) && d.identicalRows(new int[]{4,16,2048}, row));
row = new int[]{8,8,16,16,32,32};
assert(d.combineLeft(row) && d.identicalRows(new int[]{16,32,64,0,0,0}, row));
row = new int[]{2,0,2,8,0,8,64,0,64,0};
assert(d.combineLeft(row) && d.identicalRows(new int[]{4,16,128,0,0,0,0,0,0,0}, row));
row = new int[]{2,0,8,2,0,64,4,0,64,0};
assert(d.combineLeft(row) && d.identicalRows(new int[]{2,8,2,64,4,64,0,0,0,0}, row));
row = new int[]{2,0,8,2,0,64,4,0,64,0};
assert(d.combineLeft(row) && d.identicalRows(new int[]{2,8,2,64,4,64,0,0,0,0}, row));
row = new int[]{0,0,2,2,128,64,0,64};
assert(d.combineLeft(row) && d.identicalRows(new int[]{4,128,128,0,0,0,0,0}, row));
row = new int[]{0,0,2,2,128,1234,64,0,64};
assert(!d.combineLeft(row));
row = new int[]{};
assert(d.combineLeft(row) && d.identicalRows(new int[]{}, row));
row = new int[]{0,1024,512,256,128,64,32,16,8,4,2,0,2,0};
assert(d.combineLeft(row) && d.combineLeft(row) && d.combineLeft(row) && d.combineLeft(row) &&
d.combineLeft(row) && d.combineLeft(row) && d.combineLeft(row) && d.combineLeft(row) &&
d. combineLeft(row) && d.combineLeft(row) && d.identicalRows(new int[]{2048,0,0,0,0,0,0,0,0,0,0,0,0,0}, row));
}
}
2048 2/TwoDimensional.java
2048 2/TwoDimensional.java
public interface TwoDimensional {
boolean validateBoard(int[][] b);
public int[][] blankBoard(int x, int y);
public boolean identicalBoard(int[][] a, int[][] b);
public int numUnoccupied(int[][] b);
public int[] randCoord(int[][] b, int offset);
public boolean addNewValue(int[][] b);
public int[][] combineLeft(int[][] b);
public int[][] rotateLeft(int[][] b);
public int[][] left(int[][] b);
public int[][] right(int[][] b);
public int[][] up(int[][] b);
public int[][] down(int[][] b);
}
2048 2/TwoDimensional2048.java
2048...