|
-
Jul 9th, 2008, 05:17 AM
#1
Thread Starter
Frenzied Member
very complex object casting problem, experts needed.
my problem is quite complex, i will try my best to explain it to you guys.
I'm working on an competition system that should work for any kind of game. I'm just testing this system with 'noughts and crosses' as the game. Basically, students submit their computer players and my system accepts and compiles their code, and loads instances of it onto an applet
So for e.g, the student would implement a makeMove() method (compulsory methods are in ComputerPlayerInterface.java which each submission must implement)
my problem is this: for noughts and crosses i would probably use 2d array to represent the board data, so in ComputerPlayerInterface.java i would have this method signature meaning that all submitted computer players must also have this method:
int[][] makeMove(int[][] boardData);
but i need this to be generic for any kind of game, not just for noughts and crosses. i've been told by others to have something like:
GameAnswer makeMove(GameData gameData);
but i'm not sure about how i go about doing it. the gamedata could be of any type, depending on the kind of game the competition is for.
-
Jul 9th, 2008, 05:38 AM
#2
Re: very complex object casting problem, experts needed.
User Generics.. Look it up
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 9th, 2008, 07:13 AM
#3
Thread Starter
Frenzied Member
Re: very complex object casting problem, experts needed.
but i can only have 1 ComputerPlayerInterface.java for every kind of game
with generics, doesnt this mean ill have to change the type for every game.. which is not what i want to do
-
Jul 10th, 2008, 12:03 PM
#4
Hyperactive Member
Re: very complex object casting problem, experts needed.
generic classes looks to the perfect solution to the problem you have described...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|