[QUOTE=ThePuska;47556096]If you're using integers and they're bounded within, say, a few million or less, instead of sorting the array, create a bitfield of all the integers within the range (where a bit is set if the integer exists). Then the algorithm runs in linear time.
edit:
[cpp]#include <vector>
#include <algorithm>
// Fixing the integer overflow bugs in the implementation is left as an exercise to the reader
bool can_sum(const std::vector<int> &nums, int sum)
{
// Special case: The vector doesn't have enough elements for a sum.
if(nums.size() < 2) {
return false;
}
auto bounds = std::minmax_element(nums.begin(), nums.end());
int b_min = *bounds.first;
int b_max = *bounds.second;
if(b_min == b_max) {
// Special case: There is only one distinct element in the vector.
return sum == b_min + b_max;
}
// Create the bitfield: Initialize all bits to 0, then set the bits which
// correspond to integers in the vector.
std::vector<bool> bits(1 + b_max - b_min, false);
for(int i : nums) {
bits[i - b_min] = true;
}
// Check all integers, see if we have any integer 'i' for which there
// exists another integer 'p' so that 'i + p = sum'
for(int i : nums) {
int p = sum - i;
if(bits[p - b_min]) {
return true;
}
}
// No such integer exists
return false;
}[/cpp][/QUOTE]
Oh yeah! You could in fact just use a HashSet for more or less linear time. I remember I was thinking about that but dismissed it for some reason.
updated my own smartpointer class in cpp...
doing so i got reunited with some almost forgotten cpp keywords
and introduced to new usecases for well known keywords
you always learn something new in cpp!
[img]http://i.imgur.com/XzAQ5nh.png[/img]
Circles are hard.
I'm working on this game thing again
[img]http://i.imgur.com/IhkoIS7.gif[/img]
Made a simple effects system, with a coin pickup effect to test it. I'll be able to use it to show enemies dying, attacks hitting, etc.
[QUOTE=Fourier;47557287]- snip -[/QUOTE]
[code]
public void DrawCircle(Vec2i Pos, int Rad = 200) {
if (Rad < 0)
Rad *= -1;
int D = (5 - Rad * 4) / 4;
int X = 0;
int Y = Rad;
do {
if (Pos.X + X >= 0 && Pos.X + X <= WH.X - 1 && Pos.Y + Y >= 0 && Pos.Y + Y <= WH.Y - 1)
DrawPoint(Pos.X + X, Pos.Y + Y);
if (Pos.X + X >= 0 && Pos.X + X <= WH.X - 1 && Pos.Y - Y >= 0 && Pos.Y - Y <= WH.Y - 1)
DrawPoint(Pos.X + X, Pos.Y - Y);
if (Pos.X - X >= 0 && Pos.X - X <= WH.X - 1 && Pos.Y + Y >= 0 && Pos.Y + Y <= WH.Y - 1)
DrawPoint(Pos.X - X, Pos.Y + Y);
if (Pos.X - X >= 0 && Pos.X - X <= WH.X - 1 && Pos.Y - Y >= 0 && Pos.Y - Y <= WH.Y - 1)
DrawPoint(Pos.X - X, Pos.Y - Y);
if (Pos.X + Y >= 0 && Pos.X + Y <= WH.X - 1 && Pos.Y + X >= 0 && Pos.Y + X <= WH.Y - 1)
DrawPoint(Pos.X + Y, Pos.Y + X);
if (Pos.X + Y >= 0 && Pos.X + Y <= WH.X - 1 && Pos.Y - X >= 0 && Pos.Y - X <= WH.Y - 1)
DrawPoint(Pos.X + Y, Pos.Y - X);
if (Pos.X - Y >= 0 && Pos.X - Y <= WH.X - 1 && Pos.Y + X >= 0 && Pos.Y + X <= WH.Y - 1)
DrawPoint(Pos.X - Y, Pos.Y + X);
if (Pos.X - Y >= 0 && Pos.X - Y <= WH.X - 1 && Pos.Y - X >= 0 && Pos.Y - X <= WH.Y - 1)
DrawPoint(Pos.X - Y, Pos.Y - X);
if (D < 0) {
D += 2 * X + 1;
} else {
D += 2 * (X - Y) + 1;
Y--;
}
X++;
} while (X <= Y);
}
[/code]
[editline]19th April 2015[/editline]
[img]http://i.imgur.com/yg8D6n6.png[/img]
[QUOTE=cartman300;47557306][code]
public void DrawCircle(Vec2i Pos, int Rad = 200) {
if (Rad < 0)
Rad *= -1;
int D = (5 - Rad * 4) / 4;
int X = 0;
int Y = Rad;
do {
if (Pos.X + X >= 0 && Pos.X + X <= WH.X - 1 && Pos.Y + Y >= 0 && Pos.Y + Y <= WH.Y - 1)
DrawPoint(Pos.X + X, Pos.Y + Y);
if (Pos.X + X >= 0 && Pos.X + X <= WH.X - 1 && Pos.Y - Y >= 0 && Pos.Y - Y <= WH.Y - 1)
DrawPoint(Pos.X + X, Pos.Y - Y);
if (Pos.X - X >= 0 && Pos.X - X <= WH.X - 1 && Pos.Y + Y >= 0 && Pos.Y + Y <= WH.Y - 1)
DrawPoint(Pos.X - X, Pos.Y + Y);
if (Pos.X - X >= 0 && Pos.X - X <= WH.X - 1 && Pos.Y - Y >= 0 && Pos.Y - Y <= WH.Y - 1)
DrawPoint(Pos.X - X, Pos.Y - Y);
if (Pos.X + Y >= 0 && Pos.X + Y <= WH.X - 1 && Pos.Y + X >= 0 && Pos.Y + X <= WH.Y - 1)
DrawPoint(Pos.X + Y, Pos.Y + X);
if (Pos.X + Y >= 0 && Pos.X + Y <= WH.X - 1 && Pos.Y - X >= 0 && Pos.Y - X <= WH.Y - 1)
DrawPoint(Pos.X + Y, Pos.Y - X);
if (Pos.X - Y >= 0 && Pos.X - Y <= WH.X - 1 && Pos.Y + X >= 0 && Pos.Y + X <= WH.Y - 1)
DrawPoint(Pos.X - Y, Pos.Y + X);
if (Pos.X - Y >= 0 && Pos.X - Y <= WH.X - 1 && Pos.Y - X >= 0 && Pos.Y - X <= WH.Y - 1)
DrawPoint(Pos.X - Y, Pos.Y - X);
if (D < 0) {
D += 2 * X + 1;
} else {
D += 2 * (X - Y) + 1;
Y--;
}
X++;
} while (X <= Y);
}
[/code]
[editline]19th April 2015[/editline]
[img]http://i.imgur.com/yg8D6n6.png[/img][/QUOTE]
Oooh, the perfect circle on any resolution, now that is harder :v:
Meet our robot for the Spring 2015 CSU Mechanical Enginnering 202 Ram Lander competition. Final calibrations right before the competition. Made it actually work! The goal was to move the ping pong ball over a two foot wall and place it, more or less consistently, into a licence plate holder nailed to the table behind the wall. Not bad for a month of work!
I programmed our Arduino 30 minutes before leaving for the competition.
[media]http://www.youtube.com/watch?v=-g-qfvslfcg[/media]
I'm thinking of making a video with most of the build and testing process, but I have better things to do right now. Like finally start working on my game again!!
Also, have the report's title page
[img]http://i.imgur.com/SI1iz8E.jpg[/img]
139 pages long, 17642 words, about 200 diagrams/drawings; most of it was written in the last 2 days before the due date. I could upload it if you'd like to see it. Full instructions for how to buiuld it and why it's designed how it is.
Space Cruiser vs Cruiser.
[IMG]http://s1.postimg.org/wdegyvabj/op2.png[/IMG]
I've begun the process of rewriting the code for units, because the earlier code was horridly written, involving collision detection and path-finding, when I could have made it so that the pathing never moves into blocked squares, negating the need for collision detection. Not to mention that the code was filled with garbage code that didn't do anything, dead code, code that didn't make sense, etc.
Playing around with material design.
[t]http://i.imgur.com/oKZhu7o.png[/t]
I'm working on a small infrastructure for testers to try stuff.
This is how the files for software look like:
[t]http://i.imgur.com/cuhwbdP.png[/t]
The 1.zip file contains the thing that then gets unpacked and ran, the downloadtype is there in case I want the download to be available from a external server different from the master one, by changing it to external, the filetype part is because I'm not only going to be distributing executable stuff, but flash extensions too, so I could change that to "flash" and then the software would know it is a flash extension that it needs to install.
I forgot to share this in here, but yesterday when I was streaming, I fleshed out more of the [url=http://www.andrewmcwatters.com/grid/tutorials/Getting_Started]Getting Started[/url] and [url=http://www.andrewmcwatters.com/grid/tutorials/Callbacks]Callbacks[/url] articles on the Grid engine's site.
[img_thumb]http://i.imgur.com/rvcwsqE.png[/img_thumb]
[img_thumb]http://i.imgur.com/FwCzpHO.png[/img_thumb]
It's still pretty rough; there's a lot more for me to add, but it's some progress.
My Ludum Dare game, Killer Moves, for the theme "An Unconventional Weapon".
Destroy your opponent's Ego by defeating him in a dance off! :)
[vid]https://s3-eu-west-1.amazonaws.com/files.facepunch.com/adam/2015/April/20/killermoves5.mp4[/vid]
I didn't know that Ernő Rubik was a game developer.
[QUOTE=Rocket;47559763]who is facepunchad??[/QUOTE]
[url=http://facepunch.com/showthread.php?t=1426623&p=46063898#post46063898]Adam Woolridge[/url]
My half-baked Ludum Dare thingie:
[img]http://ludumdare.com/compo/wp-content/compo2//444368/18043-shot0-1429488118.png-eq-900-500.jpg[/img]
[url]http://ludumdare.com/compo/ludum-dare-32/?action=preview&uid=18043[/url]
[editline]20th April 2015[/editline]
It's always surprising how a bit of screenshake goes a long way into making your shitty game feel less shitty.
[QUOTE=Clavus;47559873]My half-baked Ludum Dare thingie:
[img]http://ludumdare.com/compo/wp-content/compo2//444368/18043-shot0-1429488118.png-eq-900-500.jpg[/img]
[url]http://ludumdare.com/compo/ludum-dare-32/?action=preview&uid=18043[/url]
[editline]20th April 2015[/editline]
It's always surprising how a bit of screenshake goes a long way into making your shitty game feel less shitty.[/QUOTE]
[img]http://i.imgur.com/IggMS0B.png[/img]
[QUOTE=Ott;47559900][img]http://i.imgur.com/IggMS0B.png[/img][/QUOTE]
Hm, Linux I guess? Make sure you're opening the .love with LÖVE 0.9.2.
[QUOTE=Clavus;47559962]Hm, Linux I guess? Make sure you're opening the .love with LÖVE 0.9.2.[/QUOTE]
Works fine on Windows 8.1!
[editline]20th April 2015[/editline]
It's fun, the old typing game mechanic was getting repetitive and this is a nice refresher.
[QUOTE=Clavus;47559962]Hm, Linux I guess? Make sure you're opening the .love with LÖVE 0.9.2.[/QUOTE]
Oops, I was running 0.9.1
Just had a weekend doing absolutely nothing when it comes to coding, right after 4 stressful weeks (cause of procrastination). Quite sure I asked this before, but what do you guys use to plan? I have trouble breaking up jobs in parts and trouble working without a schedule. Any tools tactics? I have a ton of things I could do, just don't manage my time and end up doing nothing for a while because I lack overview and think "ah, I'll have time for games now"
[QUOTE=Cyberuben;47560181]Just had a weekend doing absolutely nothing when it comes to coding, right after 4 stressful weeks (cause of procrastination). Quite sure I asked this before, but what do you guys use to plan? I have trouble breaking up jobs in parts and trouble working without a schedule. Any tools tactics? I have a ton of things I could do, just don't manage my time and end up doing nothing for a while because I lack overview and think "ah, I'll have time for games now"[/QUOTE]
I find this tactic I posted about before works for me:
[url]http://facepunch.com/showthread.php?t=1458662&p=47437747&viewfull=1#post47437747[/url]
I don't really end up sticking to even my most well-made plans, so instead of making a plan at all I take this approach to get me to mentally segregate time and tasks. Maybe it will work for you
[QUOTE=Trumple;47560204]I find this tactic I posted about before works for me:
[url]http://facepunch.com/showthread.php?t=1458662&p=47437747&viewfull=1#post47437747[/url]
I don't really end up sticking to even my most well-made plans, so instead of making a plan at all I take this approach to get me to mentally segregate time and tasks. Maybe it will work for you[/QUOTE]
But this all hindsight. That wouldn't work for me sadly. This'll not avoid my problem but prove it in the end .
[QUOTE=andrewmcwatters;47559386]I forgot to share this in here, but yesterday when I was streaming, I fleshed out more of the [URL="http://www.andrewmcwatters.com/grid/tutorials/Getting_Started"]Getting Started[/URL] and [URL="http://www.andrewmcwatters.com/grid/tutorials/Callbacks"]Callbacks[/URL] articles on the Grid engine's site.
[img_thumb]http://i.imgur.com/rvcwsqE.png[/img_thumb]
[img_thumb]http://i.imgur.com/FwCzpHO.png[/img_thumb]
It's still pretty rough; there's a lot more for me to add, but it's some progress.[/QUOTE]
I'm getting an odd bug on your site, I don't think I got it before:
[vid]https://dl.dropboxusercontent.com/u/10518681/Screenshots/2015-04-20_02-34-04.webm[/vid]
The compression kind of masks it but the sub-categories flicker when I reload
[editline]20th April 2015[/editline]
[QUOTE=Cyberuben;47560218]But this all hindsight. That wouldn't work for me sadly. This'll not avoid my problem but prove it in the end .[/QUOTE]
Maybe so, but I find it helps in the present, not just hindsight. When you start a task, you physically mark it by typing in the current time. That seems to work for me because it puts me in work mode. If I find myself procrastinating, I remember that I'm timing myself and I get back to work faster. Likewise, when you "stamp out", you mentally separate work and you can enjoy the time between tasks a lot more. As such, it's not only for looking back on in hindsight.
I've gone through 4 years of Uni, struggling to stick to schedules, procrastinating, all of what you mentioned above. Only in the past few months I tried this tactic and I find it works a lot better for me at least. It isn't perfect, but combine it with a little session at the start of the day where you plan what you're aiming to do, it might just help
[sp]Time planners HATE him, try this one simple trick[/sp]
Bit more progress! Bed now.
[vid]https://s3-eu-west-1.amazonaws.com/files.facepunch.com/adam/2015/April/20/killer_moves.mp4[/vid]
[vid]http://a.pomf.se/ovznag.webm[/vid]
Finally got my movement script done: it is a crazy mix of Half Life/Quake 3 CPM/Fortress Forever's movement. It allows bunny-hopping, strafe jumping and trimping! Walking down slopes is no longer bouncy, too.
Music is Quad Machine by Sonic Mayhem, from the Quake 2 OST
Emojis, timestamps, and unique user names! :eng101:
[IMG]http://i.imgur.com/l46OtMg.png[/IMG]
I replace the chars with unicode for the emojis. The next hurdle is correctly adding a custom font for better emojis.
Each client can change their user name as well!
[QUOTE=Trumple;47560221]I'm getting an odd bug on your site, I don't think I got it before:
-vid-
The compression kind of masks it but the sub-categories flicker when I reload
[/QUOTE]
I guess when I updated the sidebar animations, I ended up designing it in a way that looks like an [url=https://github.com/Planimeter/grid/blob/master/app/scripts/directives/sidebar.js#L42]unintentional rendering glitch than an intentional one.[/url] I didn't feel right about how it ended up, either. I should readdress that later.
[QUOTE=andrewmcwatters;47560872]I guess when I updated the sidebar animations, I ended up designing it in a way that looks like an [url=https://github.com/Planimeter/grid/blob/master/app/scripts/directives/sidebar.js#L42]unintentional rendering glitch than an intentional one.[/url] I didn't feel right about how it ended up, either. I should readdress that later.[/QUOTE]
I always thought it looked kind of neat.
I've been wanting to develop a library that allowed people to chain transitions for different degrees of motion, which you usually see in cinematic work.
Unfortunately, I haven't made the time for it because GTA V has been sucking away at my life force.
The headers in the sidebar were meant to fade in per-character in ease-out quintic time, whilst each individual character also quickly randomly changed over time but slowed down over ease-out quintic time.
To do this requires two degrees of transitions, which require a lot more lines of code with something like GSAP.
[QUOTE=andrewmcwatters;47560953]I've been wanting to develop a library that allowed people to chain transitions for different degrees of motion, which you usually see in cinematic work.
Unfortunately, I haven't made the time for it because GTA V has been sucking away at my life force.
The headers in the sidebar were meant to fade in per-character in ease-out quintic time, whilst each individual character also quickly randomly changed over time but slowed down over ease-out quintic time.
To do this requires two degrees of transitions, which require a lot more lines of code with something like GSAP.[/QUOTE]
The current effect has a sort of charm to me; it reminds me of a row of old, fluorescent light bulbs powering up. I consider it a happy accident, albeit needing some tweaking.
Sorry, you need to Log In to post a reply to this thread.