Skip to content

Commit

Permalink
Fixed early game over when addLines() crashed into the current tetrom…
Browse files Browse the repository at this point in the history
…ino.
  • Loading branch information
Julian-Wollersberger committed Jun 14, 2018
1 parent d377870 commit 617aad2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package at.dropical.wolliAI.bestPossibility;
// Created by julian on 26.04.18.

import at.dropical.wolliAI.gamefieldCopy.TetrisArena;

/**
* See Package-info.
*/
Expand Down Expand Up @@ -45,9 +47,11 @@ public BestPlace findBestColumn(GameField field) {
do {
field.moveToBottom();
int below = field.countSpacesBelowTetromino();
// The higher up, the worse
below += (TetrisArena.height - field.getPosH() )/4;

if(bestColumnCount > below
|| bestColumnCount == below && bestColumnHeight < field.getPosH()) { //lowest point
|| bestColumnCount == below && bestColumnHeight < field.getPosH()) { //prefer lowest point
bestColumnCount = below;
bestColumn = field.getPosW();
bestColumnHeight = field.getPosH();
Expand Down
15 changes: 11 additions & 4 deletions server/src/at/dropical/server/game/OnePlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ private void newNextTetromino() throws GameOverException {
throw new GameOverException(playername);
}

/** Adds random lines and pushes up the tetromino. */
void addLines(Integer lines) throws GameOverException {
//First lift Tetromino up but don't go up to high.
int newYpos = Math.max(currTetrY - lines, STARTVAL_Y);
if(arena.checkTetromino(tetromino, newYpos, currTetrX, true))
currTetrY = newYpos;

if(arena.addLines(lines))
throw new GameOverException(playername);
}


/**
* Lowering the Tetromino a block.
Expand All @@ -90,10 +101,6 @@ public void moveDown() throws GameOverException {
placeTetromino();
}

void addLines(Integer lines) throws GameOverException {
arena.addLines(lines);
}

/**
* go down as long as possible and place the Tetromino
*/
Expand Down
7 changes: 2 additions & 5 deletions server/src/at/dropical/server/gamefield/TetrisArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,8 @@ private boolean copyUp(int bottom) {
* This is for multiplayer.
* Maybe add a mode with this in singleplayer too?
* @return wherever a block got over the top of
* the arena. True -> game over!
*
* fixme The current Tetroino must go up too,
* otherwise it can lead to a wrong game over. */
public boolean addLines(int lineCount) throws GameOverException {
* the arena. True -> game over! */
public boolean addLines(int lineCount) {
boolean overTop = false;
Random rand = new Random();

Expand Down

0 comments on commit 617aad2

Please sign in to comment.