630 likes | 822 Views
Hanoi. void TowersOfHanoi ( int disks, int from, int to, int spare) { // Solve the problem of moving the number of disks specified // by the first parameter from the stack specified by the // second parameter to the stack specified by the third
E N D
Hanoi void TowersOfHanoi(int disks, int from, int to, int spare) { // Solve the problem of moving the number of disks specified // by the first parameter from the stack specified by the // second parameter to the stack specified by the third // parameter. The stack specified by the fourth parameter // is avaialable for use as a spare. if (disks == 1) { // There is only one disk to be moved. Just move it. console.putln("Move a disk from stack number " + from + " to stack number " + to); } else { // Move all but one disk to the spare stack, then move the bottom disk, then put all the // other disks on top of it. TowersOfHanoi(disks-1, from, spare, to); console.putln("Move a disk from stack number " + from + " to stack number " + to); TowersOfHanoi(disks-1, spare, to, from); } }
public classUtils{ /** readFile*/ public static String readFile(String file) { Stringstr = new String(""); charbuf[] = new char[8192]; try { FileReaderfin = new FileReader(file); while(fin.read(buf) != -1) str += new String(buf); } catch(Exception e) { str = "Eccezione rilevata: " + e + "<br>"; } returnstr; } /** replace*/ public static String replace(String str, String source, String dest) { intindex = 0, lunghSource= source.length(); while ( (index = str.indexOf(source,index)) != -1) { str = str.substring(0,index) + dest + str.substring(index+lunghSource); index += dest.length(); } returnstr; } Inseguitore
/** * getYear: from a date (source format indicated by flag) */ public static intgetYear(String date, int flag) { try { if (flag == 0) returnInteger.parseInt(date.substring(0,4)); else return 0; } catch(Exception e) {} return 0; } /** * getMonth: from a date (source format indicated by flag) */ public static intgetMonth(String date, int flag) { try { if (flag == 0) returnInteger.parseInt(date.substring(5,7)); else return 0; } catch (Exception e) {} return 0; } /** * getDay: from a date (source format indicated by flag) */ public static intgetDay(String date, int flag) { try { if (flag == 0) returnInteger.parseInt(date.substring(8,10)); else return 0; } catch(Exception e) {} return 0; } /** * getHour: from a date * (source format indicated by flag) */ public static intgetHour(String date, int flag){ try { if (flag == 0) returnInteger.parseInt(date.substring(11,13)); else return 0; } catch(Exception e) {} return 0; } /** * getMinutes: from a date (source format indicated by flag) */ public static intgetMinutes(String date, int flag) { try { if (flag == 0) return Integer.parseInt(date.substring(14,16)); else return 0; } catch (Exception e) {} return 0; }
/** * formatDate */ public static String formatDate(String date, int flag) { StringstrHour; StringstrMin; int h = Utils.getHour(date,0); if (h < 10) strHour = "0"+h; else strHour = "" + h; int m = Utils.getMinutes(date,0); if (m < 10) strMin = "0"+m; else strMin = ""+m; if (flag == 0) return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0)+ " "+strHour+":"+strMin; if (flag == 1) returnUtils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0); // default return Utils.getDay(date,0)+"-"+Utils.getMonth(date,0)+"-"+Utils.getYear(date,0)+ " "+strHour+":"+strMin; } }
/** * Interface for timer functions * * @author Ignazio Locatelli - Media Illusion - (C) 2000 */ package it.MediaIllusion.Anim; public interfaceTimerInterface { public voidtick(); }
* Timer class: calls the tickmethodevery n milliseconds. * * <PRE> * Timer timer = new Timer(this,1000); // 1 secondinterval * timer.start(); * </PRE> * * @author Ignazio Locatelli */ package it.MediaIllusion.Anim; public class Timer implementsRunnable { // mainthread protectedThreadmyThread = null; // milliseconds to wait protected long interval; // interfaceused TimerInterfacecallback;
/** * default constructor */ public Timer() { interval = 1000; } /** * constructor * @param long millisecondnumber of millisecond for the interval * @paramTimerInterfacecallbackreference to the interface */ public Timer(long milliseconds, TimerInterfacecallback) { interval = milliseconds; this.callback = callback; } /** * returnmilliseconds for an interval */ public long getInterval() { returninterval; } /** * set interval * @param long millisecondsnumber of milliseconds */ public voidsetInterval(long milliseconds) { interval = milliseconds; }
/** * starts the timer */ public void start() { myThread = new Thread(this); myThread.start(); } /** * stops the timer */ public void stop() { myThread.stop(); myThread = null; }
/** * run */ public voidrun() { while(true) { long sTime = System.currentTimeMillis(); if (callback != null) callback.tick(); long eTime = System.currentTimeMillis(); long sleep = interval - (eTime-sTime); if (sleep <= 0) continue; try{ Thread.sleep(sleep); } catch (Exception e) { System.out.println("Exceptionduringsleepoperation\n"); } } } }
/** * Pos: class abstracting a 2D position on a grid * @authorIgnazio Locatelli - Media Illusion (C) 2000 */ public classPos{ public int x; public int y; /** * Position */ public Pos() { x = y = 0; } /** * Position */ public Pos(int x, int y) { this.x = x; this.y = y; } }
public classInseguitoreConst { public staticfinalintNUM_VITE=4; public static final intMAP_ROWS = 39; public static final intMAP_COLOUMNS = 39; public static final intMAP_CELL_DIMENSION = 8; public static final intPASSO = 4; public staticfinalintDISTANZA_CONTATTO = 36; public static final intSPEED=18; public staticfinalintACCELERAZIONE=4; public static final intATTESA=1000; public static final intOFFSET_X = 54; public static final intOFFSET_Y = 34; public static final intOFFSET_PERS_X = 50; public static final intOFFSET_PERS_Y = 30; public static final intSTART_X1 = 416; public static final intSTART_X2 = 465; public static final intSTART_Y1 = 323; public static final intSTART_Y2 = 377;
public static final intmap[][][] = { //liv 1 { {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1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, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
import java.awt.image.*; import java.awt.*; import java.applet.*; public classFiltraImmagineextendsRGBImageFilter { public FiltraImmagine() { canFilterIndexColorModel = true; } public Image filter(Applet a, Image in) { returna.createImage( new FilteredImageSource(in.getSource(),this) ); } public intfilterRGB(int x, int y, intrgb) { intr = ((rgb >> 16) & 0xff)/4; // estra la componente rossa intg = ((rgb >> 8) & 0xff)/4; // verde intb = (rgb & 0xff)/4; // blu intk = (int)(.56*g+.33*r+.11*b); return(0xff000000 | k << 16 | k << 8 | k); //returnrgb; } }
* @author Ing. Alessandro Campi */ public class Rettangolo { intpezziVisitati=0; inttotalePezzi=0; //vertici //in alto a sinistra public intx1, y1; //in basso a destra public intx2, y2; public intx1RealeNormale, y1RealeNormale; public intx1RealeScuro, y1RealeScuro; public intw, h; public intsaltoNormaleX, saltoNormaleY; public intsaltoNormaleDirettoX,saltoNormaleDirettoY; public intsaltoScuroX, saltoScuroY; /** Creates new Rettangolo */ public Rettangolo(int ix1,int iy1,int ix2,int iy2, intxSfondoLivelloNormale,intySfondoLivelloNormale, intxSfondoLivelloScuro,intySfondoLivelloScuro, intxBackground,intyBackground) { x1=ix1; y1=iy1; x2=ix2; y2=iy2; x1RealeNormale=xSfondoLivelloNormale+ x1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; y1RealeNormale=ySfondoLivelloNormale+ y1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1;
x1RealeScuro=xSfondoLivelloScuro+ x1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; y1RealeScuro=ySfondoLivelloScuro+ y1*InseguitoreConst.MAP_CELL_DIMENSION- InseguitoreConst.MAP_CELL_DIMENSION/2+1; w=(x2-x1)*InseguitoreConst.MAP_CELL_DIMENSION-1; h=(y2-y1)*InseguitoreConst.MAP_CELL_DIMENSION-1; saltoNormaleX=InseguitoreConst.OFFSET_X- xSfondoLivelloNormale+xBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleY=InseguitoreConst.OFFSET_Y- ySfondoLivelloNormale+yBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleDirettoX=InseguitoreConst.OFFSET_X- xSfondoLivelloNormale+InseguitoreConst.MAP_CELL_DIMENSION; saltoNormaleDirettoY=InseguitoreConst.OFFSET_Y- ySfondoLivelloNormale+InseguitoreConst.MAP_CELL_DIMENSION; saltoScuroX=InseguitoreConst.OFFSET_X- xSfondoLivelloScuro+xBackground+ InseguitoreConst.MAP_CELL_DIMENSION; saltoScuroY=InseguitoreConst.OFFSET_Y- ySfondoLivelloScuro+yBackground+ InseguitoreConst.MAP_CELL_DIMENSION; }
public booleanisIn(intx,int y) { return (x>=x1&&x<=x2&&y>=y1&&y<=y2); } public voidincrementaVisitati() { pezziVisitati++; } public voidincrementaTotale() { totalePezzi++; } public booleancontrollaCompleto() { return (pezziVisitati==totalePezzi); } }