[R] Texte mapping
Posté : lun. 01 août 2016 21:52
Bonjour à tous, je me suis lancer dans un casse tête sans nom et je viens demander de l'aide ! 
Le but est de lire un fichier et naviguer à l’intérieur lettre par lettre (imaginons que une lettre = une case dans un jeu).
0 = mur
1 = chemin
S = (1) = start
E = (1) = End
map.txt

Le but est de lire un fichier et naviguer à l’intérieur lettre par lettre (imaginons que une lettre = une case dans un jeu).
0 = mur
1 = chemin
S = (1) = start
E = (1) = End
map.txt
Code : Tout sélectionner
S1111
10101
11111
10101
1111E
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>
#include <Array.au3>
#OnAutoItStartRegister"Dellog"
Global $MAP_PATH = @ScriptDir & "\map.txt" ;Chemin du fichier
Global $LOG_PATH = @ScriptName & ".log"
Global $X_MAX = _FileCountLines($MAP_PATH) ;Compte les lignes
Global $CMDRETURN ;Stock le contenu du retour console
Global $POS_ACTUAL_Y ;Position actuelle Y
Global $POS_ACTUAL_X ;Position actuelle X
Global $POS_LAST_Y ;Position précédente Y
Global $POS_LAST_X ;Position précédente X
Global $POS_START_Y ;Position de départ Y
Global $POS_START_X ;Position de départ X
Global $POS_END_Y ;Position de d'arrivée Y
Global $POS_END_X ;Position de d'arrivée X
Global $POS_MAX_Y ;Position maximum Y
Global $POS_MAX_X = $X_MAX ;Position maximum X
Global $TOTAL1 ;Total de 1
Global $TOTAL0 ;Total de 0
Global $MAP ;Array qui stock le fichier
Global $ERRORGO = "0"
Global $ERRORREAD = "0"
_ANALYZE() ;Analyser le fichier
_GetInfo() ;En tirer des informations
If $POS_START_Y And $POS_START_X And $POS_END_Y And $POS_END_X = "0" Then Exit ;Si aucun départ / arrivée
If $POS_START_Y And $POS_START_X And $POS_END_Y And $POS_END_X = "" Then Exit ;Si aucun départ / arrivée
_FileReadToArray($MAP_PATH, $MAP) ;Ecris le fichier dans l'array
$POS_ACTUAL_Y = $POS_START_Y ;ACTUAL = START
$POS_ACTUAL_X = $POS_START_X ;ACTUAL = START
$POS_LAST_X = $POS_START_X ;LAST = START
$POS_LAST_Y = $POS_START_Y ;LAST = START
HotKeySet("{ESC}", "_EXIT") ;Up presser
HotKeySet("{UP}", "_HOTUP") ;Up presser
HotKeySet("{DOWN}", "_HOTDOWN") ;Down presser
HotKeySet("{LEFT}", "_HOTLEFT") ;Left presser
HotKeySet("{RIGHT}", "_HOTRIGHT") ;Right presser
While 1
Sleep(100) ;Boucle d'attente de touche
WEnd
Func _ANALYZE()
Local $X_ACTUAL = 1
While $X_ACTUAL <= $X_MAX ;Boucle jusqu'à la dernière ligne
If $X_ACTUAL <> "1" Then $CMDRETURN &= @CRLF ;Ajout au Return console
Local $X_READ = FileReadLine($MAP_PATH, $X_ACTUAL) ;Lire la ligne
Local $X_LENGHT = StringLen($X_READ) ;Longueur de la chaine
If $X_LENGHT > $POS_MAX_Y Then $POS_MAX_Y = $X_LENGHT ;Ecrire la plus grosse valeur dans $POS_MAX_Y
Local $Y_ACTUAL = 1
While $Y_ACTUAL <= $X_LENGHT ;Boucle pour chaque lettres de la chaine
$Y_READ = _GetY($X_READ, $Y_ACTUAL) ;Lire la lettre actuelle de la boucle
$CMDRETURN &= $Y_READ ;Ajout au Return console
;~ _Log($X_ACTUAL & ";" & $Y_ACTUAL & "|" & $Y_READ & @CRLF) ;Ecrire Console l'état actuel
$Y_ACTUAL = $Y_ACTUAL + 1
WEnd
$X_ACTUAL = $X_ACTUAL + 1
WEnd
_Log($CMDRETURN & @CRLF) ;Ecrire Console le résultat final
$CMDRETURN = "" ;Reset du return
EndFunc ;==>_ANALYZE
Func _Direction($startposx, $startposy, $endposx, $endposy)
Local $direction
If $startposx < $endposx Then
$direction &= "Down" ;Down
Else
$direction &= "Up" ;Up
EndIf
If $startposy < $endposy Then
$direction &= "Right" ;Right
Else
$direction &= "Left" ;Left
EndIf
Return $direction
EndFunc ;==>_Direction
Func _NEAR($posx, $posy, $lastx, $lasty)
Local $Return
Local $left = _ReadLeft($posx, $posy)
If $left = "1" Or $left = "S" Or $left = "E" Then
$Return &= "[LEFT]"
_Log("[LEFT]")
EndIf
Local $right = _ReadRight($posx, $posy)
If $right = "1" Or $right = "S" Or $right = "E" Then
$Return &= "[RIGHT]"
_Log("[RIGHT]")
EndIf
Local $up = _ReadUp($posx, $posy)
If $up = "1" Or $up = "S" Or $up = "E" Then
$Return &= "[UP]"
_Log("[UP]")
EndIf
Local $down = _ReadDown($posx, $posy)
If $down = "1" Or $down = "S" Or $down = "E" Then
$Return &= "[DOWN]"
_Log("[DOWN]")
EndIf
_Log(@CRLF)
EndFunc ;==>_NEAR
Func _GetInfo()
Local $X_ACTUAL = 1
While $X_ACTUAL <= $X_MAX ;Boucle jusqu'à la dernière ligne
Local $X_READ = FileReadLine($MAP_PATH, $X_ACTUAL) ;Lire la ligne
Local $X_LENGHT = StringLen($X_READ) ;Longueur de la chaine
Local $Y_ACTUAL = 1
While $Y_ACTUAL <= $X_LENGHT ;Boucle pour chaque lettres de la chaine
$Y_READ = _GetY($X_READ, $Y_ACTUAL) ;Lire la lettre actuelle de la boucle
If $Y_READ = "S" Then
$POS_START_X = $X_ACTUAL
$POS_START_Y = $Y_ACTUAL
_Log("START[" & $X_ACTUAL & ";" & $Y_ACTUAL & "]")
ElseIf $Y_READ = "E" Then
$POS_END_X = $X_ACTUAL
$POS_END_Y = $Y_ACTUAL
_Log("END[" & $X_ACTUAL & ";" & $Y_ACTUAL & "]")
ElseIf $Y_READ = "1" Then
$TOTAL1 = $TOTAL1 + 1
ElseIf $Y_READ = "0" Then
$TOTAL0 = $TOTAL0 + 1
EndIf
$Y_ACTUAL = $Y_ACTUAL + 1
WEnd
$X_ACTUAL = $X_ACTUAL + 1
WEnd
_Log("Total[1:" & $TOTAL1 & " 0:" & $TOTAL0 & "]")
Local $POS_DIRECTION = _Direction($POS_START_X, $POS_START_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
EndFunc ;==>_GetInfo
Func _GetX()
Local $Get = $POS_ACTUAL_X
Return $Get
EndFunc ;==>_GetX
Func _GetY($str, $pos)
Local $Get = StringMid($str, $pos, 1)
;~ _Log("STRINGMID=" & $Get & @CRLF)
If $Get = "" Then Return "error"
Return $Get
EndFunc ;==>_GetY
Func _HOTLEFT()
_GoLeft($POS_ACTUAL_X, $POS_ACTUAL_Y)
If Not @error Then _NEAR($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_LAST_X, $POS_LAST_Y)
EndFunc ;==>_HOTLEFT
Func _HOTRIGHT()
_GoRight($POS_ACTUAL_X, $POS_ACTUAL_Y)
If Not @error Then _NEAR($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_LAST_X, $POS_LAST_Y)
EndFunc ;==>_HOTRIGHT
Func _HOTDOWN()
_GoDown($POS_ACTUAL_X, $POS_ACTUAL_Y)
If Not @error Then _NEAR($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_LAST_X, $POS_LAST_Y)
EndFunc ;==>_HOTDOWN
Func _HOTUP()
_GoUp($POS_ACTUAL_X, $POS_ACTUAL_Y)
If Not @error Then _NEAR($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_LAST_X, $POS_LAST_Y)
EndFunc ;==>_HOTUP
Func _GoLeft($posx, $posy)
If $posy - 1 < 1 Then
;~ _Log("GoLeft ERROR" & @CRLF)
$ERRORGO = "1"
Return @error
EndIf
If _ReadLeft($posx, $posy) = "0" Then Return @error
If _ReadLeft($posx, $posy) = "" Then Return @error
_Log("GoLeft" & "[")
$POS_LAST_Y = $POS_ACTUAL_Y
$POS_ACTUAL_Y = $posy - 1
_Log("" & $POS_ACTUAL_Y & ";" & $POS_ACTUAL_X & "]")
Local $POS_DIRECTION = _Direction($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
Return $posx & ";" & $posy - 1
EndFunc ;==>_GoLeft
Func _GoRight($posx, $posy)
If $posy + 1 > $POS_MAX_Y Then
;~ _Log("GoRight ERROR" & @CRLF)
$ERRORGO = "1"
Return @error
EndIf
If _ReadRight($posx, $posy) = "0" Then Return @error
If _ReadRight($posx, $posy) = "" Then Return @error
_Log("GoRight" & "[")
$POS_LAST_Y = $POS_ACTUAL_Y
$POS_ACTUAL_Y = $posy + 1
_Log("" & $POS_ACTUAL_X & ";" & $POS_ACTUAL_Y & "]")
Local $POS_DIRECTION = _Direction($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
Return $posx & ";" & $posy + 1
EndFunc ;==>_GoRight
Func _GoDown($posx, $posy)
If $posx + 1 > $POS_MAX_X Then
$ERRORGO = "1"
;~ _Log("GoDown ERROR" & @CRLF)
Return @error
EndIf
If _ReadDown($posx, $posy) = "0" Then Return @error
If _ReadDown($posx, $posy) = "" Then Return @error
_Log("GoDown" & "[")
$POS_LAST_X = $POS_ACTUAL_X
$POS_ACTUAL_X = $posx + 1
_Log("" & $POS_ACTUAL_X & ";" & $POS_ACTUAL_Y & "]")
Local $POS_DIRECTION = _Direction($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
Return $posx + 1 & ";" & $posy
EndFunc ;==>_GoDown
Func _GoUp($posx, $posy)
If $posx - 1 < 1 Then
;~ _Log("GoUp ERROR" & @CRLF)
$ERRORGO = "1"
Return @error
EndIf
If _ReadUp($posx, $posy) = "0" Then Return @error
If _ReadUp($posx, $posy) = "" Then Return @error
_Log("GoUp" & "[")
$POS_LAST_X = $POS_ACTUAL_X
$POS_ACTUAL_X = $posx - 1
_Log("" & $POS_ACTUAL_X & ";" & $POS_ACTUAL_Y & "]")
Local $POS_DIRECTION = _Direction($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
Return $posx - 1 & ";" & $posy
EndFunc ;==>_GoUp
Func _Read($posx, $posy)
Local $xstr = _ArrayToString($MAP, "|", $posx, $posx)
Local $str = _GetY($xstr, $posy)
Return $str
EndFunc ;==>_Read
Func _ReadLeft($posx, $posy)
Local $xstr = _ArrayToString($MAP, "|", $posx, $posx)
;~ _Log("XLEFT=" & $xstr & @CRLF)
Local $str = _GetY($xstr, $posy - 1)
If $str = $POS_MAX_Y Then Return $ERRORREAD = "1"
If $str = "0" Then Return $ERRORREAD = "1"
;~ _Log("LEFT=" & $str & @CRLF)
Return $str
EndFunc ;==>_ReadLeft
Func _ReadRight($posx, $posy)
Local $xstr = _ArrayToString($MAP, "|", $posx, $posx)
;~ _Log("XRIGHT=" & $xstr & @CRLF)
Local $str = _GetY($xstr, $posy + 1)
If $str = "0" Then Return $ERRORREAD = "1"
If $posy = StringLen($xstr) Then Return $ERRORREAD = "1"
;~ _Log("RIGHT=" & $str & @CRLF)
Return $str
EndFunc ;==>_ReadRight
Func _ReadUp($posx, $posy)
If $posx = "1" Then Return $ERRORREAD = "1"
Local $xstr = _ArrayToString($MAP, "|", $posx - 1, $posx - 1)
;~ _Log("XUP=" & $xstr & @CRLF)
Local $str = _GetY($xstr, $posy)
If $str = "0" Then Return $ERRORREAD = "1"
;~ _Log("UP=" & $str & @CRLF)
Return $str
EndFunc ;==>_ReadUp
Func _ReadDown($posx, $posy)
If $posx = $POS_MAX_X Then Return $ERRORREAD = "1"
Local $xstr = _ArrayToString($MAP, "|", $posx + 1, $posx + 1)
;~ _Log("XDOWN=" & $xstr & @CRLF)
Local $str = _GetY($xstr, $posy)
If $str = "0" Then Return $ERRORREAD = "1"
;~ _Log("DOWN=" & $str & @CRLF)
Return $str
EndFunc ;==>_ReadDown
Func _EXIT()
ShellExecute($LOG_PATH, "", @ScriptDir, "", @SW_MAXIMIZE)
Exit
EndFunc ;==>_EXIT
Func _Log($txt)
ConsoleWrite($txt)
FileWrite($LOG_PATH, $txt)
EndFunc ;==>_Log
Func Dellog()
FileDelete(@ScriptName & ".log")
EndFunc ;==>Dellog
#AutoIt3Wrapper_Change2CUI=y
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>
#include <Array.au3>
#OnAutoItStartRegister"Dellog"
Global $MAP_PATH = @ScriptDir & "\map.txt" ;Chemin du fichier
Global $LOG_PATH = @ScriptName & ".log"
Global $X_MAX = _FileCountLines($MAP_PATH) ;Compte les lignes
Global $CMDRETURN ;Stock le contenu du retour console
Global $POS_ACTUAL_Y ;Position actuelle Y
Global $POS_ACTUAL_X ;Position actuelle X
Global $POS_LAST_Y ;Position précédente Y
Global $POS_LAST_X ;Position précédente X
Global $POS_START_Y ;Position de départ Y
Global $POS_START_X ;Position de départ X
Global $POS_END_Y ;Position de d'arrivée Y
Global $POS_END_X ;Position de d'arrivée X
Global $POS_MAX_Y ;Position maximum Y
Global $POS_MAX_X = $X_MAX ;Position maximum X
Global $TOTAL1 ;Total de 1
Global $TOTAL0 ;Total de 0
Global $MAP ;Array qui stock le fichier
Global $ERRORGO = "0"
Global $ERRORREAD = "0"
_ANALYZE() ;Analyser le fichier
_GetInfo() ;En tirer des informations
If $POS_START_Y And $POS_START_X And $POS_END_Y And $POS_END_X = "0" Then Exit ;Si aucun départ / arrivée
If $POS_START_Y And $POS_START_X And $POS_END_Y And $POS_END_X = "" Then Exit ;Si aucun départ / arrivée
_FileReadToArray($MAP_PATH, $MAP) ;Ecris le fichier dans l'array
$POS_ACTUAL_Y = $POS_START_Y ;ACTUAL = START
$POS_ACTUAL_X = $POS_START_X ;ACTUAL = START
$POS_LAST_X = $POS_START_X ;LAST = START
$POS_LAST_Y = $POS_START_Y ;LAST = START
HotKeySet("{ESC}", "_EXIT") ;Up presser
HotKeySet("{UP}", "_HOTUP") ;Up presser
HotKeySet("{DOWN}", "_HOTDOWN") ;Down presser
HotKeySet("{LEFT}", "_HOTLEFT") ;Left presser
HotKeySet("{RIGHT}", "_HOTRIGHT") ;Right presser
While 1
Sleep(100) ;Boucle d'attente de touche
WEnd
Func _ANALYZE()
Local $X_ACTUAL = 1
While $X_ACTUAL <= $X_MAX ;Boucle jusqu'à la dernière ligne
If $X_ACTUAL <> "1" Then $CMDRETURN &= @CRLF ;Ajout au Return console
Local $X_READ = FileReadLine($MAP_PATH, $X_ACTUAL) ;Lire la ligne
Local $X_LENGHT = StringLen($X_READ) ;Longueur de la chaine
If $X_LENGHT > $POS_MAX_Y Then $POS_MAX_Y = $X_LENGHT ;Ecrire la plus grosse valeur dans $POS_MAX_Y
Local $Y_ACTUAL = 1
While $Y_ACTUAL <= $X_LENGHT ;Boucle pour chaque lettres de la chaine
$Y_READ = _GetY($X_READ, $Y_ACTUAL) ;Lire la lettre actuelle de la boucle
$CMDRETURN &= $Y_READ ;Ajout au Return console
;~ _Log($X_ACTUAL & ";" & $Y_ACTUAL & "|" & $Y_READ & @CRLF) ;Ecrire Console l'état actuel
$Y_ACTUAL = $Y_ACTUAL + 1
WEnd
$X_ACTUAL = $X_ACTUAL + 1
WEnd
_Log($CMDRETURN & @CRLF) ;Ecrire Console le résultat final
$CMDRETURN = "" ;Reset du return
EndFunc ;==>_ANALYZE
Func _Direction($startposx, $startposy, $endposx, $endposy)
Local $direction
If $startposx < $endposx Then
$direction &= "Down" ;Down
Else
$direction &= "Up" ;Up
EndIf
If $startposy < $endposy Then
$direction &= "Right" ;Right
Else
$direction &= "Left" ;Left
EndIf
Return $direction
EndFunc ;==>_Direction
Func _NEAR($posx, $posy, $lastx, $lasty)
Local $Return
Local $left = _ReadLeft($posx, $posy)
If $left = "1" Or $left = "S" Or $left = "E" Then
$Return &= "[LEFT]"
_Log("[LEFT]")
EndIf
Local $right = _ReadRight($posx, $posy)
If $right = "1" Or $right = "S" Or $right = "E" Then
$Return &= "[RIGHT]"
_Log("[RIGHT]")
EndIf
Local $up = _ReadUp($posx, $posy)
If $up = "1" Or $up = "S" Or $up = "E" Then
$Return &= "[UP]"
_Log("[UP]")
EndIf
Local $down = _ReadDown($posx, $posy)
If $down = "1" Or $down = "S" Or $down = "E" Then
$Return &= "[DOWN]"
_Log("[DOWN]")
EndIf
_Log(@CRLF)
EndFunc ;==>_NEAR
Func _GetInfo()
Local $X_ACTUAL = 1
While $X_ACTUAL <= $X_MAX ;Boucle jusqu'à la dernière ligne
Local $X_READ = FileReadLine($MAP_PATH, $X_ACTUAL) ;Lire la ligne
Local $X_LENGHT = StringLen($X_READ) ;Longueur de la chaine
Local $Y_ACTUAL = 1
While $Y_ACTUAL <= $X_LENGHT ;Boucle pour chaque lettres de la chaine
$Y_READ = _GetY($X_READ, $Y_ACTUAL) ;Lire la lettre actuelle de la boucle
If $Y_READ = "S" Then
$POS_START_X = $X_ACTUAL
$POS_START_Y = $Y_ACTUAL
_Log("START[" & $X_ACTUAL & ";" & $Y_ACTUAL & "]")
ElseIf $Y_READ = "E" Then
$POS_END_X = $X_ACTUAL
$POS_END_Y = $Y_ACTUAL
_Log("END[" & $X_ACTUAL & ";" & $Y_ACTUAL & "]")
ElseIf $Y_READ = "1" Then
$TOTAL1 = $TOTAL1 + 1
ElseIf $Y_READ = "0" Then
$TOTAL0 = $TOTAL0 + 1
EndIf
$Y_ACTUAL = $Y_ACTUAL + 1
WEnd
$X_ACTUAL = $X_ACTUAL + 1
WEnd
_Log("Total[1:" & $TOTAL1 & " 0:" & $TOTAL0 & "]")
Local $POS_DIRECTION = _Direction($POS_START_X, $POS_START_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
EndFunc ;==>_GetInfo
Func _GetX()
Local $Get = $POS_ACTUAL_X
Return $Get
EndFunc ;==>_GetX
Func _GetY($str, $pos)
Local $Get = StringMid($str, $pos, 1)
;~ _Log("STRINGMID=" & $Get & @CRLF)
If $Get = "" Then Return "error"
Return $Get
EndFunc ;==>_GetY
Func _HOTLEFT()
_GoLeft($POS_ACTUAL_X, $POS_ACTUAL_Y)
If Not @error Then _NEAR($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_LAST_X, $POS_LAST_Y)
EndFunc ;==>_HOTLEFT
Func _HOTRIGHT()
_GoRight($POS_ACTUAL_X, $POS_ACTUAL_Y)
If Not @error Then _NEAR($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_LAST_X, $POS_LAST_Y)
EndFunc ;==>_HOTRIGHT
Func _HOTDOWN()
_GoDown($POS_ACTUAL_X, $POS_ACTUAL_Y)
If Not @error Then _NEAR($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_LAST_X, $POS_LAST_Y)
EndFunc ;==>_HOTDOWN
Func _HOTUP()
_GoUp($POS_ACTUAL_X, $POS_ACTUAL_Y)
If Not @error Then _NEAR($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_LAST_X, $POS_LAST_Y)
EndFunc ;==>_HOTUP
Func _GoLeft($posx, $posy)
If $posy - 1 < 1 Then
;~ _Log("GoLeft ERROR" & @CRLF)
$ERRORGO = "1"
Return @error
EndIf
If _ReadLeft($posx, $posy) = "0" Then Return @error
If _ReadLeft($posx, $posy) = "" Then Return @error
_Log("GoLeft" & "[")
$POS_LAST_Y = $POS_ACTUAL_Y
$POS_ACTUAL_Y = $posy - 1
_Log("" & $POS_ACTUAL_Y & ";" & $POS_ACTUAL_X & "]")
Local $POS_DIRECTION = _Direction($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
Return $posx & ";" & $posy - 1
EndFunc ;==>_GoLeft
Func _GoRight($posx, $posy)
If $posy + 1 > $POS_MAX_Y Then
;~ _Log("GoRight ERROR" & @CRLF)
$ERRORGO = "1"
Return @error
EndIf
If _ReadRight($posx, $posy) = "0" Then Return @error
If _ReadRight($posx, $posy) = "" Then Return @error
_Log("GoRight" & "[")
$POS_LAST_Y = $POS_ACTUAL_Y
$POS_ACTUAL_Y = $posy + 1
_Log("" & $POS_ACTUAL_X & ";" & $POS_ACTUAL_Y & "]")
Local $POS_DIRECTION = _Direction($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
Return $posx & ";" & $posy + 1
EndFunc ;==>_GoRight
Func _GoDown($posx, $posy)
If $posx + 1 > $POS_MAX_X Then
$ERRORGO = "1"
;~ _Log("GoDown ERROR" & @CRLF)
Return @error
EndIf
If _ReadDown($posx, $posy) = "0" Then Return @error
If _ReadDown($posx, $posy) = "" Then Return @error
_Log("GoDown" & "[")
$POS_LAST_X = $POS_ACTUAL_X
$POS_ACTUAL_X = $posx + 1
_Log("" & $POS_ACTUAL_X & ";" & $POS_ACTUAL_Y & "]")
Local $POS_DIRECTION = _Direction($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
Return $posx + 1 & ";" & $posy
EndFunc ;==>_GoDown
Func _GoUp($posx, $posy)
If $posx - 1 < 1 Then
;~ _Log("GoUp ERROR" & @CRLF)
$ERRORGO = "1"
Return @error
EndIf
If _ReadUp($posx, $posy) = "0" Then Return @error
If _ReadUp($posx, $posy) = "" Then Return @error
_Log("GoUp" & "[")
$POS_LAST_X = $POS_ACTUAL_X
$POS_ACTUAL_X = $posx - 1
_Log("" & $POS_ACTUAL_X & ";" & $POS_ACTUAL_Y & "]")
Local $POS_DIRECTION = _Direction($POS_ACTUAL_X, $POS_ACTUAL_Y, $POS_END_X, $POS_END_Y)
_Log("Direction:" & $POS_DIRECTION & @CRLF)
Return $posx - 1 & ";" & $posy
EndFunc ;==>_GoUp
Func _Read($posx, $posy)
Local $xstr = _ArrayToString($MAP, "|", $posx, $posx)
Local $str = _GetY($xstr, $posy)
Return $str
EndFunc ;==>_Read
Func _ReadLeft($posx, $posy)
Local $xstr = _ArrayToString($MAP, "|", $posx, $posx)
;~ _Log("XLEFT=" & $xstr & @CRLF)
Local $str = _GetY($xstr, $posy - 1)
If $str = $POS_MAX_Y Then Return $ERRORREAD = "1"
If $str = "0" Then Return $ERRORREAD = "1"
;~ _Log("LEFT=" & $str & @CRLF)
Return $str
EndFunc ;==>_ReadLeft
Func _ReadRight($posx, $posy)
Local $xstr = _ArrayToString($MAP, "|", $posx, $posx)
;~ _Log("XRIGHT=" & $xstr & @CRLF)
Local $str = _GetY($xstr, $posy + 1)
If $str = "0" Then Return $ERRORREAD = "1"
If $posy = StringLen($xstr) Then Return $ERRORREAD = "1"
;~ _Log("RIGHT=" & $str & @CRLF)
Return $str
EndFunc ;==>_ReadRight
Func _ReadUp($posx, $posy)
If $posx = "1" Then Return $ERRORREAD = "1"
Local $xstr = _ArrayToString($MAP, "|", $posx - 1, $posx - 1)
;~ _Log("XUP=" & $xstr & @CRLF)
Local $str = _GetY($xstr, $posy)
If $str = "0" Then Return $ERRORREAD = "1"
;~ _Log("UP=" & $str & @CRLF)
Return $str
EndFunc ;==>_ReadUp
Func _ReadDown($posx, $posy)
If $posx = $POS_MAX_X Then Return $ERRORREAD = "1"
Local $xstr = _ArrayToString($MAP, "|", $posx + 1, $posx + 1)
;~ _Log("XDOWN=" & $xstr & @CRLF)
Local $str = _GetY($xstr, $posy)
If $str = "0" Then Return $ERRORREAD = "1"
;~ _Log("DOWN=" & $str & @CRLF)
Return $str
EndFunc ;==>_ReadDown
Func _EXIT()
ShellExecute($LOG_PATH, "", @ScriptDir, "", @SW_MAXIMIZE)
Exit
EndFunc ;==>_EXIT
Func _Log($txt)
ConsoleWrite($txt)
FileWrite($LOG_PATH, $txt)
EndFunc ;==>_Log
Func Dellog()
FileDelete(@ScriptName & ".log")
EndFunc ;==>Dellog