Пример #1
0
 private int examineMove(AbstractMove theMove, Player player, int depth, String position) {
   Player player2 = player.getOpponent();
   player2.findAllMoves(theMove.isCheck());
   int endPositionScore = getScoreForEndPosition(player2);
   if (endPositionScore != -1) {
     itsTable.add(position, endPositionScore);
     return endPositionScore;
   } else if (depth == 1) {
     int score = itsScorer.getScore(itsBoard, itsPlayer);
     itsTable.add(position, score);
     return score;
   } else {
     int bestScore = 1234;
     Collection moves = getAllMoves(player2);
     for (Iterator i = moves.iterator(); i.hasNext(); ) {
       AbstractMove move = (AbstractMove) i.next();
       move.getPiece().findMoves_safe();
       move = player2.movePiece(move);
       String newPosition = itsBoard.getPositionCode() + player2.getColor();
       int thisScore = -321;
       boolean hasIt = itsTable.has(newPosition);
       if (hasIt) {
         thisScore = itsTable.getScore();
       } else {
         thisScore = examineMove(move, player2, depth - 1, newPosition);
         itsTable.add(newPosition, thisScore);
       }
       bestScore = compareScores(player2, bestScore, thisScore);
       player2.reverseMove(move);
     }
     return bestScore;
   }
 }
Пример #2
0
 private int removeStone(Player s) {
   int i = 0;
   if (s.getColor() == TokenColor.WHITE) i = 1;
   stonesOnField[i] = stonesOnField[i] - 1;
   sf.getTriangle(a).remove();
   return stonesOnField[i] == 0 ? 111 : 0;
 }
Пример #3
0
 public void showPromotion(Cuadro destino, Player activePlayer) {
   this.destino = destino;
   this.activePlayer = activePlayer;
   this.activeColor = activePlayer.getColor();
   setIcons();
   this.setVisible(true);
 }
Пример #4
0
    /**
     * Broadcast a message to all players in a game session
     *
     * @param message Broadcast message
     * @throws IOException Connection exceptions
     */
    private void broadcast(String message) {

      System.out.println("Broadcasting to users: " + message);

      // For every player in session; send the message
      for (Player player : players) {
        player.getOut().println(message + " " + player.getColor());
      }
    }
Пример #5
0
  /*
   * Orders the Amoebas on this field to die, if they have
   * too many damage points.
   */
  public ArrayList<Amoeba> orderAmoebasToDieIfTooMuchDamage(Player[] players) {
    ArrayList<Amoeba> deadAmebas = new ArrayList<Amoeba>();
    for (int i = 0; i < amoebas.size(); i++) {
      if (amoebas.get(i).getDamagePoints() > amoebas.get(i).maxDamagePoints()) {
        deadAmebas.add(amoebas.remove(i));
        i--;
      }
    }

    for (Amoeba a : amoebas) {
      for (Player p : players) {
        if (!p.hasGene("LifeExpectancy") && a.getColor().equals(p.getColor()))
          assert a.getDamagePoints() <= 1;
        else assert a.getDamagePoints() <= 2;
      }
    }

    return deadAmebas;
  }
Пример #6
0
 public void search(ChessBoard board, Player player) {
   itsTable = new PositionHashTable();
   itsMoves.clear();
   itsPlayer = player;
   itsBoard = board;
   Collection moves = getAllMoves(player);
   for (Iterator i = moves.iterator(); i.hasNext(); ) {
     AbstractMove move = (AbstractMove) i.next();
     move.getPiece().findMoves_safe();
     move = player.movePiece(move);
     itsBoard.recordPosition();
     String positionCode = itsBoard.getPositionCode() + player.getColor();
     int score = examineMove(move, player, itsSearchQuality, positionCode);
     move.setScore(score);
     itsMoves.add(move);
     itsBoard.removeLastPosition();
     player.reverseMove(move);
   }
 }
Пример #7
0
 @FXML
 public void loadGame(ActionEvent event) {
   Stage newStage = new Stage();
   if (event.getSource() == loadButton) {
     loadData = LoadSaveGame.load();
     if (loadData != null) {
       Controller.loaded = true;
       GameController.numPasses = (int) Controller.loadData.get(4);
       // GameController.landButton.setDisable(true);
       try {
         gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml"));
         gameScene = new Scene(gameRoot);
         Parent startWindow = FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml"));
         startScene = new Scene(startWindow);
       } catch (IOException e) {
         e.printStackTrace();
       }
       newStage.setScene(gameScene);
       newStage.setTitle("Game Screen");
       newStage.show();
       GridPane grid = (GridPane) gameRoot;
       landPlots = (Land[][]) loadData.get(0);
       level = (String) loadData.get(1);
       players = (Player[]) loadData.get(3);
       for (Player player : players) {
         for (Land land : player.getLandOwned()) {
           landPlots[land.getCol()][land.getRow()].setOwner(player);
         }
       }
       if (grid != null) {
         for (Land[] landArray : landPlots) {
           for (Land land : landArray) {
             if (land.isOwned()) {
               Player owner = land.getOwner();
               Rectangle color = new Rectangle();
               color.setFill(Color.valueOf(owner.getColor()));
               color.setHeight(25);
               color.setWidth(25);
               color.setOpacity(1);
               GridPane.setHalignment(color, HPos.LEFT);
               GridPane.setValignment(color, VPos.TOP);
               grid.add(color, land.getCol(), land.getRow());
               if (land.hasMule()) {
                 Image mulePic = new Image("gameConfig/UIFiles/Media/aMule.png");
                 ImageView muleView = new ImageView();
                 muleView.setImage(mulePic);
                 muleView.setFitWidth(50);
                 muleView.setPreserveRatio(true);
                 GridPane.setHalignment(muleView, HPos.LEFT);
                 GridPane.setValignment(muleView, VPos.CENTER);
                 muleView.setId(String.valueOf(land.getCol()) + String.valueOf(land.getRow()));
                 grid.add(muleView, land.getCol(), land.getRow());
               }
             }
           }
         }
       }
       numPlayer = players.length;
       Turns turns = new Turns(players);
       turns.setRounds((int) loadData.get(5));
       GameController.beginTurn();
     } else {
       Controller.loaded = false;
     }
   }
 }
Пример #8
0
    /**
     * Add a new player to the game.
     *
     * @param player
     */
    public void addPlayer(Player player) {
      System.out.println(player.getColor() + " has joined.");
      this.players.add(player);

      broadcast("NEWUSERINQUEUE");
    }
Пример #9
0
    /** Start the game */
    public void run() {

      String line = null;
      String[] args;
      int dice;
      boolean noWinner = true;

      while (noWinner) {

        // Cycle players for their turn.
        for (Player player : players) {

          // Roll dice
          dice = 1 + (int) (Math.random() * Integer.parseInt(config.getConfig("dice")));
          System.out.println("Dice: " + dice);

          // Broadcast that it's player's turn and
          broadcast("TURN " + player.getColor() + " " + dice);

          // Check if player has any possible moves
          if (!player.canMoveAny(dice)) {
            continue;
          }

          // Listen for a move request from client
          while (true) {
            try {
              // Read input from client
              line = player.getIn().readLine();
            } catch (IOException e) {
              System.out.println("Lost connection with clients");
              break;
            }

            // Continue if no request
            if (line == null) {
              continue;
            }

            // Move request: MOVE <piece_id (1-4)> <color>
            if (line.startsWith("MOVE")) {
              args = line.split(" ");

              // Get piece ID and correct it for Player object
              int pieceId = Integer.parseInt(args[1]) - 1;

              // Continue (ignore) if trying to move another color
              if (!args[2].equals(player.getColor())) {
                continue;
              }

              // Move piece if allowed
              if (player.movePieceIfAllowed(pieceId, dice)) {

                // Broadcast move to everyone and continue to next user
                broadcast("MOVE " + pieceId + " " + player.getPiecePosition(pieceId));
                break;
              } else {
                // Cannot move piece
                player.getOut().println("MOVEDENIED");
              }
            }
          }

          // Check if user has won
          if (player.hasWon()) {

            // Broadcast win
            broadcast("WIN " + player.getColor());

            // Winner is found
            noWinner = false;

            // Update winner table
            this.userHandler.userWon(player.getUsername());

            // Update every player's table
            for (Player selectedPlayer : players) {
              this.userHandler.userPlayed(selectedPlayer.getUsername());
            }

            // Break from for loop
            break;
          } else {
            broadcast("NOWIN");
          }
        }
      }
    }