Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 631 632 [633] 634 635 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887396 times)

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9480 on: May 07, 2016, 03:12:30 pm »

AAAAAAAAAAA.

No.

Sides would be an array, or ArrayList, or List, or some sort of thing that stores how many/what is on the sides, IN Dice, which you use in the DiceRoller.

Code: [Select]
public class DiceRoller{
    private ArrayList<Dice> dicelist;
    //Methods and stuff.
}

public class Dice{
    String[] sides; //assuming you don't plan on having the number
    //of sides change, this is probably better than ArrayList. 
    //Store your sides in this.
    //Constructor would take a String array as args.
}
« Last Edit: May 07, 2016, 08:49:00 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9481 on: May 07, 2016, 06:07:06 pm »

Why do you have an array of strings inside a single dice object? Is that so you can have non-numerical outcomes of the dice roll or something? Also the guy is having issues working out how to do simple constructors and member variables. There are way too many levels of complexity in what you're proposing there.

3man75, the steps are:

- make a class for the Dice
- make a member variable inside Dice called "sides". You want an int for this.
- make a constructor for the Dice method that takes an int
- get the constructor to store the passed value int "sides"

At this point, you can create dice objects, and tell them how many sides they have. After that, you can make a member function for the actual dice roll, which looks up the "sides" value for the actual random roll.
« Last Edit: May 07, 2016, 06:16:13 pm by Reelya »
Logged

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9482 on: May 07, 2016, 06:29:28 pm »

If I remember my Java syntax right, it'd look something like this:
Spoiler (click to show/hide)
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9483 on: May 07, 2016, 08:44:44 pm »

@Reelya:Or for nonsequential dice, etc.

Good point, but you literally just proposed what I wrote, only with an int instead of a set of outcomes.  The actual constructor would be much the same in any case.

Also, Dice class.  Not method.

Sample class w/constructor, for reference:
Code: [Select]
public class Demo{
    //This is a thing you store the object's data in.  AKA an instance variable.
    //You access it with getters and set it with setters.
    //It's private because it's not supposed to be accessed outside of the object.
    //You can make it public if you want, though it's not that common.
    private Datatype sample_var;
    //And this is a constructor, which will set that value:
    Demo(Datatype arg){
    sample_var = arg;
    }
}
« Last Edit: May 07, 2016, 08:59:05 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9484 on: May 07, 2016, 09:12:07 pm »

But the guy wasn't going to be able to implement what you wrote, while he has a chance to implement what I suggested, and would need to be able to do that before even thinking of how your one would work - you'd have to write it for him anyway, which defeats the purpose of learning. And are we here to help the guy or do a wank about how complex a dice class we can come up with?

Your idea about ArrayLists of Dice, where each dice contains an arbitrary array of strings so that they can roll literally anything, none of that is helping this guy write a working 6-sided dice. I mean, I didn't want to be rude about this, but you're not helping, you're making it harder to help the person who asked for help.

Look, the person writing the DiceRoller doesn't know how to create a member variable or a constructor. It's too early to get into advanced data structures.
« Last Edit: May 07, 2016, 09:25:48 pm by Reelya »
Logged

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9485 on: May 07, 2016, 09:39:21 pm »

I'm pretty sure you learn about lists and arraylists before you do anything with classes. I think the list approach is just really overcomplicating things. Just have a number like any sane person would do and then if you need to associate that with a string list, have an enum and use ordinals after getting the numeric output.
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9486 on: May 08, 2016, 11:23:52 am »

To clarify I have learned about arrays lists and used them (linked list also but I only understand a superficial amount). That said, my knowledge/memory is terrible and i'm essentially re-learning by doing.

AAAAAAAAAAA.

No.

Sides would be an array, or ArrayList, or List, or some sort of thing that stores how many/what is on the sides, IN Dice, which you use in the DiceRoller.

Code: [Select]
public class DiceRoller{
    private ArrayList<Dice> dicelist;
    //Methods and stuff.
}

public class Dice{
    String[] sides; //assuming you don't plan on having the number
    //of sides change, this is probably better than ArrayList. 
    //Store your sides in this.
    //Constructor would take a String array as args.
}

Very interesting that you used an array list for a simple problem. But I'm still trying to to call function so this is as useful to me as ferrari without ignition. Great to look at but I can't use it.

Thank you for the help though but all I want to do is:

1. get main to call DiceRoller class.
2. DiceRoller *picks up* the call and sends main what it needs.
3. Win.
4. Look for other methods to make it more efficient/cost me less code.
5. Profit??

Haven't been able to work on the project do to mothers day shopping. Which btw happy mothers day to you all (if it applies). Will continue to work on it later and lurk.

Why do you have an array of strings inside a single dice object? Is that so you can have non-numerical outcomes of the dice roll or something? Also the guy is having issues working out how to do simple constructors and member variables. There are way too many levels of complexity in what you're proposing there.

3man75, the steps are:

- make a class for the Dice
- make a member variable inside Dice called "sides". You want an int for this.
- make a constructor for the Dice method that takes an int
- get the constructor to store the passed value int "sides"


At this point, you can create dice objects, and tell them how many sides they have. After that, you can make a member function for the actual dice roll, which looks up the "sides" value for the actual random roll.

Btw this resembles my goals more accurately.
Logged

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9487 on: May 08, 2016, 07:55:49 pm »

Okay, do you just want to...Roll a die, by calling DiceRoller?

Because here is what you need to do that:

Code: [Select]
public class DiceRoller{
    //static so you don't even need to make a DiceRoller object.
    public static int roll(int sides){
        //I'm assuming you want it to be [1-sides] as opposed to [0-(sides-1)].
        return (int)((Math.random()*(sides-1))+1);
    }
}
You use this by calling DiceRoller.roll(integer_value);

But seriously, if you just want to random numbers, just call Math.random() in main itself.  Less class-related overhead.

Or, if you want to store the roll value, which I suppose you probably do...
Code: [Select]
public class DiceRoller{
    int sides; //stores the number of sides.
   
    //This is the constructor.  It takes the argument and assigns it to the instance variable.
    DiceRoller(int num_sides){
        sides=num_sides;
    }
   
    //This returns a random number in the range [1-sides].
    public int roll(){
        return (int)((Math.random()*(sides-1))+1);
    }
   
    //This returns the number of sides.
    public int getSides(){
        return sides;
    }

    //in case you want to change the size of the die.
    public void setSides(int num_sides){
        sides=num_sides;
    }
}
You use this by making a DiceRoller d = new DiceRoller(integer_value); and calling d.roll(); to get a number.
« Last Edit: May 08, 2016, 08:08:44 pm by TheBiggerFish »
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9488 on: May 08, 2016, 08:43:46 pm »

It's a learning exercise. He wants to use the concept of dice to learn about how to work with classes. Which is why making a simple Dice class is a good goal at this point.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9489 on: May 08, 2016, 08:57:06 pm »

But that's just kind of silly.  Unless DiceRoller is the class in which his main method is, in which case, it's literally a case of changing the class name on the latter of my most recent blocks of code.

Unless you're saying that I should not have included the getter/setter for sides?
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9490 on: May 08, 2016, 09:27:08 pm »

But that's just kind of silly.  Unless DiceRoller is the class in which his main method is, in which case, it's literally a case of changing the class name on the latter of my most recent blocks of code.

Unless you're saying that I should not have included the getter/setter for sides?
So I haven't been to any place that teaches programming myself, but I have talked to quite a few who have. And the impression I've gotten is that you learn data structures by building them yourself in several of these places, even though it's basically reinventing things that come in many standard library packages. In this way, I don't think it's very silly to build something that comes with the standard libraries as a learning exercise. Especially by a poster who has come to this topic for help more than once without gaining an understanding of the fundamental processes they need to finish it.

So maybe don't be a harsh critic?
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9491 on: May 08, 2016, 09:41:11 pm »

When learning data structures, yeah, making them yourself is how you learn. When programming... there's not really any point if it can be done faster without any code-maintenance issues.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9492 on: May 08, 2016, 10:17:51 pm »

But that's just kind of silly.  Unless DiceRoller is the class in which his main method is, in which case, it's literally a case of changing the class name on the latter of my most recent blocks of code.

Unless you're saying that I should not have included the getter/setter for sides?

You're completely missing the point. The point is that he wants to learn how to code. He doesn't want an off-the-shelf solution to the problem of rolling dice.

Previously, me and others have assessed which language features he's mastered, and which language features he doesn't understand. Then, we picked the simplest thing he didn't understand, and have focused on that one thing, before we try and throw all the bells and whistles at him. You seem oblivious of that.

Quote
But seriously, if you just want to random numbers, just call Math.random() in main itself.  Less class-related overhead.

^ this is the thing I thought was dumb. Because the entire stated point of the exercise was 3man75 learning how to create objects. Doing away with the object because it's "simpler" defeats the purpose of the learning exercise.

And the code you followed that up with is just a more-complex version of the code we already provided as an example. How's that helping if the previous, simpler, examples were not?
« Last Edit: May 08, 2016, 10:34:14 pm by Reelya »
Logged

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9493 on: May 09, 2016, 12:27:29 am »

If Reelya's argument isn't convincing enough, try this metaphor:

3man75 has asked how to use the alphabet to construct words. Showing him how to diagram sentences is not quite useful yet. Teaching someone how to use preconstructed words that convey the meanings very efficiently in a given situation is much less important at this stage than their understanding of how to spell 'hello world'. And when the questions coming in are "Why can I not spell it 'hello wurld'?" the answer is not "Actually, phrase it 'Why can't I say "hello world"?' for best results."
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9494 on: May 09, 2016, 08:56:26 am »

But that's just kind of silly.  Unless DiceRoller is the class in which his main method is, in which case, it's literally a case of changing the class name on the latter of my most recent blocks of code.

Unless you're saying that I should not have included the getter/setter for sides?

I know that BUT I need to learn how to program things differently. I testify honestly that it's not efficient but I forgot how to use different classes. I forgot object oriented programming. I suck. I'm trying to re-learn and continue where I left on in this journey after personal events threw it off track.

I have time to re-learn thankfully and hopefully I do before going into a programming team (If I get in. Were all trying out and theirs no 'regualar' members').

No one take this the wrong way though, I am extremely grateful for your help (and sorry about re-asking).
Logged
Pages: 1 ... 631 632 [633] 634 635 ... 796