Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 38 39 [40] 41 42 ... 796

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

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #585 on: January 16, 2012, 06:17:41 pm »

Code: [Select]
MobObject[] mobs = new MobObject[mobList.Count];
mobList.CopyTo(mobs);
return mobs[mobNumber].GetLocation();

Managed to compress that ugly block into this:

Code: [Select]
MobObject[] mobs = mobList.ToArray();
return mobs[mobNumber].GetLocation();

And then got it smaller into this:

Code: [Select]
return mobList[mobNumber].GetLocation();

I'm also learning how to use the "foreach" function, and it's going swimmingly.  I feel like I'm delving into dark magic now, messing with forces no one taught me and which I do not fully understand.

Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #586 on: January 16, 2012, 06:22:47 pm »

Well if things ever get too cryptic, I'm here duel wielding ancient grimoires...
Now LINQ, that shit is amazing, but can be incredibly cryptic. Seriously, you can compress twelve lines of code into one, and it will look like a totally different programming language (Partly because it is based on one!)

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #587 on: January 16, 2012, 06:27:26 pm »

I'm also learning how to use the "foreach" function, and it's going swimmingly.  I feel like I'm delving into dark magic now, messing with forces no one taught me and which I do not fully understand.

Excellent! 

Reducing code complexity is one of the things that make me feel great as a programmer.  My current project is almost due for me to go and re-work a bunch of things that should make it a lot easier to continue.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #588 on: January 16, 2012, 06:46:25 pm »

I always love taking 50 lines of code that I've written and writing 3 lines of new code that do the same thing, only faster. C++-11 is my new love.

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #589 on: January 16, 2012, 07:04:46 pm »

Code: [Select]
[code = What my code structure looks like.]
Main Program Body
| | |
| | > Key Interface Spacesaver
| > Main Screen Display
|
> Map Object Class
 | | |
 | | > Map Generator > List of Rooms > Room Object
 | > Array of MapTiles > MapTile Object
 > List of Mobs > Mob Object

Now, where the heck do I put the giant stack of methods I'm going to need for making Mobs act?  Do I define their intelligence as an Object in itself?  What's the most efficient way to send the movement information up and down between the Map Object and the Main Program?  And how do I reinterpret all this into attacks?

I have a lot of decisions ahead of me, and then I have to make them work.

I suddenly get the feeling that I must revise my conception of the Player from being static information stored in the main program to being an object within the Map.  Or maybe not, errrrrg.
« Last Edit: January 16, 2012, 07:07:46 pm by Aqizzar »
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #590 on: January 16, 2012, 07:16:54 pm »

Hold on, I'm pretty sure this is what you are describing

Spoiler (click to show/hide)

Ok, now why do you need static methods for the mobs? Couldn't you have nonstatic methods in the mob class for the mobs?

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #591 on: January 16, 2012, 07:23:20 pm »

Now, where the heck do I put the giant stack of methods I'm going to need for making Mobs act?  Do I define their intelligence as an Object in itself?  What's the most efficient way to send the movement information up and down between the Map Object and the Main Program?  And how do I reinterpret all this into attacks?

I'd put the actual AI in each Mob's object to begin with.  Once you've gotten a few of them working, then it'll be easier to see how to abstract it.


I've been liking how I've got my AI organized though.  I've got a set of AI objects like:

IdleAI, WanderAI, PatrolAI, DigAI, RunAwayAI, SeeAndAttackAI.

And each monster definition includes a list of these AI objects in a particular order.

Whenever the AI is queried for an action, it starts at the top of the list and if an AI doesn't return an action, it goes and checks the next one until it finds one that feels like doing something.

So I've got a digging monster that has the AI's

- RunAwayAI
- DigAI
- WanderAI

So his first priority is to run away if there is danger.  If there is no danger, the RunAwayAI doesn't return an action, so it moves to the DigAI.  DigAI looks to see if there is anything appropriate for digging.  If there is, it'll wander over and start digging until it runs out or the RunAwayAI is triggered.  If there is nothing to run from and nothing to dig, it falls back to the last AI routine, where it just wanders around doing nothing in particular.

This way I can have each monster have a somewhat customized AI without writing a big routine for each one.


Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #592 on: January 16, 2012, 07:26:18 pm »

Interesting concept Levi.  I'll keep it in mind, but I think I've got a good objectless AI system in mind, or at least one that encapsulates all of the mob's possible actions into one object.  Yours is not a bad idea though.

Ok, now why do you need static methods for the mobs? Couldn't you have nonstatic methods in the mob class for the mobs?

...Nonstatic methods?  Okay, now you've lost me again.

Essentially, my plan was to have the Main Program call the Map Object to make every Mob do whatever it needs to do (and send it the player's location in the process).  The Map Object then iterates through its list of Mobs, checks their AI Type Byte (defined and implemented according to my external documentation), compares that to the player's location if necessary, and then tells the Mob to do whatever it needs to do.  The Mob then acts by some method inside its class, and updates itself as appropriate.

Walking around won't be particularly hard, it'll be interaction with the player - getting the mob to send information back to the Main Program, alter the player, and then print all the relevant information to the Main Screen.
« Last Edit: January 16, 2012, 07:27:56 pm by Aqizzar »
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #593 on: January 16, 2012, 07:35:48 pm »

~Epic snip
That... Is pretty cool. I was going to have a one to one relationship between a creature and it's AI, so for example, have a 'PassiveDigger' class that does the above example in a single class, but your way is a lot better! Totally taking that idea!

~snip
Ah, I see... Why not just tell the mob to update, then let the mob figure itself out and if it needs to make any interaction with the map it can just tell the map, instead of trying to pass all this information back at once?
Can you navigate to the map from your mobs?

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #594 on: January 16, 2012, 07:43:11 pm »

~Epic snip
That... Is pretty cool. I was going to have a one to one relationship between a creature and it's AI, so for example, have a 'PassiveDigger' class that does the above example in a single class, but your way is a lot better! Totally taking that idea!

That is actually exactly how mine started.  I had a DiggerMonster class that had all the relevant AI and everything to begin with, but it was starting to seem to complicated and I wanted to have lots of monster types.  Looking at the amount of work I'd have to do writing AI's for every kind of monster gave me the above idea, and so far its working beautifully. 
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #595 on: January 16, 2012, 07:45:01 pm »

~snip
Ah, I see... Why not just tell the mob to update, then let the mob figure itself out and if it needs to make any interaction with the map it can just tell the map, instead of trying to pass all this information back at once?
Can you navigate to the map from your mobs?

I'm pretty sure having the mob update itself is what I meant.  But as for navigating to the map from the mob, I don't know how.  The Mobs are contained in a List in the instantiation of the Map Object.  If the Mobs have the power to call down map information on their own, without having to have it sent to them in a method, I'd have to see an example of how to do that.  Likewise for the Player Position information, which I can't seem to make Public from the main program in a way that will compile.
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #596 on: January 16, 2012, 07:47:34 pm »

This is why I have a class called "World" that sits over the Map class and holds the Map as a static object. Though you could have the Map hold itself as a static object just as well. My World class usually does more than just hold the map though, so it tends to justify its existence.

I use a variant of Levi's system for my own AI, and I will describe that soon enough, but I don't want to be ninja'd.
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 /

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #597 on: January 16, 2012, 07:52:32 pm »

I'm pretty sure having the mob update itself is what I meant.  But as for navigating to the map from the mob, I don't know how.  The Mobs are contained in a List in the instantiation of the Map Object.  If the Mobs have the power to call down map information on their own, without having to have it sent to them in a method, I'd have to see an example of how to do that.  Likewise for the Player Position information, which I can't seem to make Public from the main program in a way that will compile.

Your mobs need to have access to the Map to do this. It is called bidirectional navigability. Big words make for cool shit.

This is just a small piece of code to show you how it is done:
Spoiler (click to show/hide)

From that, the mob can access the map by calling map.WhatEverMethodYouMake();

nenjin

  • Bay Watcher
  • Inscrubtable Exhortations of the Soul
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #598 on: January 16, 2012, 07:54:01 pm »

Quote
The Mobs are contained in a List in the instantiation of the Map Object.  If the Mobs have the power to call down map information on their own, without having to have it sent to them in a method, I'd have to see an example of how to do that.

I'm still far behind you, but I think this is your issue with having the player stored in the main program. If the player were constructed as a class and created as an object, you could put public methods in it that monsters could call to pull up player stats and communicate change back to player object.

This is probably my lack of knowledge showing, but it seems like you've got the player set up as global variables? You really don't want global variables if you can help it, especially considering how often and consistently they're going to be manipulated. If I'm off base here just ignore me.
Logged
Cautivo del Milagro seamos, Penitente.
Quote from: Viktor Frankl
When we are no longer able to change a situation, we are challenged to change ourselves.
Quote from: Sindain
Its kinda silly to complain that a friendly NPC isn't a well designed boss fight.
Quote from: Eric Blank
How will I cheese now assholes?
Quote from: MrRoboto75
Always spaghetti, never forghetti

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #599 on: January 16, 2012, 08:00:09 pm »

From that, the mob can access the map by calling map.WhatEverMethodYouMake();

This make sense when I look at it, but it's a question I've had about method arguments and such like that.  When the mob is created, and it is created "containing" a Map, does that mean it has its own full copy of the map stored in its memory?  Or is it just a pointer, to the original map?  If the Map is changed, does the Map the mob would reference from itself reflect those changes, or is it static from what the Map looked like when the Mob is created?

This is probably my lack of knowledge showing, but it seems like you've got the player set up as global variables? You really don't want global variables if you can help it, especially considering how often and consistently they're going to be manipulated. If I'm off base here just ignore me.

Yes, that is exactly what I was doing, and the only real problem I can see with doing it this way is that it doesn't seem to want to compile.  Comes back to the same question though I guess.
« Last Edit: January 16, 2012, 08:05:00 pm by Aqizzar »
Logged
And here is where my beef pops up like a looming awkward boner.
Please amplify your relaxed states.
Quote from: PTTG??
The ancients built these quote pyramids to forever store vast quantities of rage.
Pages: 1 ... 38 39 [40] 41 42 ... 796