Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 392 393 [394] 395 396 ... 796

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

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5895 on: May 21, 2014, 03:31:00 pm »

What are you all talking about? It's really not that hard. Get an input string, convert to lower case, split by whitespace. Compare the beginning of the resulting word list to a set of possible verbs, and get the command corresponding to that verb. Feed that command the rest of the word list, as well as a context (usually a room full of items) that this command can modify. If the command needs to use an item (e.g. "pick up dressing gown"), then the command (in this case a pickup command) can look through all the context's items and get the item such that the command's word list begins with that item's name or an alias or abbreviation thereof (remember that the "pick" and "up" weren't passed to the command). It should be straightforward to program the individual commands to recognize syntactic words such as "with" or "on" if necessary.

To add new commands, you could simply write a function registerCommand(Command commandToUse, string verb), and register all commands under all their aliases at the beginning of the program.
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5896 on: May 21, 2014, 04:42:29 pm »

What are you all talking about? It's really not that hard. Get an input string, convert to lower case, split by whitespace. Compare the beginning of the resulting word list to a set of possible verbs, and get the command corresponding to that verb. Feed that command the rest of the word list, as well as a context (usually a room full of items) that this command can modify. If the command needs to use an item (e.g. "pick up dressing gown"), then the command (in this case a pickup command) can look through all the context's items and get the item such that the command's word list begins with that item's name or an alias or abbreviation thereof (remember that the "pick" and "up" weren't passed to the command). It should be straightforward to program the individual commands to recognize syntactic words such as "with" or "on" if necessary.

To add new commands, you could simply write a function registerCommand(Command commandToUse, string verb), and register all commands under all their aliases at the beginning of the program.
Was I the one overcomplicating things? Because you just described exactly what I did. Only mine recognizes multi-word actions like "pick up".
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5897 on: May 21, 2014, 04:56:41 pm »

Mine does too, but it doesn't need that weird sentence structure separator you did there.
Logged

Johuotar

  • Bay Watcher
    • View Profile
    • Some game projects
Re: if self.isCoder(): post() #Programming Thread
« Reply #5898 on: May 22, 2014, 12:45:09 pm »

I'm making a tiny roguelike in c# and the screen flickers constantly. Searching about the issue has lead me to the topic of buffering. Apparently this happens because the screen goes black for a while when using Console.Clear. Googling about buffering didn't really get me anywhere because no place really explained how the solution works. Can someone here explain why buffering is needed and how the solution works?
Logged
[img height=x width=y]http://LINK TO IMAGE HERE[/img]
The Toad hops in mysterious ways.
This pure mountain spring water is indispensable. Literally. I'm out of paper cups.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5899 on: May 22, 2014, 12:58:58 pm »

This is a story probably worth telling here.
I am a /tg/station maintainer, but I was just a normal coder before this, obviously.
I once tried to fix a long-standing bug, which resulted in my largest fuckup ever.

The space station is equipped with a pneumatic garbage disposal/mail system. It features four major components: intakes, outlets, bins and pipes. Pipes can be walked over. Outlets just "throw" out things and intakes will put anything in the system that is thrown/pushed into them. Bins are just garbage bins that flush into the system at regular intervals. An outlet can throw things into an intake and cause an infinite loop, but that is considered a feature.

Disconnected pipes obviously just throw things out in their direction. But they cannot magically put stuff through floors, that makes sense. So they are supposed to break intact floors and spawn a floor tile item. This was not happening properly, I forgot the exact details. After a lot of fiddling I came up with a fix that made a new floor tile spawn.
However, a faulty check made a floor tile spawn even when there's no intact flooring.

Somehow, this code got merged into master. The server updated.
My fault did no go unnoticed by griefers for long. It did not take long for somebody to set up infinite loops with floor tiles. One floor tile creates two floor tiles, two floors tiles will each spawn a new tile, so you have four tiles, etc. I assume you get the gist: exponential floor tile growth. Somebody adjusted the disposal loop present  by default on the station to have broken pipes followed by intakes almost immedieatly so floor tiles would be spammed everywhere. But that's not all. Floor tiles do above average damage when thrown. So anyone walking in the way would get hit in the face by a dozen floor tiles and die. The server quickly started lagging, and people started dieing quickly while floortiles slowly flooded the station.

A desperate admin saw no other way than to use a debug command: del-all. This deletes all objects of a certain type. There must have been hundreds of floor tiles at this point, and deletion is one of the most expensive operations in BYOND. But he forgot one thing: Intact flooring also contains a floor tile object (for fingerprint tracking and such). So he wasn't deleting hundreds of floor tiles, he was deleting thousands. At this point, everything was ogre. The server crashed.

And that is how I indirectly killed Sybil. I just got my PR merged, went to sleep, and woke up to everyone panicking.
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5900 on: May 22, 2014, 01:01:22 pm »

LOOP THROUGH THE TEXT FORWARD WHILE LOOKING FOR SOMETHING THEN LOOP BACKWARD TO VERIFY IT THEN LOOP FORWARD AGAIN TO FIND SOMETHING MORE FITTING THEN REPEAT. That's what it feels like.

Maybe I just suck at coding :P
Needs moar LL(1) grammar.

* da_nang sees compiler theory everywhere.

First it was Prolog. Now this. Thank you, Final Exams of The Year.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5901 on: May 22, 2014, 01:24:46 pm »

I'm making a tiny roguelike in c# and the screen flickers constantly. Searching about the issue has lead me to the topic of buffering. Apparently this happens because the screen goes black for a while when using Console.Clear. Googling about buffering didn't really get me anywhere because no place really explained how the solution works. Can someone here explain why buffering is needed and how the solution works?

Imagine your program was running realllly slow, and it would only print one character at a time. After a Console.Clear, it takes a while for the screen to get filled with characters again. The blank space that is there in the meantime is what you see as flickering.
There are three ways to circumvent that.
1) Don't write your text directly to the screen, instead write it to an array and write that array to the screen all at once. This is the closest you'll get to buffering while using a console. But there are better options:
2) Try redrawing your screen only when necessary. For example, in roguelikes you usually don't need to redraw the screen while you're waiting for user input.
3) Don't clear your console, just reset the cursor position. Then you can overwrite the old screen with the new screen without having an empty screen flashing in between the screens at all.

I humbly recommend a combination of methods 2) and 3).
Logged

Johuotar

  • Bay Watcher
    • View Profile
    • Some game projects
Re: if self.isCoder(): post() #Programming Thread
« Reply #5902 on: May 22, 2014, 02:41:41 pm »

Okay, thanks. I'll think about that. :)
Logged
[img height=x width=y]http://LINK TO IMAGE HERE[/img]
The Toad hops in mysterious ways.
This pure mountain spring water is indispensable. Literally. I'm out of paper cups.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #5903 on: May 22, 2014, 06:36:20 pm »

Mine does too, but it doesn't need that weird sentence structure separator you did there.
???
I think you might have taken my example a bit too literally. When I showed those sentence structures I was just showing examples of what a command (from the user) would look like. It doesn't force them on you or anything.

I wasn't saying my system was inherently better, but if you think yours is, I'd like to know what you meant.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5904 on: May 23, 2014, 01:44:23 pm »

Is there a way to use regular expressions in ruby to capture no text or a number?

Because I'm trying to implement a die rolling program that can take either "d20" or "2d4"

And I'm sure [|1-100] wouldn't work... Would it? I'd test it quick but I'm not at a place I can do that.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5905 on: May 23, 2014, 02:04:43 pm »

Is there a way to use regular expressions in ruby to capture no text or a number?

Because I'm trying to implement a die rolling program that can take either "d20" or "2d4"

And I'm sure [|1-100] wouldn't work... Would it? I'd test it quick but I'm not at a place I can do that.

If you just want "d20" or "2d4", why not check the end of the string for those two?
Logged

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5906 on: May 23, 2014, 02:15:49 pm »

I mean more like I want to be able to roll "d20" and "20d20". The variable I want to capture is the first number. If it's not possible to capture the front line except in a separate regex that's totally fine, too.

I'm just trying to get my bearings on this whole regex deal, which I'll be able to text maybe monday cuz I'm a chump who does things on the weekends.

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5907 on: May 23, 2014, 02:27:43 pm »

You could use (\d*)d(\d+). If you don't want numbers to begin with 0, use ((?:[1-9]\d*)?)d([1-9]\d*).

EDIT: Here you go.
« Last Edit: May 23, 2014, 02:30:39 pm by MagmaMcFry »
Logged

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5908 on: May 23, 2014, 03:17:23 pm »

Thanks much! I think I'm going to spend the summer dissecting ruby and ruby regex. Should be fun!

frostshotgg

  • Bay Watcher
  • It was a ruse
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5909 on: May 23, 2014, 06:13:07 pm »

Bit of a weird question here. In Excel, how can you make one cell be modified independently by multiple other cells. For example, I want A1 to be incremented by 1 every time when A3 changes from 0 to 1 and the same for C7.

Also, programming in Excel has taught me more about computer science than anything I've ever done. Excel IF statements are basically retarded, but damn if they aren't eye opening.
Logged
Pages: 1 ... 392 393 [394] 395 396 ... 796