Thanks, for algorithm. used to convert Coordinate notations to SAN in (White Side).
ps. remark dancing popup msgbox.
#include <Array.au3>
;#include <String.au3>
Global $board[9][9]
Local $FEN= "rnbqkb1r/ppppp1bp/5p1p/5N2/3P4/5N2/PPP1PPPP/RN1QKB1R w KQkq - 0 5"
; Standard starting position (FEN)"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
; => position - player - castling - enpassent target - 50 move rule - move number
_EPD_Board_SetUp($FEN)
MsgBox($MB_SYSTEMMODAL, "BOARD", _EPD_Board_Show())
Local $CON= "f5g7" ; Coordinate notation
_contoSAN($CON)
Func _EPD_Board_SetUp($FEN)
Local $forsythEdwards, $edwardsForsyth, $fenBoard, $castlingOptions, $piece, $y, $x, $kings[2]
$forsythEdwards = StringSplit($FEN, " ")
$castlingOptions = $forsythEdwards[3] ; To be used as search criteria.
$edwardsForsyth = StringReverse($forsythEdwards[1]) ; Sets up the pieces from black's POV.
$fenBoard = StringSplit($edwardsForsyth, "/") ; Separates the eight ranks of the chessboard.
For $i = 8 To 1 step -1; ranks 1 to 8
$y = $i ; vertical coordinate
$x = 1 ; horizontal coordinate
For $j = StringLen($fenBoard[$i]) To 1 step -1
If StringIsDigit(StringMid($fenBoard[$i], $j, 1)) Then ; Indicates one or more unoccupied squares.
For $k = 1 To StringMid($fenBoard[$i], $j, 1)
$board[$y][$x] = "-"
$x += 1
Next
Else
$piece = StringMid($fenBoard[$i], $j, 1)
$board[$y][$x] = $piece ; Places chess pieces on the chessboard.
MsgBox($MB_SYSTEMMODAL, $y&":"&$x, $piece,0.31)
Select ; To keep tabs on king coordinates for later reference.
Case $piece == "K"
$kings[0] = $y & $x ; White king location
Case $piece == "k"
$kings[1] = $y & $x ; Black king location
EndSelect
$x += 1
EndIf
Next
Next
EndFunc
Func _EPD_Board_Show()
local $m
For $y = 1 To 8
For $x = 1 To 8
$m &= $board[$y][$x]
Next
$m &= @CRLF
Next
Return $m
EndFunc
Func _contoSAN($CON)
local $a = StringMid($CON, 1, 1)
local $Y = StringMid($CON, 2, 1), $X
If $a = "a" Then
$X=1
ElseIf $a = "b" Then
$X=2
ElseIf $a = "c" Then
$X=3
ElseIf $a = "d" Then
$X=4
ElseIf $a = "e" Then
$X=5
ElseIf $a = "f" Then
$X=6
ElseIf $a = "g" Then
$X=7
ElseIf $a = "h" Then
$X=8
EndIf
local $PIECE = $board[$Y][$X]
If $PIECE = "P" or $PIECE = "p" Then ; NO purIFY needed BESTMOVE CORDINATE NOTATION for pawn
$SAN = $CON
Else ; purIFY BESTMOVE CORDINATE NOTATION TO SAN
$SAN = $board[$Y][$X]
$SAN = StringUpper($SAN)
$SAN &= $CON
EndIf
MsgBox($MB_SYSTEMMODAL, "_contoSAN", "CON: "& $CON&@CRLF&@CRLF&$X&":"&$Y& " PIECE: "& $PIECE&@CRLF&@CRLF&"SANmove: "&$SAN)
return $SAN
EndFunc