DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Creating a Fitness Function, need help ASAP!

1. Registered User
Join Date
Oct 2005
Posts
10

## Creating a Fitness Function, need help ASAP!

Suppose you have an altered chess board:

0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0

where the 1's are spaces where nothing can be placed.

Now suppose you have four tetris shapes, where each shape contains only four 'units'

I need to create a fitness function where all four of the shapes are continuously and randomly added onto the board until no additional shapes can fit. The fitness function should return the # of spaces filled divided by the total number of spaces.

(Without using a GUI).

I was told to do this in such a way where each shape has the function:

f (shape, x coord., y coord., orientation) x 10 (So each shape has 4 ints)

Then, I was told to, using a 1-Dimensional Array of size 40 ints, add the shapes into the array for ten different iterations. For each iteration, the x and y coordinates as well as the orientation of each shape should be random.

After each iteration, the number of spaces filled should be printed.

I have the idea down, but have NO idea how to code this. Remember, it should return the # of spaces filled over the total number of spaces. Please help me! I have no idea how to represent the shapes, their coordinates, and their orientations. Thanks!
Last edited by behrk2; 10-25-2005 at 10:05 PM.

2. Registered User
Join Date
Jul 2005
Location
SW MO, USA
Posts
299
Java is probably the wrong language to do this in.

3. Registered User
Join Date
Oct 2005
Posts
10
unfortunately, it has to be java

4. Registered User
Join Date
Jul 2005
Location
SW MO, USA
Posts
299
Looks too hard for me. Isn't there some professor that has written a paper on how to do it that you could use to get the algorithm from?
Given the algorithm, you could start writing the program and come back here with specific programming questions when you have problems.

5. Registered User
Join Date
Oct 2005
Posts
10
I'm afraid not, this is my own original idea (well, it's original as far as I know)...My professor approved it, however. My biggest problem is representing the shapes numbers and adding them to lets say a board represented by a 2D Array.

6. Registered User
Join Date
Jul 2005
Location
SW MO, USA
Posts
299
What is your design for painting shapes on a board? You'll have to define what a "shapes number" is.

7. Registered User
Join Date
Jul 2005
Location
SW MO, USA
Posts
299
What is the name of the course you're taking? How much programming have you done? Why did you choose Java?

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise