If match timer is used, the AI consumes now also time for their priority action. Some minor changes to Gamemanager.

This commit is contained in:
LevelX2 2014-09-03 09:49:44 +02:00
parent e8a72466d6
commit cb6cc62ed4
5 changed files with 98 additions and 58 deletions

View file

@ -93,9 +93,16 @@ public class ComputerPlayer7 extends ComputerPlayer6 {
@Override
public boolean priority(Game game) {
game.resumeTimer(playerId);
boolean result = priorityPlay(game);
game.pauseTimer(playerId);
return result;
}
private boolean priorityPlay(Game game) {
if (lastLoggedTurn != game.getTurnNum()) {
lastLoggedTurn = game.getTurnNum();
logger.info(new StringBuilder("======================= ").append("Turn: ").append(game.getTurnNum()).append(" [").append(game.getPlayer(game.getActivePlayerId()).getName()).append("] =========================================").toString());
logger.info("======================= Turn: "+ game.getTurnNum() + " ["+ game.getPlayer(game.getActivePlayerId()).getName() +"] =========================================");
}
logState(game);
logger.debug("Priority -- Step: " + (game.getTurn().getStepType() + " ").substring(0,25) + " ActivePlayer-" + game.getPlayer(game.getActivePlayerId()).getName() + " PriorityPlayer-" + name);

View file

@ -728,7 +728,14 @@ public class ComputerPlayer extends PlayerImpl implements Player {
@Override
public boolean priority(Game game) {
game.resumeTimer(playerId);
log.debug("priority");
boolean result = priorityPlay(game);
game.pauseTimer(playerId);
return result;
}
private boolean priorityPlay(Game game) {
UUID opponentId = game.getOpponents(playerId).iterator().next();
if (game.getActivePlayerId().equals(playerId)) {
if (game.isMainPhase() && game.getStack().isEmpty()) {
@ -815,11 +822,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
break;
}
}
pass(game);
pass(game);
return true;
}
@Override
public boolean activateAbility(ActivatedAbility ability, Game game) {
for (Target target: ability.getModes().getMode().getTargets()) {

View file

@ -98,7 +98,7 @@ public class GameController implements GameCallback {
this.choosingPlayerId = choosingPlayerId;
for (Player player: game.getPlayers().values()) {
if (!player.isHuman()) {
useTimeout = false;
useTimeout = false; // no timeout because of beeing idle if playing against AI
break;
}
}
@ -421,14 +421,19 @@ public class GameController implements GameCallback {
}
public void kill(UUID userId) {
if (userPlayerMap.containsKey(userId)) {
gameSessions.get(userPlayerMap.get(userId)).setKilled();
gameSessions.remove(userPlayerMap.get(userId));
leave(userId);
userPlayerMap.remove(userId);
UUID playerId = userPlayerMap.get(userId);
if (playerId != null) {
GameSession gameSession = gameSessions.get(playerId);
if (gameSession != null) {
gameSession.setKilled();
gameSessions.remove(playerId);
leave(userId);
userPlayerMap.remove(userId);
}
}
if (watchers.containsKey(userId)) {
watchers.get(userId).setKilled();
GameWatcher gameWatcher = watchers.get(userId);
if (gameWatcher != null) {
gameWatcher.setKilled();
watchers.remove(userId);
}
}

View file

@ -57,99 +57,115 @@ public class GameManager {
}
public void joinGame(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).join(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.join(userId);
}
}
public UUID getChatId(UUID gameId) {
if (gameControllers.containsKey(gameId)) {
return gameControllers.get(gameId).getChatId();
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
return gameController.getChatId();
}
return null;
}
public void sendPlayerUUID(UUID gameId, UUID userId, UUID data) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).sendPlayerUUID(userId, data);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.sendPlayerUUID(userId, data);
}
}
public void sendPlayerString(UUID gameId, UUID userId, String data) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).sendPlayerString(userId, data);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.sendPlayerString(userId, data);
}
}
public void sendPlayerManaType(UUID gameId, UUID playerId, UUID userId, ManaType data) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).sendPlayerManaType(userId, playerId, data);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.sendPlayerManaType(userId, playerId, data);
}
}
public void sendPlayerBoolean(UUID gameId, UUID userId, Boolean data) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).sendPlayerBoolean(userId, data);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.sendPlayerBoolean(userId, data);
}
}
public void sendPlayerInteger(UUID gameId, UUID userId, Integer data) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).sendPlayerInteger(userId, data);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.sendPlayerInteger(userId, data);
}
}
public void setManaPoolMode(UUID gameId, UUID userId, boolean autoPayment) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).setManaPoolMode(userId, autoPayment);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.setManaPoolMode(userId, autoPayment);
}
}
public void concedeGame(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).concede(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.concede(userId);
}
}
public void quitMatch(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).quit(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.quit(userId);
}
}
public void undo(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).undo(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.undo(userId);
}
}
public void passPriorityUntilNextYourTurn(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).passPriorityUntilNextYourTurn(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.passPriorityUntilNextYourTurn(userId);
}
}
public void passTurnPriority(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).passTurnPriority(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.passTurnPriority(userId);
}
}
public void restorePriority(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).restorePriority(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.restorePriority(userId);
}
}
public void watchGame(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).watch(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.watch(userId);
}
}
public void stopWatching(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).stopWatching(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.stopWatching(userId);
}
}
@ -160,27 +176,31 @@ public class GameManager {
// }
public void kill(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).kill(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.kill(userId);
}
}
public void cheat(UUID gameId, UUID userId, UUID playerId, DeckCardLists deckList) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).cheat(userId, playerId, deckList);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.cheat(userId, playerId, deckList);
}
}
public boolean cheat(UUID gameId, UUID userId, UUID playerId, String cardName) {
if (gameControllers.containsKey(gameId)) {
return gameControllers.get(gameId).cheat(userId, playerId, cardName);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
return gameController.cheat(userId, playerId, cardName);
}
return false;
}
public void timeout(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).timeout(userId);
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
gameController.timeout(userId);
}
}
@ -193,16 +213,18 @@ public class GameManager {
}
public boolean saveGame(UUID gameId) {
if (gameControllers.containsKey(gameId)) {
return gameControllers.get(gameId).saveGame();
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
return gameController.saveGame();
}
return false;
}
public GameView getGameView(UUID gameId, UUID userId, UUID playerId) {
if (gameControllers.containsKey(gameId)) {
return gameControllers.get(gameId).getGameView(playerId);
}
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {
return gameController.getGameView(playerId);
}
return null;
}

View file

@ -216,14 +216,14 @@ public class Table implements Serializable {
}
}
final public synchronized void setState(TableState state) {
final public void setState(TableState state) {
this.state = state;
if (isTournament()) {
getTournament().setTournamentState(state.toString());
}
}
public synchronized TableState getState() {
public TableState getState() {
return state;
}