[Tkabber-dev] r1481 - in trunk/tkabber-plugins: . checkers chess chess/msgs renju reversi

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Aug 8 14:48:30 MSD 2008


Author: sergei
Date: 2008-08-08 14:48:29 +0400 (Fri, 08 Aug 2008)
New Revision: 1481

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/checkers/checkers.tcl
   trunk/tkabber-plugins/chess/chess.tcl
   trunk/tkabber-plugins/chess/msgs/ru.msg
   trunk/tkabber-plugins/renju/renju.tcl
   trunk/tkabber-plugins/reversi/reversi.tcl
Log:
	* checkers/checkers.tcl, chess/chess.tcl, renju/renju.tcl,
	  reversi/reversi.tcl: Don't warn user about not received move replies
	  on disconnect.

	* chess/chess.tcl: Added draw by repetition.

	* chess/msgs/ru.msg: Updated Russian translation.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2008-08-03 17:57:40 UTC (rev 1480)
+++ trunk/tkabber-plugins/ChangeLog	2008-08-08 10:48:29 UTC (rev 1481)
@@ -1,3 +1,13 @@
+2008-08-08  Sergei Golovan <sgolovan at nes.ru>
+
+	* checkers/checkers.tcl, chess/chess.tcl, renju/renju.tcl,
+	  reversi/reversi.tcl: Don't warn user about not received move replies
+	  on disconnect.
+
+	* chess/chess.tcl: Added draw by repetition.
+
+	* chess/msgs/ru.msg: Updated Russian translation.
+
 2008-07-12  Sergei Golovan <sgolovan at nes.ru>
 
 	* whiteboard/whiteboard.tcl: Fixed typo.

Modified: trunk/tkabber-plugins/checkers/checkers.tcl
===================================================================
--- trunk/tkabber-plugins/checkers/checkers.tcl	2008-08-03 17:57:40 UTC (rev 1480)
+++ trunk/tkabber-plugins/checkers/checkers.tcl	2008-08-08 10:48:29 UTC (rev 1481)
@@ -1127,7 +1127,7 @@
 }
 
 proc checkers::send_result {gid res child} {
-    if {$res != "OK"} {
+    if {$res == "ERR"} {
 	attention_message $gid \
 	    [format [::msgcat::mc "\n\n Opponent rejected move:\n %s\n\n"] \
 		[error_to_string $child]]

Modified: trunk/tkabber-plugins/chess/chess.tcl
===================================================================
--- trunk/tkabber-plugins/chess/chess.tcl	2008-08-03 17:57:40 UTC (rev 1480)
+++ trunk/tkabber-plugins/chess/chess.tcl	2008-08-08 10:48:29 UTC (rev 1481)
@@ -296,6 +296,8 @@
     set flags(position,draw) 0
     set flags(position,halfmove) 0
     set flags(position,history) {}
+
+    set flags(position,repetitions) [list [code_position $gid] 1]
 }
 
 proc chess::save_position {gid} {
@@ -316,6 +318,33 @@
     find_legal_moves $gid $flags(position,turn)
 }
 
+proc chess::code_position {gid} {
+    variable $gid
+    upvar 0 $gid flags
+
+    set code ""
+    for {set c 0} {$c < 8} {incr c} {
+	for {set r 0} {$r < 8} {incr r} {
+	    switch -- $flags(position,$c,$r) {
+		wk {append code K}
+		wq {append code Q}
+		wr {append code R}
+		wb {append code B}
+		wn {append code N}
+		wp {append code P}
+		bk {append code k}
+		bq {append code q}
+		br {append code r}
+		bb {append code b}
+		bn {append code n}
+		bp {append code p}
+		default {append code .}
+	    }
+	}
+    }
+    return $code
+}
+
 proc chess::make_gid {jid id} {
     jid_to_tag [concat $jid $id]
 }
@@ -1023,6 +1052,9 @@
     }
     lappend opts $prm $suffix
     add_move_to_history $gid $cf $rf $ct $rt $f $opts
+
+    set repetitions [add_to_repetitions $gid]
+
     if {$draw && !$my_move} {
 	attention_message $gid \
 	    [::msgcat::mc "\n\n Opponent proposes a draw\n\n"]
@@ -1033,8 +1065,11 @@
     }
 
     if {$stalemate} {
-	# Draw
+	# Draw by stalemate
 	end_game $gid 0.5 [::msgcat::mc "Draw (Stalemate)"]
+    } elseif {$repetitions >= 3} {
+	# Draw by repetition
+	end_game $gid 0.5 [::msgcat::mc "Draw (Repetition)"]
     } elseif {$checkmate} {
 	if {$my_move} {
 	    # I win
@@ -1186,7 +1221,7 @@
 }
 
 proc chess::send_result {gid res child} {
-    if {$res != "OK"} {
+    if {$res == "ERR"} {
 	attention_message $gid \
 	    [format [::msgcat::mc "\n\n Opponent rejected move:\n %s\n\n"] \
 		[error_to_string $child]]
@@ -1206,6 +1241,21 @@
     }
 }
 
+proc chess::add_to_repetitions {gid} {
+    variable $gid
+    upvar 0 $gid flags
+
+    array set repetitions $flags(position,repetitions)
+    set code [code_position $gid]
+    if {[info exists repetitions($code)]} {
+	incr repetitions($code)
+    } else {
+	set repetitions($code) 1
+    }
+    set flags(position,repetitions) [array get repetitions]
+    return $repetitions($code)
+}
+
 proc chess::add_move_to_history {gid cf rf ct rt f opts} {
     variable piece_name
     variable $gid

Modified: trunk/tkabber-plugins/chess/msgs/ru.msg
===================================================================
--- trunk/tkabber-plugins/chess/msgs/ru.msg	2008-08-03 17:57:40 UTC (rev 1480)
+++ trunk/tkabber-plugins/chess/msgs/ru.msg	2008-08-08 10:48:29 UTC (rev 1481)
@@ -44,6 +44,7 @@
 ::msgcat::mcset ru "Opponent wins (You resigned)" "Оппонент выиграл (Вы сдались)"
 ::msgcat::mcset ru "You win (Opponent resigned)" "Вы выиграли (Оппонент сдался)"
 ::msgcat::mcset ru "Draw (Stalemate)" "Ничья (Пат)"
+::msgcat::mcset ru "Draw (Repetition)" "Ничья (Повторение позиции)"
 ::msgcat::mcset ru "Draw (You accepted)" "Ничья (Вы приняли)"
 ::msgcat::mcset ru "Draw (Opponent accepted)" "Ничья (Оппонент принял)"
 ::msgcat::mcset ru "Press button and make move if you want propose draw" "Нажмите кнопку и сделайте ход, если хотите предложить ничью"

Modified: trunk/tkabber-plugins/renju/renju.tcl
===================================================================
--- trunk/tkabber-plugins/renju/renju.tcl	2008-08-03 17:57:40 UTC (rev 1480)
+++ trunk/tkabber-plugins/renju/renju.tcl	2008-08-08 10:48:29 UTC (rev 1481)
@@ -988,7 +988,7 @@
 }
 
 proc renju::send_result {gid res child} {
-    if {$res != "OK"} {
+    if {$res == "ERR"} {
 	attention_message $gid \
 	    [format [::msgcat::mc "\n\n Opponent rejected move:\n %s\n\n"] \
 		[error_to_string $child]]

Modified: trunk/tkabber-plugins/reversi/reversi.tcl
===================================================================
--- trunk/tkabber-plugins/reversi/reversi.tcl	2008-08-03 17:57:40 UTC (rev 1480)
+++ trunk/tkabber-plugins/reversi/reversi.tcl	2008-08-08 10:48:29 UTC (rev 1481)
@@ -960,7 +960,7 @@
 }
 
 proc reversi::send_result {gid res child} {
-    if {$res != "OK"} {
+    if {$res == "ERR"} {
 	attention_message $gid \
 	    [format [::msgcat::mc "\n\n Opponent rejected move:\n %s\n\n"] \
 		[error_to_string $child]]



More information about the Tkabber-dev mailing list