Package player

Examples of player.PlayerAI


  /**
   * Creates players.
   */
  private void createPlayers() {
    //create players
    playerAI = new PlayerAI(board, getMove(), 1);
    playerAI2 = new PlayerAI(board, getMove(), 0);
    player1 = new PlayerHuman(0);
    player2 = new PlayerHuman(1);
  }
View Full Code Here


   * @param player1
   * @param player2
   */
  public boolean checkCheckmate(Board board, Move move, Player player1, Player player2) {
    //AI player is needed for isCheckmate method
    PlayerAI AI = new PlayerAI(board, move, 0);
    //check if player1 is in checkmate
    if (AI.isCheckmate(player1)) {
      String winnerSide;
      if (player1.getSide()==0) {
        winnerSide = "black";
      } else {
        winnerSide = "white";
      }
      System.out.println("Checkmate! " +winnerSide+" won!");
      return true;
    } else if (AI.isCheckmate(player2)) {
      String winnerSide;
      if (player2.getSide()==0) {
        winnerSide = "black";
      } else {
        winnerSide = "white";
View Full Code Here

//        }
      }
    } else if (mode==2) {
      //create human and AI
      PlayerHuman player1 = new PlayerHuman(0);
      PlayerAI player2 = new PlayerAI(board, move, 1);
      System.out.println("Player1: White");
      System.out.println("Player2: Black");
      int whosTurn = 0; //white starts
      System.out.println();
      System.out.println("Player1's turn");
//      board.showGameStateWithNotation();
      boolean cont = true;
      String src, dest;
      sc.nextLine(); //clear buffer
      while (cont && !checkmate) {
        boolean legalMove = false;
        //repeat until move is legal
        if (whosTurn==0) {
          while (!legalMove) {
            System.out.println("What piece you'd like to move? (notation)");
            src = sc.nextLine();
            System.out.println("Where you'd like to move that piece? (notation)");
            dest = sc.nextLine();
            if (whosTurn==player1.getSide()) {
              legalMove = move.doMove(player1, src, dest);
            }
            if (!legalMove) {
              System.out.println("Illegal move");
            }
          }
          whosTurn = 1;
        } else if (whosTurn==1) {
          player2.doBestMove(player2);
          whosTurn = 0;
        }
//        board.showGameStateWithNotation();
        //inform that player turn changes
        if (whosTurn==player1.getSide()) {
          System.out.println("Player1's turn");
        } else {
          System.out.println("Player2's turn");
        }
        //check for checkmate
        checkmate = game.checkCheckmate(board, move, player1, player2);
      }
    } else if (mode==3) {
      //create two AIs
      PlayerAI player1 = new PlayerAI(board, move, 0);
      PlayerAI player2 = new PlayerAI(board, move, 1);
      System.out.println("Player1: White");
      System.out.println("Player2: Black");
      //limit moves to 50
      loop: for (int i=0; i<50; i++) {
        player2.doBestMove(player1);
        player2.doBestMove(player2);
        System.out.println((i+1)+". round");
//        board.showGameStateWithNotation();
        //check for checkmate
        if (game.checkCheckmate(board, move, player1, player2)) {
          break loop;
View Full Code Here

TOP

Related Classes of player.PlayerAI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.