As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/
We're funding a new Acquisitions Incorporated series on Kickstarter right now! Check it out at https://www.kickstarter.com/projects/pennyarcade/acquisitions-incorporated-the-series-2

Giant Programming Clusterfuck++

1161719212263

Posts

  • SmasherSmasher Starting to get dizzy Registered User regular
    edited April 2009
    I'm not sure you need to do anything. The example input you showed before was already sorted by time, so as long as that's assured to be the case in the assignment and you put jobs into the queue in the same order they appear in the file everything should be fine. If they're not guaranteed to be sorted then you'll need to throw all the jobs into an array or something and sort them with one of the standard sorting algorithms (I'm assuming you've already covered that stuff since you're dealing with priority queues; if not there's gobs of information online about sorting).

    What is your goal with the separate if() blocks (such as "if(jobs.getTime() <=10){...}")in your last post? Try it with a few unsorted values and see what happens.

    Smasher on
  • EvigilantEvigilant VARegistered User regular
    edited April 2009
    Smasher wrote: »
    I'm not sure you need to do anything. The example input you showed before was already sorted by time, so as long as that's assured to be the case in the assignment and you put jobs into the queue in the same order they appear in the file everything should be fine. If they're not guaranteed to be sorted then you'll need to throw all the jobs into an array or something and sort them with one of the standard sorting algorithms (I'm assuming you've already covered that stuff since you're dealing with priority queues; if not there's gobs of information online about sorting).

    What is your goal with the separate if() blocks (such as "if(jobs.getTime() <=10){...}")in your last post? Try it with a few unsorted values and see what happens.

    I give. I really appreciate all the help smasher (seriously, thank you), but I decided to turn it in as is, partially completed, rather than go another day late. It's pretty close to what it needed to be, but just that last bit was annoying me. I'll talk with my professor about the project.

    My next project is doublyLinkedList, so that should be fun.

    Evigilant on
    XBL\PSN\Steam\Origin: Evigilant
  • NightslyrNightslyr Registered User regular
    edited April 2009
    Infidel wrote: »
    There's a lot of your stuff all over, so forgive me if I forget something or misunderstood it.

    You have a main game engine that knows pretty much all whats going on right? It can reference the web session, the game objects and players, etc. And the problem is when you pass things down and dig deep enough to reach something like a doAttack method, that method doesn't know about things like the web session.

    I'm in the process of creating a combat engine within the game. Given the way ASP.NET is structured, with each web page having its own corresponding code-behind file, I figured that would be the best way to go. So, the combat engine resides within the combat page's code. But, yes, you have the crux of my problem correct.
    Which is good, because it shouldn't. So you're doing it right, but getting stuck on what is the next step? Pass the results back up! Instead of firing your events to eventually get an attack resolved and wanting to just jam the result text straight into a session, you should be unwinding things and somehow getting that message in a general way back up to the main engine which DOES know things about sessions and other players and such.

    Well, this is what I want to do, I'm just not sure exactly how to do it. I'm not sure how to pass the results back up the chain.
    Many ways to do things, but whatever you do, you should not tie parts of your code and classes to a doAttack type method that don't have anything directly to do with resolving an attack. :) (the players/npc's involved, the weapon, etc.)

    I could probably explain this a hell of a lot better with an example but I don't have much time atm.

    Hmm...this could be my problem. The only thing is that, realistically, an attack does need to know that info. Each attack object has its own properties, but in order to execute, it needs to know things about the attacker and the target. I think, ideally, I'd like to pass the attacker and target into the method as arguments, but I need to look through C#'s event model again to figure out how to do it, if it's even possible.

    I've thought about storing the attacks in a different way. Instead of a character holding the attack objects themselves, they'd merely hold a list of strings representing the names of the attacks they currently have access to. Then, when an attack should be executed, the character would retrieve the proper attack from a prototype registry, and use that to act. But, I'm not entirely sure if that would make the output problem easier to handle.

    Nightslyr on
    PSN/XBL/Nintendo/Origin/Steam: Nightslyr 3DS: 1607-1682-2948
    Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
  • AntishowAntishow Registered User regular
    edited April 2009
    ilmmad wrote: »
    Once while using StumbleUpon I came across a game that was the exact same as yours, with reskinning.

    I'm assuming you came first.

    Maybe? Bill is about 5 years old now, are you thinking of LightBot? That does seem to borrow quite a bit, but still it's much better than my game, so I don't mind :)

    Besides, I'm pretty much ripping off the Island of Dr. Brain anyway, so I deserve it.

    Antishow on
  • jackaljackal Fuck Yes. That is an orderly anal warehouse. Registered User regular
    edited April 2009
    That's pretty cool too. I'm not a big fan of the isometric view because it makes it harder to think about what's left and what's right from the robots perspective. It's funny; unlike yours they allow recursion, so the robot can get stuck in an infinite loop.

    jackal on
  • ZackSchillingZackSchilling Registered User regular
    edited April 2009
    I'll admit, I was pretty disappointed when Bill the Robot couldn't handle recursive functions. I played up until one level where I had to use just about every block of the main loop and the first subroutine and I made an error on the first instruction.

    ZackSchilling on
    ghost-robot.jpg
  • Serious_ScrubSerious_Scrub Registered User regular
    edited April 2009
    Oh man, I thought I was the only one who remembered that Dr Brain minigame. I was thinking about recreating it a while back, but I haven't had much free time. Now I see that there's not just one, but two other people who still remember it.

    Serious_Scrub on
  • Randall_FlaggRandall_Flagg Registered User regular
    edited April 2009
    yo what is a good C IDE

    I heard Bloodshed Dev-C++ is good; is that true?

    Randall_Flagg on
  • lazerbeardlazerbeard Registered User regular
    edited April 2009
    I like Visual Studio Express, I dunno what you guys feel about micro$oft, but if Linux is your thing I've used KDevelop, it wasn't too bad.

    lazerbeard on
  • ZackSchillingZackSchilling Registered User regular
    edited April 2009
    XCode is great if you're on Mac OS X.

    ZackSchilling on
    ghost-robot.jpg
  • jackaljackal Fuck Yes. That is an orderly anal warehouse. Registered User regular
    edited April 2009
    lazerbeard wrote: »
    I like Visual Studio Express, I dunno what you guys feel about micro$oft, but if Linux is your thing I've used KDevelop, it wasn't too bad.

    Seriously, did you just unironically type, "micro$oft"?

    /. is :arrow:

    jackal on
  • marty_0001marty_0001 I am a file and you put documents in meRegistered User regular
    edited April 2009
    OK I'm starting to get a handle on this array business in java. I got a textbook which is a bit... friendlier. It's not quite 'dummies' but it's almost there.

    What's wrong here? I can sum and average the array, but it doesn't like my attempts to find the largest number. Compiles, but gets an out of bounds error.
    class AverageArrayTest {
    	
    	public static void main(String[] args) {
    		
    		int total = 0;
    		float average = 0;
    		int max = 0;
    		
    		int[] scores = { 1, 2, 3, 4, 5 };
    		for (int i= 0; i <= scores.length; i++) {
    			total = total + i;
    			average = (total)/(scores.length);
    			if (max < scores[i]) {
    				max = i;
    			}
    			
    		}
    		System.out.println(total);
    		System.out.println(average);
    		System.out.println(max);
    		}
    }
    

    Basically it picks up the first slot in the array, tests to see if it's bigger than the max value, and then either replaces max with that or loops on to the next slot.

    Just a note: I put the i is less than or equals to length, rather than just less than (which is what I've traditionally seen), because when I tried summing the array, it would leave the last slot out.

    marty_0001 on
  • AntishowAntishow Registered User regular
    edited April 2009
    I think you need to change
    total = total + i;
    

    to
    total = total + scores[i];
    

    and the same for setting your max.

    Antishow on
  • marty_0001marty_0001 I am a file and you put documents in meRegistered User regular
    edited April 2009
    Ah of course. Because i is simply the slot in the array, not the number actually contained in that slot!

    That would explain why the last slot was being "missed" - it wasn't really, it was adding up the positions. Having 1,2,3,4,5 as my array made me think it was doing it almost right :P

    <3 thankyou

    marty_0001 on
  • bowenbowen How you doin'? Registered User regular
    edited April 2009
    VC++.NET has a great C++ IDE.

    Intellisense too if you're into that sort of thing.

    Code::Blocks is the one I use on linux, by the way.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • ASimPersonASimPerson Cold... and hard.Registered User regular
    edited April 2009
    I roll with straight emacs or if I'm feeling fancy Eclipse with CDT.

    ASimPerson on
  • TzyrTzyr Registered User regular
    edited April 2009
    marty_0001 wrote: »
    OK I'm starting to get a handle on this array business in java. I got a textbook which is a bit... friendlier. It's not quite 'dummies' but it's almost there.

    What's wrong here? I can sum and average the array, but it doesn't like my attempts to find the largest number. Compiles, but gets an out of bounds error.
    class AverageArrayTest {
    	
    	public static void main(String[] args) {
    		
    		int total = 0;
    		float average = 0;
    		int max = 0;
    		
    		int[] scores = { 1, 2, 3, 4, 5 };
    		for (int i= 0; i <= scores.length; i++) {
    			total = total + i;
    			average = (total)/(scores.length);
    			if (max < scores[i]) {
    				max = i;
    			}
    			
    		}
    		System.out.println(total);
    		System.out.println(average);
    		System.out.println(max);
    		}
    }
    
    Basically it picks up the first slot in the array, tests to see if it's bigger than the max value, and then either replaces max with that or loops on to the next slot.

    Just a note: I put the i is less than or equals to length, rather than just less than (which is what I've traditionally seen), because when I tried summing the array, it would leave the last slot out.

    marty_0001, I know you said that you put i <= scores.length because it was ignoring the last number, but that would only happen if you were doing something else wrong.

    Accessing scores[6] when there are only 5 numbers in scores will cause the out of bounds error.

    So try it again with i < scores.length and if you are getting it that it misses the last number, post it so we can see what else you have done so we can help.

    And finally, why do you calculate the average every iteration? Because it is not like total where you add it to the result, all you are doing is calculations each time that do nothing.

    What you can do is calculate average = (total)/(scores.length); after the loop, which will get you the same result as what you did, but not doing the extra calculations each time. Notice how the variables in the equation do not use i, which again is why you needed to do that to total.

    Tzyr on
  • zeenyzeeny Registered User regular
    edited April 2009
    ASimPerson wrote: »
    I roll with straight emacs

    zeeny on
  • Smug DucklingSmug Duckling Registered User regular
    edited April 2009
    vim representin' yo

    Smug Duckling on
    smugduckling,pc,days.png
  • bowenbowen How you doin'? Registered User regular
    edited April 2009
    Emacs is fine. Vim is just horrible.

    It's like sure I can drive a car(fancy editor), I can even drive automatic(notepad), but I sure like what the Flintstones have going on there (vim).

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • JHunzJHunz Registered User regular
    edited April 2009
    That's a terrible analogy. vim is more like a car with square wheels

    JHunz on
    bunny.gif Gamertag: JHunz. R.I.P. Mygamercard.net bunny.gif
  • AntinumericAntinumeric Registered User regular
    edited April 2009
    Does anyone have experience with matlab. I am trying to decypher this guys code on mesh deformation.
    I = [];
    [tmp,I(1)] = min(vertex(1,:)+vertex(2,:));
    [tmp,I(2)] = max(vertex(1,:)+vertex(2,:));
    
    // bunch of extraneous code 
    
    L1(I,:) = 0;
    L1(I + (I-1)*n) = 1;   <----- This line right here
    
    

    L is n by n matrix
    L1 is a large square matrix. the marked line is where I have no idea what is going on.

    Antinumeric on
    In this moment, I am euphoric. Not because of any phony god’s blessing. But because, I am enlightened by my intelligence.
  • jackaljackal Fuck Yes. That is an orderly anal warehouse. Registered User regular
    edited April 2009
    JHunz wrote: »
    That's a terrible analogy. vim is more like a car with square wheels

    I guess emacs is a car that can turn into a space shuttle if you throw enough lisp at it.

    jackal on
  • marty_0001marty_0001 I am a file and you put documents in meRegistered User regular
    edited April 2009
    Methods within methods:

    Most of the stuff I've done so far has been in the main method. Now I am trying to call a method, and looping that call continuously until the condition is met. The method being called needs to access and change a class array. It also needs to call another method within that (there is a bit of a hiearchy of methods going on).

    It builds okay but running it results in NullPointerException errors.

    This is where it starts. Since I am getting the errors for the initial startup of the loop, I will probably get the same errors for the other methods.
    
    class ScoreKeeper {
    
    	int[] p1setArray;
    	int[] p2setArray;
    
    	//setScorer method.
    	void sets() {
    		ScoreKeeper  gameScorer = new ScoreKeeper ();
    		while ((p1setArray[0] != 2) && (p2setArray[0] != 2)) {
    			gameScorer.games();
    		}
    		if (p1setArray[0] == 2) {
    			System.out.println("Player 1 wins the match!");
    		}
    		else {
    			System.out.println("Player 2 wins the match!");
    		}
    		
    	}
    	
    	
    	public static void main(String[] args) {
    		ScoreKeeper setScorer = new ScoreKeeper();
    		setScorer.sets();
    	}
    }
    

    1. Arrays are initialized. They only need one slot, and that slot contains an integer, zero (which is the default, yes?)
    2. The main method creates the setScorer object. This runs the sets method.
    3. The sets method creates the gameScorer object. So long as sets != 2, it then runs the games method. It starts at 0, so the loop should execute.

    My object creation is probably lousy - I put the other new's within the methods because I thought this might be causing my problem. But I should create the new objects in the main, right?

    I think my problem is calling methods or creating objects wrong... but I feel like I've followed the textbook example correctly.


    Tzyr: yes I later realised I was calculating the average repeatedly when I tried to calculate the standard deviation (which uses the average). It's all working smooth now :D

    marty_0001 on
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited April 2009
    Ok, now I could be way off base here, but those arrays don't look very initialized to me.

    iTunesIsEvil on
  • bowenbowen How you doin'? Registered User regular
    edited April 2009
    I think in Java they autoinitialize.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • marty_0001marty_0001 I am a file and you put documents in meRegistered User regular
    edited April 2009
    Oops. I thought they did too, but that seems to be only variables. This seems to work:
    int[] p1setArray = new int[1];
    	int[] p2setArray = new int[1];
    

    marty_0001 on
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited April 2009
    marty_0001 wrote: »
    Oops. I thought they did too, but that seems to be only variables. This seems to work:
    int[] p1setArray = new int[1];
    	int[] p2setArray = new int[1];
    
    :^: This makes sense to me.

    I had no idea that an array would ever auto-initialize. A straight-up int? Yeah, that'll autoinit to 0, but not an array.

    iTunesIsEvil on
  • ZackSchillingZackSchilling Registered User regular
    edited April 2009
    In java, arrays autoinitialize to the default values of their type (char arrays are null, boolean arrays are false, int arrays are 0, etc)

    ZackSchilling on
    ghost-robot.jpg
  • JHunzJHunz Registered User regular
    edited April 2009
    Does anyone have experience with matlab. I am trying to decypher this guys code on mesh deformation.
    I = [];
    [tmp,I(1)] = min(vertex(1,:)+vertex(2,:));
    [tmp,I(2)] = max(vertex(1,:)+vertex(2,:));
    
    // bunch of extraneous code 
    
    L1(I,:) = 0;
    L1(I + (I-1)*n) = 1;   <----- This line right here
    
    

    L is n by n matrix
    L1 is a large square matrix. the marked line is where I have no idea what is going on.
    That code is blanking out two rows of the array and replacing them with equivalent rows from an n by n identity matrix, presumably so that it can be used in matrix multiplication later on.
    L1(I,:)=0
    
    rows I(1) and I(2) of the matrix L1 are replaced with all zeros
    L1(I + (I-1)*n) = 1
    
    Let's assume for a moment a 4x4 matrix, and I=[1,2]. This becomes:
    L1([1,2] + ([1,2]-1)*4) = 1
    L1([1,2] + [0,4]) = 1
    L1(1,6) = 1
    This will make elements 1 and 6 of the matrix be set to 1. In a 4 by 4 matrix, elements 1-4 are the first row, 5-8 are the second row, etc. If you try it out with different numbers, you'll find that the 1s inserted are always on the diagonal. See this article if you're still confused about how he's indexing things.

    JHunz on
    bunny.gif Gamertag: JHunz. R.I.P. Mygamercard.net bunny.gif
  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    edited April 2009
    In java, arrays autoinitialize to the default values of their type (char arrays are null, boolean arrays are false, int arrays are 0, etc)
    It makes sense that the individual elements in the array will initialize. Just not the array itself.

    iTunesIsEvil on
  • AntinumericAntinumeric Registered User regular
    edited April 2009
    Thank you very much. That makes perfect sense. Now I can actually understand the formula properly, (something about least squares). The code is stopping the set values from being changed by the multiplication, I think.

    Antinumeric on
    In this moment, I am euphoric. Not because of any phony god’s blessing. But because, I am enlightened by my intelligence.
  • ZackSchillingZackSchilling Registered User regular
    edited April 2009
    In java, arrays autoinitialize to the default values of their type (char arrays are null, boolean arrays are false, int arrays are 0, etc)
    It makes sense that the individual elements in the array will initialize. Just not the array itself.

    Got it. I went back and read the original code. Array references defined as members are automatically initialized to NULL whereas array references defined inline in a method are not. Not that either behavior is particularly useful, beyond potentially saving a little typing in the class definition.

    ZackSchilling on
    ghost-robot.jpg
  • TheBigDaddyDowdTheBigDaddyDowd Registered User regular
    edited April 2009
    I made a program in Microsoft Visual C++ but when I try to run the .exe file on a different computer I always get "Application failed to start because its side by side configuration is incorrect". Can someone tell why I'm getting this and how to stop it?

    TheBigDaddyDowd on
    TheBigDaddyDowd.png
    AC City folk=2965-2082-7154
  • bowenbowen How you doin'? Registered User regular
    edited April 2009
    Sounds like your application needs administrative privileges in vista. I could be wrong though.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • SmasherSmasher Starting to get dizzy Registered User regular
    edited April 2009
    Looks like it's a DLL problem.

    Smasher on
  • InfestedGnomeInfestedGnome Registered User regular
    edited April 2009
    I have a question for PHP.

    I want to read a file, get to a certain line, and then update it.

    Can I use str_replace on fgets while reading through the file to do that, or will that not work?

    Thanks

    InfestedGnome on
    IGsig.jpg
    AKA [PA]Ilovepandas :D
  • ZackSchillingZackSchilling Registered User regular
    edited April 2009
    I have a question for PHP.

    I want to read a file, get to a certain line, and then update it.

    Can I use str_replace on fgets while reading through the file to do that, or will that not work?

    Thanks

    No.

    All that will do is load up the line and create a changed version in memory. You'll have to write back to the file in order to make the change stick. If the length of the line might change as a result of the replace, it might be better just to rewrite the whole file.

    Open up the file with the "r" flag and use a loop or whatever to repeatedly call fgets and throw each and every line into an array. When you get to the line you want to process, use str_replace and then throw it into the array also. Once you're done, close the file and open it again with the "w" flag. This will erase the file and prepare it for writing. Iterate back over the array, using fputs to push each line back into the file. Close it and you're done.

    ZackSchilling on
    ghost-robot.jpg
  • InfestedGnomeInfestedGnome Registered User regular
    edited April 2009
    seems a bit much to just update one part, but if it works Ill try it.

    InfestedGnome on
    IGsig.jpg
    AKA [PA]Ilovepandas :D
  • ZackSchillingZackSchilling Registered User regular
    edited April 2009
    It's not a bit much, it's basically how all file I/O is done. If you want to change a file in the middle and that change is going to alter the length of the file, you're going to have to address the fact that content after the change will need to be shifted left or right.

    There are complex ways around this issue when dealing with incredibly large files, but for small files (under 25MB), forget it. Read in, change, write out.

    ZackSchilling on
    ghost-robot.jpg
This discussion has been closed.