Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 677 678 [679] 680 681 ... 795

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

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10170 on: October 31, 2016, 11:46:13 am »

You get a pointer to the first element, then go to the "next" pointer for that, and so on, until you hit a null, which means end-of-list. This is just how a basic linked list works. You have a pointer for "head" and that's it, and you follow the pointers until you run out of list.
« Last Edit: October 31, 2016, 11:49:55 am by Reelya »
Logged

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10171 on: October 31, 2016, 05:57:12 pm »

You could also just get a forward iterator to the first element and then use that to iterate.
Yeah a forward iterator is basically a standardized way to automatically handle all the for loop + this = this.next stuff without you needing to manually worry about it.
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10172 on: October 31, 2016, 06:36:54 pm »

Is anyone familiar with clustering algorithms?

Say I have a finite set of numbers. I want to divide this set into k partitions such that the sum of the variances of each set's consecutive differences is minimized, assuming all sets are ordered.

Is there a suitable algorithm for this? I'm thinking k-means can be modified to do this but is there a better approach?
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Elephant Parade

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10173 on: October 31, 2016, 09:52:25 pm »

Working on an assignment for my Computer Science class. For some reason, my second System.in.read() just doesn't work, and I haven't been able to fix it or figure out why.

Code: [Select]
class ConstructedPower {
    int base, exponent;
   
    ConstructedPower(int bs, int exp) {
        base = bs;
        exponent = exp;
    }
   
    double getValue() {
       
        if(exponent < 0) {
            System.out.println("ERROR: exponent below 0");
            return 0;
        }
        else return Math.pow(base, exponent);
    }
   
    double customValue() throws java.io.IOException {
        int[] baseArray = {2, 10, 16};
        int[] exponentArray = {1, 2, 4};
       
        System.out.println("INPUT BASE - A = 2, B = 10, C = 16, D = EXIT");
        char ch = (char) System.in.read();
       
        if(ch == 'A') base = baseArray[0];
        if(ch == 'B') base = baseArray[1];
        if(ch == 'C') base = baseArray[2];
        if(ch == 'D') {
            System.out.println("QUITTING");
            return 0;
        }
       
        System.out.println("INPUT EXPONENT - A = 1, B = 2, C = 4, D = EXIT");
        ch = (char) System.in.read(); // this usually doesn't trigger. why? I have no idea!
       
        if(ch == 'A') exponent = exponentArray[0];
        if(ch == 'B') exponent = exponentArray[1];
        if(ch == 'C') exponent = exponentArray[2];
        if(ch == 'D') {
            System.out.println("QUITTING");
            return 0;
        }
       
        return Math.pow(base, exponent);
    }
}

public class SanePower {
    public static void main(String[] args) throws java.io.IOException {
        System.out.println("Initializing...");
       
        ConstructedPower newPower = new ConstructedPower(2, 2);
       
        double a = newPower.getValue();
        System.out.println(a);
       
        double b;
       
        do {
            b = newPower.customValue();
            System.out.println(b);
        }
        while(b != 0);
       
    }
}

I hate to just dump a bug on the thread like this, but it's too late in the evening to contact the professor, the assignment is (weirdly) due at midnight, and I legitimately have no clue what's causing this.

edit: never mind, figured it out. I feel pretty silly now.
« Last Edit: October 31, 2016, 10:07:53 pm by Elephant Parade »
Logged

Avis-Mergulus

  • Bay Watcher
  • This adorable animal can't work.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10174 on: November 01, 2016, 04:58:49 am »

Ignore me.
I can do that.

...Well, shit.
Logged
“See this Payam!” cried the gods, “He deceives us! He cruelly abuses our lustful hearts!”

Parsely

  • Bay Watcher
    • View Profile
    • My games!
Re: if self.isCoder(): post() #Programming Thread
« Reply #10175 on: November 08, 2016, 04:13:08 pm »

edit: never mind, figured it out. I feel pretty silly now.
That's normal. I just spent an hour or so reading about Twitter APIs only to find that Twitter has a function in the settings to generate the HTML for an embedded Twitter timeline for you. One copy-paste job and googling of parameters to give it the desired styling, and the goal was achieved. And it only took 5 minutes.
Logged

sprinkled chariot

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10176 on: November 10, 2016, 05:01:15 pm »

Ehm, how are beam/laser weapons usually made codewise?  ???

Cant figure, how to make one, which stops upon hitting something, without everything looking awful.

 1) uninterrupting stream of small projectiles starts looking like wave emitter, if fired not in 90/180/360/0 degrees direction, unless our projectiles are 1 x 1 pixel
2) creating single object with animation and fully animated sprite bumps into the problem of having to add  several more pixels on each of  800 animation frames frames
3) just having one very long object has problem of hitting everything on its way
Logged

Dozebôm Lolumzalěs

  • Bay Watcher
  • what even is truth
    • View Profile
    • test
Re: if self.isCoder(): post() #Programming Thread
« Reply #10177 on: November 10, 2016, 05:03:29 pm »

You don't make them codewise, you start with a beam weapon and then you code the interface.

:P
Logged
Quote from: King James Programming
...Simplification leaves us with the black extra-cosmic gulfs it throws open before our frenzied eyes...
Quote from: Salvané Descocrates
The only difference between me and a fool is that I know that I know only that I think, therefore I am.
Sigtext!

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10178 on: November 10, 2016, 05:10:08 pm »

There is no good way to answer that without any other information. Look into raycasting, maybe?

As for the sprite, can't you just have a short sprite and repeat it as many times as neccessary? Sure, you might have to cut off a little on at least one side, but it seems the best solution for something that isn't a simple gradient beam.
« Last Edit: November 10, 2016, 05:12:52 pm by miauw62 »
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.

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10179 on: November 10, 2016, 05:11:30 pm »

You map a texture onto a "beam"of arbitrary length, or draw all pixels along a line, or...
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10180 on: November 10, 2016, 05:13:04 pm »

You map a texture onto a "beam"of arbitrary length, or draw all pixels along a line, or...
Exactly.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10181 on: November 11, 2016, 01:17:43 am »

For the edges use some alpha blending or anti-aliasing, too, which will make it look more laser-like or less jaggy/pixelated.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10182 on: November 13, 2016, 08:07:25 am »

When you log in to public wi-fi, often there's a landing page with a button you have to press before it'll let you actually connect to the Internet. How is this done? I assume it's the local network serving its own page to a new user when it first requests something, but what is the more specific answer?
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Shadowlord

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10183 on: November 13, 2016, 11:53:03 am »

I don't know how they do it, but I know how I would do it: Devices on a network send their MAC address in the packets they send (it isn't sent outside the network, however). Since this is a unique identifier for the network card (or equivalent), it's possible to use it to fingerprint devices on a network. This would require keeping a hashtable or the like of known mac addresses and whether they've agreed to the terms. I would expect that it would be possible to filter all network traffic by anyone who hasn't agreed and redirect them to the agreement page when they try to use a web browser.
Logged
<Dakkan> There are human laws, and then there are laws of physics. I don't bike in the city because of the second.
Dwarf Fortress Map Archive

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10184 on: November 13, 2016, 12:26:56 pm »

This would require keeping a hashtable or the like of known mac addresses and whether they've agreed to the terms. I would expect that it would be possible to filter all network traffic by anyone who hasn't agreed and redirect them to the agreement page when they try to use a web browser.
Pretty much, though most of them only keep you in the list for a rather short time, (an hour or so is pretty common) and then dump you from it.

As for how they actually do it, the most common way is just intercepting all DNS requests from unauthenticated clients and repointing them at their own pages (it's basically a codified man-in-the-middle attack, set up so that it has absolute minimum impact on the network outside itself). The other way you'll sometimes see it set up is just basically by setting up an ICMP redirect that pushes all unauthorized clients onto their own page no matter where they go.
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.
Pages: 1 ... 677 678 [679] 680 681 ... 795