Bay 12 Games Forum

Please login or register.

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

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

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5865 on: May 15, 2014, 12:03:32 pm »

I actually think think the might, but I'm not sure.
I don't think so.

Let α, β and γ be regular expressions. Can α(?=β)γ be transformed to a regular expression without lookahead? Note, I'm assuming the parser doesn't do substring matching i.e. the whole string must satisfy the regular expression since I think it would otherwise be possible to parse context-free languages. In other words, ^ and $ are applied.

First off, what does "lookahead" mean? AFAIK, it simply says if the parser can match a string satisfying β after α, then it will proceed "without consuming" the match. To me, that says that in order for the whole input string to be accepted, the regular expression β must exist within γ. Therefore it follows that γ = δβζ, where δ and ζ are regular expressions, which may be the empty string.

Assuming that γ = δβζ such that δ and ζ are known, then one can easily construct an NFA-ε that is equivalent to the regular expression and therefore represents regular languages.

For α(?!β)γ, the negative lookahead says that β should not occur after α. Therefore, γ = δηζ where η is the negation of β. The other regular expressions remain the same but also don't contain β. Hence the regular expression is now αδηζ and should be convertible to an NFA-ε.

The same method should work for lookbehind as well, only that you apply it to α instead of γ.
« Last Edit: May 15, 2014, 12:06:47 pm by da_nang »
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5866 on: May 15, 2014, 07:05:04 pm »

And regular expressions are awesome. Hell, I use them all the time just for the games I run on the forum or when writing scripts. They are incredibly for any sort of "find/replace" need, since they support backreferences.
Deep inside me, a formal language theory student cries.
Wait, what do formal language theory students have against capture groups? I've... don't think I've seen a regex implementation that *doesn't* support them in quite a while...

Next you'll be saying lookaheads and lookbehinds and recursive patterns make you cringe in pain or something!
Simply put, there are two definitions of regular expressions. The first and classic one is based entirely on Kleene algebra and supports union '+' (sometimes '|'), concatenation '·' and Kleene star '*'. This definition is equivalent to a DFA and thus represents regular languages (and in turn finite languages). This is what they teach you in Formal Language Theory.

The second one is based on either POSIX Extended Regular Expressions or Perl Regular Expressions (I forget which) that supports backreferences. Backreferences essentially add "memory" to the parser, something which DFAs do not support. In fact, it can be proven by the pumping lemma that the addition of backreferences leads to the parser being able to parse more than just regular languages (such as palindromes).

Calling them regular expressions to someone who is more familiar with the former definition sounds more like a misnomer, hence the cringe.

Lookaheads and lookbehinds, on the other hand, don't change what languages can be parsed AFAIK.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5867 on: May 15, 2014, 08:18:51 pm »

C++'s implementation of templates has a gotcha I dislike. You can't do the traditional declaration-in-header, definition-in-cpp file structure. You have to either put the whole thing into the header, or make a, say, tpp file that has the definitions of only the templated functions and #include them right after the declarations. At least that way you can keep the header files simple, but it effectively pastes the file content into the header :(

Oh, one more way is explicitly declaring what templated types of that function you want to use.
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

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5868 on: May 16, 2014, 01:01:04 am »

And regular expressions are awesome. Hell, I use them all the time just for the games I run on the forum or when writing scripts. They are incredibly for any sort of "find/replace" need, since they support backreferences.
Deep inside me, a formal language theory student cries.
Wait, what do formal language theory students have against capture groups? I've... don't think I've seen a regex implementation that *doesn't* support them in quite a while...

Next you'll be saying lookaheads and lookbehinds and recursive patterns make you cringe in pain or something!
Simply put, there are two definitions of regular expressions. The first and classic one is based entirely on Kleene algebra and supports union '+' (sometimes '|'), concatenation '·' and Kleene star '*'. This definition is equivalent to a DFA and thus represents regular languages (and in turn finite languages). This is what they teach you in Formal Language Theory.

The second one is based on either POSIX Extended Regular Expressions or Perl Regular Expressions (I forget which) that supports backreferences. Backreferences essentially add "memory" to the parser, something which DFAs do not support. In fact, it can be proven by the pumping lemma that the addition of backreferences leads to the parser being able to parse more than just regular languages (such as palindromes).

Calling them regular expressions to someone who is more familiar with the former definition sounds more like a misnomer, hence the cringe.

Lookaheads and lookbehinds, on the other hand, don't change what languages can be parsed AFAIK.

There's technically one set of languages "above" type 0, though. The hierarchy is more specifically:

All formal languages (uncountably infinite set, yay!)
Recursively enumerable languages (Languages that can be computed/parsed on a Turing machine)
Recursive languages (Languages that can be computed/parsed on a total Turing machine)
Context-sensitive languages
Context-free languages (Virtually all syntax grammars in programming languages, can be parsed on a pushdown automaton)
Regular languages (Pattern matching, yay! Can be parsed by DFA)
Finite languages (The "boring" set)
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #5869 on: May 16, 2014, 05:11:52 am »

I made a gaem for my coursework for university :) Wrote it using Scala and JSFML in like 3 days whilst dealing with the pain and the painkillers from wisdom tooth infection xD Well, I wrote some of the background code about a week ago (the basic client/server and Game "launch/run/close" framework), but the actual "game" part of it was written in 3 days.

Spoiler (click to show/hide)
Spoiler (click to show/hide)

It's just a rapidly developed prototype and it's basically a poorly coded pacman (by my standards at least). But it's not just a poorly coded pacman, it's a multiplayer pacman played over a network where one player is pac and up to 3 players control the ghosts.

Ghosts have limited field of view, so can only see tiles close to them, but they do also share sight with the other ghosts. So they have to work together to find and kill the Pacman.

I didn't get a chance to play around with Akka or Actors so all the networking uses Java sockets over TCP. Not ideal, but it serves it's purpose I guess.

Not bad for 3 days of delirious work. Exploitable as hell, ghosts can make it impossible for the pac player to win by just staying still since I didn't get around to implementing the power pellet before calling it a day and handing it in. But as far as "proof of concept prototype" I guess it works :P

But on a whole, developing games in Scala? Surprisingly pleasant. Scala is rapidly becoming my go-to language.

Oh, source code can be found at github. It uses sbt for compiling, so "sbt universal:package-bin" will create a zip archive containing the launch scripts, resources and jar files.
« Last Edit: May 16, 2014, 05:28:23 am by MorleyDev »
Logged

DrKillPatient

  • Bay Watcher
  • The yak falls infinitely
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5870 on: May 16, 2014, 03:04:09 pm »

Hi. Quick regex question; I found this in Ruby's documentation:

Code: [Select]
[a-w&&[^c-g]z]
Why does this regex exclude 'z'? My understanding is that it reads "Anything from 'a' to 'w' that is NOT anything from 'c' to 'g' or that is 'z', but it seems I'm not right about the last part.
Logged
"Frankly, if you're hanging out with people who tell you to use v.begin() instead of &v[0], you need to rethink your social circle."
    Scott Meyers, Effective STL

I've written bash scripts to make using DF easier under Linux!

gigaraptor487

  • Bay Watcher
  • Escaped Lunatic now civilised
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5871 on: May 16, 2014, 03:36:46 pm »

Thats awesome morleydev! I may have a look through some the games I have written and take screenshots
Logged
Hehe, you thought there would be an interesting sig here

I now run a program which brings old multiplayer games back to life : click

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5872 on: May 16, 2014, 04:10:08 pm »

See if this works then: [abh-wz]
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral

DrKillPatient

  • Bay Watcher
  • The yak falls infinitely
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5873 on: May 16, 2014, 04:39:14 pm »

See if this works then: [abh-wz]

Well, I know that that particular regex does what I described — what I'm wondering is why the one I mentioned doesn't do the same thing. I'm curious about what the syntax there means, really.
Logged
"Frankly, if you're hanging out with people who tell you to use v.begin() instead of &v[0], you need to rethink your social circle."
    Scott Meyers, Effective STL

I've written bash scripts to make using DF easier under Linux!

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5874 on: May 16, 2014, 05:28:45 pm »

Hi. Quick regex question; I found this in Ruby's documentation:

Code: [Select]
[a-w&&[^c-g]z]
Why does this regex exclude 'z'? My understanding is that it reads "Anything from 'a' to 'w' that is NOT anything from 'c' to 'g' or that is 'z', but it seems I'm not right about the last part.

BTW, here is a handy website for figuring out ruby regexps:  http://rubular.com/


It sounds like the && is an intersect operator(never used it in a regex myself).  So the regular expression is kind of like:

a-w AND (not(c-g) or z).

z doesn't intersect with a-w, so its excluded.  Its essentially means
Code: [Select]
[a-w&&[^c-g]z] is the same as
Code: [Select]
[a-w&&[^c-g]] which is the same as
Code: [Select]
[a-w&&[a-b][h-z]] which is the same as
Code: [Select]
[a-b[h-w]]
« Last Edit: May 16, 2014, 05:33:29 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Angle

  • Bay Watcher
  • 39 Indigo Spear Questions the Poor
    • View Profile
    • Agora Forum Demo!
Re: if self.isCoder(): post() #Programming Thread
« Reply #5875 on: May 16, 2014, 08:48:37 pm »

Alright, so I've got my Perplexicon RL game, right? Right now I'm trying to program items to take damage. The problem here is that I have a variety of effects that can happen from damage, and I want to keep open the possibility of modding in more. I'm thinking of having the attack have a list of damage types- Electric, peircing, peicing+, impaling, crushing, burning, etc. then I'll have a soft-coded list of scripts, one for each type of damage, that calculate the effects of that damage. So if you decide to add void damage, or sonic damage, or whatever, you can simply modify the item information and add a script for it. This is fairly complicated, but it's possible, and even if difficult at least I'll be doing something instead of sitting here failing to make any kind of decision. I'll be soft-coding the scripts in groovy, and using one of these techniques to import them into java. Can anyone think of a better way to do things?
Logged

Agora: open-source platform to facilitate complicated discussions between large numbers of people. Now with test site!

The Temple of the Elements: Quirky Dungeon Crawler

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5876 on: May 17, 2014, 06:13:34 am »

I don't think you need that many types of damage at all. Give items a single HP value, and give them three damage multipliers: against blunt damage (crushing, sonic, void, impact), pierce damage (piercing, impaling, cutting) and heat damage (electric, burning). All other damage types are usually close to one of those three.
Logged

Kassire

  • Bay Watcher
  • The damning skull motif
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5877 on: May 18, 2014, 05:08:28 pm »

Am I an idiot? I've been working with the unity3d 2d tools (Sample assets) and for some reason the box collider 2d won't work as I'm trying to have the player be on the ground and the player is just clipping through the ground. 
Logged
All shall be well, and all shall be well and all manner of thing shall be well

alexandertnt

  • Bay Watcher
  • (map 'list (lambda (post) (+ post awesome)) posts)
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5878 on: May 18, 2014, 08:45:24 pm »

Am I an idiot? I've been working with the unity3d 2d tools (Sample assets) and for some reason the box collider 2d won't work as I'm trying to have the player be on the ground and the player is just clipping through the ground.

Some things to try:

  • Are the player and the ground on the same layer?
  • Are either colliders marked as a trigger (triggers won't physically collide with anything)
  • Are you accidently mixing 2d and 3d colliders/rigidbodies
  • Is everything scaled properly? i.e. no microscopic player and floors. (compare it to a default cube, which is 1m x 1m x 1m)
Logged
This is when I imagine the hilarity which may happen if certain things are glichy. Such as targeting your own body parts to eat.

You eat your own head
YOU HAVE BEEN STRUCK DOWN!

Lightningfalcon

  • Bay Watcher
  • Target locked. Firing main cannon.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5879 on: May 18, 2014, 08:50:00 pm »

I have a question.  I have an RSA program where I can specify the size of two different prime numbers.  How do I calculate the size of the number they form when multiplied?
Logged
Interdum feror cupidine partium magnarum circo vincendarum
W-we just... wanted our...
Actually most of the people here explicitly wanted chaos and tragedy. So. Uh.
Pages: 1 ... 390 391 [392] 393 394 ... 796