private static void MarkRecords(Records records) { Stopwatch watch = new Stopwatch(); watch.Start(); records = new Records(); MyDemoDialog.Clear(); PGNReader reader = new PGNReader(); //reader.Filename = Program.PGNFile_CHS_Game; reader.Filename = Program.PGNFile_Test_2_Game; //reader.Filename = @"e:\ChessBase\Bases\08a.pgn"; reader.AddEvents(records); reader.Parse(); watch.Stop(); double rTime = watch.ElapsedMilliseconds;//总时间 double fTIme = rTime / records.Count; MyDemoDialog.StatusText1 = string.Format("记录个数:{2}, 总时间:{0},每个记录的解析时间为:{1}", rTime, fTIme, records.Count); MyDemoDialog.RecordTree.BeginUpdate(); foreach (Record record in records) { TreeNode node = new TreeNode(); node.Text = (string)record.Tags.Get("Event"); node.Tag = record; MyDemoDialog.RecordTree.Nodes.Add(node); } MyDemoDialog.RecordTree.EndUpdate(); }
void OnMove(bool whiteMoved, ushort move) { if (relinquishUserScrollbarControlNextMove) { relinquishUserScrollbarControlNextMove = false; userControllingScrollbar = false; } if (whiteMoved) { fullGamePGN += (Board.GetFullMoveCount() + 1) + ". " + PGNReader.NotationFromMove(move); moveNumberUI.text += (Board.GetFullMoveCount() + 1) + ". \n"; moveNotationWhiteUI.text += PGNReader.NotationFromMove(move) + "\n"; } else { fullGamePGN += " " + PGNReader.NotationFromMove(move) + " "; moveNotationBlackUI.text += PGNReader.NotationFromMove(move) + "\n"; if (Board.GetFullMoveCount() > 14) { int size = -30 * (Board.GetFullMoveCount() - 14); contentBounds.offsetMin = new Vector2(contentBounds.offsetMin.x, size); contentBounds.offsetMax = new Vector2(contentBounds.offsetMax.x, 0); } } }
private void chessBoard1_MoveMade(object sender, EventArgs e) { scoreSheet1.Text = "White: Ji Hu\n"; scoreSheet1.Text += "Black: Kin Fi\n\n"; Board board = new Board(); board.setup_fen(chessBoard1.FenString); for (int i = 0; i < chessBoard1.MoveList.ToArray().Length; i++) { int l = chessBoard1.MoveList.ToArray().Length - 1; int[] mv = chessBoard1.MoveList.ToArray()[l - i]; String move = PGNReader.convertMove(board, mv); if (i % 2 == 0) { scoreSheet1.Text += (i / 2 + 1) + "." + move; } else { scoreSheet1.Text += move; } scoreSheet1.Text += " "; board.Move(mv[0], mv[1]); } }
static void Main(string[] args) { //still need to grab the List <ChessGame> games = PGNReader.ReadFromFile(filename: @"C:\Users\Zander Nickle\source\repos\znickle\DataSystemsAndApplications\ChessTools\KingBase2018-01.pgn"); foreach (ChessGame g in games) { g.Print(); } // Prevent the console from closing after it's done printing Console.Read(); }
void OnMoveMade(bool whiteMoved, ushort move) { if (whiteMoved) { moveInputBlack.text = "..."; input.Freeze(); moveInputWhite.text = PGNReader.NotationFromMove(move); } else { input.UnFreeze(); input.Clear(); moveInputBlack.text = PGNReader.NotationFromMove(move); } }
//F5:针对PGN文件进行转换与解析 private void PGNConvent(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; Duration duration = new Duration(); duration.Start(); PGNReader reader = new PGNReader(); reader.Filename = Path.GetFullPath(Path.Combine(_demoFile, PGNFile)); reader.AddEvents(_records); reader.Parse(); string s = _records[0].ToString(); this._recordListView.Items.Clear(); foreach (var item in _records) { this._recordListView.Add(item); } duration.Stop(); this._label.Text = string.Format("[Count: {0} record]. [Duration time: {1}]. [{2} Time/Record.]", _records.Count, duration.DurationValue, duration.DurationValue / _records.Count); this.Cursor = Cursors.Default; }
static void ProcessFiles(string[] files, int minGameLengthPly, int recordToPly) { Board.SetPositionFromFen(Definitions.startFen); // Read pgns and convert to opening book dictionary for (int fileIndex = 0; fileIndex < files.Length; fileIndex++) { StreamReader reader = new StreamReader(files[fileIndex]); List <string> pgns = new List <string>(); // split text into array of pgn strings bool readingPGN = false; int pgnIndex = -1; bool finishedReadingPGN = false; while (reader.Peek() != -1) { string line = reader.ReadLine() + " "; if (line.Contains("[")) // comment line { finishedReadingPGN = false; readingPGN = false; continue; } else if (!finishedReadingPGN) { for (int charIndex = 0; charIndex < line.Length; charIndex++) { if (!readingPGN && line[charIndex] == '1') { readingPGN = true; pgns.Add(""); pgnIndex++; } if (readingPGN) { pgns[pgnIndex] += line[charIndex] + ""; if (pgns[pgnIndex].Split('.').Length * 2 > recordToPly) // only record the first n moves for opening book { finishedReadingPGN = true; break; } } } } } reader.Close(); // get moves from pgn files for (int i = 0; i < pgns.Count; i++) { string pgn = pgns[i]; if (pgn.Split('.').Length * 2 < minGameLengthPly) // don't record games that were shorter than minGameLengthPly. This is to avoid games where an opening distaster occured { continue; } List <string> moveStrings = PGNReader.MoveStringsFromPGN(pgn); List <ushort> moves = PGNReader.MovesFromPGN(pgn); for (int j = 0; j < moves.Count; j++) { if (!book.ContainsKey(Board.zobristKey)) { keys.Add(Board.zobristKey); book.Add(Board.zobristKey, new List <ushort>()); } if (!book[Board.zobristKey].Contains(moves[j])) { book[Board.zobristKey].Add(moves[j]); } Board.MakeMove(moves[j]); } for (int k = moves.Count - 1; k >= 0; k--) { Board.UnmakeMove(moves[k]); } } } }
public void TestMethod1() { string filepath = @"C:\Users\Snark\Downloads\kb1.pgn"; List <ChessGame> result = PGNReader.ParseFile(filepath); }
public bool ValidateEntry() { if (currentInput.Length > 0) { List <ushort> inputtedMoves = PGNReader.MovesFromPGN(currentInput); if (inputtedMoves.Count > 0) { string cleanedInput = PGNReader.MoveStringsFromPGN(currentInput) [0]; ushort inputMove = inputtedMoves [0]; int movePieceCode = PieceTypeCodeFromNotation(cleanedInput) + ((Board.IsWhiteToPlay()) ? 1 : 0); ushort[] legalMoves = moveGen.GetMoves(false, false).moves; bool ambiguousCaseSpecified = false; // does the inputted string describe an ambiguous case (e.g Rad1) if (cleanedInput.Length >= 3) { ambiguousCaseSpecified = Definitions.fileNames.Contains(cleanedInput [2] + ""); } if ((movePieceCode & ~1) == Board.kingCode || (movePieceCode & ~1) == Board.pawnCode) // king and pawn moves can't be ambiguous { ambiguousCaseSpecified = true; } bool moveIsAmbiguous = false; if (!ambiguousCaseSpecified) // check if case is ambiguous if no specification has been given in input { int movesFoundFollowingInput = 0; for (int i = 0; i < legalMoves.Length; i++) { int moveFromIndex = legalMoves [i] & 127; int moveToIndex = (legalMoves [i] >> 7) & 127; if (Board.boardArray [moveFromIndex] == movePieceCode && moveToIndex == ((inputMove >> 7) & 127)) // is move as described by input string { movesFoundFollowingInput++; if (movesFoundFollowingInput == 2) { moveIsAmbiguous = true; break; } } } } if (moveIsAmbiguous) { uiManager.SetMessage("move is ambiguous. please specify file/rank of piece you wish to move", 3, true); } else { if (player != null) { player.TryMakeMove(inputMove); } return(true); } } else { print("Move illegal/incorrect format"); } } return(false); }
private void ChessBoard_Load(object sender, EventArgs e) { new_game(); Console.WriteLine("FEN: " + PGNReader.convert_FEN(board)); }
private void copyToolStripMenuItem_Click(object sender, EventArgs e) { Clipboard.SetText(PGNReader.convert_FEN(board)); }