Some more questions . .

L

Luc The Perverse

I have a bit of a dilema (sp?) that I can't figure out. I just finished Day
13 in Learn Java in 21 days, and I know I am never going to learn any of
this stuff if I don't get my feet wet a little with a projec that I make.

Here is my layout:
class StandardMaze inherits abstract class Discrete2DMaze with a function
for drawing the maze and enabling pacman style loop around.

Then I have JMPanel extends JPanel which draws the maze
(JMPanel contains a Discrete2DMaze object passed in from elsewhere)

class Walkable2DMaze extends JMPanel implements Runnable

This is designed to let someone, or an AI go through the maze in an
interactive animated manner. But I would also like to have a mode in which
there is no display and I could run thousands of tests on various AI's. So
I will need to attach a class with a link to the maze for going through the
maze.

I don't know yet how to capture the keystrokes, but I think I can figure
that out on my own.

Here are my questions:

1. What is the proper way to "attach" an AI? I'm envisioning something
like

abstract class AI{
abstract Command WhatToDoNext(Surroundings WhatYouSee);
}

I haven't decided what goes in the Command or Surroundings classes yet
though. Setting it up like this will make latency from animation a virtual
non issue.

(As a matter of semantics, can you think of a better classname than AI,
since theoretically I could set up a text based maze game, and it would be
up to a person what to do next.)

2. How do I get "Command"s into the queue in a safe manner? Even though
the AI will not queue commands in the above format, I would like the key
listener to be able to queue commands while an animation is running.

A thread safe object queue class with two functions AddToTail and GetHead
would be great :) (You know . . when I put it like that, I am starting to
think it probably already exists.)
 
T

Thomas G. Marshall

L

Luc The Perverse

Thomas G. Marshall said:
Luc The Perverse coughed up:
I have a bit of a dilema (sp?) that I can't figure out. I just finished
Day
13 in Learn Java in 21 days,

First of all, at least in the beginning, that was a horrible book.
Perhaps she fixed it, but I'll leave that opinion to others. Please
consider "Just Java 2" by Peter VanDerLinden. SPECTACULAR beginner book.

http://www.amazon.com/exec/obidos/t...002-5965693-3942418?v=glance&s=books&n=507846


...[rip]...


I have no doubt that this is a shitty book . . but . . . it is the book
that I have. I owe too much in late fees at the library, and I can hardly
afford a dollar burger at McDonalds :(

If someone wants to charitably mail me that book - I'm open to it. But
otherwise, I will have to stick with what I got.
 
Z

zero

I have a bit of a dilema (sp?) that I can't figure out. I just
finished Day 13 in Learn Java in 21 days, and I know I am never going
to learn any of this stuff if I don't get my feet wet a little with a
projec that I make.

Here is my layout:
class StandardMaze inherits abstract class Discrete2DMaze with a
function for drawing the maze and enabling pacman style loop around.

Then I have JMPanel extends JPanel which draws the maze
(JMPanel contains a Discrete2DMaze object passed in from elsewhere)

class Walkable2DMaze extends JMPanel implements Runnable

This is designed to let someone, or an AI go through the maze in an
interactive animated manner. But I would also like to have a mode in
which there is no display and I could run thousands of tests on
various AI's. So I will need to attach a class with a link to the
maze for going through the maze.

I don't know yet how to capture the keystrokes, but I think I can
figure that out on my own.

Here are my questions:

1. What is the proper way to "attach" an AI? I'm envisioning
something like

abstract class AI{
abstract Command WhatToDoNext(Surroundings WhatYouSee);
}

I haven't decided what goes in the Command or Surroundings classes yet
though. Setting it up like this will make latency from animation a
virtual non issue.

(As a matter of semantics, can you think of a better classname than
AI, since theoretically I could set up a text based maze game, and it
would be up to a person what to do next.)

2. How do I get "Command"s into the queue in a safe manner? Even
though the AI will not queue commands in the above format, I would
like the key listener to be able to queue commands while an animation
is running.

A thread safe object queue class with two functions AddToTail and
GetHead would be great :) (You know . . when I put it like that, I
am starting to think it probably already exists.)


I'm not sure I understand exactly what you want, but I'll try to give
some suggestions.

For question 2: java 1.5 has ConcurrentLinkedQueue, which I think is what
you asked for: a thread-safe queue with linked nodes as underlying data
structure. You could also look at the other classes that implement the
Queue interface, for a list look at
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Queue.html
To get thread-safe versions of common collections you should check out
Collections.synchronizedCollection and similar functions.

As for the proper way to attach an AI: in computer programming there
usually is no proper way to do anything. If you find a way that works
for you, that is the correct way. Other programmers may find other ways,
and the discussion of what is the best way is not an easy one. It all
depends on the situation.

I also suggest you read up on the model-view-controller design pattern.
Your maze would be the model, and the JPanel that draws it is the gui.
Then you put a controller between them which relays messages between
them, effectively separating the two. That way you can develop the model
independently from the gui. Then when you want to run it without gui,
you just write a simple class that talks to the controller and, instead
of drawing the maze, simply gives some console output.

As for capturing keystrokes: use a KeyListener.
http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyListener.html
 
Z

zero

I have no doubt that this is a shitty book . . but . . . it is the
book that I have. I owe too much in late fees at the library, and I
can hardly afford a dollar burger at McDonalds :(

If someone wants to charitably mail me that book - I'm open to it.
But otherwise, I will have to stick with what I got.

java tutorials: http://java.sun.com/docs/books/tutorial/
 
T

Thomas G. Marshall

zero coughed up:
....[rip]...
1. What is the proper way to "attach" an AI? I'm envisioning
something like
....[rip]...

As for the proper way to attach an AI: in computer programming there
usually is no proper way to do anything. If you find a way that works
for you, that is the correct way. Other programmers may find other ways,
and the discussion of what is the best way is not an easy one. It all
depends on the situation.

I had to change fonts views to see that the AI was ay eye and not ay ell.
The latter would have been Artificial Life, which is what it seems he's
doing anyway.

Regarding what you said about there are usually no proper ways to do
anything. That may be a tad surly, but not far from the mark if you were to
restate it as the related "In computer science, much of what you know you
learn by seeing how /not/ to do something".


....[rip]...
 
L

Luc The Perverse

Thomas G. Marshall said:
zero coughed up:
...[rip]...
1. What is the proper way to "attach" an AI? I'm envisioning
something like
...[rip]...

As for the proper way to attach an AI: in computer programming there
usually is no proper way to do anything. If you find a way that works
for you, that is the correct way. Other programmers may find other ways,
and the discussion of what is the best way is not an easy one. It all
depends on the situation.

I had to change fonts views to see that the AI was ay eye and not ay ell.
The latter would have been Artificial Life, which is what it seems he's
doing anyway.

Regarding what you said about there are usually no proper ways to do
anything. That may be a tad surly, but not far from the mark if you were
to restate it as the related "In computer science, much of what you know
you learn by seeing how /not/ to do something".


...[rip]...

A list of the four most common ways it is done wrong would suffice.

I suppose what I needed was a single right way to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top