ó
 ,µ[c           @   sU  d  Z  d d l j Z d d l Z d d d d d g Z d d	 „ Z e d
 k rQe ƒ  Z	 e	 j
 ƒ  Z e	 j ƒ  Z d e e f GHe e j e	 j ƒ  ƒ ƒ Z e e ƒ d k rÂ d GHe d j ƒ  GHn  e g  e	 j d e ƒ D] \ Z Z Z e d ^ qØ ƒ Z d e e ƒ GHd GHd GHxw e	 j d e ƒ D]c \ Z Z Z e d d k r&e d e f GHx+ e j ƒ  D] \ Z Z d e d e f GHq`Wd GHq&q&We j e	 ƒ Z g  Z  xB e j d e ƒ D]. \ Z! Z Z" e  j# e e	 j$ e! e ƒ ƒ ƒ qµWe% j& e	 j ƒ  d ƒ Z' xœ e	 j d e ƒ D]ˆ \ Z! Z Z" e" d j( d ƒ Z) e) d d k rWe' e! c d 7<qe) d d k rŠe' e! c d 7<e' e c d 7<qe' e c d 7<qWy e j* j+ e ƒ Z, Wn e j- e d d ƒZ, n Xe. e j/ d  <e j0 d! d? ƒ e j1 e e, d# d$ d% e  d& d' ƒg  e D] Z e' e d( ^ qZ2 e j3 e e, d) e2 d* d+ d# d, ƒe j1 e e, d# d, d) d d% d d& d- ƒe j4 e e, d. d/ ƒi d0 d1 6d- d2 6d3 d4 6d/ d. 6Z5 e j6 d5 e5 ƒ i d0 d1 6d6 d2 6d3 d4 6d/ d. 6Z5 e j7 d d7 d8 d9 d: d; e j8 ƒ  j9 ƒe j7 d d< d= d9 d: d; e j8 ƒ  j9 ƒe j: d> ƒ e j; ƒ  n  d S(@   s  
=============
Chess Masters
=============

An example of the MultiDiGraph clas

The function chess_pgn_graph reads a collection of chess matches stored in the
specified PGN file (PGN ="Portable Game Notation").  Here the (compressed)
default file::

    chess_masters_WCC.pgn.bz2

contains all 685 World Chess Championship matches from 1886--1985.
(data from http://chessproblem.my-free-games.com/chess/games/Download-PGN.php)

The `chess_pgn_graph()` function returns a `MultiDiGraph` with multiple edges.
Each node is the last name of a chess master. Each edge is directed from white
to black and contains selected game info.

The key statement in `chess_pgn_graph` below is::

    G.add_edge(white, black, game_info)

where `game_info` is a `dict` describing each game.
iÿÿÿÿNt   Eventt   Datet   Resultt   ECOt   Sites   chess_masters_WCC.pgn.bz2c         C   sÜ   d d l  } t j ƒ  } i  } | j |  ƒ } d „  | Dƒ } x˜ | D] } | j d ƒ r” | d d !j d d ƒ \ } } | j d ƒ | t | ƒ <qD | rD | j d ƒ }	 | j d	 ƒ }
 | j	 |	 |
 |  i  } qD qD W| S(
   sÖ   Read chess games in pgn format in pgn_file.

    Filenames ending in .gz or .bz2 will be uncompressed.

    Return the MultiDiGraph of players connected by a chess game.
    Edges contain game data in a dict.

    iÿÿÿÿNc         s   s$   |  ] } | j  ƒ  j d  ƒ Vq d S(   s   
N(   t   decodet   rstrip(   t   .0t   line(    (    s=   share/doc/networkx-2.2/examples/drawing/plot_chess_masters.pys	   <genexpr>=   s    t   [i   t    t   "t   Whitet   Black(
   t   bz2t   nxt   MultiDiGrapht   BZ2Filet
   startswitht   splitt   stript   strt   popt   add_edge(   t   pgn_fileR   t   Gt   gamet   datafilet   linesR   t   tagt   valuet   whitet   black(    (    s=   share/doc/networkx-2.2/examples/drawing/plot_chess_masters.pyt   chess_pgn_graph0   s    	t   __main__s)   Loaded %d chess games between %d players
i   s.   Note the disconnected component consisting of:t   datas'   
From a total of %d different openings,s-   the following games used the Sicilian openings5   with the Najdorff 7...Qb6 "Poisoned Pawn" variation.
t   B97t   vss      s   : s   
g        t   -i    t   1g      ð?s   1/2g      à?t
   iterationsi   s   text.usetext   figsizei   t   alphag333333Ó?t   widtht
   edge_colort   mi2   t	   node_sizet
   node_colort   wgš™™™™™Ù?t   kt   fontsizei   t	   Helveticat   fontnamet   colort   boldt
   fontweights+   World Chess Championship Games: 1886 - 1985t   rg
×£p=
ï?s   edge width = # games playedt   horizontalalignmentt   centert	   transformg®Gázî?s   node size = # games wont   off(   i   i   (<   t   __doc__t   matplotlib.pyplott   pyplott   pltt   networkxR   t   game_detailsR!   t   __name__R   t   number_of_edgest   ngamest   number_of_nodest   nplayerst   listt   connected_component_subgraphst   to_undirectedt   Gcct   lent   nodest   sett   edgest   TrueR   R    t	   game_infot   openingst   itemsR1   t   vt   Grapht   Ht	   edgewidtht   ut   dt   appendt   get_edge_datat   dictt   fromkeyst   winsR   R8   t	   nx_agrapht   graphviz_layoutt   post   spring_layoutt   Falset   rcParamst   figuret   draw_networkx_edgest   nodesizet   draw_networkx_nodest   draw_networkx_labelst   fontt   titlet   textt   gcat	   transAxest   axist   show(    (    (    s=   share/doc/networkx-2.2/examples/drawing/plot_chess_masters.pyt   <module>   sŒ   		2""#""!"(



