Jump to content

Recommended Posts

Posted

Hey everybody.... I'm having a tough go at solving this problem.

So I'm trying to read through a file line by line (theres one of 2 characters B or P on each line).

I have certain patterns that I need to be identified. Let's just start with a simple example:

B

B

B

P

B

So one of the patterns I'm looking for is 2 or more of the same character.

How can I compare previous lines in a file such that it will recognize 3 B's, but also recognize that the pattern is over when it comes to the P?

Posted

Hey everybody.... I'm having a tough go at solving this problem.

So I'm trying to read through a file line by line (theres one of 2 characters B or P on each line).

I have certain patterns that I need to be identified. Let's just start with a simple example:

B

B

B

P

B

So one of the patterns I'm looking for is 2 or more of the same character.

How can I compare previous lines in a file such that it will recognize 3 B's, but also recognize that the pattern is over when it comes to the P?

Not sure if this will work exactly for your purposes, but something along these lines:

_FileReadToArray(), concatenate, StringInStr(), or alternatively you can just do a FileRead(), StringStripCR() and then StringInStr()

[u]You can download my projects at:[/u] Pulsar Software
Posted (edited)

I should also mention that I need to compare a prediction to the next line that will be read.

Here is my NON-WORKING code, but maybe it will give you an idea of what I'm after. The problem with this code is that I don't think I've used a correct method for giving a handle to next line to be read.

CODE

$file = FileOpen("results.txt", 0)

; Error If File Can't Open

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

;Read Every Line

$count = 0

$i = 1

While $i > 0

$i = $i

$i1 = $i - 1

$next = $i + 1

$currentLine = FileReadLine($file, $i)

$lastLine = FileReadLine($file, $i1)

$nextLine = FileReadLine($file, $next)

$prediction = ""

;2 or More

If $lastLine = $currentLine Then

$prediction = $currentLine

EndIf

If $prediction = $nextLine Then

$count = $count + 1

Else

$count = $count - 1

EndIf

MsgBox(0, "Count", $count)

$i = $i + 1

WEnd

Edited by Aeterna
Posted

I guess I don't understand what you are trying to accomplish.

What kind of report do you want your script to give when it is done analyzing the file?

[u]You can download my projects at:[/u] Pulsar Software
Posted

Basically its a betting script. It's reading through the lines finding patterns, and making a bet, or prediction about what the next line will be based on those patterns. If the bet is right, the total goes up, if the bet is wrong, the total goes down.

I have the logic and the patterns, just trying to translate it into programming.

Posted (edited)

is this more or less what you want?

#include <File.au3>
$file = FileOpen("results.txt", 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$prediction = ""
$count = 0
$linecount = _FileCountLines("results.txt")
For $i = 1 to $linecount
    $currentLine = FileReadLine($file, $i)
    $lastLine = FileReadLine($file, $i - 1)
    $nextLine = FileReadLine($file, $i + 1)
    If $lastLine = $currentLine Then
        $prediction = $currentLine
    EndIf
    If $prediction = $nextLine Then
        $count = $count + 1
    Else
        $count = $count - 1
    EndIf
Next

MsgBox(64,"Count",$count)

Edit: it doesn't take into account when there is no next line however

Edited by maqleod
[u]You can download my projects at:[/u] Pulsar Software
Posted

I'm writing a program to test some betting logic I have for the game Baccarat.

So here's the gist of the program. It reads through the file "results.txt" which is about 60,000 lines, with 1 character each ("B", or "P"). On each line it reads, it tests for some patterns in the previous lines, and then makes a prediction about the next line. If the prediction = the value of the next line, the total goes up by 1 and the program repeats line by line.

CODE

$include <File.au3>

$file = FileOpen("results.txt", 0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

$prediction = ""

$count = 0

$linecount = _FileCountLines("results.txt")

For $i = 1 to $linecount

$currentLine = FileReadLine($file, $i)

$lastLine = FileReadLine($file, $i - 1)

$nextLine = FileReadLine($file, $i + 1)

; If the last 2 or more results were the same, bet that it will be the same again

If $lastLine = $currentLine Then

$prediction = $currentLine

EndIf

If $prediction = $nextLine Then

$count = $count + 1

Else

$count = $count - 1

EndIf

;Other Logic To Go Below

Next

I wanted to to kind of show you guys the direction I want to go with this program, and see if I'm doing it the right way, or if somebody has a better way?

Alternatively, I can give the logic to a more capable programmer and we can all just get rich playing baccarat if it works haha!

Posted

I think this whole direction might be wrong. I moved this thread to the General help forum, I guess I put it here mistakenly by accident it doesn't really belong in GUI.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...