/// <summary> /// Write move to log. /// </summary> /// <param name="move"></param> private void _writeLog(cgSimpleMove move) { if (moveLog != null) { if (NotationType == cgNotation.NotationType.Coordinate) { if (_loggedMoves % 2 == 0) { moveLog.text += "\n"; } else { moveLog.text += " | "; } moveLog.text += _abstractBoard.SquareNames[move.from] + "-" + _abstractBoard.SquareNames[move.to]; } else if (NotationType == cgNotation.NotationType.Algebraic) { moveLog.text = "Moves:\n"; cgNotation note = new cgNotation(_abstractBoard.duplicate()); moveLog.text = note.getLogFriendlyNotation(); } _loggedMoves++; } }
public void Clone(ctLine _line) { this.name = _line.name; this.moves = _line.moves; cgNotation not = new cgNotation(new cgBoard()); not.Read(this.moves); }
/// <summary> /// Copy game notation to clipboard, if for instance the user wants to save his current game. /// </summary> private void _copyGameToClipboard() { //Debug.Log("herp"); string curgame; cgNotation notation = new cgNotation(_abstractBoard); curgame = notation.writeFullNotation(cgNotation.NotationType.Algebraic, cgNotation.FormatType.None); GUIUtility.systemCopyBuffer = curgame; //moveLog.text += "ctrl+c"; }
/// <summary> /// Paste the game notation from clipboard onto the board. /// </summary> private void _pasteGameFromClipboard() { string curgame = GUIUtility.systemCopyBuffer; _abstractBoard = new cgBoard(); Debug.Log("Pasted game from clipboard: " + curgame); cgNotation notation = new cgNotation(_abstractBoard); notation.Read(curgame); _abstractBoard.LoadGame(notation); _setBoardTo(_abstractBoard); }
void UpdateInfos() { // update notation cgNotation not = new cgNotation(board); Lbl_Moves.text = not.writeFullNotation(cgNotation.NotationType.Algebraic); // for change scroll position float height = Lbl_Moves.preferredHeight + 20; NotationTextScrollRect.content.sizeDelta = new Vector2(NotationTextScrollRect.content.sizeDelta.x, height); if (NotationTextScrollRect.viewport.rect.height < height) { NotationTextScrollRect.content.anchoredPosition = new Vector2(0, height - NotationTextScrollRect.viewport.rect.height); } // update move count Lbl_MoveCount.text = string.Format("({0}) moves", moveList.Count); }
void UpdateInfos() { Lbl_LineScore.text = string.Format("Score : {0} out of {1}", m_Score, m_MaxScore); Lbl_TotalScore.text = string.Format("Total Score : {0} out of {1}", m_TotalScore, m_TotalMaxScore); cgNotation not = new cgNotation(m_Board); Lbl_Notation.text = not.writeFullNotation(cgNotation.NotationType.Algebraic); // for change scroll position float height = Lbl_Notation.preferredHeight + 20; NotationTextScrollRect.content.sizeDelta = new Vector2(NotationTextScrollRect.content.sizeDelta.x, height); if (NotationTextScrollRect.viewport.rect.height < height) { NotationTextScrollRect.content.anchoredPosition = new Vector2(0, height - NotationTextScrollRect.viewport.rect.height); } Wnd_Board.UpdateBoard(); }
/// <summary> /// Generates a board matching the provided notation. /// </summary> /// <param name="notation">The notation of the game to be recreated</param> public void LoadGame(cgNotation notation) { foreach (cgSimpleMove newmove in notation.moves) { List <cgSimpleMove> nmoves = findLegalMoves(_whiteTurnToMove); bool found = false; foreach (cgSimpleMove safemove in nmoves) { if (safemove.to == newmove.to && safemove.from == newmove.from) { move(safemove); found = true; } } if (!found) { Debug.Log("couldn't find: " + cgGlobal.MoveToString(newmove)); move(newmove); } } }
public void OnSelectPGN(string _path) { try { StreamReader sr = new StreamReader(_path); string line; string strNot = ""; bool started = false; using (sr) { while ((line = sr.ReadLine()) != null) { if (!started) { if (line.Equals("") || line[0] == '[') { continue; } else { started = true; } } line = line.Trim(); strNot += line + " "; if (strNot.Contains("1-0") || strNot.Contains("0-1") || strNot.Contains("1/2-1/2")) { break; } } } int nCommentStart = 0; while ((nCommentStart = strNot.IndexOf("{")) != -1) { int nCommentEnd = strNot.IndexOf("}"); if (nCommentEnd != -1) { strNot = strNot.Remove(nCommentStart, nCommentEnd - nCommentStart + 1); } else { strNot = strNot.Remove(nCommentStart, strNot.Length - nCommentStart); } nCommentStart = strNot.IndexOf("{"); } while ((nCommentStart = strNot.IndexOf("(")) != -1) { int nCommentEnd = strNot.IndexOf(")"); if (nCommentEnd != -1) { strNot = strNot.Remove(nCommentStart, nCommentEnd - nCommentStart + 1); } else { strNot = strNot.Remove(nCommentStart, strNot.Length - nCommentStart); } } cgNotation not = new cgNotation(new cgBoard()); not.Read(strNot); loadedNotation = not.writeFullNotation(cgNotation.NotationType.Algebraic); if (!loadedNotation.Equals("")) { WndManager.Singleton.OpenInputBox("Enter line name:", CallBackAdd); } else { WndManager.Singleton.OpenMsgBox("Invalid file format"); } } catch (System.Exception e) { WndManager.Singleton.OpenMsgBox(string.Format("Failed to open \"{0}\"file.", _path)); } }