package capital;
import java.io.*;
import java.lang.*;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class pushing extends JPanel{
private final int WIDTH=1000,HEIGHT=800;
public pushing() {
setSize(WIDTH,HEIGHT);
}
public void paintComponent(Graphics g){
Dimension size=this.getSize();
super.paintComponent(g);
g.setColor(Color.white);
g.fillRect(0,0,size.width,size.height);
g.translate(30,740);
g.setColor(Color.BLACK);
g.drawRect(0,-700, 950,700); // a rectangular area: 950*700
// System.out.print("painting screen again \n");
}
public void clearCanvas(){
Graphics g=this.getGraphics();
Dimension size=this.getSize();
g.setColor(Color.white);
g.fillRect(0,0,size.width,size.height);
g.translate(30,740);
g.setColor(Color.white);
g.fillRect(0,-700, 950,700);
g.setColor(Color.black);
g.drawRect(0,-700, 950,700);
}
public static void main(String[] args) {
//create the frame
JFrame f=new JFrame("Capital with some New");
//create the panel
pushing mainPanel=new pushing();
//add panel into the frame
f.getContentPane().add(mainPanel);
//set the frame parameters
f.setSize(mainPanel.getSize().width,mainPanel.getSize().height);
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
// create Env
env myEnv=new env(950,700);
// create Goal
point p1=new point(700,550);
goal theGoal=new goal(p1);
//create obstacles
point p=new point(0,0);
p.x=300;
p.y=500;
obstacle obst1=new obstacle(p,10);
p.x=600;
p.y=300;
obstacle obst2=new obstacle(p,15);
p.x=500;
p.y=400;
obstacle obst3=new obstacle(p,20);
p.x=500;
p.y=500;
obstacle obst4=new obstacle(p,25);
p.x=300;
p.y=300;
obstacle obst5=new obstacle(p,10);
p.x=600;
p.y=200;
obstacle obst6=new obstacle(p,20);
p.x=400;
p.y=600;
obstacle obst7=new obstacle(p,10);
p.x=800;
p.y=350;
obstacle obst8=new obstacle(p,15);
p.x=260;
p.y=195;
obstacle obst9=new obstacle(p,10);
p.x=260;
p.y=115;
obstacle obst10=new obstacle(p,10);
p.x=130;
p.y=220;
obstacle obst11=new obstacle(p,15);
Vector obstacleGroup=new Vector();
obstacleGroup.add(obst1);
obstacleGroup.add(obst2);
obstacleGroup.add(obst3);
obstacleGroup.add(obst4);
obstacleGroup.add(obst5);
obstacleGroup.add(obst6);
obstacleGroup.add(obst7);
obstacleGroup.add(obst8);
obstacleGroup.add(obst9);
obstacleGroup.add(obst10);
obstacleGroup.add(obst11);
// create the robot Vector
Vector robotGroup=new Vector();
//create the Box
p.x=50;
p.y=70;
box theBox=new box(myEnv, theGoal, obstacleGroup, p, robotGroup);
//create the Cvbots
cvbot cvbot1=new cvbot(theBox, 30, 0);
cvbot cvbot2=new cvbot(theBox,30, 1);
cvbot cvbot3=new cvbot(theBox,30, 2);
cvbotGroup.add(cvbot1);
cvbotGroup.add(cvbot2);
cvbotGroup.add(cvbot3);
//create the Painter
painter thePainter=new painter(mainPanel,theGoal,theBox, obstacleGroup, cvbotGroup,myEnv);
//start the box
theBox.start();
//start the painter
thePainter.start();
// cvbot1.readQtable("e:\\t1.txt");
// cvbot2.readQtable("e:\\t2.txt");
// cvbot3.readQtable("e:\\t3.txt");
int i=1;
while(true){
System.out.print("The #"+ i+ " pushing started \n");
if(i==1){
//Start the cvbots
cvbot1.start();
cvbot2.start();
cvbot3.start();
}
boolean t1,t2,t3;
do { // wait until cvbots finish a pushing
t1=cvbot1.isPushing();
t2=cvbot2.isPushing();
t3=cvbot3.isPushing();
} while (t1 || t2 || t3);
// System.out.print("\n The #"+ i+ " pushing is finished \n");
/* //change the goal location randomly
theGoal.position.x=randomNum(50,900);
theGoal.position.y=randomNum(50,650);
//change the obstacle positions randomly
theBox.moveObstacle();
//initiate the box to a random position
if(i<100000){ //training stage
boolean isSuccess;
do{
p.x=randomNum(50,900); // select box pose randomly
p.y=randomNum(50,650);
double angle=randomNum(0,360);
isSuccess=theBox.setBoxpose(p, angle);
}while(isSuccess==false);
}
else{ // physical stage
p.x=50;
p.y=50;
theBox.setBoxpose(p, 0);
}
*/
//reset the box pose
p.x=50;
p.y=70;
theBox.setBoxpose(p, 45);
//reset the action selection constant of the robots
cvbot1.tao=0.9;
cvbot2.tao=0.9;
cvbot3.tao=0.9;
i=i+1;
if(i<=500){ //TOAL ROUND NUMBER
cvbot1.awakeMe();
cvbot2.awakeMe();
cvbot3.awakeMe();
mainPanel.clearCanvas();
}
else
break;
}
// cvbot1.recordQtable("e:\\t1.txt");
// cvbot2.recordQtable("e:\\t2.txt");
// cvbot3.recordQtable("e:\\t3.txt");
System.out.print("pushing is finished !!! \n");
int tt;
while(true)
tt=1;
// System.exit(0);
}
public static double randomNum(double a1, double a2){ //return a random value between a1 and a2
return (Math.random()*(a2-a1)+a1);
}
}
need to convert JAVA code to C++ codeI tried to convert following code to C++. but fail. pl. help me.
Page 1 of 1
1 Replies - 1251 Views - Last Post: 23 December 2008 - 10:01 PM
Replies To: need to convert JAVA code to C++ code
#2
Re: need to convert JAVA code to C++ code
Posted 23 December 2008 - 10:01 PM
This can't be done easily unless you already know a graphics library you want to use. C++ doesn't have one built in.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|