public void CanRokade(string fenString, RokadeEnum expected) { Fen.Of(fenString).CreatePositionAbstraction() .Match( None: () => { Assert.Fail(); return(true); }, Some: p => { Assert.AreEqual(expected, possibleRokade(p)); return(true); }); }
public void NullFen() { string fen = null; Assert.Throws <ArgumentNullException>( () => Fen.Parse(fen)); }
public void AllValid960Positions() { int validStartCount = 0; string classicStart = "rnbqkbnr"; List <string> solutions = new List <string>(); IEnumerable <IEnumerable <char> > allPermutations = GetPermutations(classicStart, 8); foreach (IEnumerable <char> permutation in allPermutations) { StringBuilder sb = new StringBuilder(); foreach (char c in permutation) { sb.Append(c); } if (Fen.Validate960StartPosition(sb.ToString())) { string validPositions = sb.ToString(); if (!solutions.Contains(validPositions)) { solutions.Add(validPositions); validStartCount++; } } } Assert.AreEqual(960, validStartCount); }
private void CheckFenButton_Click(object sender, RoutedEventArgs e) { var input = FenTextBox.Text ?? string.Empty; var lines = input.Split(new[] { "\r\n", "\r", "\n" }, System.StringSplitOptions.RemoveEmptyEntries); var listOfIllegalFens = new List <int>(); for (var i = 0; i < lines.Length; i++) { var jonasFenFlag = Fen.CheckJonasFen(lines[i]); if (!jonasFenFlag) { listOfIllegalFens.Add(i); } } foreach (var failedNumber in listOfIllegalFens) { MessageBox.Show("FEN in line " + (failedNumber + 1) + " could not be parsed."); } if (listOfIllegalFens.Count == 0 && lines.Length != 0) { var checkWindow = new CheckWindow(lines); checkWindow.ShowDialog(); } }
private void InitFiguresPosition() { string[] parts = Fen.Split(); if (parts.Length < 6) { return; } var castlingFenPart = parts[2]; WhiteCastlingFenPart = new string(castlingFenPart.Where(c => char.IsUpper(c)).ToArray()); BlackCastlingFenPart = new string(castlingFenPart.Where(c => char.IsLower(c)).ToArray()); InitFigures(parts[0]); MoveColor = string.Equals("b", parts[1].Trim().ToLower()) ? Color.Black : Color.White; MoveNumber = int.Parse(parts[5]); void InitFigures(string data) { for (int i = 8; i >= 2; i--) { data = data.Replace(i.ToString(), (i - 1).ToString() + "1"); } var lines = data.Split('/'); for (int y = 7; y >= 0; y--) { for (int x = 0; x < 8; x++) { figures[x, y] = (Figure)lines[7 - y][x]; } } } }
static void Main(string[] args) { string fen = "1R6/P1PN1p2/kpPbpK1P/Bpp2R2/2PrP1Q1/N1P1p1np/bpq1P1r1/5Bn1 w - - 0 1"; FenResult result = Fen.Parse(fen); if (result.Error) { Console.WriteLine("Error parsing FEN."); } else { for (int i = 0; i < 8; ++i) { for (int j = 0; j < 8; ++j) { if (result.Board[i, j] == '\0') { Console.Write('.'); } else { Console.Write(result.Board[i, j]); } Console.Write(' '); } Console.WriteLine(); Console.WriteLine(); } } Console.ReadKey(); }
public void NoSpaces() { string fen = "8/8/8/8/8/8/8/8w--01"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void NoActiveColor() { string fen = "8/8/8/8/8/8/8/8 - - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void EmptyValueOnFirstRank() { string fen = "8/8/8/8/8/8/8/ w - - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void DoubleCastling() { string fen = "8/8/8/8/8/8/8/8 w KK - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void CastlingHyphen() { string fen = "8/8/8/8/8/8/8/8 w Kq- - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void InvalidCastling() { string fen = "8/8/8/8/8/8/8/8 w X - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void HyphenBeforeEnPassant() { string fen = "8/8/8/8/8/8/8/8 w - -c4 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void HyphenBeforeCastling() { string fen = "8/8/8/8/8/8/8/8 w -KQkq - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public static IPositionImpl Create(Fen fen, IPositionAbstraction abstraction) { ulong[] maps = new ulong[14]; int i = 0; fen.ForEachPosition() .Where(c => !'/'.Equals(c)) .Select(c => new { index = i += int.TryParse(c.ToString(), out int result) ? result : 1, piece = c })
public void RankTooMuch() { string fen = "8/8/8/8/8/8/8/8/8 w - - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void InvalidEnPassantOrder() { string fen = "8/8/8/8/8/8/8/8 w - 1a 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void ZeroFullMoves() { string fen = "8/8/8/8/8/8/8/8 w - - 0 0"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void InvalidHalfMoves() { string fen = "8/8/8/8/8/8/8/8 w - - X 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void EmptyFen() { string fen = ""; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void InvalidPiece() { string fen = "7X/8/8/8/8/8/8/8 w - - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void EnPassantHyphen() { string fen = "8/8/8/8/8/8/8/8 w - c4- 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void NegativeHalfMoves() { string fen = "8/8/8/8/8/8/8/8 w - - -1 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
public void PieceShort() { string fen = "ppppppp/8/8/8/8/8/8/8 w - - 0 1"; FenResult result = Fen.Parse(fen); Assert.IsTrue(result.Error); }
private void Init() { var parts = Fen.Split(); //if (parts.Length != 7) return; InitFigures(parts[0]); moveColor = (parts[1] == "b") ? Color.black : Color.white; MoveNumber = int.Parse(parts[5]); }
public void Of_IsValid() { // Act foreach (FenString fenString in FenArray) { Fen.Of(fenString.Fen).Match( None: () => { Assert.IsFalse(fenString.IsValid); return(true); }, Some: s => { Assert.IsTrue(fenString.IsValid); return(true); }); } }
public async Task <IActionResult> StartNewWorker(string fenPositionString, byte color, ChessAI.OponentAlgorith oponent) { if (fenPositionString == null || !Fen.ISStringFen(fenPositionString) || (color != PieceData.White && color != PieceData.Black)) { return(BadRequest("Bad Parameters")); } if (ModelState.IsValid) { try { WorkerResult newWorkerResult = new WorkerResult(); newWorkerResult.Finished = false; int i = 0; while (WorkerResultExists(i)) { ++i; } newWorkerResult.WorkerID = i; _context.Add(newWorkerResult); //Start new Thread WorkerInfo newWorkerInfo = new WorkerInfo(Fen.LoadPositionFromFen(fenPositionString), color, newWorkerResult.WorkerID); _context.SaveChanges(); bool WorkerQueued = false; if (oponent.Equals(ChessAI.OponentAlgorith.Rand)) { WorkerQueued = ThreadPool.QueueUserWorkItem(new ChessAIService(new DbContextFactory()).GetRandMoveWrapper, newWorkerInfo); } else if (oponent.Equals(ChessAI.OponentAlgorith.NegaMax)) { WorkerQueued = ThreadPool.QueueUserWorkItem(new ChessAIService(new DbContextFactory()).GetNegaMaxMoveWrapper, newWorkerInfo); } if (WorkerQueued) { return(Accepted(HttpContext.Request.PathBase + "/Worker/Result/", newWorkerInfo.WorkerID)); } else { _context.Remove(newWorkerInfo); _context.SaveChanges(); return(BadRequest("Couldn't queue Task")); } } catch (DbUpdateConcurrencyException) { throw; } } return(BadRequest("Invalid ModelState")); }
public void OpponentIsInCheck_IsValid() { // Act foreach (FenString fenString in FenTests.FenOpponentInCheckArray) { Fen.Of(fenString.Fen).CreatePositionAbstraction() .Match( None: () => { Assert.Fail(); return(true); }, Some: p => { Assert.AreEqual(fenString.IsValid, isOpponentIncheck(p)); return(true); }); } }
/// <summary> /// 转换为字符串,保留到小数点后n位 /// </summary> /// <param name="n">保留到小数点后n位</param> /// <returns></returns> public string ToFormatString(int n) { if (Miao >= 0) { return(Du.ToString() + "°" + Fen.ToString() + "′" + Miao.ToFormatString(n) + "″"); } else { return(Du.ToString() + "°" + (-Fen).ToString() + "′" + (-Miao).ToFormatString(n) + "″"); } }
public void FenAndValidateLegalMove() { var move = Move.Parse("b7-b8=Q"); var legalMove = Fen .Parse("8/1P6/8/8/8/8/8/8 w - - 0 1") .ValidateLegalMove(move); var nextPosition = legalMove.ToPosition(); Fen.Print(nextPosition) .Should().Be("1Q6/8/8/8/8/8/8/8 b - - 0 1"); }