public object Clone() { FullMove ret = new FullMove(); ret.mNumOfMove = this.mNumOfMove; ret.mWhiteMove = this.mWhiteMove; ret.mBlackMove = this.mBlackMove; ret.mComment = this.mComment; return(ret); }
public List <FullMove> ParseMovesPgn(string moves, out int gameResult) { int startToken = 0; int endToken = 0; List <FullMove> retList = new List <FullMove>(); List <string> ll = new List <string>(); string token; int moveInd = 0; int length = moves.Length - 1; bool readMove = true; string move = null; bool isComment = true; FullMove fullMove = new FullMove(); bool halfMove = false; int retGameResult = -1; while (endToken < length) { isComment = false; readMove = true; move = null; if (moves.Substring(startToken, 1).CompareTo("{") == 0) { //we have comment startToken += 1; //skip on the "{" endToken = moves.IndexOf("}", startToken + 1); isComment = true; readMove = false; } else { endToken = moves.IndexOf(" ", startToken + 1); } token = moves.Substring(startToken, endToken - startToken); //handle multiple " " if exists while ((endToken < moves.Length - 1) && (moves.Substring(endToken + 1, 1).CompareTo(" ") == 0)) { endToken++; } if (token.CompareTo("1-0") == 0 || token.CompareTo("0-1") == 0 || token.CompareTo("1/2-1/2") == 0) { //handle end of game readMove = false; fullMove.mBlackMove = null; retList.Add((FullMove)fullMove.Clone()); if (token.CompareTo("1-0") == 0) { retGameResult = 0; } else if (token.CompareTo("0-1") == 0) { retGameResult = 1; } else { retGameResult = 2; } } /*need to handle the 2 cases: * case A: 1. e4 e5 * case B: 1.e4 e5 */ else if (StartsWithNumber(token)) { moveInd = Int32.Parse(token.Substring(0, token.IndexOf("."))); fullMove.mNumOfMove = moveInd; //case A if (token.EndsWith(".")) { readMove = false; } else // case B { int tmpStart = token.IndexOf(".") + 1; int tmpLength = token.Length - tmpStart; token = token.Substring(tmpStart, tmpLength); } } if (readMove)//read move { ///////////////////////////////////////////////////// #warning need to add to position moves without source #warning need to parse all kinds of move (+, ++, !, ?, O-O, O-O-O, =, x ///////////////////////////////////////////////////// if (!halfMove) { fullMove.mComment = null; fullMove.mWhiteMove = token; halfMove = true; } else { fullMove.mBlackMove = token; halfMove = false; retList.Add((FullMove)fullMove.Clone()); } } if (isComment) { //take into account the " " after the "}" startToken = endToken + 1; fullMove.mComment = token; } else { startToken = endToken + 1; } } gameResult = retGameResult; return(retList); }