Package player

Examples of player.PlayerHuman


   */
  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


    System.out.println("3 = AI vs AI");
    int mode = sc.nextInt();
    boolean checkmate = false;
    if (mode==1) {
      //create two human players
      PlayerHuman player1 = new PlayerHuman(0);
      PlayerHuman player2 = new PlayerHuman(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
        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);
          } else if (whosTurn==player2.getSide()) {
            legalMove = move.doMove(player2, src, dest);
          }
          if (!legalMove) {
            System.out.println("Illegal move");
          }
        }
        //after a successful move, change player
        if (whosTurn == 0) {
          whosTurn = 1;
        } else {
          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);
//        System.out.println("Continue playing? (y/n)");
//        String ans = sc.nextLine();
//        if (ans.equalsIgnoreCase("y")) {
//          cont = true;
//        } else {
//          cont = false;
//        }
      }
    } 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
View Full Code Here

TOP

Related Classes of player.PlayerHuman

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.