Jump to content
Sign in to follow this  
james3mg

Network Dark Chess

Recommended Posts

james3mg

Hey all...

Another game here...I guess I just like making my own versions of games I find intriguing. Anyway, I used it as an excuse for practicing TCP send/receive functions. This script uses ports 14-17. You can play it against yourself on the same computer...in fact if you launch two copies of the script it will set itself up to do that for you- just click the connect button.

What is dark chess? It's a variant on the game of chess in which you can only see the spaces on the board which you could conceivably occupy on your next turn. There's no check or checkmate...your goal is to capture the King. Also, if your opponent has a piece within your "vision", you can only see that there's a piece there...not what the piece is. So finding the king is really a stab in the dark.

So...I'm calling this 75% done because:

1) it's not pretty :mellow:

2) I know of at least two moves that are missing (castling and pawn promotion at the far end of the board). But I'm no chess master, so there may be others I'm unaware of

3) Everything else works! I've got the pieces set up correctly (queen on her color), moving/capturing and endgame all work correctly. That being said, I don't like some of the methods I used here, so I consider improving those part of the 25% of work still remaining on this game. (For instance, because of how I ended up checking if a space was occupied, it would be incredibly easy for AutoIt'ers to cheat at this game by directly modifying what the label controls read.)

Before someone screams at me...as far as I've read, in dark chess the board is only updated at the BEGINNING of your turn. So if you move adjacent to an enemy piece on your turn but then your opponent moves it out of your vision on their turn, you won't ever know it was there. That's part of the game.

Anyway, I think it's pretty good for a first stab. I hope you enjoy it...let me know what you think or if you find other bugs/missing gameplay I'm unaware of.

#include <GUIConstantsEX.au3>
#include <StaticConstants.au3>
#include <GuiIPAddress.au3>

Global $IsMyTurn=-1, $AdlibRunning=0
Global $MeIn, $MeOut, $ThemIn, $ThemOut

$ConnectGUI=GUICreate("New AutoIt Network Dark Chess game:",360,300)
$ConnectGroup=GUICtrlCreateGroup("Connection options",5,5,350,180)
$ConnectRadioServer=GUICtrlCreateRadio("Host a Dark Chess game",20,40,300,20)
GUICtrlSetState(-1,$GUI_CHECKED)
$ConnectServerIPaddress=GUICtrlCreateLabel("Give the following IP address to your network opponent:"&@CRLF&@IPAddress1,30,60,300,30)

$ConnectRadioClient=GUICtrlCreateRadio("Connect to a Dark Chess game",20,110,300,20)
$ConnectClientLabel=GUICtrlCreateLabel("Enter the IP address of the host below:",30,130,300,20)
GUICtrlSetState(-1,$GUI_DISABLE)
$ConnectClientIPaddress=_GUICtrlIpAddress_Create($ConnectGUI,30,150)
_GUICtrlIpAddress_ShowHide($ConnectClientIPaddress,False)
$ConnectClientFakeIPBox=GUICtrlCreateInput("",30,150,125,25)
GUICtrlSetState(-1,$GUI_DISABLE)
$ConnectClientGoButton=GUICtrlCreateButton("Connect",160,150,60,25)
GUICtrlSetState(-1,$GUI_DISABLE)

$ConnectStatusBox=GUICtrlCreateEdit("",5,200,350,90)

GUISetState()
;#cs
TCPStartup()
GUICtrlSetData($ConnectStatusBox,GUICtrlRead($ConnectStatusBox)&"Waiting for client..."&@CRLF)
Global $SocketInPre=TCPListen(@IPAddress1,14,10)
If @error Then
    GUICtrlSetState($ConnectRadioClient,$GUI_CHECKED)
    GUICtrlSetState($ConnectRadioServer,$GUI_UNCHECKED)
            TCPCloseSocket($SocketInPre)
            GUICtrlSetData($ConnectStatusBox,"Ready"&@CRLF&"Switching to client mode"&@CRLF&"This computer may already be acting as a host")
            GUICtrlSetState($ConnectServerIPaddress,$GUI_DISABLE)
            GUICtrlSetState($ConnectClientLabel,$GUI_ENABLE)
            _GUICtrlIpAddress_ShowHide($ConnectClientIPaddress,TRUE)
            GUICtrlSetState($ConnectClientFakeIPBox,$GUI_HIDE)
            GUICtrlSetState($ConnectClientGoButton,$GUI_ENABLE)
    _GUICtrlIPAddress_Set($ConnectClientIPAddress,@IPAddress1)
EndIf


While 1
    Switch GUIGetMsg()
        Case -3
            Exit
        Case $ConnectRadioServer
            GUICtrlSetState($ConnectServerIPaddress,$GUI_ENABLE)
            GUICtrlSetState($ConnectClientLabel,$GUI_DISABLE)
            _GUICtrlIpAddress_ShowHide($ConnectClientIPaddress,False)
            GUICtrlSetState($ConnectClientFakeIPBox,$GUI_SHOW)
            GUICtrlSetState($ConnectClientGoButton,$GUI_DISABLE)
            
            GUICtrlSetData($ConnectStatusBox,"Waiting for client"&@CRLF&GUICtrlRead($ConnectStatusBox))
            Global $SocketInPre=TCPListen(@IPAddress1,14)
            
        Case $ConnectRadioClient
            TCPCloseSocket($SocketInPre)
            GUICtrlSetData($ConnectStatusBox,"Ended server mode"&@CRLF&GUICtrlRead($ConnectStatusBox))
            GUICtrlSetState($ConnectServerIPaddress,$GUI_DISABLE)
            GUICtrlSetState($ConnectClientLabel,$GUI_ENABLE)
            _GUICtrlIpAddress_ShowHide($ConnectClientIPaddress,TRUE)
            GUICtrlSetState($ConnectClientFakeIPBox,$GUI_HIDE)
            GUICtrlSetState($ConnectClientGoButton,$GUI_ENABLE)
            
        Case $ConnectClientGoButton
            GUICtrlSetState($ConnectClientGoButton,$GUI_DISABLE)
            GUICtrlSetData($ConnectStatusBox,"Attempting to connect..."&@CRLF&GUICtrlRead($ConnectStatusBox))
            Global $MeOut=TCPConnect(_GUICtrlIpAddress_Get($ConnectClientIPaddress),14)
            If $MeOut <> -1 Then
                GUICtrlSetData($ConnectStatusBox,"Establishing 2-way communication..."&@CRLF&">> Server contacted!"&@CRLF&GUICtrlRead($ConnectStatusBox))
                If ClientMake2Way() = 1 Then
                    ExitLoop
                Else
                    GUICtrlSetData($ConnectStatusBox,"Connection failed"&@CRLF&GUICtrlRead($ConnectStatusBox))
                EndIf
            Else
                GUICtrlSetData($ConnectStatusBox,"No response."&@CRLF&GUICtrlRead($ConnectStatusBox))
            EndIf
            GUICtrlSetState($ConnectClientGoButton,$GUI_ENABLE)
    EndSwitch
    $ThemIn=TCPAccept($SocketInPre)
    If $ThemIn <> -1 Then;Makes sure that this instance is "server" and that the connection worked
        GUICtrlSetData($ConnectStatusBox,"Establishing 2-way communication..."&@CRLF&">> Client found!"&@CRLF&GUICtrlRead($ConnectStatusBox))
        If ServerMake2Way() = 1 Then
            ExitLoop
        Else
            GUICtrlSetData($ConnectStatusBox,"Connection failed; waiting for another client connection"&@CRLF&GUICtrlRead($ConnectStatusBox))
        EndIf
    EndIf
WEnd

Func ServerMake2Way()
    Global $ThemOut=TCPConnect(SocketToIP($ThemIn),15)
    If $ThemOut <> -1 Then
        $SocketInPre=TCPListen(@IPAddress1,16,10)
        Local $timer=TimerInit()
        Do
            Global $MeIn=TCPAccept($SocketInPre)
            If $MeIn <> -1 Then
                Global $MeOut=TCPConnect(SocketToIP($ThemIn),17)
                If $MeOut <> -1 Then
                    Global $IsMyTurn=1;host always gets first turn
                    Return 1
                Else
                    Return 0
                EndIf
            EndIf
        Until TimerDiff($timer) > 30000
        Return 0
    Else
        Return 0
    EndIf
EndFunc

Func ClientMake2Way()
    Global $SocketInPre=TCPListen(@IPAddress1,15,10)
    Local $timer=TimerInit()
    Do
        Global $MeIn=TCPAccept($SocketInPre)
        If $MeIn <> -1 Then
            Global $ThemOut=TCPConnect(_GUICtrlIpAddress_Get($ConnectClientIPaddress),16)
            If $ThemOut <> -1 Then
                Global $SocketInPre=TCPListen(@IPAddress1,17,10)
                Local $timer=TimerInit()
                Do
                    Global $ThemIn=TCPAccept($SocketInPre)
                    If $ThemIn <> -1 Then
                        Global $IsMyTurn=0;host always gets first turn
                        Return 1
                    EndIf
                Until TimerDiff($timer) > 30000
                Return 0
            Else
                Return 0
            EndIf
        EndIf
    Until TimerDiff($timer) > 30000
    Return 0
EndFunc

Func SocketToIP($SHOCKET)
    Local $sockaddr = DllStructCreate("short;ushort;uint;char[8]")
    Local $aRet = DllCall("Ws2_32.dll", "int", "getpeername", "int", $SHOCKET, "ptr", DllStructGetPtr($sockaddr), "int*", DllStructGetSize($sockaddr))
    If Not @error And $aRet[0] = 0 Then
        $aRet = DllCall("Ws2_32.dll", "str", "inet_ntoa", "int", DllStructGetData($sockaddr, 3))
        If Not @error Then $aRet = $aRet[0]
    Else
        $aRet = 0
    EndIf
    $sockaddr = 0
    Return $aRet
EndFunc  ;==>SocketToIP
;#ce
GUISetState(@SW_HIDE)

$MainGUI=GUICreate("AutoIt Network Dark Chess by james3mg",600,640)
Global $OpponentTurnLight=GUICtrlCreateLabel("Your opponent is making their move",0,0,600,20,$SS_CENTER)
GUICtrlSetColor(-1,0x666666)
Global $MyTurnLight=GUICtrlCreateLabel("",0,620,600,20,$SS_CENTER)
GUICtrlSetColor(-1,0xFFFFFF)
If $IsMyTurn Then
    GUICtrlSetBkColor($opponentTurnLight,0x666666)
    GUICtrlSetBkColor($MyTurnLight,0x0000FF)
Else
    GUICtrlSetBkColor($opponentTurnLight,0x0000FF)
    GUICtrlSetBkColor($MyTurnLight,0x666666)
EndIf
    
Global $SquaresArray[8][8]
For $y=0 To 7
    For $x=0 To 7
        $SquaresArray[$x][$y]=GUICtrlCreateLabel("",$x*75,$y*75+20,75,75,BitOR($GUI_SS_DEFAULT_LABEL,$SS_CENTER,$SS_CENTERIMAGE))
        GUICtrlSetColor(-1,0xFF8040)
        GUICtrlSetFont(-1,8.5,600)
    Next
Next
GUISetState()

Global $Pieces[16][2]
For $i=0 To 7
    $Pieces[$i][0]="Pawn"
    $Pieces[$i][1]=$i&6
    GUICtrlSetData($SquaresArray[$i][6],"Pawn")
Next
$Pieces[8][0]="Rook"
$Pieces[8][1]="07"
GUICtrlSetData($SquaresArray[0][7],"Rook")
$Pieces[9][0]="Knight"
$Pieces[9][1]="17"
GUICtrlSetData($SquaresArray[1][7],"Knight")
$Pieces[10][0]="Bishop"
$Pieces[10][1]="27"
GUICtrlSetData($SquaresArray[2][7],"Bishop")
If $IsMyTurn Then
    $Pieces[11][0]="Queen"
    $Pieces[11][1]="37"
    GUICtrlSetData($SquaresArray[3][7],"Queen")
    $Pieces[12][0]="King"
    $Pieces[12][1]="47"
    GUICtrlSetData($SquaresArray[4][7],"King")
Else
    $Pieces[11][0]="King"
    $Pieces[11][1]="37"
    GUICtrlSetData($SquaresArray[3][7],"King")
    $Pieces[12][0]="Queen"
    $Pieces[12][1]="47"
    GUICtrlSetData($SquaresArray[4][7],"Queen")
EndIf
$Pieces[13][0]="Bishop"
$Pieces[13][1]="57"
GUICtrlSetData($SquaresArray[5][7],"Bishop")
$Pieces[14][0]="Knight"
$Pieces[14][1]="67"
GUICtrlSetData($SquaresArray[6][7],"Knight")
$Pieces[15][0]="Rook"
$Pieces[15][1]="77"
GUICtrlSetData($SquaresArray[7][7],"Rook")

AdlibEnable("AdlibFunc",15)
SetVisible()

While 1
    $msg=GUIGetMsg()
    If $msg=-3 Then Exit
    If $msg < 0 Then
        Sleep(15)
        ContinueLoop
    EndIf
    If $IsMyTurn Then
        If GUICtrlRead($msg) = "Enemy" OR GUICtrlRead($msg) = "" Then ContinueLoop
        For $x=0 To 7
            For $y=0 To 7
                If $msg=$SquaresArray[$x][$y] Then
                    GUICtrlSetData($MyTurnLight,"")
                    GUICtrlSetColor($msg,0x4080FF)
                    $AvailMoves=GetAvailMoves(GUICtrlRead($msg),$x&$y)
                    For $i=1 To $AvailMoves[0]
                        If BitAND(StringLeft($AvailMoves[$i],1)+StringRight($AvailMoves[$i]+1,1),1) Then
                            GUICtrlSetBkColor($SquaresArray[StringLeft($AvailMoves[$i],1)][StringRight($AvailMoves[$i],1)],0x9999FF)
                        Else
                            GUICtrlSetBkColor($SquaresArray[StringLeft($AvailMoves[$i],1)][StringRight($AvailMoves[$i],1)],0x000066)
                        EndIf
                    Next
                    Local $ActivePiece=$msg
                    Local $ActiveCoord=$x&$y
                    While 1
                        $msg=GUIGetMsg()
                        Switch $msg
                            Case -3
                                Exit
                        EndSwitch
                        If $msg=$ActivePiece Then
                            GUICtrlSetColor($msg,0xFF8040)
                            SetVisible()
                            ExitLoop 3
                        EndIf
                        For $x=0 To 7
                            For $y=0 To 7
                                If $msg=$SquaresArray[$x][$y] Then
                                    Local $Capture=0
                                    For $i=1 To $AvailMoves[0]
                                        If $AvailMoves[$i]=$x&$y Then
                                            If GUICtrlRead($msg)="Enemy" Then $Capture=1
                                            GUICtrlSetData($msg,GUICtrlRead($ActivePiece))
                                            GUICtrlSetData($ActivePiece,"")
                                            For $p=0 To UBound($Pieces)-1
                                                If $Pieces[$p][1]=$ActiveCoord Then
                                                    $Pieces[$p][1]=$x&$y
                                                    ExitLoop
                                                EndIf
                                            Next
                                            For $n=1 To $AvailMoves[0]
                                                If BitAND(StringLeft($AvailMoves[$n],1)+StringRight($AvailMoves[$n]+1,1),1) Then
                                                    GUICtrlSetBkColor($SquaresArray[StringLeft($AvailMoves[$n],1)][StringRight($AvailMoves[$n],1)],0xFFFFFF)
                                                Else
                                                    GUICtrlSetBkColor($SquaresArray[StringLeft($AvailMoves[$n],1)][StringRight($AvailMoves[$n],1)],0x000000)
                                                EndIf
                                            Next
                                            GUICtrlSetColor($ActivePiece,0xFF8040)
                                            If $Capture Then
                                                TCPSend($MeOut,"-"&$x&$y)
                                            Else
                                                TCPSend($MeOut,"-88")
                                            EndIf
                                            $IsMyTurn=0
                                            GUICtrlSetBkColor($opponentTurnLight,0x0000FF)
                                            GUICtrlSetBkColor($MyTurnLight,0x666666)
                                            ExitLoop 6
                                        EndIf
                                    Next
                                EndIf
                            Next
                        Next
                    WEnd
                EndIf
            Next
        Next
    EndIf
WEnd

Func AdlibFunc()
    Local $pq, $recv, $ans, $pi
    $recv=String(TCPRecv($ThemIn,3))
    If @error Then Exit
    If $recv="" Or StringLen($recv) <> 3 Then Return
    If $recv="!!!" Then
        MsgBox(0,"Game over","You have captured your opponent's King, and so have won the game!")
        Exit
    EndIf
    If StringLeft($recv,1)="-" Then;end of turn marker
        If StringRight($recv,2) <> 88 Then
            $recv="-"&7-StringMid($recv,2,1)&7-StringRight($recv,1)
            For $pi=0 To UBound($Pieces)-1
                If $Pieces[$pi][1]=StringRight($recv,2) Then
                    If $Pieces[$pi][0]="King" Then
                        TCPSend($MeOut,"!!!")
                        MsgBox(0,"Game over","Your opponent has captured your King, and so has won the game!")
                        Exit
                    EndIf
                    GUICtrlSetData($MyTurnLight,$Pieces[$pi][0]&" has been captured")
                    For $pi=$pi To UBound($Pieces)-2
                        $Pieces[$pi][0]=$Pieces[$pi+1][0]
                        $Pieces[$pi][1]=$Pieces[$pi+1][1]
                    Next
                    ReDim $Pieces[UBound($Pieces)-1][2]
                    ExitLoop
                EndIf
            Next
        EndIf
        $IsMyTurn=NOT $IsMyTurn
        If $IsMyTurn Then
            GUICtrlSetBkColor($opponentTurnLight,0x666666)
            GUICtrlSetBkColor($MyTurnLight,0x0000FF)
        Else
            GUICtrlSetBkColor($opponentTurnLight,0x0000FF)
            GUICtrlSetBkColor($MyTurnLight,0x666666)
        EndIf
        SetVisible()
        Return
    ElseIf StringLeft($recv,1)="?" Then;IsOccupied query
        $recv=(7-StringMid($recv,2,1))&(7-StringRight($recv,1))
        If GUICtrlRead($SquaresArray[StringLeft($recv,1)][StringRight($recv,1)]) <> "" AND GUICtrlRead($SquaresArray[StringLeft($recv,1)][StringRight($recv,1)]) <> "Enemy" Then
            TCPSend($ThemOut,"a1")
            Return
        Else
            TCPSend($ThemOut,"a0")
            Return
        EndIf
    ;below is not used anymore...I don't know why it has issues
        #cs
        For $pq=1 To UBound($Pieces)-1
            If $Pieces[$pq][1]=$recv Then
                TCPSend($ThemOut,"a1")
                $AdlibRunning=0
                Return
            Else
                TCPSend($ThemOut,"a0")
                Return
            EndIf
        Next
        Return
        #ce
    EndIf
EndFunc

Func SetVisible()
    Local $x,$y,$i,$n
    For $y=0 To 7
        For $x=0 To 7
            GUICtrlSetData($SquaresArray[$x][$y],"")
            If BitAND($y+$x+1,1) Then
                GUICtrlSetBkColor($SquaresArray[$x][$y],0x888888)
            Else
                GUICtrlSetBkColor($SquaresArray[$x][$y],0x777777)
            EndIf
        Next
    Next
    For $i=0 To UBound($Pieces)-1
        GUICtrlSetData($SquaresArray[StringLeft($Pieces[$i][1],1)][StringRight($Pieces[$i][1],1)],$Pieces[$i][0])
        If BitAND(StringLeft($Pieces[$i][1],1)+StringRight($Pieces[$i][1],1)+1,1) Then
            GUICtrlSetBkColor($SquaresArray[StringLeft($Pieces[$i][1],1)][StringRight($Pieces[$i][1],1)],0xFFFFFF)
        Else
            GUICtrlSetBkColor($SquaresArray[StringLeft($Pieces[$i][1],1)][StringRight($Pieces[$i][1],1)],0x000000)
        EndIf
        $AvailMoves=GetAvailMoves($Pieces[$i][0],$Pieces[$i][1])
        For $n=1 To $AvailMoves[0]
            If IsOccupied(StringLeft($AvailMoves[$n],1)&StringRight($AvailMoves[$n],1))=1 Then
                GUICtrlSetData($SquaresArray[StringLeft($AvailMoves[$n],1)][StringRight($AvailMoves[$n],1)],"Enemy")
                If BitAND(StringLeft($AvailMoves[$n],1)+StringRight($AvailMoves[$n]+1,1),1) Then
                    GUICtrlSetBkColor($SquaresArray[StringLeft($AvailMoves[$n],1)][StringRight($AvailMoves[$n],1)],0xFFBBBB)
                Else
                    GUICtrlSetBkColor($SquaresArray[StringLeft($AvailMoves[$n],1)][StringRight($AvailMoves[$n],1)],0x660000)
                EndIf
            Else
                If BitAND(StringLeft($AvailMoves[$n],1)+StringRight($AvailMoves[$n]+1,1),1) Then
                    GUICtrlSetBkColor($SquaresArray[StringLeft($AvailMoves[$n],1)][StringRight($AvailMoves[$n],1)],0xFFFFFF)
                Else
                    GUICtrlSetBkColor($SquaresArray[StringLeft($AvailMoves[$n],1)][StringRight($AvailMoves[$n],1)],0x000000)
                EndIf
            EndIf
        Next
    Next
EndFunc

Func GetAvailMoves($pName,$pCoord);returns an array where [0] is the number of spaces and the rest are space coords of available moves
    Local $retVal[1]=[0]
    Local $allDirs[8][2]=[[-1,-1],[0,-1],[1,-1],[-1,0],[1,0],[-1,1],[0,1],[1,1]]
    Switch $pName
        Case "Pawn"
            If StringRight($pCoord,1) > 0 AND StringRight($pCoord,1)-1 >= 0 AND GUICtrlRead($SquaresArray[StringLeft($pCoord,1)][StringRight($pCoord,1)-1]) = "" Then
                ReDim $retVal[UBound($retVal)+1]
                $retVal[0]+=1
                $retVal[$retVal[0]]=StringLeft($pCoord,1)&(StringRight($pCoord,1)-1)
                If IsOccupied(StringLeft($pCoord,1)&(StringRight($pCoord,1)-1))=0 AND StringRight($pCoord,1) = 6 AND GUICtrlRead($SquaresArray[StringLeft($pCoord,1)][StringRight($pCoord,1)-2]) = "" Then;allows for the double-space opening move by the pawns.
                    ReDim $retVal[UBound($retVal)+1]
                    $retVal[0]+=1
                    $retVal[$retVal[0]]=StringLeft($pCoord,1)&StringRight($pCoord,1)-2
                EndIf
            EndIf
        ;#cs
            If StringRight($pCoord,1) > 0 AND IsOccupied(StringLeft($pCoord,1)-1&(StringRight($pCoord,1))-1)=1 AND StringLeft($pCoord,1) > 0 Then
                ReDim $retVal[UBound($retVal)+1]
                $retVal[0]+=1
                $retVal[$retVal[0]]=StringLeft($pCoord,1)-1&(StringRight($pCoord,1)-1)
            EndIf
            If StringRight($pCoord,1) > 0 AND IsOccupied(StringLeft($pCoord,1)+1&(StringRight($pCoord,1)-1))=1 AND StringLeft($pCoord,1) < 7 Then
                ReDim $retVal[UBound($retVal)+1]
                $retVal[0]+=1
                $retVal[$retVal[0]]=StringLeft($pCoord,1)+1&(StringRight($pCoord,1)-1)
            EndIf
        ;#ce
        Case "Rook"
            Local $dirs[4]=[1,3,4,6]
            For $d=0 To 3
                Local $pos=$pCoord
                Do
                    $pos=StringLeft($pos,1)+$allDirs[$dirs[$d]][0]&StringRight($pos,1)+$allDirs[$dirs[$d]][1]
                    If StringLen($pos) = 2 AND StringLeft($pos,1) < 8 AND StringRight($pos,1) < 8 AND (GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "" OR GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "Enemy") Then
                        ReDim $retVal[UBound($retVal)+1]
                        $retVal[0]+=1
                        $retVal[$retVal[0]]=$pos
                        If IsOccupied($pos)=1 Then ExitLoop
                    Else
                        ExitLoop
                    EndIf
                Until StringLen($pos) <> 2 OR StringLeft($pos,1) > 7 OR StringRight($pos,1) > 7 OR IsOccupied($pos)=1 OR GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) <> "" 
            Next
        Case "Knight"
            Local $allDirs[8][2]=[[-2,-1],[-1,-2],[-2,1],[-1,2],[1,2],[2,1],[2,-1],[1,-2]]
            For $d=0 To 7
                $pos=StringLeft($pCoord,1)+$allDirs[$d][0]&StringRight($pCoord,1)+$allDirs[$d][1]
                If StringLen($pos) = 2 AND StringLeft($pos,1) < 8 AND StringRight($pos,1) < 8 AND (GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "" OR GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "Enemy") Then
                    ReDim $retVal[UBound($retVal)+1]
                    $retVal[0]+=1
                    $retVal[$retVal[0]]=$pos
                EndIf
            Next
        Case "Bishop"
            Local $dirs[4]=[0,2,5,7]
            For $d=0 To 3
                Local $pos=$pCoord
                Do
                    $pos=StringLeft($pos,1)+$allDirs[$dirs[$d]][0]&StringRight($pos,1)+$allDirs[$dirs[$d]][1]
                    If StringLen($pos) = 2 AND StringLeft($pos,1) < 8 AND StringRight($pos,1) < 8 AND (GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "" OR GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "Enemy") Then
                        ReDim $retVal[UBound($retVal)+1]
                        $retVal[0]+=1
                        $retVal[$retVal[0]]=$pos
                        If IsOccupied($pos)=1 Then ExitLoop
                    Else
                        ExitLoop
                    EndIf
                Until StringLen($pos) <> 2 OR StringLeft($pos,1) > 7 OR StringRight($pos,1) > 7 OR IsOccupied($pos)=1 OR GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) <> "" 
            Next
        Case "Queen"
            For $d=0 To 7
                Local $pos=$pCoord
                Do
                    $pos=StringLeft($pos,1)+$allDirs[$d][0]&StringRight($pos,1)+$allDirs[$d][1]
                    If StringLen($pos) = 2 AND StringLeft($pos,1) < 8 AND StringRight($pos,1) < 8 AND (GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "" OR GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "Enemy") Then
                        ReDim $retVal[UBound($retVal)+1]
                        $retVal[0]+=1
                        $retVal[$retVal[0]]=$pos
                        If IsOccupied($pos)=1 Then ExitLoop
                    Else
                        ExitLoop
                    EndIf
                Until StringLen($pos) <> 2 OR StringLeft($pos,1) > 7 OR StringRight($pos,1) > 7 OR IsOccupied($pos)=1 OR GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) <> "" 
            Next
        Case "King"
            For $d=0 To 7
                $pos=StringLeft($pCoord,1)+$allDirs[$d][0]&StringRight($pCoord,1)+$allDirs[$d][1]
                If StringLen($pos) = 2 AND StringLeft($pos,1) < 8 AND StringRight($pos,1) < 8 AND (GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "" OR GUICtrlRead($SquaresArray[StringLeft($pos,1)][StringRight($pos,1)]) = "Enemy") Then
                    ReDim $retVal[UBound($retVal)+1]
                    $retVal[0]+=1
                    $retVal[$retVal[0]]=$pos
                EndIf
            Next
        ;add in something here for "castling"
    EndSwitch   
    Return $retVal
EndFunc

Func IsOccupied($pCoord)
    TCPSend($MeOut,"?"&$pCoord)
    Local $timer=TimerInit()
    Do
        $recv=TCPRecv($MeIn,2)
        If @error Then
            ConsoleWrite("Connection lost...shutting down"&@CRLF)
            Exit
        EndIf
        If TimerDiff($timer) > 3000 Then
            TCPSend($MeOut,"?"&$pCoord)
            $timer=TimerInit()
        EndIf
    Until $recv<>""
    Return StringRight($recv,1)
EndFunc

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites
BillLuvsU

Don't forget {le' cousant???} , the rule that states that if they double move a pawn then do't move it again, and you get a pawn next to it, you can move your pawn behimd there pawn and take it.

Edit: Other than that good work.

Edited by BillLuvsU

[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites
james3mg

Don't forget {le' cousant???} , the rule that states that if they double move a pawn then do't move it again, and you get a pawn next to it, you can move your pawn behimd there pawn and take it.

Edit: Other than that good work.

I appreciate the heads-up...I was unaware of that rule. That will probably come when I get Castling (is that the proper term?) supported...right now I've got nothing built in to tell me if a piece has moved or not, so either of those rules will require additional infrastructure.

But thanks for the feedback!

...wanna play? :mellow: J/K...I'm at work and wouldn't be able to get through the firewall.


"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites
BillLuvsU

Haha, ya I'll play with you. And if you need any help I have a pretty extensive knowledge of chess, so just send me a message.


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites
ludocus

cool.. although its very hard to understand..

I don't understand it..

Share this post


Link to post
Share on other sites
dbzfanatic

Looks good. I played and beat myself in 187,000 moves even :mellow: lol. I didn't really count or pay attention but it did work fairly well. Perhaps set up a hosting server where people can connect and just add rooms/games or add the option to become one in the script?

Share this post


Link to post
Share on other sites
james3mg

Looks good. I played and beat myself in 187,000 moves even :mellow: lol. I didn't really count or pay attention but it did work fairly well. Perhaps set up a hosting server where people can connect and just add rooms/games or add the option to become one in the script?

Glad you liked it. A server, however, is quite out of the scope of this script. I could set up my server to connect players, theoretically, but I'd never be able to get my script to get through firewalls using my methods. This script is designed for two players on the same LAN to play. Though two players each with publicly accessible TCP ports 14-17 (that is, no firewall or else ports forwarded through the firewall, and a knowledge of their public IP address) could get it to work over the 'net as well...

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites
james3mg

Don't forget {le' cousant???} , the rule that states that if they double move a pawn then do't move it again, and you get a pawn next to it, you can move your pawn behimd there pawn and take it.

Edit: Other than that good work.

Is this the move you're referring to? It may be easier than I thought, since this states it has to be done on the VERY NEXT turn...

If that's what you meant and this description of the rule is good, you'll probably see it on the next version I make up. :mellow:


"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites
Emiel Wieldraaijer

Yes that the set he refers to ..

Cool script


Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.