Updated 2012-08-25 23:20:04 by RLE

Michael Jacobson ~ 2003/04/03

After reading a Microsoft case study on .NET on the PocketPc with a chess game (that could also be run on the PC with no code changes - WOW! ;)[1]. I remembered Chess in Tcl on the Wiki and figured out how to resize and color it, in 9 lines of Tcl code, so it looked better on the PocketPC. Then I saw in the article, that the author uses a web service to implement online play against a computer. So I found the service on http://www.xmethods.net [2] and wrote my first TclSOAP interface code ever (took a hour ~ most of the time to read the docs - only 4 line of Tcl code). Then with another couple of lines of code I added online play to Chess in Tcl. I do so like this language Sam I Am!!!

There are a couple of problems because Chess in Tcl does not support all the valid moves but this is my first crack at the code. Please feel free to make changes...

LV so after I add this code, how do I activate it?

George Peter Staplin This code is interesting. Thanks for sharing. :)

A somewhat related chess RPC project is in the Tequila cvs tree. See: [3]
 ### Mike's Add for Smart Network Opponent to Chess in Tcl
 ###  put at the bottom of the Chess in Tcl code ... http://wiki.tcl.tk/4070
 proc InitChessServer {} {
    package require SOAP
    set uri "urn:BorlandChess-IBorlandChess#XML_GetNextMove"
    set proxy "http://www.danmarinescu.com/WebServices/ChessCGIServer.exe/soap/IBorlandChess"
    #SOAP::configure \
    #    -transport http -proxy host:port \
    #    -headers { "Proxy-Authorization" "Basic XXYYZZ" } 
    SOAP::create XML_GetNextMove \
        -uri $uri -proxy $proxy \
        -params {"Position" "string" "WhiteMovesNext" "boolean" "SearchDepth" "integer"}
    # example from the danmainescu site
    #set a "rnbqkbnrpppppppp[string repeat { } 32]PPPPPPPPRNBQKBNR"
    #XML_GetNextMove $a true 3  ;# returns "e2e4 OK"

 proc GetNextMove {} {
    global game
    set board {}
    foreach row {8 7 6 5 4 3 2 1} {
        foreach col {A B C D E F G H} {
            if {$game($col$row) == "."} {
                append board " "
            } else {
                append board $game($col$row)
    set result [string toupper [XML_GetNextMove $board false 3]]
    return "[string range [lindex $result 0] 0 1]-[string range [lindex $result 0] 2 3]"
 after 1000 CheckBoard
 set game(autoMove) 1
 proc CheckBoard {} {
    global game
    if {$game(toMove) == "black" && $game(autoMove)} {
        set ::game(results) [GetNextMove]
        if {$::game(results) != "A1-A1"} {
            puts [uplevel {chess::move game $::game(results)}]
            game drawBoard .c           ame $::game(results)}]
        } else {
            #some prompt that game is over so you want to play somemore
        set game(autoMove) 0
    return [after 1000 CheckBoard]
 proc MoveInfo {- - -} {
    set ::info "$::game(toMove) to move - [chess::values ::game]"
    set ::game(autoMove) 1