Example #1
0
 public void AddHistory(GameInfo Info, BitBoard Move)
 {
     this.history[Info].Add(BitBoard.CopyFigureValues(Move));
     this.activeColor *= -1;
 }
Example #2
0
        public bool LoadHistoryFromDisk(string PathToLoad)
        {
            bool result = false;

            if (!string.IsNullOrEmpty(PathToLoad))
            {
                if (File.Exists(PathToLoad))
                {
                    this.history.Clear();
                    using (StreamReader sr = new StreamReader(PathToLoad, Encoding.UTF8))
                    {
                        GameInfo info  = (GameInfo)DeserializeObject(sr.ReadLine());
                        BitBoard board = new BitBoard();
                        this.history.Add(info, new List <BitBoard>());
                        int amount = 0;
                        if (int.TryParse(sr.ReadLine(), out amount))
                        {
                            for (int step = 0; step < amount; ++step)
                            {
                                board.WhiteKing           = UInt64.Parse(sr.ReadLine());
                                board.WhiteQueens         = UInt64.Parse(sr.ReadLine());
                                board.WhiteRooks          = UInt64.Parse(sr.ReadLine());
                                board.WhiteBishops        = UInt64.Parse(sr.ReadLine());
                                board.WhiteKnights        = UInt64.Parse(sr.ReadLine());
                                board.WhitePawns          = UInt64.Parse(sr.ReadLine());
                                board.EnPassantWhite      = UInt64.Parse(sr.ReadLine());
                                board.BlackKing           = UInt64.Parse(sr.ReadLine());
                                board.BlackQueens         = UInt64.Parse(sr.ReadLine());
                                board.BlackRooks          = UInt64.Parse(sr.ReadLine());
                                board.Blackbishops        = UInt64.Parse(sr.ReadLine());
                                board.BlackKnights        = UInt64.Parse(sr.ReadLine());
                                board.BlackPawns          = UInt64.Parse(sr.ReadLine());
                                board.EnPassantBlack      = UInt64.Parse(sr.ReadLine());
                                board.BalckKingMoved      = sr.ReadLine() == "1" ? true : false;
                                board.WhiteKingMoved      = sr.ReadLine() == "1" ? true : false;
                                board.BlackLeftRookMoved  = sr.ReadLine() == "1" ? true : false;
                                board.BlackRightRookMoved = sr.ReadLine() == "1" ? true : false;
                                board.WhiteLeftRookMoved  = sr.ReadLine() == "1" ? true : false;
                                board.WhiteRightRookMoved = sr.ReadLine() == "1" ? true : false;
                                this.history[info].Add(BitBoard.CopyFigureValues(board));
                            }
                            this.activeColor = int.Parse(sr.ReadLine());
                            //Current state
                            board.WhiteKing           = UInt64.Parse(sr.ReadLine());
                            board.WhiteQueens         = UInt64.Parse(sr.ReadLine());
                            board.WhiteRooks          = UInt64.Parse(sr.ReadLine());
                            board.WhiteBishops        = UInt64.Parse(sr.ReadLine());
                            board.WhiteKnights        = UInt64.Parse(sr.ReadLine());
                            board.WhitePawns          = UInt64.Parse(sr.ReadLine());
                            board.EnPassantWhite      = UInt64.Parse(sr.ReadLine());
                            board.BlackKing           = UInt64.Parse(sr.ReadLine());
                            board.BlackQueens         = UInt64.Parse(sr.ReadLine());
                            board.BlackRooks          = UInt64.Parse(sr.ReadLine());
                            board.Blackbishops        = UInt64.Parse(sr.ReadLine());
                            board.BlackKnights        = UInt64.Parse(sr.ReadLine());
                            board.BlackPawns          = UInt64.Parse(sr.ReadLine());
                            board.EnPassantBlack      = UInt64.Parse(sr.ReadLine());
                            board.BalckKingMoved      = sr.ReadLine() == "1" ? true : false;
                            board.WhiteKingMoved      = sr.ReadLine() == "1" ? true : false;
                            board.BlackLeftRookMoved  = sr.ReadLine() == "1" ? true : false;
                            board.BlackRightRookMoved = sr.ReadLine() == "1" ? true : false;
                            board.WhiteLeftRookMoved  = sr.ReadLine() == "1" ? true : false;
                            board.WhiteRightRookMoved = sr.ReadLine() == "1" ? true : false;
                            this.history[info].Add(BitBoard.CopyFigureValues(board));

                            result = true;
                        }
                        else
                        {
                            throw new Exception("Invalid save file");
                        }
                    }
                }
            }
            return(result);
        }