Results 1 to 4 of 4

Thread: very complex object casting problem, experts needed.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    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

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    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

  4. #4
    Hyperactive Member pgag45's Avatar
    Join Date
    Mar 2007
    Location
    Colorado
    Posts
    262

    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
  •  



Click Here to Expand Forum to Full Width