public void Whether_GameParser_ParsesFENGame_On_Parse() { var parser = new GameParser(); var result = parser.Parse(fenGame); Assert.That(result != null); }
static void Main(string[] args) { using (var context = new GamesStoreContext()) { var parser = new GameParser(); var repo = new Repository <GameDTO>(context); for (int i = 1; i <= 8; i++) { using (var errorLog = new StreamWriter($"..\\..\\puzzles\\errorLog.txt")) using (var reader = new StreamReader($"..\\..\\puzzles\\m2_{i}.pgn")) { var builder = new StringBuilder(); var line = string.Empty; while (!reader.EndOfStream) { builder.Clear(); builder.AppendLine(line); while (!reader.EndOfStream && !(line = reader.ReadLine()).Contains("Event")) { if (line.Contains("Date")) { line = line.Replace("-", "."); line.Replace("\"?\"", "\"????\""); } // Skip [Round] as it's not properly parsed by pgn if (line.Contains("Round")) { continue; } builder.AppendLine(line); } var text = builder.ToString(); text = text.TrimEnd('\r', '\n'); try { foreach (var game in parser.Parse(text)) { var gameDto = new GameDTO() { PgnString = text }; repo.Insert(gameDto); repo.Save(); } } catch (Exception ex) { errorLog.WriteLine($"File m2_{i}.pgn\n Error: {ex.Message}\n While parsing FEN: {text}"); } } } Console.WriteLine($"File m2_{i}.pgn processed"); } } }
public void Whether_GameParser_ParsesMultipleGames_On_Parse() { var parser = new GameParser(); var result = parser.Parse(gamesPgn); Assert.That(result != null); Assert.That(result.Count() == 2); }
public void Whether_Game_ParsesPgnGame_On_Construct() { var parser = new GameParser(); var game = parser.Parse(fenGame).FirstOrDefault(); Assert.That(game.Board != null); Assert.That(game.Board.Pieces.Count() == 17); }
public void Whether_GameParser_ParsesIsWhiteMove_On_Parse(string fenGame, bool isWhiteMove) { var parser = new GameParser(); var result = parser.Parse(fenGame); var game = result.FirstOrDefault(); Assert.That(game != null); Assert.That(game.Board.IsWhiteMove == isWhiteMove); }
public void Whether_GameParser_ParsesFENGameMoves_On_Parse() { var parser = new GameParser(); var result = parser.Parse(fenBlackMove); var game = result.FirstOrDefault(); Assert.That(game != null); Assert.That(game.MoveEntries != null); Assert.That(game.MoveEntries.Count() == 3); }
public void SetUp() { const string gameText = "1 0 | 2 1 | 3 1 | 4 1 | 5 1 | 6 1 | 7 1 | 8 1 | 9 1 | / 1 1 "; _mockFrame = new Frame { RollOne = 1, RollTwo = 0 }; var frameParser = Substitute.For <IFrameParser>(); frameParser.Parse(null).ReturnsForAnyArgs(_mockFrame); var subject = new GameParser(frameParser); _gameState = subject.Parse(gameText); }
public static string Parser(string input) { if (parserSelect == 0) { string output = MainMenuParser.Parse(input); previousParser = parserSelect; parserSelect = stateChange(output); return(output); } else if (parserSelect == 1) { string output = GameParser.Parse(input); previousParser = parserSelect; parserSelect = stateChange(output); return(output); } else if (parserSelect == 2) { string output = GameData.saveParser(input); previousParser = parserSelect; stateChange(output); return(output); } else if (parserSelect == 3) { string output = GameData.loadParser(input); previousParser = parserSelect; parserSelect = stateChange(output); return(output); } else if (parserSelect == 4) { string output = NewGameParser.Parse(input); previousParser = parserSelect; parserSelect = stateChange(output); return(output); } else if (parserSelect == 5) { string output = GenericCommands.quitParser(input); previousParser = parserSelect; parserSelect = stateChange(output); return(output); } else { return(input); } }
public async Task <Game> GetById(int id) { var serviceUrl = @"http://chezzles.azurewebsites.net/api/puzzles/{0}"; var uri = new Uri(string.Format(serviceUrl, id)); var response = client.GetAsync(uri).Result; if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var strGame = JsonConvert.DeserializeObject <GameDTO>(content); var parser = new GameParser(); return(parser.Parse(strGame.PgnString).FirstOrDefault()); } return(null); }
public async Task <List <Game> > GetAll() { var serviceUrl = @"http://chezzles.azurewebsites.net/api/puzzles"; var uri = new Uri(serviceUrl); var response = client.GetAsync(uri).Result; if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); var strGames = JsonConvert.DeserializeObject <List <GameDTO> >(content); var parser = new GameParser(); return(parser.Parse(string.Join(" ", strGames.Select(x => x.PgnString))).ToList()); } return(null); }
public void Whether_Game_NotifiesWhenPuzzleFailed_On_PieceMove() { var failed = false; var parser = new GameParser(); var result = parser.Parse(fenWhiteMove); var game = result.FirstOrDefault(); game.PuzzleFailed += (b, m) => failed = true; var targetSquare = new Square(7, 7); var rook = game.Board.Pieces.FirstOrDefault(x => x.Type == PieceType.Rook && x.PossibleMoves().Contains(targetSquare)); game.Board.PutPiece(targetSquare, rook); Assert.That(failed, Is.True); }
public void Whether_Game_SendsPuzzleFailedMessage_On_PuzzleSolved() { var failed = false; var parser = new GameParser(); var result = parser.Parse(fenWhiteMove); var game = result.FirstOrDefault(); var targetSquare = new Square(7, 7); Messenger.Default.Register <PuzzleCompletedMessage>(this, (msg) => failed = !msg.IsSolved); var rook = game.Board.Pieces.FirstOrDefault(x => x.Type == PieceType.Rook && x.PossibleMoves().Contains(targetSquare) && x.Color == (game.Board.IsWhiteMove ? PieceColor.White : PieceColor.Black)); game.Board.PutPiece(targetSquare, rook); Assert.That(failed, Is.True); }
public void Whether_Game_OpponentMakesNextMove_On_PieceMoved() { var pieceMoved = false; var parser = new GameParser(); var result = parser.Parse(fenGame); var game = result.FirstOrDefault(); var targetSquare = new Square(8, 3); var rook = game.Board.Pieces.FirstOrDefault(x => x.Type == PieceType.Rook && x.PossibleMoves().Contains(targetSquare) && x.Color == (game.Board.IsWhiteMove ? PieceColor.White : PieceColor.Black)); var whiteQueen = game.Board.Pieces.FirstOrDefault(x => x.Type == PieceType.Queen && x.Color == PieceColor.White); whiteQueen.PositionUpdated += (e, s) => pieceMoved = true; game.Board.PutPiece(targetSquare, rook); Assert.That(pieceMoved, Is.True); }
private void ReceivedPackets(string datas) { lock (locker) parser.Parse(datas); }