<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forum.eggheads.org/app.php/feed/topic/9706" />

	<title>egghelp/eggheads community</title>
	<subtitle>Discussion of eggdrop bots, shell accounts and tcl scripts.</subtitle>
	<link href="https://forum.eggheads.org/index.php" />
	<updated>2005-05-27T15:09:35-04:00</updated>

	<author><name><![CDATA[egghelp/eggheads community]]></name></author>
	<id>https://forum.eggheads.org/app.php/feed/topic/9706</id>

		<entry>
		<author><name><![CDATA[^DooM^]]></name></author>
		<updated>2005-05-27T15:09:35-04:00</updated>

		<published>2005-05-27T15:09:35-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=49907#p49907</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=49907#p49907"/>
		<title type="html"><![CDATA[If someone can fix this chess tcl]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=49907#p49907"><![CDATA[
Loozer please stop asking why TCL files not even intended to be run on eggdrops do not work.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=3723">^DooM^</a> — Fri May 27, 2005 3:09 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[greenbear]]></name></author>
		<updated>2005-05-27T11:52:20-04:00</updated>

		<published>2005-05-27T11:52:20-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=49898#p49898</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=49898#p49898"/>
		<title type="html"><![CDATA[If someone can fix this chess tcl]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=49898#p49898"><![CDATA[
for one its not a eggdrop script, its using Tk do draw a ui.<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=24">greenbear</a> — Fri May 27, 2005 11:52 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[arcane]]></name></author>
		<updated>2005-05-27T11:38:21-04:00</updated>

		<published>2005-05-27T11:38:21-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=49897#p49897</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=49897#p49897"/>
		<title type="html"><![CDATA[If someone can fix this chess tcl]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=49897#p49897"><![CDATA[
nice, a chess tcl...<br><br>but maybe you should tell us what's wrong with it (and use code-tags next time)...<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=2617">arcane</a> — Fri May 27, 2005 11:38 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[loozer]]></name></author>
		<updated>2005-05-26T18:56:52-04:00</updated>

		<published>2005-05-26T18:56:52-04:00</published>
		<id>https://forum.eggheads.org/viewtopic.php?p=49869#p49869</id>
		<link href="https://forum.eggheads.org/viewtopic.php?p=49869#p49869"/>
		<title type="html"><![CDATA[If someone can fix this chess tcl]]></title>

		
		<content type="html" xml:base="https://forum.eggheads.org/viewtopic.php?p=49869#p49869"><![CDATA[
hi there if anyone can fix this tcl or make better just contact me<br><br>namespace eval chess {set version 0.2 ;# resize on &lt;Configure&gt;}<br> proc chess::new board {<br>    # create a new game (generic dispatcher) with the board name<br>    proc ::$board {{cmd format} args} \<br>        "uplevel 1 chess::\$cmd $board \$args"<br>    uplevel 1 $board reset<br> }<br> proc chess::reset {boardName {setup ""}} {<br>    upvar 1 $boardName board<br>    if {$setup == ""} {set setup \<br>        "r n b q k b n r<br>         p p p p p p p p<br>         . . . . . . . .<br>         . . . . . . . .<br>         . . . . . . . .<br>         . . . . . . . .<br>         P P P P P P P P<br>         R N B Q K B N R"<br>    }<br>    foreach line [split [string trim $setup] \n] y {8 7 6 5 4 3 2 1} {<br>        foreach word $line x {A B C D E F G H} {<br>            set board($x$y) $word<br>        }<br>    }<br>    set board(toMove) white<br>    set board(history) {} ;# start a new history...<br> }<br> proc chess::format boardName {<br>    # render current board into a well-readable string<br>    upvar 1 $boardName board<br>    foreach row {8 7 6 5 4 3 2 1} {<br>        foreach column {A B C D E F G H} {<br>            append res " " $board($column$row)<br>        }<br>        append res \n<br>    }<br>    set res<br> }<br> proc chess::move {boardName move} {<br>    upvar 1 $boardName board<br>    foreach {from to} [split $move -] break<br>    set fromMan $board($from)<br>    if {$fromMan == "."} {error "no man to move at $from"}<br>    set toMan   $board($to)<br>    if ![valid? board $move] {error "invalid move for a [manName $fromMan]"}<br>    set board($from) .<br>    set board($to)   $fromMan<br>    if {$toMan != "."} {append move -$toMan} ;# taken one<br>    lappend board(history) $move<br>    set board(toMove) [expr {$board(toMove) == "white"? "black": "white"}]<br>    set toMan ;# report possible victim<br> }<br> proc chess::color man {expr {[string is upper $man]? "white" : "black"}}<br><br> proc chess::valid? {boardName move} {<br>    upvar 1 $boardName board<br>    foreach {from to} [split $move -] break<br>    if {$to==""} {return 0}<br>    set fromMan $board($from)<br>    if {[color $fromMan] != $board(toMove)} {return 0}<br>    set toMan   $board($to)<br>    if [sameSide $fromMan $toMan] {return 0}<br>    foreach {x0 y0} [coords $from] {x1 y1} [coords $to] break<br>    set dx  [expr {$x1-$x0}]<br>    set adx [expr {abs($dx)}]<br>    set dy  [expr {$y1-$y0}]<br>    set ady [expr {abs($dy)}]<br>    if {[string tolower $fromMan] != "n" &amp;&amp; (!$adx || !$ady || $adx==$ady)} {<br>        for {set x $x0; set y $y0} {($x!=$x1 || $y!=$y1)} \<br>          {incr x [sgn $dx]; incr y [sgn $dy]} {<br>            if {($x!=$x0 || $y!=$y0) &amp;&amp; $board([square $x $y])!="."} {<br>                return 0<br>            } ;# planned path is blocked<br>        }<br>    }<br>    switch -- $fromMan {<br>        K - k {expr $adx&lt;2 &amp;&amp; $ady&lt;2}<br>        Q - q {expr $adx==0 || $ady==0 || $adx==$ady}<br>        B - b {expr $adx==$ady}<br>        N - n {expr ($adx==1 &amp;&amp; $ady==2)||($adx==2 &amp;&amp; $ady==1)}<br>        R - r {expr $adx==0 || $ady==0}<br>        P {<br>            expr {(($y0==2 &amp;&amp; $dy==2) || $dy==1)<br>              &amp;&amp; (($dx==0 &amp;&amp; $toMan==".") ||<br>                ($adx==1 &amp;&amp; $ady==1 &amp;&amp; [sameSide p $toMan]))<br>            }<br>        }<br>        p {<br>            expr {(($y0==7 &amp;&amp; $dy==-2) || $dy==-1)<br>              &amp;&amp; (($dx==0 &amp;&amp; $toMan==".") ||<br>                ($adx==1 &amp;&amp; $ady==1 &amp;&amp; [sameSide P $toMan]))<br>            }<br>        }<br>        default {return 0}<br>    }<br> }<br> proc chess::validMoves {boardName from} {<br>    upvar 1 $boardName board<br>    set res {}<br>    foreach to [array names board ??] {<br>        set move $from-$to<br>        if [valid? board $move] {<br>            if {$board($to) != "."} {append move -$board($to)}<br>            lappend res $move<br>        }<br>    }<br>    lsort $res<br> }<br> proc chess::coords square {<br>    # translate square name to numeric coords: C5 -&gt; {3 5}<br>    foreach {c y} [split $square ""] break<br>    list [lsearch {- A B C D E F G H} $c] $y<br> }<br> proc chess::square {x y} {<br>    # translate numeric coords to sq uare name: {3 5} -&gt; C5<br>    return [string map {1 A 2 B 3 C 4 D 5 E 6 F 7 G 8 H} $x]$y<br> }<br> proc chess::undo boardName {<br>    upvar 1 $boardName board<br>    if ![llength $board(history)] {error "Nothing to undo"}<br>    set move [lindex $board(history) end]<br>    foreach {from to hit} [split $move -]  break<br>    set board(history) [lrange $board(history) 0 end-1]<br>    set board($from)   $board($to)<br>    if {$hit==""} {set hit .}<br>    set board($to) $hit<br>    set board(toMove) [expr {$board(toMove) == "white"? "bl ack": "white"}]<br> }<br> proc chess::sameSide {a b} {regexp {[a-z][a-z]|[A-Z][A-Z]} $a$b]}<br><br> proc chess::history boardName {uplevel 1 set $boardName\(history)}<br><br> proc chess::manName man {<br>    set table {- k king q queen b bishop n knight r rook p pawn}<br>    set i [l search $table [string tolower $man]]<br>    lindex $table [incr i]<br> }<br> proc chess::values boardName {<br>    # returns the current numeric value of white and black crews<br>    upvar 1 $boardName board<br>    set white 0; set black 0<br>    foreach square [array names b oard ??] {<br>        set man $board($square)<br>        switch -regexp -- $man {<br>            [A-Z] {set white [expr {$white + [manValue $man]}]}<br>            [a-z] {set black [expr {$black + [manValue $man]}]}<br>        }<br>    }<br>    list $white $black<br> }<br> proc chess::manValue man {<br>    array set a {k 0 q 9 b 3.2 n 3 r 5 p 1}<br>    set a([string tolower $man])<br> }<br> #----------------------------------------------------------- Tk UI<br>  proc chess::drawBoard {boardName w args} {<br>    upvar #0 $boardName board<br>    array set opt {-width 300 -colors {bisque tan3} -side white -usefont 0}<br>    array set opt $args<br>    if {![winfo exists $w]} {<br>        canvas $w -width $opt(-width) -height $opt(-width)<br>        bind $w &lt;Configure&gt; "chess::drawBoard $boardName $w $args"<br>        set board(usefont) $opt(-usefont)<br>        $w bind mv &lt;1&gt; [list chess::click1 $boardName $w %x %y]<br>        $w bind mv &lt;B1-Motion&gt; {<br>            %W move current [expr {%x-$chess::x}] [expr {%y-$chess::y}]<br>            set chess::x %x; set chess::y %y<br>        }<br>        $w bind mv &lt;ButtonRelease-1&gt; "chess::release1 $boardName $w %x %y"<br>    } else {<br>        $w delete all<br>    }<br>    set board(side)   $opt(-side)<br>    set dim [min [winfo height $w] [winfo width $w]]<br>    if {$dim&lt;2} {set dim $opt(-width)}<br>    set board(sqw) [set sqw [expr {($dim - 20) / 8}]]<br>    set x0 15<br>    set x $x0; set y 5; set colorIndex 0<br>    set rows {8 7 6 5 4 3 2 1}<br>    set cols {A B C D E F G H}<br>    if {$board(side) != "white"} {<br>        set rows [lrevert $rows]<br>        set cols [lrevert $cols]<br>    }<br>    foreach row $rows {<br>        $w create text 5 [expr {$y+$sqw/2}] -text $row<br>        foreach col $cols {<br>            $w create rect $x $y [incr x $sqw] [expr $y+$sqw] \<br>                -fill [lindex $opt(-colors) $colorIndex] \<br>                -tag [list square $col$row]<br>            set colorIndex [expr {1-$colorIndex}]<br>        }<br>        set x $x0; incr y $sqw<br>        set colorIndex [expr {1-$colorIndex}]<br>    }<br>    set x [expr {$x0 - $sqw/2}]<br>    incr y 8 ;# letters go below chess board<br>    foreach col $cols {$w create text [incr x $sqw] $y -text $col}<br>    drawSetup $boardName $w<br>    set w<br> }<br> proc chess::click1 {boardName w cx cy} {<br>    upvar #0 $boardName board<br>    variable x $cx y $cy from<br>    $w raise current<br>    regexp {@(..)} [$w gettags current] -&gt; from<br>    foreach move [validMoves board $from] {<br>        foreach {- to victim} [split $move -] break<br>        set fill [$w itemcget $to -fill]<br>        if {$fill != "green" &amp;&amp; $fill != "red"} {<br>            set newfill [expr {$victim==""? "green" : "red"}]<br>            $w itemconfig $to -fill $newfill<br>            after 1000 $w itemconfig $to -fill $fill<br>        }<br>    }<br> }<br> proc chess::release1 {boardName w cx cy} {<br>    upvar #0 $boardName board<br>    variable from<br>    set to ""<br>    foreach i [$w find overlap $cx $cy $cx $cy] {<br>        set tags [$w gettags $i]<br>        if {[lsearch $tags square]&gt;=0} {<br>            set to [lindex $tags end]<br>            break<br>        }<br>    }<br>    if [valid? board $from-$to] {<br>        set victim [move board $from-$to]<br>        if {[string tolower $victim]=="k"} {set ::info Checkmate.}<br>        $w delete @$to<br>        set target $to<br>        $w dtag current @$from<br>        $w addtag @$to withtag current<br>    } else {set target $from} ;# go back on invalid move<br>    foreach {x0 y0 x1 y1}     [$w bbox $target] break<br>    foreach {xm0 ym0 xm1 ym1} [$w bbox current] break<br>    set dx [expr {($x0+ $x1-$xm0-$xm1)/2}]<br>    set dy [expr {($y0+$y1-$ym0-$ym1)/2}]<br>    $w move current $dx $dy<br> }<br> proc chess::drawSetup {boardName w} {<br>    upvar #0 $boardName board<br>    $w delete mv<br>    foreach square [array names board ??] {<br>        drawMan $boardName $w $square $board($square)<br>    }<br> }<br> proc chess::drawMan {boardName w where what} {<br>    if {$what=="."} return<br>    upvar #0 $boardName board<br>    set fill [expr {[regexp {[A-Z]} $what]? "white": "black"}]<br>    if $board(usefont) {<br>        set unicode [string map {<br>            k \u265a q \u265b r \u265c b \u265d n \u265e p \u265f<br>          k K q Q r R b B n N p P<br>        } [string tolower $what]]<br>        set font [list Helvetica [expr {$board(sqw)/2}] bold]<br>        $w create text 0 0 -text $unicode -font $font \<br>            -tag [list mv @$where] -fill $fill<br>    } else {<br>        $w create poly [manPolygon $what] -fill $fill \<br>            -tag [list mv @$where] -outline gray<br>        set f [expr {$board(sqw)*0.035}]<br>        $w scale @$where 0 0 $f $f<br>    }<br>    foreach {x0 y0 x1 y1} [$w bbox $where] break<br>    $w move  @$where [expr {($x0+$x1)/2}] [expr {($y0+$y1)/2}]<br> }<br> proc chess::manPolygon what {<br>    # very simple shapes of the chess men - feel free to improve!<br>    switch -- [string tolower $what] {<br>     b {list -10 8  -5 5  -9 0  -6 -6  0 -10  6 -6  9 0  5 5  10 8\<br>        6 10  0 6  -6 10}<br>     k {list -8 10  -10 1  -3 -1  -3 -3  -6 -3  -6 -7  -3 -7  -3 -10\<br>        3 -10  3 -7  6 -7  6 -3  3 -3  3 -1  10 1  8 10}<br>     n {list -8 10  -1 -1  -7 0  -10 -4  0 -10  6 -10  10 10}<br>     p {list -8 10  -8 7  -5 7  -2 -1  -4 -5  -2 -10  2 -10  4 -5 \<br>          2 -1  5 7  8 7  8 10}<br>     q {list -6 10  -10 -10  -3 0  0 -10  3 0  10 -10  6 10}<br>     r {list -10 10  -7 1  -10 0  -10 -10  -5 -10  -5 -6  -3 -6  -3 -10\<br>          3 -10  3 -6  5 -6  5 -10  10 -10 10 0  7 1  10 10}<br>    }<br> }<br> proc chess::flipSides {boardName w} {<br>    upvar #0 $boardName board<br>    $w delete all<br>    set side [expr {$board(side)=="white"? "black": "white"}]<br>    $boardName drawBoard $w -side $side<br> }<br><br>#------------------------------------- some general utilities:<br><br> proc lrevert list {<br>    set res {}<br>    set i [llength $list]<br>    while {$i} {lappend res [lindex $list [incr i -1]]}<br>    set res<br> }<br> proc min args {lindex [lsort -real $args] 0}<br> proc sgn x {expr {$x&gt;0? 1: $x&lt;0? -1: 0}}<br><br>#------------------------------------------------testing demo:<br><br> if {[file tail [info script]]==[file tail $argv0]} {<br>    chess::new game<br>    frame .f<br>    label  .f.e -width 30 -anchor w -textvar info -relief sunken<br>    button .f.u -text Undo  -command {game undo;  game drawSetup .c}<br>    button .f.r -text Reset -command {game reset; game drawSetup .c}<br>    button .f.f -text Flip  -command {game flipSides .c}<br>    eval pack [winfo children .f] -side left -fill both<br>    pack .f -fill x -side bottom<br>    pack [game drawBoard .c] -fill both -expand 1<br>    trace variable game(toMove) w MoveInfo<br>    proc MoveInfo {- - -} {<br>        set ::info "$::game(toMove) to move - [chess::values ::game]"<br>    }<br>    set info "white to move"<br>    bind . &lt;3&gt; {<br>        set game(usefont) [expr 1-$game(usefont)]<br>        event generate .c &lt;Configure&gt;<br>    }<br>    bind . ?        {console show}<br>    bind . &lt;Escape&gt; {exec wish $argv0 &amp;; exit}<br> }<p>Statistics: Posted by <a href="https://forum.eggheads.org/memberlist.php?mode=viewprofile&amp;u=6274">loozer</a> — Thu May 26, 2005 6:56 pm</p><hr />
]]></content>
	</entry>
	</feed>
