Hello.
I'm trying to interpret chaotic input and reassess it in a readable manner. This is fairly easy to do if the input is static.
Consider the following example, copied from an OGame espionage report:
[code]
Small Cargo 406 Large Cargo 1.062
Light Fighter 8.438 Heavy Fighter 82
Cruiser 300 Battleship 1.500
[/code]
It looks horrible that way, I want to assess the different values to textboxes for a neat overview.
Normally, I'd do this with ReadLines and Split.
However, consider the next example:
[code]
Small Cargo 406 Large Cargo 1.062
Cruiser 300 Battleship 1.500
[/code]
Now lets imagine the player with the ships in the first example didn't have the light and heavy fighters. This causes the input to be non-static, rendering ReadLines useless because ReadLines(1) wouldn't consist of the values for the light and heavy fighters any longer, but rather cruiser and battleships.
I seriously can't put my head around this problem, can someone help me develop a solid method for interpreting the input correctly?
Every solution I've though of and tried have required a static input.
I'm not sure if I understand your problem correctly, but what stops you from reading the input line for line and only evaluating one line at once?
I know, sorry, it's really difficult to explain.
As I tried to show with the two examples, the content of the espionage report depends on what ships the player has.
Lets consider the first espionage example. The player has the following ships:
[code]
Small Cargo 406 Large Cargo 1.062
Light Fighter 8.438 Heavy Fighter 82
Cruiser 300 Battleship 1.500
[/code]
Now lets imagine that player didn't actually have any light or heavy fighters, ideally it would look like this:
[code]
Small Cargo 406 Large Cargo 1.062
Light Fighter 0 Heavy Fighter 0
Cruiser 300 Battleship 1.500
[/code]
It would make it possible to evaluate the input line by line because I could just gather programatically that the player doesn't have any light or heavy fighters.
However, the actual input looks like this if the player doesn't have have any light or heavy fighters:
[code]
Small Cargo 406 Large Cargo 1.062
Cruiser 300 Battleship 1.500
[/code]
As you can tell, the line that [I]should[/I] be telling me the amount of light and heavy fighters is now telling me the amount of cruisers and battleships instead. So if I programatically read the second line, it'll give me false results because it is looking for the light and heavy fighters (which doesn't exist because the player doesn't have them), thus causing the textboxes that [I]should[/I] contain the values for light and heavy fighters to contain the values of cruisers and battleships.
Hope that clears something up.
You have to parse every line and find out which ships are in it. [url=http://en.wikipedia.org/wiki/Regular_expression]Regular expressions[/url] make it extremely easy.
All you have to do is use them to split each line in shipname, number of ships, shipname, number of ships and find the correct text boxes based on the shipname and set them to the correct amount of ships.
Would it help if I showed you how to do it with pseudo code? I don't know any VB.
Yes, please show me. I'm not sure I understand.
[cpp]String line;
while((line=readLine())!=null){
Regex regex=new Regex("(\w[\w\s]*?)\s(\d+?)");
while(regex.findNextMatch(line)){
String shipname=regex.group(1);
int count=regex.group(2);
Textbox tb=getCorrectTextbox(shipname);
tb.setText(count);
}
}[/cpp]
You'll have to google how to use regular expressions in .NET
I've been watching a tutorial on YouTube and it is very straight forward with the input used in the video, I just can't get it to work with my input. I've tried using your regex but I have absolutely no clue how that works.
Link to video, if it helps: [url]http://www.youtube.com/watch?annotation_id=annotation_986812&feature=iv&v=SUmSwV2lZ9U[/url]
I fully understand what you want me to do here:
[quote]All you have to do is use them to split each line in shipname, number of ships, shipname, number of ships and find the correct text boxes based on the shipname and set them to the correct amount of ships.[/quote]
I just have no idea how to translate that to code.
Can someone help me, please? I've been trying but I can't figure it out.
Just look for a regular expression tutorial for VB.net. Google isn't hard, and regular expressions aren't hard.
Here's one, for example: [url]http://visualbasic.about.com/od/usingvbnet/a/RegExNET.htm[/url]
I can get the ship names, the problem is getting the amount of ships without getting the rest of the line, too.
I tried using <ship name>\d{1,5} but that also return the next shipname on the line. I'm really puzzled.
Sorry if I'm being dumb here, I have never worked with this before and I'm having a hard time putting my head around it.
Couldn't you just split each line and use if statements?
Something like this:
[code]Dim tmp() As String = Split(CurrentLine)
Dim i as integer=-1
Do Until i>=tmp.lenght
i+=1
if tmp(i)="Small" and tmp(i+1)="Cargo" then
SmallCargos=tmp(i+2)
i+=2
elseif tmp(i)="Light" and tmp(i+1)="Fighter" then
LightFighter= tmp(i+2)
i+=2
end if
Loop[/code]You get the idea.
Ohh and you should add some lenght tests. and or start at the smallest ones first. (Cruiser and Battleship)
That's actually a good idea, I'll see if I can get it to work later. I thought about something similar but couldn't comprehend it at the time.
Thanks!
Sorry, you need to Log In to post a reply to this thread.