gnome-games r8071 - in trunk/glchess/src/lib: chess gtkui



Author: rancell
Date: Sat Oct 18 06:20:06 2008
New Revision: 8071
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8071&view=rev

Log:
Added support for Figurine Algebraic Notation (FAN) (Bug #556803)

Modified:
   trunk/glchess/src/lib/chess/__init__.py
   trunk/glchess/src/lib/gtkui/chessview.py
   trunk/glchess/src/lib/gtkui/dialogs.py

Modified: trunk/glchess/src/lib/chess/__init__.py
==============================================================================
--- trunk/glchess/src/lib/chess/__init__.py	(original)
+++ trunk/glchess/src/lib/chess/__init__.py	Sat Oct 18 06:20:06 2008
@@ -124,3 +124,30 @@
         except KeyError:
             out += c
     return out
+
+_figurineMap = {(board.WHITE, 'P'): 'â', (board.WHITE, 'N'): 'â', (board.WHITE, 'B'): 'â',
+                (board.WHITE, 'R'): 'â', (board.WHITE, 'Q'): 'â', (board.WHITE, 'K'): 'â',
+                (board.BLACK, 'P'): 'â', (board.BLACK, 'N'): 'â', (board.BLACK, 'B'): 'â',
+                (board.BLACK, 'R'): 'â', (board.BLACK, 'Q'): 'â', (board.BLACK, 'K'): 'â'}
+
+def translate_figurine_notation(colour, notation):
+    """Get the translated form of a chess move in FAN notation
+    
+    'colour' is the colour of the player making the move (board.WHITE or board.BLACK).
+    'notation' is the notation to translate (e.g. 'Nxc6', 'f2f4').
+    
+    Returns a translated form of this notation.
+    """
+    out = ''
+    isTake = False
+    oppositeColour = {board.WHITE: board.BLACK, board.BLACK: board.WHITE}[colour]
+    for c in notation:
+        try:
+            if isTake:
+                out += _figurineMap[(oppositeColour, c)]
+            else:
+                out += _figurineMap[(colour, c)]                
+        except KeyError:
+            out += c
+        isTake = (c == 'x')
+    return out

Modified: trunk/glchess/src/lib/gtkui/chessview.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/chessview.py	(original)
+++ trunk/glchess/src/lib/gtkui/chessview.py	Sat Oct 18 06:20:06 2008
@@ -373,6 +373,9 @@
         """
         """
         moveNumber = (move.number - 1) / 2 + 1
+        WHITE  = glchess.chess.board.WHITE
+        BLACK  = glchess.chess.board.BLACK
+        colour = {0: BLACK, 1: WHITE}[move.number % 2]
         
         # Note SAN format is intentionally not translated
         if self.moveFormat == 'san':
@@ -382,6 +385,14 @@
                 format = '%(movenum)2i. %(move_san)s'
             return format % {'movenum': moveNumber, 'move_san': glchess.chess.translate_notation(move.sanMove)}
         
+        # Note SAN format is intentionally not translated
+        if self.moveFormat == 'fan':
+            if move.number % 2 == 0:
+                format = '%(movenum)2i. ... %(move_san)s'
+            else:
+                format = '%(movenum)2i. %(move_san)s'
+            return format % {'movenum': moveNumber, 'move_san': glchess.chess.translate_figurine_notation(colour, move.sanMove)}
+
         # Note LAN format is intentionally not translated
         if self.moveFormat == 'lan':
             if move.number % 2 == 0:
@@ -390,15 +401,12 @@
                 format = '%(movenum)2i. %(move_can)s'
             return format % {'movenum': moveNumber, 'move_can': glchess.chess.translate_notation(move.canMove)}
 
-        WHITE  = glchess.chess.board.WHITE
-        BLACK  = glchess.chess.board.BLACK
         PAWN   = glchess.chess.board.PAWN
         ROOK   = glchess.chess.board.ROOK
         KNIGHT = glchess.chess.board.KNIGHT
         BISHOP = glchess.chess.board.BISHOP
         QUEEN  = glchess.chess.board.QUEEN
         KING   = glchess.chess.board.KING
-        colour = {0: BLACK, 1: WHITE}[move.number % 2]
 
         if move.sanMove.startswith('O-O-O'):
                            # Translators: Human Move String: Description of the white player making a long castle

Modified: trunk/glchess/src/lib/gtkui/dialogs.py
==============================================================================
--- trunk/glchess/src/lib/gtkui/dialogs.py	(original)
+++ trunk/glchess/src/lib/gtkui/dialogs.py	Sat Oct 18 06:20:06 2008
@@ -582,10 +582,12 @@
         widget.set_model(moveModel)
                         # Translators: Move Format Combo: Moves shown in human descriptive notation
         move_formats = [('human', _('Human')),
-                        # Translators: Move Format Combo: Moves shown in long algebraic notation (LAN)
-                        ('lan', _('Long Algebraic')),
                         # Translators: Move Format Combo: Moves shown in standard algebraic notation (SAN)
-                        ('san', _('Standard Algebraic'))]
+                        ('san', _('Standard Algebraic')),
+                        # Translators: Move Format Combo: Moves shown in standard figurine algebraic notation (FAN)
+                        ('fan', _('Figurine')),
+                        # Translators: Move Format Combo: Moves shown in long algebraic notation (LAN)
+                        ('lan', _('Long Algebraic'))]
         for (key, label) in move_formats:
             iter = moveModel.append()
             moveModel.set(iter, 0, label, 1, key)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]