Package echiquier.outils

Examples of echiquier.outils.Position


    @Override
  public Position next(Position pi, Position pf, Couleur c) {
      int deltaY = pf.getY() - pi.getY();
    if (Math.abs(deltaY) == 2) {
      return new Position(pi.getX(), pi.getY() + deltaY/2);     
    }
    return pf;
  }
View Full Code Here


      else if (pi.getY() > pf.getY())
        yNext = pi.getY()-1;
      else
        yNext = pi.getY();
    }
    return new Position(xNext, yNext);
  }
View Full Code Here

   * @return Roi roi
   */
  public Position getRoiPosition(Couleur c) {
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        if (plateau.get(new Position(i, j)) != null
            && plateau.get(new Position(i, j)).getClass()
                .getSimpleName().equals("Roi")
            && plateau.get(new Position(i, j)).getCouleur() == c) {
          // System.out.println("Roi : "+new
          // Position(i,j)+" "+c.toString());
          return new Position(i, j);
        }
      }
    }
    return null;
  }
View Full Code Here

   * @return
   */
  public boolean roiEstEnDanger(Position pRoi) {
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        Piece piece = plateau.get(new Position(i, j));
        if (piece != null
            && piece.getCouleur() != getPieceAt(pRoi).getCouleur()
            && getDeplacementEtat(getPiecePosition(piece), pRoi) == DeplacementEtat.SUCCES) {
          return true;
        }
View Full Code Here

      return DeplacementEtat.INCORRECT;
    }
    if (this.estDeMemeCouleur(pf, pieceInit)) {
      return DeplacementEtat.DEJAOCCUPE;
    }
    Position before = this.getPiecePosition(pieceInit);
    while (!before.equals(pf)) {
      Position nextPosition = pieceInit.next(before, pf,
          pieceInit.getCouleur());
      if (!nextPosition.equals(pf) && getPieceAt(nextPosition) != null) {
        return DeplacementEtat.COLLISION;
      }
      before = pieceInit.next(before, pf, pieceInit.getCouleur());
    }
View Full Code Here

        if (piece != null && piece.getCouleur() == couleurEnnemie) {
          System.out.println(piece.getClass().getSimpleName());
          // on parcours tout le plateau et on simule les déplacements
          for (int i = 0; i < 8; ++i) {
            for (int j = 0; j < 8; ++j) {
              Position posF = new Position(i, j);
              Position posI = getPiecePosition(piece);
              if (getDeplacementEtat(posI, posF) == DeplacementEtat.SUCCES) {
                // simulation du déplacement
                plateau.put(posF, piece);
                plateau.remove(posI);
                if (!roiEstEnDanger(getRoiPosition(couleurEnnemie))) {
View Full Code Here

    historique.clear();

    plateau = new HashMap<Position, Piece>();

    for (int i = 0; i < 8; ++i) {
      plateau.put(new Position(i, 1), new Pion(Couleur.BLANC));
      plateau.put(new Position(i, 6), new Pion(Couleur.NOIR));
    }

    plateau.put(new Position(0, 0), new Tour(Couleur.BLANC));
    plateau.put(new Position(7, 0), new Tour(Couleur.BLANC));
    plateau.put(new Position(0, 7), new Tour(Couleur.NOIR));
    plateau.put(new Position(7, 7), new Tour(Couleur.NOIR));

    plateau.put(new Position(1, 0), new Cavalier(Couleur.BLANC));
    plateau.put(new Position(6, 0), new Cavalier(Couleur.BLANC));
    plateau.put(new Position(1, 7), new Cavalier(Couleur.NOIR));
    plateau.put(new Position(6, 7), new Cavalier(Couleur.NOIR));

    plateau.put(new Position(2, 0), new Fou(Couleur.BLANC));
    plateau.put(new Position(5, 0), new Fou(Couleur.BLANC));
    plateau.put(new Position(2, 7), new Fou(Couleur.NOIR));
    plateau.put(new Position(5, 7), new Fou(Couleur.NOIR));

    plateau.put(new Position(3, 0), new Roi(Couleur.BLANC));
    plateau.put(new Position(3, 7), new Roi(Couleur.NOIR));

    plateau.put(new Position(4, 0), new Reine(Couleur.BLANC));
    plateau.put(new Position(4, 7), new Reine(Couleur.NOIR));
  }
View Full Code Here

   */
  public void afficheTableau() {
    for (int i = 0; i < 8; ++i) {
      for (int j = 0; j < 8; ++j) {
        System.out.print(j == 0 && i != 8 ? "|" : "");
        if (plateau.get(new Position(j, i)) != null) {
          System.out.print(plateau.get(new Position(j, i)).getClass()
              .getSimpleName().substring(0, 2)
              + plateau.get(new Position(j, i)).getCouleur()
                  .toString().substring(0, 1) + "|");
        } else {
          System.out.print("   |");
        }
      }
View Full Code Here

      yp = 7 - (int) Math.floor(y / boardSize.getHeight() * 8);
    } else {
      yp = (int) Math.floor(y / boardSize.getHeight() * 8);
    }

    return new Position(xp, yp);
  }
View Full Code Here

   */
  public static void main(String[] args) {
      Echiquier eq = new Echiquier();
      eq.afficheTableau();
      //Cavalier
      assert eq.getDeplacementEtat(new Position(1,0), new Position(0,2)) == DeplacementEtat.SUCCES;
      assert eq.getDeplacementEtat(new Position(1,0), new Position(3,1)) == DeplacementEtat.DEJAOCCUPE;
      assert eq.getDeplacementEtat(new Position(1,0), new Position(3,2)) == DeplacementEtat.INCORRECT;
      assert eq.getDeplacementEtat(new Position(1,0), new Position(13,2)) == DeplacementEtat.HORSDUPLATEAU;
      //Tour
      assert eq.getDeplacementEtat(new Position(0,0), new Position(0,2)) == DeplacementEtat.SUCCES;
      assert eq.getDeplacementEtat(new Position(0,0), new Position(3,0)) == DeplacementEtat.DEJAOCCUPE;
      assert eq.getDeplacementEtat(new Position(0,0), new Position(3,1)) == DeplacementEtat.INCORRECT;
      assert eq.getDeplacementEtat(new Position(0,0), new Position(0,6)) == DeplacementEtat.SUCCES;
      assert eq.getDeplacementEtat(new Position(0,0), new Position(0,7)) == DeplacementEtat.COLLISION;
      //Fou
      assert eq.getDeplacementEtat(new Position(2,0), new Position(4,2)) == DeplacementEtat.SUCCES;
      assert eq.getDeplacementEtat(new Position(2,0), new Position(4,3)) == DeplacementEtat.INCORRECT;
      //Roi
      assert eq.getDeplacementEtat(new Position(3,7), new Position(3,6)) == DeplacementEtat.DEJAOCCUPE;
      //Roi
      assert eq.getDeplacementEtat(new Position(4,7), new Position(4,0)) == DeplacementEtat.COLLISION;
  }
View Full Code Here

TOP

Related Classes of echiquier.outils.Position

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.