
Hat tip to PhDComics.
package com.referata.soccer;
import org.jsoar.kernel.Agent;
import org.jsoar.kernel.RunType;
import org.jsoar.kernel.events.InputCycleEvent;
import org.jsoar.kernel.io.InputBuilder;
import org.jsoar.tcl.SoarTclInterface;
import org.jsoar.util.events.SoarEvent;
import org.jsoar.util.events.SoarEventListener;
public class SoccerSoarTest implements SoarEventListener {
private Agent agent;
public SoccerSoarTest() throws Exception {
agent = new Agent();
SoarTclInterface ifc = new SoarTclInterface(agent);
agent.initialize();
agent.getEventManager().addListener(
InputCycleEvent.class, this);
ifc.sourceFile("/res/soccer.soar");
agent.runFor(3, RunType.DECISIONS);
}
/**
* @param args
*/
public static void main(String[] args) throws Exception {
new SoccerSoarTest();
}
@Override
public void onEvent(SoarEvent arg0) {
InputBuilder builder = InputBuilder.create(agent.io);
builder.push("ball").markId("b1").
add("controlledBy", "me");
}
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.Timer;
/**
* A very simple panel that demonstrates
* how to create a Swing component that updates
* and repaints itself with a Timer.
*
* @author Keith Knudsen
*/
public class JSimpleAnimationComponent extends JComponent
implements ActionListener {
/**
* @param args
*/
public static void main(String[] args) {
JFrame frame = new JFrame("AnimationPanel");
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(
new JSimpleAnimationComponent(),
BorderLayout.CENTER);
frame.setSize(200,200);
frame.setVisible(true);
}
public JSimpleAnimationComponent () {
Timer timer = new Timer(50, this);
timer.start();
}
/* position of our little moving square */
double squareX1 = 10;
double squareY1 = 10;
/* ... and our fixed square that we point to */
double squareX2 = 100;
double squareY2 = 50;
/**
* Called by the timer. Update the position of
* our little moving square and then call repaint.
*/
public void actionPerformed(ActionEvent e) {
squareX1++;
// keep the little square from running off the edge
if(squareX1 > this.getWidth()) {
squareX1 = 10;
}
repaint();
}
/*
* Paint the background and the little square
* at it's current position.
*/
public void paintComponent ( Graphics g )
{
// clean up the background from the previous draw
super.paintComponent(g);
// need this for rotate function
Graphics2D g2 = (Graphics2D) g;
// draw fixed square
g2.setColor(Color.BLUE);
g2.drawRect((int)squareX2, (int)squareY2, 10, 10);
// draw sprite
g2.translate(squareX1, squareY1);
g2.setColor(Color.RED);
// rotate square1 to point at square2
double radians = Math.atan2(
squareY2-squareY1, squareX2-squareX1);
g2.rotate(radians);
g2.drawRect(0, 0, 10, 10);
}
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.Timer;
/**
* A very simple panel that demonstrates
* how to create a Swing component that updates
* and repaints itself with a Timer.
*
* @author Keith Knudsen
*/
public class JSimpleAnimationComponent extends JComponent
implements ActionListener {
/**
* @param args
*/
public static void main(String[] args) {
JFrame frame = new JFrame("AnimationPanel");
frame.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(
new JSimpleAnimationComponent(),
BorderLayout.CENTER);
frame.setSize(200,200);
frame.setVisible(true);
}
public JSimpleAnimationComponent () {
Timer timer = new Timer(50, this);
timer.start();
}
/* position of our little moving square */
int x = 10;
int y = 10;
/**
* Called by the timer. Update the position of
* our little moving square and then call repaint.
*/
public void actionPerformed(ActionEvent e) {
x++;
// keep the little square from running off the edge
if(x > this.getWidth()) {
x = 10;
}
repaint();
}
/*
* Paint the background and the little square
* at it's current position.
*/
public void paintComponent ( Graphics g )
{
// clean up the background from the previous draw
super.paintComponent(g);
// draw sprite
g.setColor(Color.RED);
g.drawRect(x, y, 10, 10);
}
}