Skip to content
Permalink
Browse files

肝到头晕眼花

  • Loading branch information...
ltxom committed Mar 12, 2019
1 parent db2aae9 commit 047c867eb1c176edb57e850a3741b74c1dd6adc7
@@ -1,6 +1,9 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class Block {
static int[][] standardSpaceMatrix;
static int[][][] rotationalSpaceMatrix;
public interface Block {

int[][] getStandardSpaceMatrix();

int[][][] getRotationalSpaceMatrix();

}
@@ -1,8 +1,17 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class BlockI extends Block{
static {
standardSpaceMatrix = new int[][]{{1, 1, 1, 1}};
rotationalSpaceMatrix = new int[][][]{{{1},{1},{1},{1}}};
}
public class BlockI implements Block {

private int[][] standardSpaceMatrix = new int[][]{{1, 1, 1, 1}};
private int[][][] rotationalSpaceMatrix = new int[][][]{{{1}, {1}, {1}, {1}}};

@Override
public int[][] getStandardSpaceMatrix() {
return standardSpaceMatrix;
}

@Override
public int[][][] getRotationalSpaceMatrix() {
return rotationalSpaceMatrix;
}
}
@@ -1,11 +1,20 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class BlockJ extends Block {
static {
standardSpaceMatrix = new int[][]{{1, 0, 0}, {1, 1, 1}};
rotationalSpaceMatrix = new int[][][]{{
{1, 1}, {0, 1}, {0, 1}},
{{1, 1, 1}, { 0, 0, 1}},
{{0, 1}, {0, 1}, {1, 1}}};
}
public class BlockJ implements Block {

private int[][] standardSpaceMatrix = new int[][]{{1, 0, 0}, {1, 1, 1}};
private int[][][] rotationalSpaceMatrix = new int[][][]{{
{1, 1}, {0, 1}, {0, 1}},
{{1, 1, 1}, {0, 0, 1}},
{{0, 1}, {0, 1}, {1, 1}}};

@Override
public int[][] getStandardSpaceMatrix() {
return standardSpaceMatrix;
}

@Override
public int[][][] getRotationalSpaceMatrix() {
return rotationalSpaceMatrix;
}
}
@@ -1,11 +1,20 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class BlockL extends Block{
static {
standardSpaceMatrix = new int[][]{{0, 0, 1}, {1, 1, 1}};
rotationalSpaceMatrix = new int[][][]{{
{1, 0}, {1, 0}, {1, 1}},
{{1, 1, 1}, {1, 0, 0}},
{{1, 1}, {0, 1}, {0, 1}}};
}
public class BlockL implements Block {

private int[][] standardSpaceMatrix = new int[][]{{0, 0, 1}, {1, 1, 1}};
private int[][][] rotationalSpaceMatrix = new int[][][]{{
{1, 0}, {1, 0}, {1, 1}},
{{1, 1, 1}, {1, 0, 0}},
{{1, 1}, {0, 1}, {0, 1}}};

@Override
public int[][] getStandardSpaceMatrix() {
return standardSpaceMatrix;
}

@Override
public int[][][] getRotationalSpaceMatrix() {
return rotationalSpaceMatrix;
}
}
@@ -1,8 +1,17 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class BlockO extends Block{
static {
standardSpaceMatrix = new int[][]{{1, 1}, {1, 1}};
rotationalSpaceMatrix = new int[][][]{};
}
public class BlockO implements Block {

private int[][] standardSpaceMatrix = new int[][]{{1, 1}, {1, 1}};
private int[][][] rotationalSpaceMatrix = new int[][][]{};

@Override
public int[][] getStandardSpaceMatrix() {
return standardSpaceMatrix;
}

@Override
public int[][][] getRotationalSpaceMatrix() {
return rotationalSpaceMatrix;
}
}
@@ -1,8 +1,17 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class BlockS extends Block {
static {
standardSpaceMatrix = new int[][]{{0, 1, 1}, {1, 1, 0}};
rotationalSpaceMatrix = new int[][][]{{{1, 0}, {1, 1}, {0, 1}}};
}
public class BlockS implements Block {

private int[][] standardSpaceMatrix = new int[][]{{0, 1, 1}, {1, 1, 0}};
private int[][][] rotationalSpaceMatrix = new int[][][]{{{1, 0}, {1, 1}, {0, 1}}};

@Override
public int[][] getStandardSpaceMatrix() {
return standardSpaceMatrix;
}

@Override
public int[][][] getRotationalSpaceMatrix() {
return rotationalSpaceMatrix;
}
}
@@ -1,8 +1,18 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class BlockT extends Block {
static {
standardSpaceMatrix = new int[][]{{0, 1, 0}, {1, 1, 1}};
rotationalSpaceMatrix = new int[][][]{{{1, 0}, {1, 1}, {1, 0}}, {{1, 1, 1}, {0, 1, 0}}, {{0, 1}, {1, 1}, {0, 1}}};
}
public class BlockT implements Block {

private int[][] standardSpaceMatrix = new int[][]{{0, 1, 0}, {1, 1, 1}};
private int[][][] rotationalSpaceMatrix = new int[][][]{{{1, 0}, {1, 1}, {1, 0}}, {{1, 1
, 1}, {0, 1, 0}}, {{0, 1}, {1, 1}, {0, 1}}};

@Override
public int[][] getStandardSpaceMatrix() {
return standardSpaceMatrix;
}

@Override
public int[][][] getRotationalSpaceMatrix() {
return rotationalSpaceMatrix;
}
}
@@ -1,8 +1,17 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class BlockZ extends Block{
static {
standardSpaceMatrix = new int[][]{{1, 1, 0}, {0, 1, 1}};
rotationalSpaceMatrix = new int[][][]{{{0, 1}, {1, 1}, {1, 0}}};
}
public class BlockZ implements Block {

private int[][] standardSpaceMatrix = new int[][]{{1, 1, 0}, {0, 1, 1}};
private int[][][] rotationalSpaceMatrix = new int[][][]{{{0, 1}, {1, 1}, {1, 0}}};

@Override
public int[][] getStandardSpaceMatrix() {
return standardSpaceMatrix;
}

@Override
public int[][][] getRotationalSpaceMatrix() {
return rotationalSpaceMatrix;
}
}
@@ -0,0 +1,14 @@
package me.ltxom.tetrisplayer.entity.tetris;

public class Move {
// deltaX > 0 toward right x unit
private int deltaX;

public Move(int deltaX) {
this.deltaX = deltaX;
}

public int getDeltaX() {
return deltaX;
}
}
@@ -0,0 +1,50 @@
package me.ltxom.tetrisplayer.entity.tetris;

import java.util.List;

public class PossibleMove {
private Move move;
private double score;
private Block block;
private int rotation;
private int[][] boardMatrix;

public PossibleMove(Move move, double score, Block block, int rotation,
int[][] boardMatrix) {
this.move = move;
this.score = score;
this.block = block;
this.rotation = rotation;
this.boardMatrix = boardMatrix;
}

public static PossibleMove findHighestScoreMove(List<PossibleMove> possibleMoves) {
double score = -Double.MAX_VALUE;
PossibleMove result = null;
for (PossibleMove possibleMove : possibleMoves) {
if (score < possibleMove.score) {
result = possibleMove;
score = result.score;
}
}
return result;
}

public Move getMove() {
return move;
}

public void setMove(Move move) {
this.move = move;
}

public void setScore(double score) {
this.score = score;
}

public void addScore(double score) {
this.score += score;
}


}
@@ -3,59 +3,91 @@
import java.util.Date;

public class TetrisBoard {
private Date captureTime;
private int[][] boardMatrix;
private Block fallingBlock;
private Block[] nextBlocks;
private Block holdingBlock;
private int attackers;

public Date getCaptureTime() {
return captureTime;
}

public void setCaptureTime(Date captureTime) {
this.captureTime = captureTime;
}

public int[][] getBoardMatrix() {
return boardMatrix;
}

public void setBoardMatrix(int[][] boardMatrix) {
this.boardMatrix = boardMatrix;
}

public Block getFallingBlock() {
return fallingBlock;
}

public void setFallingBlock(Block fallingBlock) {
this.fallingBlock = fallingBlock;
}

public Block[] getNextBlocks() {
return nextBlocks;
}

public void setNextBlocks(Block[] nextBlocks) {
this.nextBlocks = nextBlocks;
}

public Block getHoldingBlock() {
return holdingBlock;
}

public void setHoldingBlock(Block holdingBlock) {
this.holdingBlock = holdingBlock;
}

public int getAttackers() {
return attackers;
}

public void setAttackers(int attackers) {
this.attackers = attackers;
}
private static final double completeLineScore = 5;
private static final double leavingHoldScore = -3;
private static final double fillSpaceScore = 1.0;
private static final double depthWeight = 2;

private Date captureTime;
private int[][] boardMatrix;
private Block fallingBlock;
private Block[] nextBlocks;
private Block holdingBlock;
private int attackers;

public static double computeScore(int[][] boardMatrix) {
double score = 0.0;
boolean lineComplete = true;
for (int y = 0; y < 20; y++) {
boolean flag = false;
for (int x = 0; x < 10; x++) {
if (boardMatrix[y][x] == 1)
flag = true;
}
if (!flag) {
break;
}
lineComplete = true;
for (int x = 0; x < 10; x++) {
score += (boardMatrix[y][x] == 1 ? fillSpaceScore : leavingHoldScore) * (20 - y) * depthWeight;

if (boardMatrix[y][x] == 0)
lineComplete = false;
}
if (lineComplete) {
System.out.println(y);
score += completeLineScore * (20 - y) * depthWeight;
}
}
return score;
}

public Date getCaptureTime() {
return captureTime;
}

public void setCaptureTime(Date captureTime) {
this.captureTime = captureTime;
}

public int[][] getBoardMatrix() {
return boardMatrix;
}

public void setBoardMatrix(int[][] boardMatrix) {
this.boardMatrix = boardMatrix;
}

public Block getFallingBlock() {
return fallingBlock;
}

public void setFallingBlock(Block fallingBlock) {
this.fallingBlock = fallingBlock;
}

public Block[] getNextBlocks() {
return nextBlocks;
}

public void setNextBlocks(Block[] nextBlocks) {
this.nextBlocks = nextBlocks;
}

public Block getHoldingBlock() {
return holdingBlock;
}

public void setHoldingBlock(Block holdingBlock) {
this.holdingBlock = holdingBlock;
}

public int getAttackers() {
return attackers;
}

public void setAttackers(int attackers) {
this.attackers = attackers;
}

}

0 comments on commit 047c867

Please sign in to comment.
You can’t perform that action at this time.