Examples of Piece


Examples of general.Piece

    ownList = ownPieceArray.listIterator()
    enemyList = enemyPieceArray.listIterator();
    if (!ownPieceArray.isEmpty()) { //no pieces to capture
      //while pieces left and suitable move not found
      while (ownList.hasNext() && enemyList.hasNext() && !moveDone) {
        Piece ownPiece = ownList.next(); //own piece
        Piece enemyPiece = enemyList.next(); //piece to capture
        /*
         * before making move, check that own piece can't be captured during next move
         * or at least the captured enemy piece is more valuable
         */
        //temporarily make target square empty
        board.removePiece(enemyPiece.getRow(), enemyPiece.getCol()); //remove piece from the square
        //get all squares enemy can move during the next turn (now including the square
        //where enemy's piece was located)
        ArrayList<ArrayList<Integer>> possibleEnemyMoves = getAllSquaresPossibleToMove(player.getEnemySide());
        //place the removed piece on board
        board.addPiece(enemyPiece);
        ArrayList<Integer> possibleEnemyMovesX = possibleEnemyMoves.get(0); //get x coordinates
        ArrayList<Integer> possibleEnemyMovesY = possibleEnemyMoves.get(1); //get y coordinates
        //convert arraylist of enemy x movement coordinates into an array
        int[] pexArray = new int[possibleEnemyMovesX.size()];
          for (int i=0; i < pexArray.length; i++) {
            pexArray[i] = possibleEnemyMovesX.get(i).intValue();
          }
          //convert arraylist of enemy y movement coordinates into an array
        int[] peyArray = new int[possibleEnemyMovesY.size()];
          for (int i=0; i < peyArray.length; i++) {
            peyArray[i] = possibleEnemyMovesY.get(i).intValue();
          }
          //check if enemy can do counter attack on next move
          boolean capturedNextRound = false;
        comp: for (int i=0; i<pexArray.length; i++) {
          //compare
          if (enemyPiece.getRow()==pexArray[i] && enemyPiece.getCol()==peyArray[i]) {
            capturedNextRound = true;
            break comp;
          }
        }
          //check is enemy piece is more valuable
          boolean enemyMoreValuable = false;
          //if enemy piece is at least as valuable as own piece
          if (enemyPiece.getValue() >= ownPiece.getValue()) {
            enemyMoreValuable = true;
          }
        /*
         * do move if enemy can't counter attack during next move or it can but
         * traded piece is less valuable
         */
          if (!capturedNextRound || (capturedNextRound && enemyMoreValuable)) {
          move.doMove(player, board.coordinatesToNotation(ownPiece.getRow(),
              ownPiece.getCol()), board.coordinatesToNotation(enemyPiece.getRow(),
              enemyPiece.getCol()));
          moveDone=true;
          } else {
          advance(player);
          }
      }
View Full Code Here

Examples of general.Piece

    //put list of pieces in a random order
    Collections.shuffle(allPiecesFromOneSide);
    int amountOfPieces = allPiecesFromOneSide.size();
    int piecesChecked = 0;
    boolean advancingMove = false;
    Piece reservePiece = new Piece(), lastHope = new Piece();
    int reserveX=0, reserveY=0, lastHopeX=0, lastHopeY=0;
    Piece p;
    ArrayList<ArrayList<Integer>> moves;
    ArrayList<Integer> xList, yList, moveCheckOrder;
    int moveAmount;
    int moveLoc;
    boolean moveDone = false;
    //until advancing move is found or no pieces left to check
    while (!advancingMove && piecesChecked<amountOfPieces) {
      //get a piece
      p = allPiecesFromOneSide.get(piecesChecked);
      //get all possible moves that piece can do
      moves = move.possiblePieceMoves(p, false);
      xList = moves.get(0); //x coordinates
      yList = moves.get(1); //y coordinates
      moveAmount = xList.size(); //amount of moves
      moveLoc = 0; //move index in list
      //create order to check moves
      moveCheckOrder = new ArrayList<Integer>();
      for (int i=0; i<moveAmount; i++) {
        moveCheckOrder.add(i);
      }
      //randomize order in which moves are checked
      Collections.shuffle(moveCheckOrder);
      int counter = 0;
      if (moveAmount>0) { //if there's moves at all
        //save first move as a reserve/last chance move
        lastHope = p;
        int firstMove = moveCheckOrder.get(0);
        lastHopeX=xList.get(firstMove);
        lastHopeY=yList.get(firstMove);
        //while advancing move not found and still moves left
        while (!advancingMove && counter<moveAmount) {
          moveLoc = moveCheckOrder.get(counter); //get next move
          //check if move is safe (enemy can't attack during next move)
          if (isSquareSafe(xList.get(moveLoc), yList.get(moveLoc), player)) {
            //best move is to advance/go forward: white -vertical, black +vertical
            if(player.getSide()==0) { //if white side
              //if advancing move
              if(xList.get(moveLoc)<p.getRow()) {
                advancingMove=true;
              }
            }
            else { //black side
              //if advancing move
              if(xList.get(moveLoc)>p.getRow()) {
                advancingMove=true
             
            }
            //if not found a safe piece which can move forward
            //put piece in reserve because at least it's safe
            if(!advancingMove) {
              reservePiece=p;
              reserveX=xList.get(moveLoc);
              reserveY=yList.get(moveLoc);
            }
          }
          counter++;
        }
        if (advancingMove) { //advancing move found
          move.doMove(player, board.coordinatesToNotation(p.getRow(),
              p.getCol()), board.coordinatesToNotation(xList.get(moveLoc),
              yList.get(moveLoc)));
          moveDone=true;
        }
      }
      piecesChecked++;
View Full Code Here

Examples of model.Piece

    myRandom  = new Random();
   
    myDico = new Dico("ressources/dictionnaire");
    myArbitre = new Arbitre(myPlateau, 2, myDico);
   
    p = new Piece();
    p.creerPiece(myRandom.nextInt(7)+1);
    p.currentPosition(0);
   
    np = new Piece();
    np.creerPiece(myRandom.nextInt(7)+1);
    np.currentPosition(0);
 
    /*CONTENEUR PLATEAU*/
   
 
View Full Code Here

Examples of net.sourceforge.java_stratego.stratego.Piece

      case GRID:
        x = in.readInt();
        y = in.readInt();
        color = in.readInt();
        rank = in.readInt();
        view.update(new Spot(x, y), new Piece(0, color, Rank.values()[rank]));
        return true;
      case TRAY:
        x = in.readInt();
        color = in.readInt();
        rank = in.readInt();
        view.update(Board.IN_TRAY, new Piece(x, color, Rank.values()[rank]));
        return true;
      case GAMEOVER:
        x = in.readInt();
        view.gameOver(x);
        return true;
View Full Code Here

Examples of net.sourceforge.java_stratego.stratego.Piece

   
    //double check the ai setup
    for (int i=0;i<10;i++)
    for (int j=0;j<4; j++)
    {
      Piece p = null;
      for (int k=0;k<board.getTraySize();k++)
        if (board.getTrayPiece(k).getColor() == Settings.topColor)
        {
          p = board.getTrayPiece(k);
          break;
        }

      if (p==null)
        break;
       
      engine.aiReturnPlace(p, new Spot(i, j));
    }
   
    //if the user didn't finish placing pieces just put them on
    for (int i=0;i<10;i++)
    for (int j=6;j<10;j++)
    {
      Piece p = null;
      for (int k=0;k<board.getTraySize();k++)
        if (board.getTrayPiece(k).getColor() != Settings.topColor)
        {
          p = board.getTrayPiece(k);
          break;
View Full Code Here

Examples of net.sourceforge.java_stratego.stratego.Piece

        if (b.validMove(f, t))
        {
          hasMove = true;
         
          Move tmpM = new Move(b.getPiece(f), f, t);
          Piece fp = b.getPiece(f);
          Piece tp = b.getPiece(t);
          b.move(tmpM);
          //int tmpV = valueBoard(b) + (int)(valueNMoves(b, n-1) * ALPHA);
          int tmpV = valueBoard(b);
          if (tp == null ||
            (fp.isKnown() && turn == Settings.bottomColor) ||
            (tp.isKnown() && turn == Settings.topColor))
            tmpV += valueNMoves(b, n-1, guesses);
          else if (guesses <= MAX_GUESSES)
            tmpV += (int) (ALPHA * valueNMoves(b, n-1, guesses+1));
           
          b.undo(fp, f, tp, t);
View Full Code Here

Examples of net.sourceforge.java_stratego.stratego.Piece

        switch (Message.values()[type])
        {
        case MOVE:
          int x1, x2, y1, y2, rank;
          Spot from, to;
          Piece p;
          x1 = in.readInt();
          y1 = in.readInt();
          x2 = in.readInt();
          y2 = in.readInt();
          rank = in.readInt();
          if (x1 < 0)
          {
            from = Board.IN_TRAY;
            p = new Piece(0, 0, Rank.values()[rank]);
          }
          else
          {
            from = new Spot(x1, y1);
            p = engine.getBoardPiece(x1, y1);
View Full Code Here

Examples of org.darkhelm.dragonchess.shared.pieces.Piece

        PieceMoveSet moves = pDef.getMoves(getType());

        long hash = Zobrist.getHash(getType(), team, horiz, vert,
            bPiece.getType());

        Piece piece = new Piece(hash, bPiece.getType(), team,
            pDef.getValue());

        if (getSet().isFrozen(getType(), horiz, vert)) {
          piece.addMove(new Move(getSet().hash(), 0, getType(),
              horiz, vert, MoveTypes.FREEZE));
        } else {
          piece.addAllMoves(moves.getMoves(team, this, horiz, vert));
        }

        pieceMap.put(Position.create(getType(), horiz, vert), piece);
      }
    }
View Full Code Here

Examples of org.eclipse.ecf.protocol.bittorrent.internal.torrent.Piece

    int numPieces = torrent.getNumPieces();
    pieces = new Vector(numPieces);
    trackerThread = new TrackerThread();
    states = PieceState.createStates(numPieces);
    for (int i = 0; i < numPieces; i++) {
      pieces.add(new Piece(states[i], i));
    }
    bitfield = new byte[numPieces % 8 != 0 ? (numPieces / 8) + 1
        : (numPieces / 8)];
    hasPiece = new boolean[numPieces];
    pieceAvailability = new int[numPieces];
    priorityPieces = new boolean[numPieces];
    interestedPieces = new boolean[numPieces];
    uninterestedPieces = new boolean[numPieces];
    incompletePieces = new Vector();
    stateListeners = new Vector();
    errorListeners = new Vector();
    pieceListeners = new Vector();
    progressListeners = new Vector();
    hashCheckListeners = new Vector();
    propertiesFile = new File(statePath, hexHash + ".properties"); //$NON-NLS-1$
    if (!propertiesFile.exists()) {
      properties = new Properties();
      properties.setProperty("target", targetFile.getAbsolutePath()); //$NON-NLS-1$
    } else if (properties == null) {
      properties = new Properties();
      properties.load(new FileInputStream(propertiesFile));
      restore(properties);
    } else {
      restore(properties);
    }
    this.properties = properties;
    store();

    String[] filenames = torrent.getFilenames();
    if (filenames.length != 1 && !targetFile.exists()
        && !targetFile.mkdirs()) {
      throw new IOException("The folders needed by this torrent could not be created"); //$NON-NLS-1$
    }
    files = new DataFile[filenames.length];

    fileInitialization(filenames, targetFile);
    for (int i = 0; i < numPieces; i++) {
      Piece piece = (Piece) pieces.get(i);
      piece.setLength(pieceLength);
    }
    ((Piece) pieces.get(numPieces - 1))
        .setLength((int) (total % pieceLength));

    checkFile();
View Full Code Here

Examples of org.gudy.azureus2.plugins.peers.Piece

                    eventOccurred(
                      PeerManagerEvent  event )
                    {
                      if ( event.getType() == PeerManagerEvent.ET_PIECE_COMPLETION_CHANGED ){
                       
                        Piece piece = (Piece)event.getData();
                       
                        System.out.println( "piece: " + piece.getIndex() + ", done=" + piece.isDone());
                       
                        try{
                          peer_manager.getDiskManager().read(
                            piece.getIndex(),
                            0,
                            piece.getLength(),
                            new DiskManagerReadRequestListener()
                            {
                              public void
                              complete(
                                DiskManagerReadRequest    request,
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.