public void Set(PGNChessGame g)
            {
                idx = -1;
                move = null;
                total_moves = 0;

                player = g.HasTag ("FEN") ? ChessGamePlayer.
                    CreateFromFEN (g.
                               GetTagValue ("FEN",
                                    null)) :
                    ChessGamePlayer.CreatePlayer ();

                game = g;

                int n = game.Moves.Count;
                if (n > 0)
                  {
                      total_moves = (n - 1) * 2;
                      // now see the last move
                      ChessMove lastmove =
                          (ChessMove) game.Moves[n -
                                     1];
                      if (lastmove.blackmove == null)
                          total_moves += 1;
                      else
                            total_moves += 2;
                  }

                if (total_moves == 0)
                    hasNext = false;
                else
                      hasNext = true;
            }
            protected static string GenerateHash(PGNChessGame
							      game)
            {
                StringBuilder buffer = new StringBuilder ();
                int nmoves = game.Moves.Count;
                buffer.Append (String.
                           Format ("{0}:", nmoves));
                ChessGamePlayer player;
                player = game.HasTag ("FEN") ?
                    ChessGamePlayer.
                    CreateFromFEN (game.GetTagValue
                               ("FEN",
                            null))
                    : ChessGamePlayer.CreatePlayer ();
                player = Chess.Game.
                    ChessGamePlayer.CreatePlayer ();
                foreach (PGNChessMove move in game.Moves)
                {
                    player.Move (move.Move);
                }

                buffer.Append (player.GetPositionAsFEN ());
                buffer.Append (((nmoves + 1) / 2));
                return buffer.ToString ();
            }
            private void WriteGame(PGNChessGame game)
            {
                GameSession session = new GameSession ();
                session.Set (game);
                string white = game.White;
                string black = game.Black;
                string result = game.Result;

                if (white == null)
                    white = Catalog.GetString("[White]");
                if (black == null)
                    black = Catalog.GetString("[Black]");
                if (result == null)
                    result = Catalog.GetString("Unknown");

                printer.Font = fonts.titleFont;
                printer.PrintText (white + Catalog.GetString(" vs ") + black +
                           "\n\n");
                printer.Font = fonts.regularFont;
                printer.PrintText (Catalog.GetString("Result: ") + result +
                           "\n\n");

                printer.Font = fonts.moveFont;
                int moveno = 1;
                if (game.HasTag ("FEN"))
                    PrintImageForPosition
                        (session.player);

                foreach (ChessMove move in game.Moves)
                {
                    // print move
                    if (move.whitemove == null)
                        break;
                    printer.PrintText (moveno + ". " +
                               move.whitemove);
                    if (session.HasNext ())
                      {
                          session.Next ();
                          session.player.
                              Move (session.
                                CurrentMove);
                      }
                    if (move.whiteComment != null)
                      {
                          printer.LineBreak ();
                          PrintImageForPosition
                              (session.player);
                          printer.Font =
                              fonts.commentFont;
                          printer.PrintText (move.
                                     whiteComment);
                          printer.Font =
                              fonts.moveFont;
                          if (move.blackmove == null)
                              break;
                          printer.PrintText ("\n" +
                                     moveno +
                                     "...");
                      }

                    if (move.blackmove == null)
                        break;
                    if (session.HasNext ())
                      {
                          session.Next ();
                          session.player.
                              Move (session.
                                CurrentMove);
                      }
                    printer.PrintText (" " +
                               move.blackmove +
                               " ");
                    if (move.blackComment != null)
                      {
                          printer.LineBreak ();
                          PrintImageForPosition
                              (session.player);
                          printer.Font =
                              fonts.commentFont;
                          printer.PrintText (move.
                                     blackComment);
                          printer.Font =
                              fonts.moveFont;
                          printer.PrintText ("\n");
                      }
                    moveno++;
                }
            }