/// <summary> /// エンジンから取得(エンジン名・作者名) /// </summary> private void buttonGetByEngine_Click(object sender, EventArgs e) { textBoxName.Enabled = false; textBoxAuthor.Enabled = false; buttonGetByEngine.Enabled = false; ThreadPool.QueueUserWorkItem(new WaitCallback(arg => { try { using (USIDriver usi = new USIDriver(textBoxPath.Text)) { usi.Start(); FormUtility.SafeInvoke(this, () => { textBoxName.Text = usi.IdName; textBoxAuthor.Text = usi.IdAuthor; }); } } catch (Exception ex) { logger.Warn("エンジンからの情報取得に失敗", ex); FormUtility.SafeInvoke(this, () => { // 空なら仮でファイル名を設定 if (textBoxName.TextLength <= 0) { try { textBoxName.Text = Path.GetFileNameWithoutExtension(textBoxPath.Text); } catch (Exception ex2) { logger.Warn("ファイル名の取得に失敗", ex2); } } // エラーメッセージ MessageBox.Show(this, "エンジンからの名前/作者取得に失敗しました。", "エラー"); }); } finally { FormUtility.SafeInvoke(this, () => { buttonGetByEngine.Enabled = true; textBoxAuthor.Enabled = true; textBoxName.Enabled = true; }); } })); }
/// <summary> /// 手数の設定 /// </summary> public void SetMoveCount(int moveCount) { this.moveCount = moveCount; if (moveCount == 0) { FormUtility.SafeInvoke(this, () => { labelLine.Visible = false; }); } else { int x = moveCount * WidthPerMoves * panel2.Width / bitmapWidth; FormUtility.SafeInvoke(this, () => { SuspendLayout(); try { labelLine.Location = new Point(x, 0); labelLine.Size = new Size(1, Height); labelLine.Visible = true; } catch { ResumeLayout(); } }); } }
private void Player_PonderStopped(object sender, DataEventArgs <Board> e) { // 予想手をクリア FormUtility.SafeInvoke(this, () => { labelPonder.Text = "予想手:"; }); }
private void Player_PositionChanged(object sender, DataEventArgs <Board> e) { Board = e.Data; FormUtility.SafeInvoke(this, () => { Clear(); }); }
void Player_InfoReceived(object sender, ShogiCore.USI.USIInfoEventArgs e) { string infoDepth = ""; string infoSelDepth = ""; string infoTime = ""; string infoNodes = ""; string infoNPS = ""; string infoScore = ""; string infoCurrMove = ""; string infoHashFull = ""; string infoPVOrString = null; string pvLengthString = null; bool lowerBound = false, upperBound = false; foreach (USIInfo info in e.SubCommands) { switch (info.Name) { case "depth": infoDepth = info.Parameters.FirstOrDefault(); break; case "seldepth": infoSelDepth = info.Parameters.FirstOrDefault(); break; case "time": infoTime = info.Parameters.FirstOrDefault(); break; case "nodes": infoNodes = info.Parameters.FirstOrDefault(); break; case "nps": infoNPS = info.Parameters.FirstOrDefault(); break; case "currmove": infoCurrMove = info.Parameters.FirstOrDefault(); break; case "hashfull": infoHashFull = info.Parameters.FirstOrDefault(); break; case "score": if (player.LastScoreWasMate) { int mateCount = Math.Abs(player.LastScore) - USIPlayer.MateValue; string mateCountStr = mateCount == 0 ? "" : ":" + mateCount.ToString(); infoScore = (0 < player.LastScore ? "+Mate" : "-Mate") + mateCountStr; } else { infoScore = player.LastScoreString; } break; case "lowerbound": lowerBound = true; break; case "upperbound": upperBound = true; break; case "pv": { var pvList = info.Parameters; BoardData b = Board == null ? null : Board.ToBoardData(); List <string> itemList = new List <string>(); int pvLength = 0; foreach (var pv in pvList) { try { MoveData moveData = SFENNotationReader.ToMoveData(pv); if (b == null) { itemList.Add(moveData.ToString()); } else { itemList.Add(moveData.ToString(b)); b.Do(moveData); } pvLength++; } catch (NotationException) { itemList.Add(pv); } } infoPVOrString = string.Concat(itemList.ToArray()); pvLengthString = "PV長=" + pvLength; } break; case "string": infoPVOrString = string.Join(" ", info.Parameters); break; } } if (!string.IsNullOrEmpty(infoSelDepth)) { infoDepth += "/" + infoSelDepth; } long time, nodes, hashFull; if (long.TryParse(infoTime, out time)) { infoTime = time.ToString("#,##0"); } if (long.TryParse(infoNodes, out nodes)) { infoNodes = nodes.ToString("#,##0"); } if (long.TryParse(infoHashFull, out hashFull)) { infoHashFull = (hashFull / 10.0).ToString("0.0").PadLeft(5) + "%"; } if (lowerBound) { infoScore += "↑"; } if (upperBound) { infoScore += "↓"; } string toolTipText = pvLengthString; if (!string.IsNullOrEmpty(infoDepth)) { toolTipText = "深さ=" + infoDepth + " " + toolTipText; } try { FormUtility.SafeInvoke(this, () => { if (!string.IsNullOrEmpty(infoNPS)) { long nps; labelNPS.Text = long.TryParse(infoNPS, out nps) ? "NPS:" + nps.ToString("#,##0") : "NPS:" + infoNPS; } if (!string.IsNullOrEmpty(infoCurrMove)) { if (Board == null) { labelCurMove.Text = "探索手:" + SFENNotationReader.ToMoveData(infoCurrMove).ToString(); } else { labelCurMove.Text = "探索手:" + ShogiCore.Move.FromNotation(Board, SFENNotationReader.ToMoveData(infoCurrMove)).ToString(Board); } } if (!string.IsNullOrEmpty(infoHashFull)) { labelHashFull.Text = "ハッシュ使用率:" + infoHashFull; } if (!string.IsNullOrEmpty(infoPVOrString)) { AddListItem(infoTime, infoDepth, infoNodes, infoScore, infoPVOrString, pvLengthString); } double?meanDepth = stat.MeanDepth; double?meanNPS = stat.MeanNPS; if (meanDepth.HasValue) { labelMeanDepth.Text = "平均深さ:" + meanDepth.Value.ToString("#0.0"); } else { labelMeanDepth.Text = "平均深さ:-"; } if (meanNPS.HasValue) { labelMeanNPS.Text = "平均NPS:" + meanNPS.Value.ToString("#,##0"); } else { labelMeanNPS.Text = "平均NPS:-"; } }); } catch { // 無視 } }