Reordering PriorityQueue for A* algorithm

Hi there,
I've been trying to implement an A* search algorithm in java which has been going well for the most part.
I'm using a PriorityQueue to implement the OpenList which basically has to keep the lowest cost node at the start of the queue.
However, when I dynamically change the cost of a node when it's already inside the PriorityQueue, it doesn't automatically reposition itself. Like say the lowest node with a cost of 5 is at the start of the queue. Then some other node already in the queue has it's cost changed to 4, it doesn't go to the start of the list.
Does anyone know a way of reordering PriorityQueues? Or an alternative data structure that can dynamically reorder things?
Thank you.

When looking at the PriorityQueue documentation (especially the following part):
Implementation note: this implementation provides O(log(n)) time for the insertion methods (offer, poll, remove() and add) methods; linear time for the remove(Object) and contains(Object) methods; and constant time for the retrieval methods (peek, element, and size). you see that the queue will only check for the weight of the elements when they are entered. No method is provided to rebuild the queue order directly so I think you may go with removing the element, changing the weight and adding it again.

Similar Messages

  • I Need Java code for following Algorithm

    * I Need Java code for following algorithm. Kindly any one help.
    1. Read the contents (ideas and its corresponding scores) from two files named as 'a' and 'b'.
    2. Stored the file 'a' contents in array a[].
    3. Stored the file 'b' contents in array b[].
    4. compare both files like
    if(a.equals(b[j])
    Writing the common idea and add the score from file 'a' and 'b'.
    else
    write the uncommon idea and its score..
    For example :
    Form Agents.txt
    action,65
    architecture,85
    eco-,15
    essay,30
    form,85
    form,85
    link,40
    tangent,25
    Form Agents1.txt
    Black holes,69
    essay,78
    Herewith i have above mentioned two files named as Form Agents and Form Agents1.
    Form Agents has eight fields
    Form Agents1 has two fields
    --> 'essay' is common in two files, so store the idea 'essay' and add the score from Form Agents score is '30' and Form Agents1 has 78 (essay 108).
    Finally it stores idea in another file with uncommon fields also.
    Please help us.

    We have tried with following code.
    But we cant add the scores.
    For Example:
    Form Agents.txt --> has "essay,30"
    Form Agents1.txt --> has "essay,78"
    Result is: essay,108
    Finally it stores idea in another file with uncommon fields also.
    So Any one pls correct the following code.
    try
    DataOutputStream o1=new DataOutputStream(new
    FileOutputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\CandidateResponses\\Form
    Agents.txt"));
    //Reading the contents of the files
    BufferedReader br= new BufferedReader(new InputStreamReader(new
    FileInputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\Ideological\\Form
    Agents.txt")));
    BufferedReader br1= new BufferedReader(new InputStreamReader(new
    FileInputStream("C:\\Interfaces\\interfaces\\temp\\BlackBoard\\My Design
    World\\Project\\Material\\art\\System Agents\\Form Agents\\Related\\Form
    Agents.txt")));
    while((s=br.readLine())!=null)
    s1+=s+"\n";
    while((s2=br1.readLine())!=null)
    s3+=s2+"\n";
    int numTokens = 0;
    StringTokenizer st = new StringTokenizer(s1);
    String[] a = new String[10000];
    String[] br_n=new String[10000];
    int i=0;
    while (st.hasMoreTokens())
    s2 = st.nextToken();
    a=s2.substring(0,s2.length()-3);
    s6=s2.substring(s2.length()-2);
    br_n[i]=s6;
    i++;
    numTokens++;
    int numTokens1 = 0;
    StringTokenizer st1 = new StringTokenizer (s3);
    String[] b = new String[10000];
    String[] br1_n=new String[1000];
    int j=0;
    while (st1.hasMoreTokens())
    s4 = st1.nextToken();
    b[j]=s4.substring(0,s4.length()-3);
    s7=s4.substring(s4.length()-2);
    br1_n[j]=s7;
    j++;
    numTokens1++;
    int x=0;
    for(int m=0;m<a.length;m++)
    for(int n=0;n<b.length;n++)
    if(a[m].equalsIgnoreCase(b[n])){
    int sc=Integer.parseInt(br_n[m]);
         int sc1=Integer.parseInt(br1_n[n]);
    int score=sc+sc1;
         o.writeBytes(a[m]+","+score+"\n");
    break;
    else
    o.writeBytes(a[m]+","+br_n[m]+"\n");
    break;
    }catch(Exception e){}

  • Ask again:  Where can I find source code for CPRM algorithm?

    Hi, everyone.
    Where can I find reference implementation or some sample codes for CPRM(content protection for recordable media) algorithm? Can anyone help?
    Information about CPRM can be find here,
    http://www.4centity.com/
    JAVA version is preferred and C/C++ implementation is also OK.
    Thanks in advance,
    Geo

    Thanks, edsonw buddy!
    I only found C2 cipher source code and some other documents dealing with CPRM algorithm. And what I want is total CPRM implementation reference source code (C2 is only a basic module of CPRM algorithm).
    So can you provide me some useful information dealing with how to get total CPRM implementation reference source code? Both JAVA and C/C++ will be OK.
    Have a wonderful weekend,
    George

  • Where can I find source code for CPRM algorithm?

    Hi, everyone.
    Where can I find reference implementation or some sample codes for CPRM(content protection for recordable media) algorithm? Can anyone help?
    Information about CPRM can be find here,
    http://www.4centity.com/
    Thanks in advance,
    Geo

    Thanks, edsonw buddy!
    I really take rather a lot of time to search reference implementation in this site but failed to find it out. Can you give me the precise link from which I can download reference implementation and sample vectors?
    Best regards,
    George

  • Looking for good algorithm to calculate a list of figures

    Hello,
    Given a list of figures:
    1899.09
    345.55
    300.00
    130.05
    90023.00
    45.90
    120.50
    8831781.56
    505.00
    45.55
    Then the program need to find all the possible addition of figures that will able to produce a answer, for example, 550.55
    Then the possible additions are:
    300.00 + 120.50 + 130.05 = 550.55
    505.00 + 45.55 = 550.55
    any good algorithm or sample code?
    Thanks for any help.

    A general knapsack problem solver is overkill here if one just wants to find a combination that fits 'perfectly'. If the list of numbers is small (< 100), a simple exhaustive search will do fine (read: it's fast). Have a look at the following sample class that solves this particular problem. Note that the set of numbers is a set of integer numbers, because floating point numbers don't add up well; in particular large and small numbers added will result in very inaccurate sums.
    kind regards,
    public class Comb {
         private int   u; // index of used numbers sofar
         private int   s; // the sum to be found
         private int[] c; // the candidate numbers
            // given a set of numbers and a sum, instantiate a solver
         public Comb(int[] c, int s) {
              this.c= c;
              this.s= s;
              this.u= c.length;
            // yes, swap two elements in array c
         private void swap(int i, int j) {
              int t= c;
              c[i] = c[j];
              c[j] = t;
    // use the number at index i as a try
         private void use(int i) {
              swap(i, --u);
    // unuse the number at index i
         private void unuse(int i) {
              swap(i, u++);
    // proccess (e.g. print) a current solution
    // note that this method could throw an exception if
    // just one solution is needed.
         private void solution() {
              for (int i= u; i < c.length; ++i) {
                   System.out.print(c[i]);
                   if (i < c.length-1)
                        System.out.print("+");
              System.out.println("="+s);
    // find all solutions to this problem
         public void find(int t) {
              if (t == 0) // ready?
                   solution();
              else if (t > 0) // still more to do?
                   for (int i= 0; i < u; ++i) {
                        use(i);
                        find(t-c);
                        unuse(i);
    // solve the example problem ... == 11
         public static void main(String[] args) {
              int c[]= { 5, 3, 6, 8 };
              int s = 11;
              new Comb(c, s).find(s);

  • How to generate all possible keys for DES algorithm

    Hello every one,
    I want to generate all the possible key combinations for the DES algorithm 56-bit "actuallly 64 but the last 8 bits are just padding", so can anyone plz help how can i do that? or give me article or something that might help me?
    Thanks in advance,
    Amr M. Kamel.

    I know that but who said that it will be one
    processor it will be on distributed and clustered
    environment :). I just want to know how to generate
    the keys "or write binary".
    Thans again for your helpA cluster of 2285 machines will still take a year! The simplest algorithm is to just count from 0 to 2^56 .
    If you are thinking of cracking DES then there is a Book I have on my shelf 'Cracking DES' published by the 'Electronic Frontier Foundation' ISBN 1-56592-520-3 . It contains the C code and describes the hardware used. The hardware cost was about $100,000 and it cracks DES in about 3.5 days.
    Assuming Moore's law ( http://en.wikipedia.org/wiki/Moore's_law ) applies then it should now take about much less than a day and cost much less than $100,000. BUT - it will take a long time using basic computers.

  • Where does the password for Elgamal algorithm is stored

    hi,
    i am doing a project in Intelligent security in java using Elagamal algorithm. The feature of Elgamal is that the password is not stored in database . Then where is the password is stored to check for a existing user .
    If i am an existing user then when i type the username and password then it should check or compare and tell that password is right or wrong . so where is the password is stored to compare ?? please give me the coding in java .
    i need the coding immediately , of how to get the password and to store and then to compare where the user is correct else message should display "type the correct password".
    Given below is my Main window coding plz help me where to include the coding,
         This simple extension of the java.awt.Frame class
         contains all the elements necessary to act as the
         main window of an application.
    // LOGIN WINDOW ( FIRST WINDOW ) FOR LOGIN AND EXISTING USER
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import java.sql.*;
    import java.math.*;
    import java.security.*;
    import java.io.IOException;
    import javax.crypto.Cipher;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.KeyGenerator;
    import javax.crypto.SecretKey;
    public class Smart extends Frame
         public Smart()
              // This code is automatically generated by Visual Cafe when you add
              // components to the visual environment. It instantiates and initializes
              // the components. To modify the code, only use code syntax that matches
              // what Visual Cafe can generate, or Visual Cafe may be unable to back
              // parse your Java file into its visual environment.
              //{{INIT_CONTROLS
              setLayout(null);
              setBackground(new java.awt.Color(255,247,192));
              setSize(1200,900);
    // 157,135,178
              setVisible(false);
              label1.setText("USERID");
              add(label1);
              label1.setFont(new Font("Dialog", Font.PLAIN, 14));
              label1.setBounds(315,180,84,48);
              label2.setText("PASSWORD");
              add(label2);
              label2.setFont(new Font("Dialog", Font.PLAIN, 14));
              label2.setBounds(315,260,100,40);
              textField1.setBounds(430,180,216,36);
              //textField1.setBackground(new java.awt.Color(196,197,233));//textfieldcolor
              add(textField1);
              textField2.setEchoChar('*');
              //textField2.setBackground(new java.awt.Color(196,197,233));
              add(textField2);
              textField2.setBounds(430,260,213,36);
              button1.setLabel("SUBMIT");
              add(button1);
              button1.setBackground(new java.awt.Color(196,197,233));
              button1.setBounds(320,360,120,40);
              button2.setLabel("CLEAR");
              add(button2);
              button2.setBackground(new java.awt.Color(196,197,233));
              button2.setBounds(520,360,120,40);
              label3.setText("REGISTRATION FORM");
              add(label3);
              label3.setFont(new Font("Dialog", Font.BOLD, 20));
              label3.setBounds(324,54,550,80);
              button3.setLabel("NEW USER REGISTRATION");
              add(button3);
              button3.setBackground(new java.awt.Color(196,197,233));
              button3.setBounds(369,450,232,40);
              //add(textArea1);
              //textArea1.setBounds(0,360,576,52);
              setTitle("LOGIN PHASE Application");
              /*int mStrength = 16;
              SecureRandom mSecureRandom = new SecureRandom();
              p = new BigInteger(mStrength, 16, mSecureRandom);*/
              //{{INIT_MENUS
              //{{REGISTER_LISTENERS
              SymWindow aSymWindow = new SymWindow();
              this.addWindowListener(aSymWindow);
              SymAction lSymAction = new SymAction();
              button1.addActionListener(lSymAction);
              button2.addActionListener(lSymAction);
              button3.addActionListener(lSymAction);
         public Smart(String title)
              this();
              setTitle(title);
    * Shows or hides the component depending on the boolean flag b.
    * @param b if true, show the component; otherwise, hide the component.
    * @see java.awt.Component#isVisible
    public void setVisible(boolean b)
              if(b)
              setLocation(50, 50);
              super.setVisible(b);
         public static void main(String args[])
         try
                   //Create a new instance of our application's frame, and make it visible.
              (new Smart()).setVisible(true);
              catch (Throwable t)
                   System.err.println(t);
                   t.printStackTrace();
                   // Ensure the application exits with an error condition.
                   System.exit(1);
              public void addNotify()
              // Record the size of the window prior to calling parents addNotify.
              Dimension d = getSize();
              super.addNotify();
              if (fComponentsAdjusted)
                   return;
              // Adjust components according to the insets
              setSize(getInsets().left + getInsets().right + d.width, getInsets().top + getInsets().bottom + d.height);
              Component components[] = getComponents();
              for (int i = 0; i < components.length; i++)
                   Point p = components.getLocation();
                   p.translate(getInsets().left, getInsets().top);
                   components[i].setLocation(p);
              fComponentsAdjusted = true;
         // Used for addNotify check.
         boolean fComponentsAdjusted = false;
         //{{DECLARE_CONTROLS
         java.awt.Button button1 = new java.awt.Button();
         java.awt.Button button2 = new java.awt.Button();
         java.awt.Label label1 = new java.awt.Label();
         java.awt.Label label2 = new java.awt.Label();
         java.awt.Label label3 = new java.awt.Label();
         java.awt.Button button3 = new java.awt.Button();
         java.awt.TextField textField1 = new java.awt.TextField();
         java.awt.TextField textField2 = new java.awt.TextField();
         java.awt.TextArea textArea1 = new java.awt.TextArea();
         //BigInteger p;
         //{{DECLARE_MENUS
         class SymWindow extends java.awt.event.WindowAdapter
              public void windowClosing(java.awt.event.WindowEvent event)
                   Object object = event.getSource();
                   if (object == Smart.this)
                        Smart_WindowClosing(event);
         void Smart_WindowClosing(java.awt.event.WindowEvent event)
              System.exit(0);
         class SymAction implements java.awt.event.ActionListener
              public void actionPerformed(java.awt.event.ActionEvent event)
                   Object object = event.getSource();
                   if (object == button1)
                        button1_ActionPerformed(event);
                   else if (object == button2)
                        button2_ActionPerformed(event);
                   else if (object == button3)
                        button3_ActionPerformed(event);
         void button1_ActionPerformed(java.awt.event.ActionEvent event)
              //try{
              String ids = textField1.getText();
              String pss = textField2.getText();
              byte [] bt = ids.getBytes();
              BigInteger id = new BigInteger(bt);
              //by samy byte [] bts = pss.getBytes();
              //BigInteger ps = new BigInteger(bts);
         int mStrength = 16;
         SecureRandom mSecureRandom = new SecureRandom();
         BigInteger p = new BigInteger(mStrength, 16, mSecureRandom);
         System.out.println("p = "+p.toString(16));
         BigInteger g = new BigInteger(mStrength - 1, mSecureRandom);
         System.out.println("g= "+g.toString(16));
         BigInteger x = new BigInteger(mStrength - 1, mSecureRandom);
         System.out.println("x="+x.toString(16));
         //byte[] bt = id.getBytes();
         BigInteger idb = new BigInteger(bt);
         //System.out.println("id= "+idb.toString(16));
         BigInteger ps = idb.modPow(x, p);
         //String pw = new String("pass = "+ps.toByteArray());
         System.out.println("ps ="+ps.toString(16));
         BigInteger r =null;
    BigInteger ONE = BigInteger.valueOf(1L);
    BigInteger p_1 = p.subtract(ONE);
    SecureRandom sr = new SecureRandom();
    do {
    r = new BigInteger(p.bitLength(), sr);
    } while (r.compareTo(ONE) <= 0 || r.compareTo(p_1) >= 0);
         System.out.println("r= "+r.toString(16));
         BigInteger c1 =idb.modPow(r,p);
         System.out.println("c1= "+c1.toString(16));
         long time = System.currentTimeMillis();
         System.out.println("TIME ="+time);
         BigInteger one = new BigInteger( new Integer(1).toString());
         BigInteger T = new BigInteger( new Long(time).toString());
         BigInteger t =T.xor(ps);
         BigInteger t1 = t.mod(p.subtract(one));
         System.out.println("t="+t1.toString(16));
         BigInteger M = idb.modPow(t1, p);
         System.out.println("M="+M.toString(16));
         int rnd = r.intValue();
         BigInteger c2 =ps.modPow(r,p).multiply(M).mod(p);
         System.out.println("c2 ="+c2.toString(16));
         //(bia[0].modPow(a, p).modInverse(p)).multiply(bia[1]).mod(p);
         BigInteger val1 = (c1.modPow(x,p).modInverse(p)).multiply(c2).mod(p);
         BigInteger val2 = id.modPow(t1,p);
         System.out.println(val1.toString(16));
         System.out.println(val2.toString(16));
    send s=new send();
    // }catch( IOException e){
    //System.out.println("Exception caught ") ; }     
    //     catch( Exception e){
    //System.out.println("Exception caught ") ; }               
         void button2_ActionPerformed(java.awt.event.ActionEvent event)
              textField1.setText("");
              textField2.setText("");
         void button3_ActionPerformed(java.awt.event.ActionEvent event)
         {   Security s1 = null;
              try
    System.out.println("this is in Smart ");
         //Create a new instance of our application's frame, and make it visible.
              s1 = new Security();
              s1.setVisible(true);
              catch (Throwable t)
                   System.err.println(t);
                   t.printStackTrace();
                   //Ensure the application exits with an error condition.
                   System.exit(1);
              //s1.dispose();     

    I was picking that up from your error message
    ..jsp_servlet\__savename.java:17: package com.company.project.ejb does not exist import com.company.project.ejb.UserData; //[ /SaveName.jsp; Line: 1]
    The folder structure needs to mirror the package structure exactly (standard java)
    So yes, If you have a com.company.project.ejb package with a class UserData within it
    "UserData.class" needs to be in folder "WEB-INF/classes/com/project/ejb/"
    If you don't have that class, then check your import statement - its asking for it.
    Good luck,
    evnafets

  • Looking for an algorithm

    I'm trying to make an algorithm that writes the following:
    1   0
    2   1
    3   2
    4   3
    5   3
    6   4
    7   5
    8   6
    9   6
    10   7
    11   8
    12   9
    13   9
    14  10
    15  11
    16  12
    17  12
    18  13
    19  14
    20  15The numer to the left is just a counter. The number to the right is a variable that counts upwards
    based on the counter.
    Anyone got any nifty ideas? And, before anyone hints at it: I have tried, but I'm not very good at this kind of thing :-)

    Sure. I forgot to post what I really wanted to to, because I first posted the question in another forum.
    Well. It's supposed to be an algorithm that makes these columns, simple because I want it rather than just typing in a lot of variables. The left column is a counter, which represents the level. The right one is the BAB, which is supposed to be as the column I posted first, based on the level.
                        for(int i=0 ; i<=level-1 ; i++) {
                             bab = i ;
                             if ((i+1)%4 == 1)
                             bab = i-1 ;
                             System.out.println((i+1) +" " +bab) ;               
                        }This gives this output;
    1     -1
    2     1
    3     2
    4     3
    5     3
    6     5
    7     6
    8     7
    9     7
    10   9
    11   10
    12   11
    13   11
    14   13
    15   14
    16   15
    17   15
    18   17
    19   18
    20   19The pattern for the second column is supposed to be this:
    when the counter reaches a number which is devidable with 4 (4,8,12 and 16), the next counter number
    is supposed to be the same, ie. not increment. Then on the next counter thereafter it should continue counting.
    I've got some of it, as you can see, but the problem is that when it continues it increments 2 instead of 1. (counter 6 should be give 4, and not 5).

  • Links for calendar algorithms.?

    i am looking for algorithms that can answer questions such as: Xth day of a month M in year Y(third monday of january 2003 for ex).
    Any tips or links?
    Thanks.

    Sorry - I made a couple of blunders in my last example. Check this instead:
    import java.util.*;
    public class CalendarTest {
        public static void main(String[] a) {
            Calendar c= new GregorianCalendar();
            int d= Calendar.MONDAY;
            c.set(Calendar.YEAR, 2003);
            int x= 3; // 3 for 3rd occurence
            int m= Calendar.JANUARY;
            if(a.length > 0)
                c.set(Calendar.YEAR, Integer.parseInt(a[0]));
            if(a.length > 1)
                m= Integer.parseInt(a[1])-1;
            if(a.length > 2)
                x= Integer.parseInt(a[2]);
            c.set(Calendar.MONTH, m);
            c.set(Calendar.DAY_OF_WEEK, d);
            if(c.get(Calendar.MONTH) > m)
                c.add(Calendar.DAY_OF_YEAR, -(c.get(Calendar.DAY_OF_MONTH)+7)/7*7);
            int add= (x-(c.get(Calendar.DAY_OF_MONTH)+6)/7)*7;
            if(add != 0) {
                c.add(Calendar.DAY_OF_MONTH, add);
            System.out.println(c.getTime());
    }Compile the program, and enter parameters as:
    $java CalendarTest <year> <month> <week>
    or
    $java CalendarTest <year> <month>
    or
    $java CalendarTest <year>
    or simply
    $java CalendarTest
    Year defaults to 2003, month to January (1), and week to 3.
    Kind regards

  • Need help for game algorithms

    can anyone help me with algorithm for game like tic tac toe, but with board size 10x10 and you will win with 5 sign horizontal/vertikal/diagonal. i don't know what algorithms should i use. please help me.

    Well, there's one or two loops and arrays to study in here;-import java.awt.*;
    import java.awt.event.*;
    public class Fiver extends java.applet.Applet{
       static myPanel dPanel;
       Panel panel = new Panel();
       static Label lab;
       public static myPanel DPcreate() {
          dPanel.drawMap();
          return dPanel;
       public static Label status(String s) {
          lab.setText(s);
          return lab;
       public void init() {
          this.setLayout(new BorderLayout());
          dPanel = new myPanel();
          panel.setLayout(new BorderLayout());
          panel.setBackground(new Color(58,55,70));
          Panel panel2 = new Panel();
          panel2.setBackground(Color.gray);
          panel2.setLayout(new BorderLayout());
          Button neew = new Button("New");
          lab = new Label("Click button to start");
          lab.setForeground(Color.white);
          lab.setFont(new Font("Arial",Font.BOLD,14));
          neew.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent ae){
                Fiver.dPanel.started();
          this.add(panel);
          panel.add ("Center", DPcreate());
          panel.add ("South", panel2);
          panel2.add("West",neew);
          panel2.add("Center",lab);
    class myPanel extends Panel implements MouseListener{
       public Label lab;
       int board[][];
       int win[][];
       int cgrades[][];
       int pgrades[][];
       boolean ptable[][][];
       boolean ctable[][][];
       int cGrd, pGrd, pCt, cCt, ypos, xpos, m, n, count, mat, nat, mde, nde;
       boolean player, comp, start, over, pwin, cwin, tie, fin;
       public myPanel() {
          board = new int[10][10];
          ptable = new boolean[10][10][192];
          ctable = new boolean[10][10][192];
          cgrades = new int[10][10];
          pgrades = new int[10][10];
          win = new int[2][192];
          start = true;
          setSize(400, 400);
          addMouseListener(this);
             for(int i=0;i<10;i++) for(int j=0;j<10;j++) board[i][j]=2;
             for(int i=0;i<10;i++){
                for(int j=0;j<6;j++) {
                   for(int k=0;k<5;k++) {
                      ptable[j+k][count]=true;
    ctable[j+k][i][count]=true;
    count++;
    for(int i=0;i<10;i++) {
    for(int j=0;j<6;j++) {
    for(int k=0;k<5;k++) {
    ptable[i][j+k][count]=true;
    ctable[i][j+k][count]=true;
    count++;
    for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
    for(int k=0;k<5;k++){
    ptable[j+k][i+k][count]=true;
    ctable[j+k][i+k][count]=true;
    count++;
    for(int i=0;i<6;i++) {
    for(int j=9;j>3;j--){
    for(int k=0;k<5;k++){
    ptable[j-k][i+k][count]=true;
    ctable[j-k][i+k][count]=true;
    count++;
    comp=true;
    count=0;
    public void paint(Graphics g) {
    for(int i=0; i<10;i++){
    for(int j=0;j<10;j++){
    g.setColor(Color.green);
    if(board[i][j]==0) g.fillOval(i*40+5, j*40+5, 30, 30);
    g.setColor(Color.blue);
    if(board[i][j]==1) g.fillOval(i*40+5, j*40+5, 30, 30);
    g.setColor(Color.white);
    int temp=40;
    for(int i=0;i<12;i++){
    g.drawLine(i*temp,0,i*temp,400);
    g.drawLine(0,i*temp,400,i*temp);
    if(!comp) g.drawOval(m*40+5, n*40+5, 30, 30);
    public void drawMap() {repaint();}
    public void mousePressed (MouseEvent me){}
    public void mouseReleased(MouseEvent me){
    player = true;
    int xSquare = me.getX();
    int ySquare = me.getY();
    if(player){
    Player(xSquare, ySquare);
    Win();
    if(comp){
    Computer();
    Win();
    drawMap();
    public void mouseEntered(MouseEvent me){}
    public void mouseExited (MouseEvent me){}
    public void mouseClicked(MouseEvent me){}
    public void Player(int xSquare, int ySquare) {
    if((!over)&&(xSquare<400)&&(ySquare<400)) {
    m = xSquare / 40;
    n = ySquare / 40;
    if(board[m][n] ==2) {
    board[m][n] = 0;
    pCt++;
    if((cCt==50)&&(pCt == 50))tie=over=true;
    for(int i=0;i<192;i++) {
    if((ptable[m][n][i])&&(win[0][i]!=7)) {
    win[0][i]++;
    if(ctable[m][n][i]){
    ctable[m][n][i]=false;
    win[1][i]=7;
    player=false;
    comp=true;
    lab=Fiver.status("G A M E O N !");
    else {
    player = true;
    comp = false;
    lab = Fiver.status("That square is already occupied.");
    return;
    public void Computer() {
    if(!over){
    for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
    pgrades[i][j]=0;
    if(board[i][j]==2) {
    for(int k=0;k<192;k++) {
    if(ptable[i][j][k]) {
    switch(win[0][k]){
    case 1: // '\001'
    pgrades[i][j] += 5;
    break;
    case 2: // '\002'
    pgrades[i][j] += 50;
    break;
    case 3: // '\003'
    pgrades[i][j] += 100;
    break;
    case 4: // '\004'
    pgrades[i][j] += 400;
    break;
    for(int i=0;i<10;i++) {
    for(int j=0;j<10;j++){
    cgrades[i][j]=0;
    if(board[i][j]==2){
    for(int k=0;k<192;k++){
    if(ctable[i][j][k]){
    switch(win[1][k]) {
    case 1: // '\001'
    cgrades[i][j] += 5;
    break;
    case 2: // '\002'
    cgrades[i][j] += 50;
    break;
    case 3: // '\003'
    cgrades[i][j] += 100;
    break;
    case 4: // '\004'
    cgrades[i][j] += 400;
    break;
    if(start){
    if(board[4][4]==2) m=n=4;
    else m=n=5;
    start=false;
    else{
    for(int i=0;i<10;i++) {
    for(int j=0;j<10;j++){
    if(board[i][j]==2){
    if(cgrades[i][j]>= cGrd){
    cGrd=cgrades[i][j];
    mat=i;
    nat=j;
    if(pgrades[i][j]>=pGrd){
    pGrd=pgrades[i][j];
    mde=i;
    nde=j;
    if(cGrd>=pGrd){
    m=mat;
    n=nat;
    else{
    m=mde;
    n=nde;
    cGrd=pGrd=0;
    board[m][n]=1;
    cCt++;
    if((cCt==50)&&(pCt==50)) tie=over=true;
    for(int i=0;i<192;i++) {
    if((ctable[m][n][i])&&(win[1][i]!=7)) win[1][i]++;
    if(ptable[m][n][i]) {
    ptable[m][n][i] = false;
    win[0][i]=7;
    player = true;
    comp = false;
    public void Win() {
    for(int i=0;i<2;i++) {
    for(int j=0;j<192;j++){
    if(win[i][j]==5){
    if(i==0){
    pwin=over=fin=true;
    lab = Fiver.status("Congratulations, You win!");
    else{
    cwin=over=fin=true;
    lab = Fiver.status("Sorry, game over you lost");
    break;
    if(!over) continue;
    tie=over=true;
    if(!fin)lab = Fiver.status("The game is a draw. Try again.");
    break;
    public void Initial() {
    for(int i=0;i<10;i++){
    for(int j=0;j<10;j++) {
    pgrades[i][j]=cgrades[i][j]=0;
    board[i][j]=2;
    for(int i=0;i<10;i++){
    for(int j=0;j<6;j++){
    for(int k=0;k<5;k++){
    ptable[j+k][i][count]=true;
    ctable[j+k][i][count]=true;
    count++;
    for(int i=0;i<10;i++){
    for(int j=0;j<6;j++){
    for(int k=0;k<5;k++){
    ptable[i][j+k][count]=true;
    ctable[i][j+k][count]=true;
    count++;
    for(int i=0;i<6;i++){
    for(int j=0;j<6;j++){
    for(int k=0;k<5;k++){
    ptable[j+k][i+k][count]=true;
    ctable[j+k][i+k][count]=true;
    count++;
    for(int i=0;i<6;i++){
    for(int j=9;j>3;j--){
    for(int k=0;k<5;k++){
    ptable[j-k][i+k][count]=true;
    ctable[j-k][i+k][count]=true;
    count++;
    for(int i=0;i<=1;i++) for(int j=0; j<192;j++)win[i][j]=0;
    count=cCt=pCt=0;
    over=pwin=cwin=tie=false;
    comp=start=true;
    public void started(){
    Initial();
    lab = Fiver.status("Click on any square:");
    drawMap();

  • Hi how to find runtime for sorting algorithms

    I am new to java.......please help me out by taking a sorting algorithm and find the run time of it ......
    Thanks in Advance

    If by "runtime" you just mean the amount of time it takes to execute across some set of input...then you can use java.lang.System.currentTimeMillis() to get the current time in milliseconds since Jan 1 1970. Do that both before and after you run the code that implements the algorithm, and subtract to get the difference as running time in milliseconds. Or, if this weren't part of a homework assignment, you could just use a profiler.
    If by "runtime" you mean the execution environment, then you want to use java.lang.Runtime.getRuntime(). This has nothing to do with algorithms.
    If you mean that you want to analyze the efficiency of the algorithm (eg it's "big-O" notation), then read a textbook on algorithms. This has nothing to do with Java, apart from that Java is just one computer language out of many in which algorithms can be implemented.

  • Looking for a algorithm called push down atonima??

    I am trying to get an example of a search algorithm called a
    push down atomina
    I think that is the name but not sure.
    thanks,
    steve

    Think you'll be lucky to find anything in the forum on push down automata. Do a search on google, perhaps with the keyword "parser" or "grammer checker" thrown in. There may well be whole books devoted to it!

  • Hiding Sensitive Association Rule for Sanitization algorithm implementation

    Hello Sir,
    I am doing my research in the area of Data Mining and my problem is hiding industrial information using Hiding Sensitive Association Rule. If anybody having Sanitization process and algorithm implementation using Java.
    If anybody having relate materials, algorithms implementation, documentation and related web address. Please send to my mail id: [email protected]
    Regard
    Kannan
    Message was edited by:
    user591845

    And your version of Oracle is?
    If 10g look into using Transparent Data Encryption (TDE). You can find docs on it at http://tahiti.oracle.com.

  • Name problem for an algorithm

    Hi all.
    A friend of mine had a problem where he had to go through an array containing integers and basically count how many of the numbers that were between 0 and 9, 10 and 19, 20 and 29, etc.
    My question is, just out of plain curiosity, does this type of problem have a general name, like sorting and searching does?
    //Patrik

    It's called arithmetic progression:
    http://en.wikipedia.org/wiki/Arithmetic_series
    What about matfud's answer?

  • General algorithm for cartesian product

    i am looking for an algorithm to get the cartesian product from a set of sets like {{1,2,3,4},{a,b,c},{x,y,z,7,15}...} - this means in most general form.
    google yields no results :-(. i think implementing it by myself is not a good idea.

    dermoritz wrote:
    prometheuzz is your algorithm better than n*mi n: number of sets mi: cardinality of the set i ?
    can you short explain the algorithm?You can't do any better than that because for n sets: S(0), S(1), S(2) ... S(n-1) there are prod(i in [0, n), |S(i)|) elements of the caresian product. Prometeuzz algorithm generates
    one at ever pass of the loop executing n steps per element. If you're afraid that the product number will be too large you can also fiddle with the indexes themselves:
    // scard[i] == |S(i)|
    // prod[i] == element of S(i) in product
    int[] next(int[] scard, int[] prod) {
       for (int i= prod.lerngth; i-- > 0; prod= 0)
    if (++prod[i] < scard[i]) return prod; // return indexes of next product
    return null; // no next product anymore
    }kind regards,
    Jos                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Maybe you are looking for

  • PrintToPrinter, ExportToDisk Problem

    Hello, I am using Crystal Reports 2008 inside VS2005 and I wanna get the report in PDF format. The first thing i tried was exporting the report using the ExportToDisk function. It works ok, but the fonts of the PDF generated werent the same as the fo

  • Authorization to generate a report

    Dear all, In our environment, different Zenworks administrators have their permission to manage devices on the folder in device zone. How can I setup an authorization right for them to generate the limited report?? (only the device in the specify fol

  • Volume won't mount - xsanctl returns error 5

    Dear List, One of our Volumes has failed to remount following scheduled software updates and cvfsck disk utility run. PromiseGroups, the problem volume starts, shows up in cvadmin and the GUI but won't mount either through the GUI or CLI. Recent filt

  • Safari will not go to nexxt page on Ebay and gives me this message ..

    .....Safari can't open the page "http://my.ebay.co.uk/". The error was: "cannot decode raw data" (NSURLErrorDomain:-1015) Please choose Report Bugs to Apple from the Safari menu, note the error number, and describe what you did before you saw this me

  • Unable to update brand new ipod 8 gb 4g or sync songs

    Today i brought a brand new 8gb 4gen ipod touch. when i got home and connected it to my pc i downloaded the update that it said. after the download had completed there was a notification that the network connection was lost eventhough it was connecte