mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
AI: fixed computer's errors if all players quit the game;
This commit is contained in:
parent
d41ccd11bc
commit
c1db466d05
4 changed files with 16 additions and 4 deletions
|
|
@ -26,7 +26,11 @@ public final class GameStateEvaluator2 {
|
||||||
|
|
||||||
public static PlayerEvaluateScore evaluate(UUID playerId, Game game) {
|
public static PlayerEvaluateScore evaluate(UUID playerId, Game game) {
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
||||||
Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next()); // TODO: add multi opponent support?
|
Player opponent = game.getPlayer(game.getOpponents(playerId).stream().findFirst().orElse(null)); // TODO: add multi opponent support?
|
||||||
|
if (opponent == null) {
|
||||||
|
return new PlayerEvaluateScore(WIN_GAME_SCORE);
|
||||||
|
}
|
||||||
|
|
||||||
if (game.checkIfGameIsOver()) {
|
if (game.checkIfGameIsOver()) {
|
||||||
if (player.hasLost()
|
if (player.hasLost()
|
||||||
|| opponent.hasWon()) {
|
|| opponent.hasWon()) {
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,11 @@ public class ActionSimulator {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int evaluateState() {
|
public int evaluateState() {
|
||||||
Player opponent = game.getPlayer(game.getOpponents(player.getId()).iterator().next());
|
Player opponent = game.getPlayer(game.getOpponents(player.getId()).stream().findFirst().orElse(null));
|
||||||
|
if (opponent == null) {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
if (game.checkIfGameIsOver()) {
|
if (game.checkIfGameIsOver()) {
|
||||||
if (player.hasLost() || opponent.hasWon()) {
|
if (player.hasLost() || opponent.hasWon()) {
|
||||||
return Integer.MIN_VALUE;
|
return Integer.MIN_VALUE;
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,11 @@ public final class GameStateEvaluator {
|
||||||
|
|
||||||
public static int evaluate(UUID playerId, Game game, boolean ignoreTapped) {
|
public static int evaluate(UUID playerId, Game game, boolean ignoreTapped) {
|
||||||
Player player = game.getPlayer(playerId);
|
Player player = game.getPlayer(playerId);
|
||||||
Player opponent = game.getPlayer(game.getOpponents(playerId).iterator().next());
|
Player opponent = game.getPlayer(game.getOpponents(playerId).stream().findFirst().orElse(null));
|
||||||
|
if (opponent == null) {
|
||||||
|
return WIN_SCORE;
|
||||||
|
}
|
||||||
|
|
||||||
if (game.checkIfGameIsOver()) {
|
if (game.checkIfGameIsOver()) {
|
||||||
if (player.hasLost() || opponent.hasWon()) {
|
if (player.hasLost() || opponent.hasWon()) {
|
||||||
return LOSE_SCORE;
|
return LOSE_SCORE;
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,7 @@ public final class SystemUtil {
|
||||||
// 3. system commands
|
// 3. system commands
|
||||||
if (runGroup.isSpecialCommand) {
|
if (runGroup.isSpecialCommand) {
|
||||||
|
|
||||||
Player opponent = game.getPlayer(game.getOpponents(feedbackPlayer.getId()).iterator().next());
|
Player opponent = game.getPlayer(game.getOpponents(feedbackPlayer.getId()).stream().findFirst().orElse(null));
|
||||||
|
|
||||||
String info;
|
String info;
|
||||||
switch (runGroup.name) {
|
switch (runGroup.name) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue