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;
            }
 public void SetGame(PGNChessGame g)
 {
     highlightMoveIndex = -1;
     game = g;
     gameInfoWidget.SetGame (game);
     UpdateGameDetails ();
 }
 public void GameEndFound()
 {
     PGNChessGame game =
         new PGNChessGame (initialComment,
                   curTagList,
                   curMoves);
     if (GameLoaded != null)
       {
           GameLoaded (this,
                   new
                   GameLoadedEventArgs
                   (game));
       }
     initialComment = null;
     curTagList = new ArrayList ();
     curMoves = new ArrayList ();
 }
            private static bool UpdateGameInModel(PGNChessGame
							       game,
							       PGNChessGame
							       replace,
							       TreeModel
							       model)
            {
                TreeIter iter;
                bool ret;
                for (ret = model.GetIterFirst (out iter); ret;
                     ret = model.IterNext (ref iter))
                  {
                      PGNChessGame g =
                          (PGNChessGame) model.
                          GetValue (iter, 0);
                      if (g.Equals (game))
                        {
                            model.SetValue (iter, 0,
                                    replace);
                            return true;
                        }
                  }

                return false;
            }
            public void UpdateGame(PGNChessGame game,
						PGNChessGame replace)
            {
                UpdateGameInModel (game, replace, gamesStore);
            }
Esempio n. 6
0
 public GameLoadedEventArgs(PGNChessGame game)
     : base()
 {
     this.game = game;
 }
Esempio n. 7
0
            private bool loadMoves(string
						initialtoken,
						ArrayList tagList,
						ref bool tagFound)
            {
                string token;
                StringBuilder commentBuffer =
                    new StringBuilder ();
                int moveidx = -1;
                ArrayList moves = new ArrayList ();
                ChessMove move = null;
                string initialComment = null;

                if (initialtoken == null)
                    token = tokenizer.nextToken ();
                else
                    token = initialtoken;

                for (; token != null;
                     token = tokenizer.nextToken ())
                  {
                      //      if(token.Equals("{") || token.Equals("(") || token.Equals("<")) {
                      if (token.Equals ("%"))
                        {
                            ignoreLine (token,
                                tokenizer);
                            continue;
                        }
                      else if (token.Equals (";"))
                        {
                            string comment =
                                readLineComment
                                (token,
                                 tokenizer);
                            commentBuffer.
                                Append (comment);
                            continue;
                        }
                      else if (token.Equals ("{")
                           || token.Equals ("("))
                        {
                            string comment =
                                readComment
                                (token,
                                 tokenizer);
                            commentBuffer.
                                Append (comment);
                            continue;
                        }
                      else if (isNAG (token))
                        {
                            /* TODO: convert comment into a nag */
                            commentBuffer.
                                Append (" " +
                                    token +
                                    " ");
                            continue;
                        }
                      else if (tokenIsATermination
                           (token))
                        {
                            /* end of game */
                            break;
                        }
                      else if (token.Equals ("["))
                        {
                            Console.WriteLine
                                ("Abrupt end of the game. Didnt find the termination");
                            tagFound = true;
                            break;
                        }

                      if (moveidx > 0
                          && token.Equals ("."))
                          continue;

                      /* process moves */
                      bool token_is_a_number =
                          isNumber (token);
                      if (!token_is_a_number
                          && moveidx < 0)
                          throw new
                              PGNParserException
                              ("Line " +
                               tokenizer.
                               currentLine () +
                               ": Expecting a number. Got this token: ["
                               + token + "]");

                      if (token_is_a_number)
                        {
                            int val =
                                Int32.
                                Parse (token);
                            if (moveidx < 0)
                              {	// first time
                                  moveidx = val;
                                  move = new
                                      ChessMove
                                      (moveidx);
                                  /* if there is a comment here.. add it to the previous move
                                   * If there is no previous move.. then the comment is at the
                                   * beginning of the game. So, create a dummy chess move.
                                   */
                                  if (commentBuffer.Length > 0)
                                {
                                    if (moves.Count == 0)
                                      {
                                          initialComment
                                              =
                                              commentBuffer.
                                              ToString
                                              ();
                                          commentBuffer.
                                              Remove
                                              (0,
                                               commentBuffer.
                                               Length);
                                      }
                                    else
                                      {
                                          ChessMove
                                              previousmove
                                              =
                                              (ChessMove)
                                              moves
                                              [moves.
                                               Count
                                               -
                                               1];
                                          previousmove.
                                              blackComment
                                              =
                                              commentBuffer.
                                              ToString
                                              ();
                                          commentBuffer.
                                              Remove
                                              (0,
                                               commentBuffer.
                                               Length);
                                      }
                                }
                              }
                            else if (moveidx != val)
                                throw new
                                    PGNParserException
                                    ("Line: "
                                     +
                                     tokenizer.
                                     currentLine
                                     ());
                        }
                      else if (move.whitemove == null)
                        {
                            /* first token after move number */
                            move.whitemove = token;
                        }
                      else if (move.blackmove == null)
                        {
                            move.blackmove = token;
                            if (commentBuffer.Length >
                            0)
                              {
                                  move.whiteComment = commentBuffer.ToString ();
                                  commentBuffer.
                                      Remove
                                      (0,
                                       commentBuffer.
                                       Length);
                              }
                            /* at this point we have the moveidx, whitemove and blackmove
                             * Now create a chessmove. If there is any comment after this
                             * it will be added later.
                             */
                            moves.Add (move);
                            moveidx = -1;
                            move = null;
                        }
                  }

                if (commentBuffer.Length > 0)
                  {
                      if (move == null)
                        {
                            ChessMove previousmove =
                                (ChessMove)
                                moves[moves.
                                  Count - 1];
                            previousmove.
                                blackComment =
                                commentBuffer.
                                ToString ();
                            commentBuffer.Remove (0,
                                      commentBuffer.
                                      Length);
                        }
                      else
                        {
                            if (move.blackmove ==
                            null)
                                move.whiteComment
                                    =
                                    commentBuffer.
                                    ToString
                                    ();
                            else
                                move.blackComment
                                    =
                                    commentBuffer.
                                    ToString
                                    ();
                        }
                  }

                if (move != null)
                    moves.Add (move);

                PGNChessGame game =
                    new PGNChessGame (initialComment,
                              tagList, moves);
                if (GameLoaded != null)
                  {
                      GameLoaded (this,
                              new
                              GameLoadedEventArgs
                              (game));
                  }
                return 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 ();
            }
 public PGNGameDetails(PGNChessGame game)
     : base(game)
 {
     nmoves = game.Moves.Count;
     white = game.GetTagValue ("White", "");
     black = game.GetTagValue ("Black", "");
     result = game.GetTagValue ("Result", "*");
 }
Esempio n. 10
0
 protected PGNChessGame(PGNChessGame game)
 {
     comment = game.comment;
     tagList = game.tagList;
     moves = game.moves;
 }
Esempio n. 11
0
            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++;
                }
            }
 public void SetGame(PGNChessGame g)
 {
     game = g;
     UpdateGameDetails ();
 }
Esempio n. 13
0
 public ChessGame(PGNChessGame game)
     : base(game)
 {
 }