Examples of Piece


Examples of com.oti.Piece

   * */
  private StateCode createState(Board board) {
    StateCode res = new StateCode();
    byte[] arr = res.toByteArray();
    for (int i = 0; i < 16; i++) {
      Piece cell = board.pieceAt(i%4, i/4);
      if (i%2==1)
        arr[i/2] = (byte) (arr[i/2] << 4);
     
      arr[i/2] |= (byte) (0x0F & cell.getPieceNumber());

    }
    System.out.println("SAM TO REMOVE createState() ");
    SASolverNoBigInt.printState(res);   
   
View Full Code Here

Examples of com.oti.Piece

public class TestPiece {

    @Test
    public void testPiece(){
        Piece blank = Piece.pieceForNumber(0);
        Piece one = Piece.pieceForNumber(1);
        Piece otherOne = Piece.pieceForNumber(1);
        Piece two = Piece.pieceForNumber(2);

        Assert.assertThat(one, is(one));
        Assert.assertThat(one, is(otherOne));
        Assert.assertThat(blank, is(blank));
        Assert.assertThat(blank, is(not(one)));

        Assert.assertTrue(one.compareTo(two) < 0);
        Assert.assertTrue(two.compareTo(one) > 0);
        Assert.assertTrue(one.compareTo(one) == 0);
        Assert.assertTrue(two.compareTo(two) == 0);

        // blank always comes at the end
        Assert.assertTrue(blank.compareTo(one) > 0);
        Assert.assertTrue(one.compareTo(blank) < 0);
        Assert.assertTrue(one.compareTo(one) == 0);
View Full Code Here

Examples of com.oti.Piece


public class TestMove {
    @Test
    public void testMove(){
        Piece blank = Piece.pieceForNumber(0);
        Piece one = Piece.pieceForNumber(1);
        Piece otherOne = Piece.pieceForNumber(1);
        Piece two = Piece.pieceForNumber(2);

        Location locOfBlank = Location.locationFor(3,3, 4);
        Location otherLocOfBlank = Location.locationFor(3, 3, 4);
        Location locOfOne = Location.locationFor(0,0, 4);
        Location locOfTwo = Location.locationFor(1,0, 4);
View Full Code Here

Examples of com.turn.ttorrent.client.Piece

        this.interested = false;
        break;
      case HAVE:
        // Record this peer has the given piece
        PeerMessage.HaveMessage have = (PeerMessage.HaveMessage)msg;
        Piece havePiece = this.torrent.getPiece(have.getPieceIndex());

        synchronized (this.availablePieces) {
          this.availablePieces.set(havePiece.getIndex());
          logger.trace("Peer {} now has {} [{}/{}].",
            new Object[] {
              this,
              havePiece,
              this.availablePieces.cardinality(),
              this.torrent.getPieceCount()
            });
        }

        this.firePieceAvailabity(havePiece);
        break;
      case BITFIELD:
        // Augment the hasPiece bit field from this BITFIELD message
        PeerMessage.BitfieldMessage bitfield =
          (PeerMessage.BitfieldMessage)msg;

        synchronized (this.availablePieces) {
          this.availablePieces.or(bitfield.getBitfield());
          logger.trace("Recorded bitfield from {} with {} " +
            "pieces(s) [{}/{}].",
            new Object[] {
              this,
              bitfield.getBitfield().cardinality(),
              this.availablePieces.cardinality(),
              this.torrent.getPieceCount()
            });
        }

        this.fireBitfieldAvailabity();
        break;
      case REQUEST:
        PeerMessage.RequestMessage request =
          (PeerMessage.RequestMessage)msg;
        Piece rp = this.torrent.getPiece(request.getPiece());

        // If we are choking from this peer and it still sends us
        // requests, it is a violation of the BitTorrent protocol.
        // Similarly, if the peer requests a piece we don't have, it
        // is a violation of the BitTorrent protocol. In these
        // situation, terminate the connection.
        if (this.isChoking() || !rp.isValid()) {
          logger.warn("Peer {} violated protocol, " +
            "terminating exchange.", this);
          this.unbind(true);
          break;
        }

        if (request.getLength() >
            PeerMessage.RequestMessage.MAX_REQUEST_SIZE) {
          logger.warn("Peer {} requested a block too big, " +
            "terminating exchange.", this);
          this.unbind(true);
          break;
        }

        // At this point we agree to send the requested piece block to
        // the remote peer, so let's queue a message with that block
        try {
          ByteBuffer block = rp.read(request.getOffset(),
                  request.getLength());
          this.send(PeerMessage.PieceMessage.craft(request.getPiece(),
                request.getOffset(), block));
          this.upload.add(block.capacity());

          if (request.getOffset() + request.getLength() == rp.size()) {
            this.firePieceSent(rp);
          }
        } catch (IOException ioe) {
          this.fireIOException(new IOException(
              "Error while sending piece block request!", ioe));
        }

        break;
      case PIECE:
        // Record the incoming piece block.

        // Should we keep track of the requested pieces and act when we
        // get a piece we didn't ask for, or should we just stay
        // greedy?
        PeerMessage.PieceMessage piece = (PeerMessage.PieceMessage)msg;
        Piece p = this.torrent.getPiece(piece.getPiece());

        // Remove the corresponding request from the request queue to
        // make room for next block requests.
        this.removeBlockRequest(piece);
        this.download.add(piece.getBlock().capacity());

        try {
          synchronized (p) {
            if (p.isValid()) {
              this.requestedPiece = null;
              this.cancelPendingRequests();
              this.firePeerReady();
              logger.debug("Discarding block for already completed " + p);
              break;
            }

            p.record(piece.getBlock(), piece.getOffset());

            // If the block offset equals the piece size and the block
            // length is 0, it means the piece has been entirely
            // downloaded. In this case, we have nothing to save, but
            // we should validate the piece.
            if (piece.getOffset() + piece.getBlock().capacity()
                == p.size()) {
              p.validate();
              this.firePieceCompleted(p);
              this.requestedPiece = null;
              this.firePeerReady();
            } else {
              this.requestNextBlocks();
View Full Code Here

Examples of data.programmation.Piece

      pSelectPPO.setDate(1, today);
      pSelectPPO.setDate(2, today);     
      rs = pSelectPPO.executeQuery();
    }
//    String idPieceTmp = "";
    Piece p; // = new Piece(idPieceTmp);

    while(rs.next()){
      /*
       * 1 IDPIECE = String
       * 2 TITREPIECE = String
       * 3 AUTEUR = String
       * 4 TITRESAISON = String
       * 5 TYPEPERIODE = String
       * 6 DATEDEB = Date
       * 7 DATEFIN = Date
       *
       * Ici il faut s'attendre a recevoir plusieurs fois
       * un rs avec IDPIECE identique: plusieurs types de
       * periodes de reservation!
       */
      String id = rs.getString(1);
      String titre = rs.getString(2);
      String auteur = rs.getString(3);
      String saison = rs.getString(4);

//      if(!id.equals(idPieceTmp)){
      p = new Piece(id, titre, auteur, saison);
//        idPieceTmp = id;
     
      // ajouter les representations pour cette piece:
      // le faire seulement si on cree une nouvelle piece!
      for(Iterator it = this.getSeancesPiece(id).iterator();
        it.hasNext(); ){
        p.addRepresentation((Representation)it.next());
      }
     
     
      //Ajout des tarifs
      pSelectTarifsPiece.clearParameters();
      pSelectTarifsPiece.setString(1, id);
      ResultSet rsTarifs = pSelectTarifsPiece.executeQuery();
      while(rsTarifs.next()){
        p.addTarif(rsTarifs.getString(2), rsTarifs.getString(3), rsTarifs.getDouble(4));
      }
     
      // ajouter la piece dans la liste des pieces a retourner.
      lesPieces.add(p);
     
      // ajouter la piece dans le cache:
      //this.cachePieces.put(id, p);
      //TODO: si on utilise le cache!
//      }

     
      // recuperation du reste des informations du ResultSet
      String type =rs.getString(5);
      Date deb = rs.getDate(6);
      Date fin = rs.getDate(7);
      // ajout du type et des dates debut/fin de la periode periodes
      p.setPeriodeEnCours(type);
      p.setPeriodeDebut(deb);
      p.setPeriodeFin(fin);
    }
   
    return lesPieces;
  }
View Full Code Here

Examples of data.programmation.Piece

        String message = "Vous devez sélectionnez une pièce";
        GU.warn(message);
        //System.out.println("Pas de selection");
      }else{
        // On affiche le nom de la pièce
        Piece p = (Piece)table.getValueAt(table.getSelectedRow(), 0);
        //System.out.println(p);
       
        //Si période abonnée, on affiche l'écran abonnée
        boolean periodeAbonne = ((Boolean)table.getValueAt(table.getSelectedRow(),3)).booleanValue();
       
View Full Code Here

Examples of data.programmation.Piece

    int i = 0;
    /* Récupération de toutes les piéces */
    while (it.hasNext()) {

      Piece p = (Piece) it.next();
      // System.out.println("début = "+p.getPeriodeDebut()+" fin =
      // "+p.getPeriodeFin());
      // System.out.println(p);
      Boolean periode;
      String periodeStr = p.getPeriodeEnCours();
      if (periodeStr.equals(Utils.PERIODEABONNES)) {
        periode = new Boolean(true);
      } else {
        periode = new Boolean(false);
      }
      Object[] ligne = { p, p.getPeriodeDebut(), p.getPeriodeFin(),
          periode };
      donnees[i] = ligne;
      i++;

    }
View Full Code Here

Examples of echiquier.pieces.Piece

   * @param Piece
   *            piece
   * @return boolean
   */
  public boolean estDeMemeCouleur(Position position, Piece piece) {
    Piece piecePlacee = plateau.get(position);
    if (piecePlacee == null) {
      return false;
    } else {
      if (piecePlacee.getCouleur() == piece.getCouleur())
        return true;
      else
        return false;
    }
  }
View Full Code Here

Examples of echiquier.pieces.Piece

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

Examples of echiquier.pieces.Piece

   * @param Piece
   *            piece: la piece à deplacer
   * @return DeplacementEtat etat: l'état du déplacement
   */
  public DeplacementEtat getDeplacementEtat(Position pi, Position pf) {
    Piece pieceInit = getPieceAt(pi);

    if (pieceInit == null) {
      return DeplacementEtat.PASDEPIECE;
    }
    if (!Outils.isInTheTableau(pf)) {
      return DeplacementEtat.HORSDUPLATEAU;
    }
    if (!pieceInit.deplacementCorrect(pi, pf, pieceInit.getCouleur())) {
      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());
    }

    /***********************
     * Cas spécial du pion *
     * *********************/
    if (pieceInit instanceof Pion) {
      if (Outils.isDeplacementDiagonal(pi, pf)) {
        if (getPieceAt(pf) == null)
          return DeplacementEtat.INCORRECT;
      } else if (getPieceAt(pf) != null)
        return DeplacementEtat.INCORRECT;
    }

    /***************************
     * Test de l'échec au roi *
     ***************************/

    // Enregistrement des positions
    Piece pieceF = getPieceAt(pf);

    // simulation du déplacement
    Piece pieceATester = pieceInit;
    plateau.put(pf, pieceATester);
    plateau.remove(pi);

    if (roiEstEnDanger(getRoiPosition(pieceInit.getCouleur()))) {
      // On remet comme avant quelque soit le résultat car la fonction
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.