icfp-model/src/main/java/ru/bosony/model/game/Game.java
changeset 30 666821484adc
parent 29 66aa96e8fd92
child 47 b3d48e364f9e
equal deleted inserted replaced
29:66aa96e8fd92 30:666821484adc
     1 package ru.bosony.model.game;
     1 package ru.bosony.model.game;
     2 
     2 
     3 import static ru.bosony.model.cellscontents.CellContent.ClosedLambdaLift;
     3 import static ru.bosony.model.cellscontents.CellContent.ClosedLambdaLift;
     4 import static ru.bosony.model.cellscontents.CellContent.Earth;
     4 import static ru.bosony.model.cellscontents.CellContent.Earth;
     5 import static ru.bosony.model.cellscontents.CellContent.Empty;
     5 import static ru.bosony.model.cellscontents.CellContent.Empty;
       
     6 import static ru.bosony.model.cellscontents.CellContent.HighOrderRock;
       
     7 import static ru.bosony.model.cellscontents.CellContent.HuttonsRazor;
     6 import static ru.bosony.model.cellscontents.CellContent.Lambda;
     8 import static ru.bosony.model.cellscontents.CellContent.Lambda;
     7 import static ru.bosony.model.cellscontents.CellContent.MiningRobot;
     9 import static ru.bosony.model.cellscontents.CellContent.MiningRobot;
     8 import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift;
    10 import static ru.bosony.model.cellscontents.CellContent.OpenLambdaLift;
     9 import static ru.bosony.model.cellscontents.CellContent.Rock;
    11 import static ru.bosony.model.cellscontents.CellContent.Rock;
    10 import static ru.bosony.model.cellscontents.CellContent.HuttonsRazor;
       
    11 import static ru.bosony.model.cellscontents.CellContent.WadlersBeard;
    12 import static ru.bosony.model.cellscontents.CellContent.WadlersBeard;
    12 
    13 
    13 import java.util.ArrayList;
    14 import java.util.ArrayList;
    14 import java.util.List;
    15 import java.util.List;
    15 
    16 
   128 			mine.getCell(nextRobotCoord.right()).setContent(Rock);
   129 			mine.getCell(nextRobotCoord.right()).setContent(Rock);
   129 		} else if (robotCoord.left().equals(nextRobotCoord) && nextRobotCellContent == Rock
   130 		} else if (robotCoord.left().equals(nextRobotCoord) && nextRobotCellContent == Rock
   130 				&& getContent(mine.getCell(nextRobotCoord.left())) == Empty) {
   131 				&& getContent(mine.getCell(nextRobotCoord.left())) == Empty) {
   131 			moveRobot(nextRobotCell);
   132 			moveRobot(nextRobotCell);
   132 			mine.getCell(nextRobotCoord.left()).setContent(Rock);
   133 			mine.getCell(nextRobotCoord.left()).setContent(Rock);
       
   134 		} else if (robotCoord.right().equals(nextRobotCoord) && nextRobotCellContent == HighOrderRock
       
   135 				&& getContent(mine.getCell(nextRobotCoord.right())) == Empty) {
       
   136 			moveRobot(nextRobotCell);
       
   137 			mine.getCell(nextRobotCoord.right()).setContent(HighOrderRock);
       
   138 		} else if (robotCoord.left().equals(nextRobotCoord) && nextRobotCellContent == HighOrderRock
       
   139 				&& getContent(mine.getCell(nextRobotCoord.left())) == Empty) {
       
   140 			moveRobot(nextRobotCell);
       
   141 			mine.getCell(nextRobotCoord.left()).setContent(HighOrderRock);
   133 		} else if (CellContent.getTrampolines().contains(nextRobotCellContent)
   142 		} else if (CellContent.getTrampolines().contains(nextRobotCellContent)
   134 				&& CellContent.getTargets().contains(nextRobotCellContent.getTrampolineTarget())) {
   143 				&& CellContent.getTargets().contains(nextRobotCellContent.getTrampolineTarget())) {
   135 			CellContent trampoline = nextRobotCellContent;
   144 			CellContent trampoline = nextRobotCellContent;
   136 			CellContent target = trampoline.getTrampolineTarget();
   145 			CellContent target = trampoline.getTrampolineTarget();
   137 			for (Cell targetCell : mine.findCells(target)) {
   146 			for (Cell targetCell : mine.findCells(target)) {
   172 				Cell leftAndDownCell = mine.getCell(leftAndDownCoord);
   181 				Cell leftAndDownCell = mine.getCell(leftAndDownCoord);
   173 
   182 
   174 				if (getContent(curCell) == Rock && getContent(downCell) == Empty) {
   183 				if (getContent(curCell) == Rock && getContent(downCell) == Empty) {
   175 					getCell(curCoord, newCells).setContent(Empty);
   184 					getCell(curCoord, newCells).setContent(Empty);
   176 					getCell(downCoord, newCells).setContent(Rock);
   185 					getCell(downCoord, newCells).setContent(Rock);
   177 				} else if (getContent(curCell) == Rock && getContent(downCell) == Rock
   186 				} else if (getContent(curCell) == HighOrderRock && getContent(downCell) == Empty) {
       
   187 					getCell(curCoord, newCells).setContent(Empty);
       
   188 					if (getContent(mine.getCell(downCoord.down())) != Empty)
       
   189 						getCell(downCoord, newCells).setContent(Lambda);
       
   190 					else
       
   191 						getCell(downCoord, newCells).setContent(HighOrderRock);
       
   192 				} else if (getContent(curCell) == Rock
       
   193 						&& (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock)
   178 						&& getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
   194 						&& getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
   179 					getCell(curCoord, newCells).setContent(Empty);
   195 					getCell(curCoord, newCells).setContent(Empty);
   180 					getCell(rightAndDownCoord, newCells).setContent(Rock);
   196 					getCell(rightAndDownCoord, newCells).setContent(Rock);
   181 				} else if (getContent(curCell) == Rock && getContent(downCell) == Rock
   197 				} else if (getContent(curCell) == HighOrderRock
       
   198 						&& (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock)
       
   199 						&& getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
       
   200 					getCell(curCoord, newCells).setContent(Empty);
       
   201 					if (getContent(mine.getCell(rightAndDownCoord.down())) != Empty)
       
   202 						getCell(rightAndDownCoord, newCells).setContent(Lambda);
       
   203 					else
       
   204 						getCell(rightAndDownCoord, newCells).setContent(HighOrderRock);
       
   205 				} else if (getContent(curCell) == Rock
       
   206 						&& (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock)
   182 						&& (getContent(rightCell) != Empty || getContent(rightAndDownCell) != Empty)
   207 						&& (getContent(rightCell) != Empty || getContent(rightAndDownCell) != Empty)
   183 						&& getContent(leftCell) == Empty && getContent(leftAndDownCell) == Empty) {
   208 						&& getContent(leftCell) == Empty && getContent(leftAndDownCell) == Empty) {
   184 					getCell(curCoord, newCells).setContent(Empty);
   209 					getCell(curCoord, newCells).setContent(Empty);
   185 					getCell(leftAndDownCoord, newCells).setContent(Rock);
   210 					getCell(leftAndDownCoord, newCells).setContent(Rock);
       
   211 				} else if (getContent(curCell) == HighOrderRock
       
   212 						&& (getContent(downCell) == Rock || getContent(downCell) == HighOrderRock)
       
   213 						&& (getContent(rightCell) != Empty || getContent(rightAndDownCell) != Empty)
       
   214 						&& getContent(leftCell) == Empty && getContent(leftAndDownCell) == Empty) {
       
   215 					getCell(curCoord, newCells).setContent(Empty);
       
   216 					if (getContent(mine.getCell(leftAndDownCoord.down())) != Empty)
       
   217 						getCell(leftAndDownCoord, newCells).setContent(Lambda);
       
   218 					else
       
   219 						getCell(leftAndDownCoord, newCells).setContent(HighOrderRock);
   186 				} else if (getContent(curCell) == Rock && getContent(downCell) == Lambda
   220 				} else if (getContent(curCell) == Rock && getContent(downCell) == Lambda
   187 						&& getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
   221 						&& getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
   188 					getCell(curCoord, newCells).setContent(Empty);
   222 					getCell(curCoord, newCells).setContent(Empty);
   189 					getCell(rightAndDownCoord, newCells).setContent(Rock);
   223 					getCell(rightAndDownCoord, newCells).setContent(Rock);
   190 				} else if (getContent(curCell) == ClosedLambdaLift && mine.findCells(Lambda).size() == 0) {
   224 				} else if (getContent(curCell) == HighOrderRock && getContent(downCell) == Lambda
       
   225 						&& getContent(rightCell) == Empty && getContent(rightAndDownCell) == Empty) {
       
   226 					getCell(curCoord, newCells).setContent(Empty);
       
   227 					if (getContent(mine.getCell(rightAndDownCoord.down())) != Empty)
       
   228 						getCell(rightAndDownCoord, newCells).setContent(Lambda);
       
   229 					else
       
   230 						getCell(rightAndDownCoord, newCells).setContent(HighOrderRock);
       
   231 				} else if (getContent(curCell) == ClosedLambdaLift
       
   232 						&& mine.getLambdasAndHighOrderRocksStartCount() == lambdaCollectedCount) {
   191 					getCell(curCoord, newCells).setContent(OpenLambdaLift);
   233 					getCell(curCoord, newCells).setContent(OpenLambdaLift);
   192 				} else if (getContent(curCell) == WadlersBeard && mine.getGrowth() > 0
   234 				} else if (getContent(curCell) == WadlersBeard && mine.getGrowth() > 0
   193 						&& route.size() % mine.getGrowth() == 0) {
   235 						&& route.size() % mine.getGrowth() == 0) {
   194 					if (getContent(leftCell) == Empty)
   236 					if (getContent(leftCell) == Empty)
   195 						getCell(leftCoord, newCells).setContent(WadlersBeard);
   237 						getCell(leftCoord, newCells).setContent(WadlersBeard);
   211 			}
   253 			}
   212 		}
   254 		}
   213 
   255 
   214 		// Other ending conditions
   256 		// Other ending conditions
   215 		robotCoord = mine.getRobotCell().getCoordinate();
   257 		robotCoord = mine.getRobotCell().getCoordinate();
   216 		if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock) {
   258 		if (getContent(mine.getCell(robotCoord.up())) != Rock && getContent(getCell(robotCoord.up(), newCells)) == Rock
       
   259 				|| getContent(mine.getCell(robotCoord.up())) != HighOrderRock
       
   260 				&& getContent(getCell(robotCoord.up(), newCells)) == HighOrderRock
       
   261 				|| getContent(mine.getCell(robotCoord.up())) == Empty
       
   262 				&& getContent(getCell(robotCoord.up(), newCells)) == Lambda) {
   217 			mine.setCells(newCells);
   263 			mine.setCells(newCells);
   218 
   264 
   219 			lastScoreChange = score - prevScore;
   265 			lastScoreChange = score - prevScore;
   220 			state = GameState.Lose;
   266 			state = GameState.Lose;
   221 			return state;
   267 			return state;