Example #1
0
 /** Human vs AI: ember es gep felvaltva lep. A szan alapjan dol el, hogy melyik jatekos kezd */
 private static void humanvsAI() {
   /** Ha a gepi jatekos van az X-el, akkor o kezd, kulonben az ember */
   if (pt[0].getColor() == QuixoBoard.X) {
     while (!table.win(pt[0].getColor()) && !table.win(p[0].getColor())) {
       aiStep(0, 0);
       if (winner()) {
         return;
       }
       j++;
       humanStep(0);
       winner();
       j++;
     }
   } else {
     while (!table.win(pt[0].getColor()) && !table.win(p[0].getColor())) {
       humanStep(0);
       if (winner()) {
         return;
       }
       j++;
       aiStep(0, 0);
       if (winner()) {
         return;
       }
       j++;
     }
   }
 }
Example #2
0
 /** nyert-e valamelyik jatekos */
 private static boolean winner() {
   if (table.win(QuixoBoard.X) && table.win(QuixoBoard.O)) {
     if (text == 1) {
       System.out.println("Drawn!");
     } else {
       System.out.println(2);
     }
     return true;
   }
   if (table.win(QuixoBoard.X)) {
     if (text == 1) {
       System.out.println("X won");
     } else {
       System.out.println(QuixoBoard.X);
     }
     return true;
   }
   if (table.win(QuixoBoard.O)) {
     if (text == 1) {
       System.out.println("O won");
     } else {
       System.out.println(QuixoBoard.O);
     }
     return true;
   }
   return false;
 }
Example #3
0
 /** Human vs Human: Ket emberi jatekos felvaltva lep */
 private static void people() {
   while (!table.win(p[0].getColor()) && !table.win(p[1].getColor())) {
     ind = j % 2;
     nextInd = (j + 1) % 2;
     humanStep(ind);
     winner();
     j++;
   }
 }
Example #4
0
 /** AI vs AI: ket gepi jatekos felvaltva lep */
 private static void ai() {
   while (!table.win(pt[0].getColor()) && !table.win(pt[1].getColor())) {
     ind = j % 2;
     nextInd = (j + 1) % 2;
     if (!aiStep(ind, pt[nextInd].getElapsedTime())) {
       return;
     }
     winner();
     j++;
   }
 }
Example #5
0
 /**
  * meghivja a human jatekos nextMove()-jat es vegrehajtja azt
  *
  * @param i i-edik human jatekos lep
  */
 private static void humanStep(int i) {
   table.nextSteps(p[i].getColor());
   move = p[i].nextMove(move);
   table.makeStep(move, p[i].getColor());
   if (text == 1) {
     System.out.println(
         "\n"
             + j
             + ". step "
             + ind
             + ". player stepped | "
             + move
             + " figure: "
             + p[i].getColor());
     System.out.println(table);
   }
   return;
 }
Example #6
0
  /**
   * meghivja az ai nextMove()-jat, ellenorzi az ai lepeset es vegrehajtja azt
   *
   * @param i a timb hanyadik jatekosa jon
   * @param oTime ellenfel eddig eltelt ideje
   */
  private static boolean aiStep(int i, long oTime) {
    move = pt[i].nextMove(move);
    if (move != null) {
      /** 'lejart-e az ideje?' ellenorzese */
      if (pt[i].getElapsedTime() > maxTime) {
        if (pt[i].getColor() == QuixoBoard.X) {
          if (text == 1) {
            System.out.println("X's time is expired so O won!");
          } else {
            System.out.println(QuixoBoard.O);
          }
          return false;
        } else {
          if (text == 1) {
            System.out.println("O's time is expired so X won!");
          } else {
            System.out.println(QuixoBoard.X);
          }
          return false;
        }
      }

      /** 'csalt-e valaki?' ellenorzese */
      if (table.legal(move.getX(), move.getY(), pt[i].getColor(), move.getNx(), move.getNy())) {
        table.makeStep(move, pt[i].getColor());
      } else {
        if (pt[i].getColor() == QuixoBoard.X) {
          if (text == 1) {
            System.out.println("X cheated so O won!");
          } else {
            System.out.println(QuixoBoard.O);
          }
          return false;
        } else {
          if (text == 1) {
            System.out.println("O cheated so X won!");
          } else {
            System.out.println(QuixoBoard.X);
          }
          return false;
        }
      }
      if (text == 1) {
        System.out.println(
            "\n"
                + j
                + ". step "
                + ind
                + ". player stepped | "
                + move
                + " time: "
                + pt[i].getElapsedTime()
                + " figure: "
                + pt[i].getColor()
                + " || "
                + pt[ind].sequence
                + " my name is "
                + pt[i].playerName);
        System.out.println(table);
      }

    } else {
      /** ind jatekos null-t lepett => lepes kenyszer miatt kikapott */
      if (pt[i].getColor() == QuixoBoard.X) {
        if (text == 1) {
          System.out.println("X didn't step so O won!");
        } else {
          System.out.println(QuixoBoard.O);
        }
        return false;
      } else {
        if (text == 1) {
          System.out.println("O didn't step so X won!");
        } else {
          System.out.println(QuixoBoard.X);
        }
        return false;
      }
    }
    return true;
  }