Author Topic: What are you working on? :D  (Read 36422 times)

0 Members and 1 Guest are viewing this topic.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #525 on: September 30, 2011, 10:00:20 PM »
Is that polymorphism?

So in one post you guys tell me it's Overloading Methods, and now it's classes using another class object?

Atleast what i've learnt from this point, is that Overloading Methods, like this:

Code: [Select]
public class something{

public int squareroot(double a)
{
return Math.round(Math.round(Math.Sqrt(a)));
}

public float squareroot(double a)
{
return Math.round(Math.Sqrt(a));
}

public double squareroot(double a)
{
return Math.Sqrt(a);
}

}

And Object-Orienting:

Code: [Select]

public class lol {

private Something s;

public static void main(String[] args){

s = new Something();

}

}

public class Something{

private x;
private static numThings;

public Something(){

x = 1;
numThings++;

}

}

Both are in Java...

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #526 on: October 01, 2011, 01:19:22 AM »
Yep, that looks right...

Like in the Wikipedia article you quoted, you could have read that polymorphism is a lot of things... I immediately recognize polymorphism as overloading methods, due to it's C usage, most recognize as subtype polymorphism due to it's usage in both C++ and Java, both widely used languages, and there's still parametric polymorphism used by the functional folk.

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 904
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #527 on: October 01, 2011, 01:52:15 PM »
Polymorphism actually means "having many forms", from the Greek poly (many) and morphe (form)  .

Basically, taking one thing, and changing how it is, but still being the same. In CS, overloading methods is one way of using polymorphism, as is inheritance of classes/datatypes.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #528 on: October 01, 2011, 02:54:55 PM »
Pilchard, look at your posts counter... I don't like that number... (666 is the number...)

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #529 on: October 01, 2011, 04:31:59 PM »
111 posts for divinity ^^

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #530 on: October 02, 2011, 08:57:24 PM »
Hmmm, I got a question:

In java, how do you find a specific object in a list provided the info that object on the list should have? I mean, a list goes from 0, infinite(fine by me) and contains data, or an object filled with data. Now you don't really wanna go from 0, 40 just to find the correct object, you would rather want to have the object coming to you instantly. Like if you could write in the data in the list to get to it. Though this works in lua, but not java...

A brief example:

Code: [Select]
List:
0: 0,0,0
1: 0,0,1
2: 0,0,2
3: 0,0,3
4: 0,0,4
5: 0,0,5
6: 0,0,6
7: 0,1,0
...

You want the data in 7, but you don't really know that 7 contains the data. So you do a for loop though all of them to find the perfect match. But this takes performance... So we'd like to go directly to the object with the data you require, meaning no for loop. But how the heck would you do this if theres over 1000 objects on the list and only one match?

So is there any way to do that shortcut, to prevent lag?

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #531 on: October 03, 2011, 03:03:50 PM »
I am pretty sure that Lua method is just sugar candy for a wrapped C for-loop...
Either way, if you're really not feeling like doing a for loop, you can use a hash table, with a decent hash function...
If you manage to do a perfect hash function, to your data(no collisions), time complexity will O(1), compared to the average O(n/2) that the for loop, provides...

Still, if it's only 40(or even somewhat larger ranges), it's not worth the trouble, and it will probably be slower...

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #532 on: October 03, 2011, 04:42:15 PM »
I figured it out, I jsut made an arrqay inside of the class, telling who the nighbours are, and they are checked when level is created.

Also, the size of the array would minimally be 20x20x20, so it's a large number!

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 904
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #533 on: October 03, 2011, 07:23:06 PM »
Set up a binary search for the data. You can reuse it quite easily then as well.

Admittedly this requires the data to be sorted as well, but that isn't monstrously hard to do either. It depends how you set up your data in the first place.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #534 on: October 03, 2011, 08:44:01 PM »
Heh... But I got another problem, I need to get an object that could be anything, like it's not predefined...

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #535 on: October 03, 2011, 09:37:07 PM »
Hum?Sorry, didn't understand. Can you elaborate?

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #536 on: October 03, 2011, 09:42:40 PM »
Well, I walked through some video tutorials by TheNewBoston(highly reccomended, seriously!!!) and he began talking about an object that can have any shape, so it's and object... a simple object with no specific form... I've figured out that this "object"¨s name is simply... "Object" when you write it on the code x.x

So... Lol!

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 904
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #537 on: October 04, 2011, 05:28:29 PM »
De quoi?

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: What are you working on? :D
« Reply #538 on: October 04, 2011, 07:03:28 PM »
"Object" in java is the super class for all object, nuff said.

But the binary search, how fast is the while loop usually?

And is it "lag-free" for 2d search? Like X,Y?

Orion63

  • Sapling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 73
  • We are the Knights who say... NI!
Re: What are you working on? :D
« Reply #539 on: October 04, 2011, 11:57:35 PM »
Binary Search has a time complexity of O(log2(n)) a.k.a. pretty damn good...(Still vote for hash table ^^)

Either way, unless whatever you're doing is a full-featured software or has some kind of scientific basis, you shouldn't be thinking much about timing algorithms. It's faster to write whatever you want the program to do first, and optimize it later, than spending too much time, finding the perfect method for every small thing.

And if you still insist in doing things, the hard way, Java will help you, more than pretty much any other language, around. Java has a ridiculous amount of data types, just waited to be used(including binary trees and hash tables, linked lists, graphs, etc...), so you shouldn't be spending much time in that...