public static Game Deserialize(BsonDocument document) { ObjectId id = document["_id"].AsObjectId; Player active_player = PlayerUtils.FromString(document["active_player"].AsString); GameState game_state = GameStateUtils.FromString(document["game_state"].AsString); DateTime creation_time = document["creation_time"].ToLocalTime(); var harmonics = new List <QuantumHarmonic>(); foreach (BsonValue bson_harmonic_val in document["harmonics"].AsBsonArray) { BsonDocument bson_harmonic = bson_harmonic_val.AsBsonDocument; GameState harmonic_state = GameStateUtils.FromString(bson_harmonic["harmonic_state"].AsString); ulong degeneracy = Convert.ToUInt64(bson_harmonic["degeneracy"].AsInt64); BsonArray bson_chessboard = bson_harmonic["chessboard"].AsBsonArray; var chessboard = Chessboard.EmptyChessboard(harmonic_state); for (int i = 0; i < 64; i++) { BsonValue bson_square_val = bson_chessboard[i]; if (bson_square_val.IsBsonNull) { chessboard[i] = null; } else { BsonDocument bson_square = bson_square_val.AsBsonDocument; Player square_player = PlayerUtils.FromString(bson_square["player"].AsString); PieceType square_piece = PieceTypeUtils.FromString(bson_square["piece"].AsString); chessboard[i] = new Piece(square_player, square_piece); } } harmonics.Add(new QuantumHarmonic(chessboard, degeneracy)); } var quantum_chessboard = new QuantumChessboard(harmonics, game_state); var last_move_positions = new List <Position>(); foreach (BsonValue pos_val in document["last_move_positions"].AsBsonArray) { last_move_positions.Add(Position.Parse(pos_val.AsString)); } var engine = new QuantumChessEngine(quantum_chessboard, active_player, creation_time, last_move_positions.ToArray()); return(new Game(id, engine)); }