SmasherStarting to get dizzyRegistered Userregular
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.
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.
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
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
0
jackalFuck Yes. That is an orderly anal warehouse.Registered Userregular
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.
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.
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.
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
0
marty_0001I am a fileand you put documents in meRegistered Userregular
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_0001I am a fileand you put documents in meRegistered Userregular
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
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.
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.
0
jackalFuck Yes. That is an orderly anal warehouse.Registered Userregular
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
0
marty_0001I am a fileand you put documents in meRegistered Userregular
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
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.
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.
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.
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?
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.
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.
Posts
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.
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.
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.
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.
Switch: SW-3515-0057-3813 FF XIV: Q'vehn Tia
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.
I heard Bloodshed Dev-C++ is good; is that true?
Seriously, did you just unironically type, "micro$oft"?
/. is :arrow:
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.
to
and the same for setting your max.
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
Intellisense too if you're into that sort of thing.
Code::Blocks is the one I use on linux, by the way.
SE++ Forum Battle Archive
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.
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).
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.
I guess emacs is a car that can turn into a space shuttle if you throw enough lisp at it.
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
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.
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.
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.
AC City folk=2965-2082-7154
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
AKA [PA]Ilovepandas
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.
AKA [PA]Ilovepandas
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.