Mike Smike

Ranch Hand
+ Follow
since Aug 25, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike Smike

Hi guys,

I'm working on an implementation of a minimax algorithm. However, there are two different versions of the algorithm that I need to run. They are almost identical in code, except that one algorithm calls all of its methods from an "Interface" class, and the other calls all of its methods from an "Area" class. The method names are the same, as are the parameters passed.

My problem is this. Instead of writing out the entire algorithm twice with different method calls each time, is there a way I can put an object in the place of the class names? And cast this object to the correct class each time I call the algorithm??

For example, I tried the following :



However the compile could not call anything from 'obj'.

So instead I've had to explicity make the distinction at each instance of calling the method. This has made my code look rather messy!



Is there an alternative? A way to place an object at every method call that can be successfully assigned to different classes depending on a parameter passed in the call?

If there isn't, please let me know

As ever, thanks a million for all your help

Mike
18 years ago
Wow - guys, thank you SO MUCH! Espiecailly James and Horatio - your solutions both worked tremendously! This site never ceases to impress me more and more every time I visit. I wish I could reward you with lots of cattle!

I finally have a properly implemented minimax search for my AI player! I now must somehow reduce the complexity, as a board of just 3 by 3 manages to generate 96 possible moves on the first turn alone! The exponential increase in complexity is such that when I run a 4 by 4 board, it crashes!

Thanks guys for getting me past a sticky point. My disertation says a big thankyou too Pints all round



Mike
19 years ago
Hi guys, thanks for the responses

To clarify things, I am not trying to generate every combination of elements in each list. Instead I am trying to generate every combination of elements from all lists, but with only one element from each list appearing in each configuration.

Does that help? I'm sorry it's not too clear... I think Horatio's post seems to have a good point. I'll have a bash at coding it tomorrow and post what I manage to achieve. It's 12:30 pm for me now, so I'm off to bed

Thanks for all the advice guys, I'll let you know how it goes.

Mike

ps - it's not really a homework problem, but part of the program I am writing for my disertation. The objects in the ArrayList are moves, and each ArrayList represents a unit. I need all possible combinations to use in my minimax agent.
19 years ago
I think you've misunderstood the question. I know very well how to iterate through a loop, both with iterators and with for loops. But that is not my problem. I need to combine all the elements within the ArrayLists in every possible combination... This is not a very simple task...
19 years ago
Yeah, but how do recursively iterate through loops, combining all combinations of the elements... I'm sure there is a way, I'm just having real issues trying to hammer it out as code...
19 years ago
Hi guys!

Just a quick problem I have here. Basically I have an ArrayList of ArrayLists of some object. So it would look something like this:

[ [1,2,3], [4], [5,6,7,8,9], [10,11] ]

Now I want to get every possible combination of elements, selecting at least one from each arraylist. So I'd need:

[1,4,5,10], [1,4,5,11], [1,4,6,10], [1,4,6,11].... [3,4,9,11]

But my problem is that I could have any number of ArrayLists in the ArrayList, containing any number of elements, so a simple combination of for loops won't work. I was hoping there might be a method in the API which multiplies out every possible combination of elements in an ArrayList, but there doesn't appear to be.

I wonder if I'm just being a bit dim, but it's been giving me a headache for days. Does anyone have any ideas? Or am I heading down a bit of a dead end

Thanks for your time and help

Mike
[ March 03, 2005: Message edited by: Mike Smike ]
19 years ago
Thankyou muchos amigos! Very much appreciated. I will have a look at these JEditorPane and JTextPane things.

Mike
19 years ago
Thanks for the advice guys! I found that the problem was the Canvas3D object - I had re-initialised it at some point, so it was infact empty when I added it to the universe.

Anyway, I managed to get the work done on time

Thanks for the help

Mike
19 years ago
Hi guys,

I've searched the forums and the API, but I can't find what I'm looking for!

I have say, a JTextArea, in which there are some strings. My problem is that I want the strings to be different colours. The only method I can find it the setForeGround(Color c) for the JTextArea, but this is no good as it colours all the text the same!

Surely there is a way to colour individual letters/words/strings differently??

If there isn't - please let me know. I found a post from 2001 asking something similar but with no answers! eek

Please help

Thanks for your time

Mike
[ February 17, 2005: Message edited by: Mike Smike ]
19 years ago
Hi guys, I'm having a bit of a nightmare and hope someone can help. My problem is pretty simple. I'm trying to enable picking on two objects I have created. However, when I run the program and click onto one of them I get the following error in the terminal:



Why is this happening? I'm going crazy trying to work it out? Other programs that use picking do work on my computer so I know that's not the issue.

This is my Picking Code:



If it helps I can supply my main method too? The picking is supposed to happen on two buttons which I have created using the following code:





EEEK! Please help soon - I have to have this done by Friday

Thanks oh wonderous java people

Mike

[ January 19, 2005: Message edited by: Mike Smike ]

EDIT: Lasse edited thread subject
[ January 28, 2005: Message edited by: Lasse Koskela ]
19 years ago
Yeah that makes loads of sense!! Thanks for spelling it out so clearly for me. I still seem to have fundamental misunderstandings with Java :roll:

I'll give it a go now.

Thanks again for speedy response and great advice



Mike
19 years ago
Yes I do have 1 Cavalry object that is referenced from each square. I create them using the following method for example


That initialises them onto the board. The FightingUnit constructor is as follows :

So if the strength variable is static, how can I change it for just one unit?

Thanks for all your help guys!
19 years ago
Hmmm not quite. The board is a single ArrayList and each item in the list contains an ArrayList of Fighting Units, which can be any number of either Cavalry or Infantry. The strenght for each square is calculated by iterating through the Fighting Unit arraylist, and adding up the strengths. Therefore, the strength of a wounded cavalry unit needs to be set lower than a health cavalry unit.

A calvary unit is constructed like this


I need to somehow change the strength for individual units...

Any ideas??
19 years ago
Hi buddies!

Right, I have a problem. I've made a game with 100 squares, and in each square are units. There can be any number of Cavalry and Infantry. I have an abstract class 'FightingUnit' from which Cavalry and Infactry extend. Infantry have a max strength of 1, whereas Cavalry can have 2.

The problem is this! When there is just one cavalry unit left on a square, the total strength is 2. But if that unit loses just 1 strength, he should be left with 1. The unit does infact lose 1 strength but so does every other cavalry unit on the board belonging to that player!!! Below is my code:


The problem is the line I think! It calls the method setStrength which is declared in the FightingUnit class. But it calls it for every Cavalry unit on the entire board, not just the one losing strength

How can I do it so that just the strength value of that one unit changes and not the entire army. The strength must be set correctly as the method used in the interface to display strenght relies on this.

Hope someone can help

Thanks guys

Mike
19 years ago
Thank you muchos mister!! You've made my day



Mike
19 years ago