Raised This Month: $ Target: $400
 0% 

String manipulation fun!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flynn
Senior Member
Join Date: Sep 2009
Old 09-22-2009 , 20:47   Re: String manipulation fun!
Reply With Quote #1

Quote:
Originally Posted by PM View Post
The result of true + true is always 2. But when you assign the result, 2, back to a bool variable, the integer result 2 automatically gets converted to bool which is != 0 so it becomes "true".
Aye, and that is why the StringSwapper hack works - it's abusing that logic.

Quote:
Originally Posted by PM View Post
This conversion is why MSVC outputs a warning on bool c = true + true;
Which would be an issue with typecasting (MSVC is known for making complaints about 'security' of string copiers recommending no less... MS's very own implementation!). However, it's typically handled by default. You really want to convert it to a bool...

bool a = !!(true + true).

Done. But a waste of time and more obscure. And a waste of two additional operations (double inversion... waste of time really).

Besides, bits in memory have to work with that 'one-way' toggle so they retain the information.
Quote:
Originally Posted by Theme97 View Post
Since you're not casting it to a bool, "(true+true+true)" evaluates to "(1+1+1)" = 3.
I answered that already. B1 and B2 (Boolean 1 and Boolean 2) are... uh... Booleans.

Well, beats trying to explain dynamically allocated memory using pointers to pointers.
Quote:
Originally Posted by Theme97 View Post
Of course, both of these aren't very efficient. Not only will most compilers optimize out the temporary variable for a swap, but this method also kills threading because each statement relies on the previous.
I was trying a smartalex-y attempt (that didn't go too well ) at some bit operations (as you can see with the demo image in the previous post) but I just ended up noticing it worked quite nicely as a single (kind of) line string-swapper if I only tacked it to a loop.

So now we have a substring remover, a last substring remover (* 3) and a stringswapper. I suppose the next stage would be a substring... swapper? Or maybe a substring replacer? Maybe a stringreverser? Or a substring reverser?

Or, if you're feeling more ambitious, a loop that... calculates every possible letter combination of a string. I never even scratch the surface with that ages ago, couldn't be arsed.

Or, something that's probably more practical; a random substring swapper; one that finds a single word in a string of words, and replaces that word with underscores, and the aim is the player has to guess what that randomly chosen substring is.

Or a string scrambler based on an encryption chiper string that uses it to also decryption. Too many ideas...

How about some mathematical functions instead?
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Theme97
Senior Member
Join Date: Mar 2009
Old 09-22-2009 , 21:17   Re: String manipulation fun!
Reply With Quote #2

Quote:
Originally Posted by Flynn View Post
Or, if you're feeling more ambitious, a loop that... calculates every possible letter combination of a string. I never even scratch the surface with that ages ago, couldn't be arsed.
Did something similar for Project Euler in PHP, but alas, the code is on the other computer.

Mathematical functions might be nice to obfuscate.
__________________
I now have very little time to work on stuff and my main computer (which is the only one that can run TF2) is not cooperating with me, so don't expect many updates from me anytime soon.

[ALL] Karaoke
[TF2] Intel Timer | Crabmod | Randomizer | Stopwatch | Crits 4 All
Theme97 is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-23-2009 , 01:05   Re: String manipulation fun!
Reply With Quote #3

Quote:
Originally Posted by Theme97 View Post
Did something similar for Project Euler in PHP, but alas, the code is on the other computer.
Yeah. Useful for brute force hacking or paranoid re-arrangements of words to look for hidden meanings (I would love it for both).

Quote:
Originally Posted by Theme97 View Post
Mathematical functions might be nice to obfuscate.
A physics thing I wrestled with (but with far more expanded stuff for our case); code that works out the speed of two objects based on their mass and distance from each other (Advanced; calculate multiple objects and their impacts on each other) with a maximum velocity cap, with almost no movement at great distances, minor movement at medium distances, and great movement at close distances.

Ensure the object does not 'sling-shot' pass (and does not infinitely loop back) and sits on top of the object of mass. Can be 2D or 3D.

This might be harder without graphics or classes to work with. If you can think of something better, shoot for it. I'm up quite late.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Theme97
Senior Member
Join Date: Mar 2009
Old 09-23-2009 , 02:26   Re: String manipulation fun!
Reply With Quote #4

Agh I'm not knowledgable enough. Just began my first year of physics.

However, I could really use something similar to this (given object A, point B, and X frames, move A to B but only decelerate; 2D) for another plugin of mine, so it would be nice to know what algorithm to use.

Maybe I'll figure it out some day (i.e. when I'm not procrastinating schoolwork). I'm pretty sure I'll need a constant of deceleration, though.
__________________
I now have very little time to work on stuff and my main computer (which is the only one that can run TF2) is not cooperating with me, so don't expect many updates from me anytime soon.

[ALL] Karaoke
[TF2] Intel Timer | Crabmod | Randomizer | Stopwatch | Crits 4 All
Theme97 is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-23-2009 , 08:28   Re: String manipulation fun!
Reply With Quote #5

Quote:
Originally Posted by Greyscale View Post
Works out the speed based on mass and distance from each other? What speed?
Sorry, I should have provided context. Space.

Typically all objects have a continuous although very very very slight gravitation pull at a distance (apparently far away black holes have the same impact as the 'beating of a gnat's wings', if I recall correctly) which increases as the objects get closer.

My function was a lot simpler; drawing two objects together based on mass. One student had told me writing such a function was impossible (I doubted that given gravity exists and that's technically a 'mathematical function'). I missed out on physics and mathematics largely (which is a pity - I enjoyed both), but I figured speed = (mass1 + mass2)/distance (if I recall correctly) and started working on momentum and potential momentum (as all objects would gain so much speed they would overshoot on every pass). I noticed gravitation pull had 'rings' and as you pass each one, the speed would exponentially increase. Although my theories and that of other people rarely coincide.

I throw this up here as inter-related gravitation pull of various interstellar objects would be incredibly useful, whether as studying for physics generally or a more specific space-based game (I had ideas for the latter but various things meant I abandoned the project).

I'd say stick to the 2D axis, as 3D axis can be expanded from the 2D axis (if we start 3D we would have too many variables to keep track of).
Quote:
Originally Posted by PM View Post
Haha, I would still just love to know what need there is to abuse that logic if the OR operator does exactly what you want without abusing any logic -- or is it just to be more obscure?
I suppose to be more obscure. An OR operator could work in it's place, but I find adding booleans makes the code look more interesting. Plus, I wouldn't have learnt anything if I hadn't.

Bitwise physics abuse. The problem with me doing anything physics as I previously mentioned is I missed out on both physics and mathematics. I can quickly grasp and create new theories rapidly, so the physics isn't such a biggie; it's the mathematics. I might have an idea that could calculate the universe, but without knowing mathematical functions I wouldn't be able to write it (or would get bogged down re-writing mathematical functions).

Even my barrel launcher based on client eye angles uses my own written calculus to work out the directional velocity because I don't know anything about functions that convert angles to co-ordinates...

PHP Code:
    GetClientEyeAngles(client,ang);
    
    
answer ang[1];
    
    if(
RoundToFloor(answer) > -181 && RoundToFloor(answer) < 0)
    {
        
answer float(RoundToFloor(answer) * -1)
    }
    
    if(
RoundToFloor(answer) < 91 && RoundToFloor(answer) > -1)
    {
        
answer float(90 RoundToFloor(answer));
        
vel[0] = float(40 RoundToFloor(answer));
    }
    
    if(
RoundToFloor(answer) > 90 && RoundToFloor(answer) < 181)
    {
        
answer float(RoundToFloor(answer) - 90);
        
vel[0] = float(-40 RoundToFloor(answer));
    }
    
    
answer ang[1];
    
    if(
RoundToFloor(answer) < -91 && RoundToFloor(answer) > -181)
    {
        
answer float(-180-RoundToFloor(answer));
    }
    
    if(
RoundToFloor(answer) > 90 && RoundToFloor(answer) < 181)
    {
        
answer float(180-RoundToFloor(answer));
    }
    
    if(
RoundToFloor(answer) > -91 && RoundToFloor(answer) < 91)
    {
        
vel[1] = float(40 RoundToFloor(answer));
    }

    
vel[2] = float(-40 RoundToFloor(ang[0])); 
It's not like it's non-functional (quite the opposite, it's quite precise), just it's a wasted effort figuring out formulae for something that's already done. I just can't learn mathematics because it truly is written like absolute gibberish. It's the only subject area who's language I know makes up symbols or steals other symbols whether they want to represent whatever they can't be arsed to explain because it's too damn complex.
Quote:
Originally Posted by Theme97 View Post
However, I could really use something similar to this (given object A, point B, and X frames, move A to B but only decelerate; 2D) for another plugin of mine, so it would be nice to know what algorithm to use.
You don't need to know physics or mathematics to get what you want, but it helps.

Simply put, you get the two co-ordinates, using py's theorem (Which is two X co-ords added together times by themselves, the two Y co-ords added together times by themselves, add the two answers, square root the answer), calculate the distance between the two, divide that distance by the speed so you get the frame spacing (these are sometimes called 'steps').

This is the part I can't tell you how to do (although there are mathematical functions for this), calculate the angle between the two points and the horizontal line, then convert the angle into co-ordinates by combining (again with a mathematical function) angle with the frame spacing/steps, and keep running those steps until you change the speed, when you'll need to recalculate the steps.

Change speed over time by storing the time it starts, seeing the elapsed time since starting, whether or not it exceeds X, increasing it and resetting it if it has.

Edit: Thats wrong. That's acceleration. Deceleration would be division. To change speed just modify the speed and recalculate the steps.

In short?

Speed = Speed + (X.Units * Time.Units)
Distance = ((X+X2)* + (Y+Y2)*)(SquareRoot the answer)
Steps = Distance/Speed
Current X,Y = Steps+Angles (Not literally add - you need to combine to two using RadToSine or whatever).

Done. But this is what I mean about my lack of mathematical knowledge.

Last edited by Flynn; 09-23-2009 at 08:33.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
Theme97
Senior Member
Join Date: Mar 2009
Old 09-23-2009 , 18:27   Re: String manipulation fun!
Reply With Quote #6

Well, my approach now.

Since this is in TF2, I've got to used 3D coords but I set everything on the Z axis equal to each other.

So, given:
- Float:start[3]
- Float:end[3]
- Float:deceleration (positive) = -a
- frames = t

Then under the formula vf = vi + at
Since vf is 0, we can conclude that vi = -at

So, for Float:velocity and Float:accel,
PHP Code:
MakeVectorFromPoints(startendvelocity);
NormalizeVector(velocity);
accel velocity;
ScaleVector(velocitydecel frames);
ScaleVector(accel, -deceleration); 
From there on, it's just a matter of doing
PHP Code:
AddVectors(velocityaccelvelocity); 
every game frame which ends up sounding a lot easier than what you had suggested. D:

---

Edit: Also, angle between two vectors v1 and v2:

In code:
PHP Code:
stock Float:AngleBetweenVectors(const Float:a[3], const Float:b[3]) {
    return 
ArcCosine(GetVectorDotProduct(ab) / (GetVectorLength(a) * GetVectorLength(b)));

__________________
I now have very little time to work on stuff and my main computer (which is the only one that can run TF2) is not cooperating with me, so don't expect many updates from me anytime soon.

[ALL] Karaoke
[TF2] Intel Timer | Crabmod | Randomizer | Stopwatch | Crits 4 All

Last edited by Theme97; 09-24-2009 at 00:17.
Theme97 is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-23-2009 , 19:24   Re: String manipulation fun!
Reply With Quote #7

Quote:
Originally Posted by Theme97 View Post
Also, angle between two vectors v1 and v2:

In code:
PHP Code:
stock Float:AngleBetweenVectors(const Float:a[3], const Float:b[3]) {
    return 
ArcCosine(GetVectorLength(a) * GetVectorLength(b) / GetVectorDotProduct(ab));

Isn't that exactly the wrong way round? This way you'd be dividing by zero for 90 degrees.
AFAIK it should be arccos( v1 dot v2 / (||v1|| * ||v2||) ) .
__________________
hello, i am pm
PM is offline
Flynn
Senior Member
Join Date: Sep 2009
Old 09-24-2009 , 04:55   Re: String manipulation fun!
Reply With Quote #8

Quote:
Originally Posted by Greyscale View Post
You want to find the gravitational pull between 2 objects?

Simple.

Fg = G((m1*m2)/r^2)

I believe that's it.
I'll have to look up G. It's some tiny constant I can google it right now... 6.67300 × 10^-11 m^3 kg^-1 s^-2

You can ignore those intimidating units.

m1/2 are the masses of the objects and r is the radius. The distance between the objects. It's refered to as radius because normally your calculating from the center of a large mass such as earth.

This equation is how you derive the -9.81 m/s^2 constant for earth.

Fg is the force of gravity, in newtons. That's pretty much all I can think that you need to know.

Here's a more in-depth description: http://en.wikipedia.org/wiki/Gravitational_constant
Those kinds of theories make my eyes glass over. Besides I'm sure density of the matter would be involved (probably in the process of the ...
{
Hold on a minute. Light is apparently 'massless'? So how does a dense black hole pull it in if there is no mass in which to...

Or, unless light does have a mass, which means mass can travel at the speed of light. Which means we could slow down time for an object... just be a little... gooey... on the other end. Unless of course you just send information. Information can't be crushed.

(This is how my brain works!)
}
... mass itself) however, it's easier to just give it X mass and use that as the force as well (although it isn't very scientific, games don't have to be unless you're trying to precisely simulate something).

But what about multiple units? What direction does a mass head in based on the pull of two (or more) objects? Well, probably in the direction of the strongest mass, but, how do we effectively calculate that?

Wouldn't it be easier to combine the force of two or more objects and have that influence the object at greater distances and then as it gets closer make them separate?
Quote:
Originally Posted by Theme97 View Post
Since this is in TF2, I've got to used 3D coords but I set everything on the Z axis equal to each other.
It's the same method but you have to factor in angle calculations on the other 'planes'. And probably would need a way to combine the three calculated distances of the three separate triangles (again, one for each plane) or something.

But that's sketchy at best. I haven't even done the 2D version let alone the 3D one.
Flynn is offline
Send a message via MSN to Flynn Send a message via Skype™ to Flynn
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 09-23-2009 , 04:39   Re: String manipulation fun!
Reply With Quote #9

Quote:
Originally Posted by Flynn View Post
Aye, and that is why the StringSwapper hack works - it's abusing that logic.
Haha, I would still just love to know what need there is to abuse that logic if the OR operator does exactly what you want without abusing any logic -- or is it just to be more obscure?
__________________
hello, i am pm
PM is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode