Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 157 158 [159] 160 161 ... 796

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

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2370 on: May 04, 2012, 06:58:15 pm »

I know there's this huge argument out there are "truly random" numbers, but I have a feeling it's more than bad seeds making this work not so great.

Code: (A random movement calculator.) [Select]
public void RandomMovement()
        {
            int counter = -1;
            List<int> moveX = new List<int>();
            List<int> moveY = new List<int>();

            if (CheckForMovement((mobX - 1), (mobY + 1), Map) && Map.TileMap[(mobX - 1), (mobY + 1)].walkType == this.walkType && CheckForTarget((mobX - 1), (mobY + 1), player.mobX, player.mobY) == false)
            {
                counter++;
                moveX.Add(mobX - 1);
                moveY.Add(mobY + 1);
            }
            if (CheckForMovement((mobX), (mobY + 1), Map) && Map.TileMap[(mobX), (mobY + 1)].walkType == this.walkType && CheckForTarget((mobX), (mobY + 1), player.mobX, player.mobY) == false)
            {
                counter++;
                moveX.Add(mobX);
                moveY.Add(mobY + 1);
            }
            if (CheckForMovement((mobX + 1), (mobY + 1), Map) && Map.TileMap[(mobX + 1), (mobY + 1)].walkType == this.walkType && CheckForTarget((mobX + 1), (mobY + 1), player.mobX, player.mobY) == false)
            {
                counter++;
                moveX.Add(mobX + 1);
                moveY.Add(mobY + 1);
            }
            if (CheckForMovement((mobX - 1), (mobY), Map) && Map.TileMap[(mobX - 1), (mobY)].walkType == this.walkType && CheckForTarget((mobX - 1), (mobY), player.mobX, player.mobY) == false)
            {
                counter++;
                moveX.Add(mobX - 1);
                moveY.Add(mobY);
            }
            if (CheckForMovement((mobX + 1), (mobY), Map) && Map.TileMap[(mobX + 1), (mobY)].walkType == this.walkType && CheckForTarget((mobX + 1), (mobY), player.mobX, player.mobY) == false)
            {
                counter++;
                moveX.Add(mobX + 1);
                moveY.Add(mobY);
            }
            if (CheckForMovement((mobX - 1), (mobY - 1), Map) && Map.TileMap[(mobX - 1), (mobY - 1)].walkType == this.walkType && CheckForTarget((mobX - 1), (mobY - 1), player.mobX, player.mobY) == false)
            {
                counter++;
                moveX.Add(mobX - 1);
                moveY.Add(mobY - 1);
            }
            if (CheckForMovement((mobX), (mobY - 1), Map) && Map.TileMap[(mobX), (mobY - 1)].walkType == this.walkType && CheckForTarget((mobX), (mobY - 1), player.mobX, player.mobY) == false)
            {
                counter++;
                moveX.Add(mobX);
                moveY.Add(mobY - 1);
            }
            if (CheckForMovement((mobX + 1), (mobY - 1), Map) && Map.TileMap[(mobX + 1), (mobY - 1)].walkType == this.walkType && CheckForTarget((mobX + 1), (mobY - 1), player.mobX, player.mobY))
            {
                counter++;
                moveX.Add(mobX + 1);
                moveY.Add(mobY - 1);
            }

            if (counter >= 0)
            {
                int i = Rand.Next(0, (counter + 1));
                mobX = (byte)moveX[i];
                mobY = (byte)moveY[i];
                return;
            }
            else
                return;
        }

If it's not obvious what's going on, the actor checks all eight directions around itself to see if they're unoccupied and of the same 'walkType', puts all the coordinates in a pair of lists, then randomly generates a number between 0 and the number of valid directions to pick a pair of coordinates to set.  And it works fine... Except the actors have a pronounced inclination to move south-west and almost never north-east.  Since the directions are defined counting "up" as for a numpad arrangement, I imagine the problem is that C#'s default random number generator favors going low or something, but I really don't know.  Anyone have any random number tips?

EDIT: Never mind, figured it out.  Man, fuck that CheckForTarget nonsense, not only did I forget a False, but it's a stupid method anyway.  I have better ideas now.
« Last Edit: May 04, 2012, 07:08:58 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.

Sowelu

  • Bay Watcher
  • I am offishially a penguin.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2371 on: May 04, 2012, 07:25:07 pm »

Realizing that I really need to reel in the MMO I wanted to make because, well, mostly practicalities of servers and the fact that they are expensive.

Actually, dunno, because Hazeron seems to work okay with a smallish number of players.

Though Left 4 Dead has demonstrated that a coop-only game is viable so, hmm.  (Not counting versus mode)
Logged
Some things were made for one thing, for me / that one thing is the sea~
His servers are going to be powered by goat blood and moonlight.
Oh, a biomass/24 hour solar facility. How green!

SolarShado

  • Bay Watcher
  • Psi-Blade => Your Back
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2372 on: May 04, 2012, 07:41:14 pm »

Teehee. I don't think I'm going to ever learn Javascript or HTML >.>

Javascript and HTML really need compiler-like thingies.

http://validator.w3.org/ ?

Does that work as well as a regular compilerIDE in error checking? o_O I remember Shoruke complaining that is Javascript, if things don't work they just fizzle quietly; whereas if something is wrong in C++ the compiler complains loudly and clearly.

It may be important to note that the error you had wasn't actually a syntax error. However, any decent IDE/validator should have generated a warning about an undeclared variable.

Failing that, find an editor with syntax highlighting: variable names and string literals will be different colors. (Notepad++ is a pretty useful all-around text editor.)
Logged
Avid (rabid?) Linux user. Preferred flavor: Arch

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2373 on: May 04, 2012, 08:42:30 pm »

Okay, I am having an issue. I am trying to take a direction vector <x,y,z> and another direction vector <a,b,c> and finding the change in angle between each set of planes (x,y),(x,z),(y,z). Not sure how to go about checking that out. I can make them each into Unit Vectors, which I think is necessary for this, but am not sure how to find the change in angle :(
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2374 on: May 04, 2012, 08:45:24 pm »

I don't know what you are talking about, but can't you use the magical Pythagorian Triangle, then use acos, asin and stan? O_o

Uh... Can you elaborate on what you are doing for me?
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Sowelu

  • Bay Watcher
  • I am offishially a penguin.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2375 on: May 04, 2012, 08:50:27 pm »

Okay, I am having an issue. I am trying to take a direction vector <x,y,z> and another direction vector <a,b,c> and finding the change in angle between each set of planes (x,y),(x,z),(y,z). Not sure how to go about checking that out. I can make them each into Unit Vectors, which I think is necessary for this, but am not sure how to find the change in angle :(

http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors

Note that your coding library probably has functions for dot products and cross products, which should make this easier.  You can still do it 100% manually though, per the article.
Logged
Some things were made for one thing, for me / that one thing is the sea~
His servers are going to be powered by goat blood and moonlight.
Oh, a biomass/24 hour solar facility. How green!

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2376 on: May 04, 2012, 08:55:19 pm »

lol... i feel dumb. Yeah the Pythagorean Theorem probably would have worked. Thanks for the link Sowelu!
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2377 on: May 05, 2012, 09:41:43 am »

So remember that interview I mentioned? Imma getting an offer for the internship there :D Borrowing interview ideas from Google aside, they're a pretty cool place.

Reasonably wide reaching business, and the way they develop things is very structured and professional. They're big on agile development, especially pair programming and test-driven design, and code that documents itself (Mostly C# and Ajax). A very good place to get acquainted with the world of profession software development ^^

I so excited :D Now to just get through the rest of my coursework and tests for this university year :)

In other news, anybody else downloaded the Visual Studio 2011 beta. What the heck is up with it's look? It's so...gray? It's actually depressing to look at :( And that's the "Light" theme. Although at least the "Dark" theme delivers exactly what it promises...
« Last Edit: May 05, 2012, 09:57:57 am by MorleyDev »
Logged

Aqizzar

  • Bay Watcher
  • There is no 'U'.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2378 on: May 05, 2012, 10:15:54 am »

I realize this discussion has moved on a bit from just plain minor-videogame development help, but I'm working on my roguelike and I have an idea for handling actions that I'm not entirely sure of.

Turn based games have the problem of reacting to the player's perception and commands.  I know some games just take the route of "perform the player's input, then do one thing per every other actor".  If you want to get fancy, you can assign ticks to activities and speeds to actors, so every time the player does an action, it advances as many ticks as to the next one, and mobs whose speed is ticked past perform actions as they come up.

That's all well and good, but I like doing things differently, even when I didn't learn how to implement the normal way in the first place.

There exists a global metaobject, the Action Controller.  When the player enters a command, it sends an Action Request (object) to the Controller.  The Controller then pings every actor in the relevant mapspace, who run through their AI and send back a Request each.  The Controller reorders these Requests by their contained initiative calculation, then cycles down.  If a Request has a null Target Actor (like movement) then no big deal.  If a Request has a Target, the Action checks if the Target is still valid (visible, hasn't moved out of range, etc) and does whatever if it fails. Otherwise the Target is pinged for a Response, and pulls from its AI.  If the Target is the player, this might prompt a choice but will usually be automatic.

And that's it.  Basically, every Actor tries to do one thing a turn, might do nothing if they're down the ladder and their Target is gone by the time they act, might do a bunch of things if say the Player is in a group and gets a Response to several actions.  Does this sound like a stupid way to do things, or am I onto something here?


So remember that interview I mentioned? Imma getting an offer for the internship there :D Borrowing interview ideas from Google aside, they're a pretty cool place.

In other news, anybody else downloaded the Visual Studio 2011 beta. What the heck is up with it's look? It's so...gray? It's actually depressing to look at :( And that's the "Light" theme. Although at least the "Dark" theme delivers exactly what it promises...

Congrats man, that's how things worked out for me.  Hopefully you get one of those good internships and not just a temping-for-no-pay internship.

Haven't seen VS2011 beta, which seems dumb that it would still be in beta in mid-2012.  I might like that Dark thing though, if there's one thing that bugs me about doing computer stuff, it's staring at a white screen all day.
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.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2379 on: May 05, 2012, 10:28:07 am »

The problem is in light everything but the part with the code is grey or black. Everything.

This is what it looks like when you boot it up.
This is what it looks like with code.
This is what it looks like in a menu.
This is what the solution explorer looks like.

Congrats man, that's how things worked out for me.  Hopefully you get one of those good internships and not just a temping-for-no-pay internship.

Yep, fully paid. More than the minimum wage even :D Which means I can afford to rent my own flat and not live with the parents for the year...
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2380 on: May 05, 2012, 10:31:56 am »

Aqizzar, that sounds like an interest way of handling turn-based stuff. In the end, the result will be the same, so I don't see any problem with it. Debugging sounds like it will be painful, though.

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2381 on: May 05, 2012, 09:48:26 pm »

Actually, debugging it shouldn't be all that difficult. if you want to have it print the debug info to the screen you could do a turn by turn batch print of the debug info with all of the information in the form:
Code: [Select]
Entity type: "something" -- Action Request ("action requested") -- (Targeted? "state target" | "null") -- (success | fail)
Something like that but for an entire turn's worth of action requests and resolutions in the order that the request(s) is processed in and out of the action listener.

From there the information can be either printed to a console or put into a log file with a turn heading such as:
Code: [Select]
Turn "x" -- Real Time: hh:mm:ss dd/mm/yy -- Run Time: hh:mm:ss

That would be the debug process for the action listener request/resolve chain per turn displayed once all resolutions are complete.

Sort of a long-winded explanation but it was to demonstrate (vaguely as possible) that debugging that process wouldn't necessarily be a pain in the rump :) as it would give a decent amount of information for little overhead using batch printing/writing. You could even add in a tick-number field to the action chain debug information so you can make sure that everything is firing off at the right times.

@Mego: Does this look like a good way to debug the process to you? If there's something wrong with it that looks like it should be altered/thrown away then please let me know :D

@Aqizzar: Same question that I gave to Mego :D Also, does the debug code look like something you could implement into your code for the purposes of debugging should anything start looking like it isn't working?
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2382 on: May 05, 2012, 10:17:42 pm »

That's my typical method of debugging, making my program barf up as much information as possible and sifting through it. In fact, keeping a log of actions could make for a very interesting AI with learning capabilities. Maybe a sort of final boss that can watch the whole dungeon, and "takes notes" on what the PC does.

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #2383 on: May 05, 2012, 10:25:54 pm »

To the learning boss thing, something like:
Boss: Oh hey, I'm weak against fire. This guy seems to be kicking some ass with his fire spells. But he only uses it every now and then even though he could come fight me really quick if he just spammed it all the time. Maybe he only has a limited amount of magic points? Ooh, I might be able to take advantage of that!
*Boss writes some notes to figure out how to restrict the player's available magic points*
Boss: Oh yes... that guy's goin down!

Lols, that would be pretty cool to be honest. I would love to have to tailor my play style with the knowledge that the level bosses are essentially looking over my shoulder to figure out my strengths and weaknesses by putting me into different situations as tests.
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2384 on: May 05, 2012, 10:31:47 pm »

Spoiler (click to show/hide)
Pages: 1 ... 157 158 [159] 160 161 ... 796