/// <summary> /// 与えられたプレイヤーが含まれているか調べます。 /// </summary> public bool Contains(ShogiPlayer player) { if (player == null) { return false; } return Contains(player.PlayerId); }
public void ParsePlayerTest() { var player1 = new ShogiPlayer() { Nickname = "てすと", SkillLevel = new SkillLevel(SkillKind.Kyu, 9), }; AssertPlayer( player1, ShogiParserEx.ParsePlayer("てすと 9級")); AssertPlayer( player1, ShogiParserEx.ParsePlayer(" てすと きゅうきゅう")); AssertPlayer( player1, ShogiParserEx.ParsePlayer(" てすと きゅう級")); AssertPlayer( player1, ShogiParserEx.ParsePlayer(" てすと 9級")); AssertPlayerNot( player1, ShogiParserEx.ParsePlayer(" てすと 級きゅう")); AssertPlayer( player1, ShogiParserEx.ParsePlayer("てすと 急急")); /*var player2 = new ShogiPlayer() * { * Nickname = "三級", * }; * AssertPlayer( * player2, * ShogiParserEx.ParsePlayer("三級"));*/ /*AssertPlayer( * player2, * ShogiParserEx.ParsePlayer(" @ 三級"));*/ /*AssertPlayer( * player2, * ShogiParserEx.ParsePlayer("三級 三級"));*/ }
/*/// <summary> /// プレイヤーリストのコピーを取得します。 /// </summary> public Dictionary<string, RegistereredPlayer> Players { get { lock (this.playerDic) { return new Dictionary<string, RegistereredPlayer>( this.playerDic); } } }*/ /// <summary> /// プレイヤーを追加します。 /// </summary> public void Add(ShogiPlayer player, DateTime timestamp) { if (player == null || !player.Validate()) { return; } lock (this.playerDic) { if (Contains(player)) { this.playerDic.Remove(player.PlayerId); } this.playerDic[player.PlayerId] = new RegistereredPlayer() { Player = player, Timestamp = timestamp, }; } }
public void ParsePlayerTest() { var player1 = new ShogiPlayer() { Nickname = "てすと", SkillLevel = new SkillLevel(SkillKind.Kyu, 9), }; AssertPlayer( player1, ShogiParser.ParsePlayer("てすと 9級")); AssertPlayer( player1, ShogiParser.ParsePlayer(" てすと きゅうきゅう")); AssertPlayer( player1, ShogiParser.ParsePlayer(" てすと きゅう級")); AssertPlayer( player1, ShogiParser.ParsePlayer(" てすと 9級")); AssertPlayerNot( player1, ShogiParser.ParsePlayer(" てすと 級きゅう")); AssertPlayer( player1, ShogiParser.ParsePlayer("てすと 急急")); var player2 = new ShogiPlayer() { Nickname = "三級", }; /*AssertPlayer( player2, ShogiParser.ParsePlayer("三級"));*/ /*AssertPlayer( player2, ShogiParser.ParsePlayer(" @ 三級"));*/ /*AssertPlayer( player2, ShogiParser.ParsePlayer("三級 三級"));*/ }
private void AssertPlayerNot(ShogiPlayer expected, ShogiPlayer actual) { Assert.AreEqual(expected.Nickname, actual.Nickname); Assert.AreNotEqual(expected.SkillLevel, actual.SkillLevel); }
/// <summary> /// 投票された指し手があれば、それを取得します。 /// </summary> public RegistereredMove GetVote(string userId) { var player = new ShogiPlayer() { PlayerId = userId, }; using (LazyLock()) { RegistereredMove move; if (!this.moveDatas.TryGetValue(player, out move)) { return null; } return move; } }
/// <summary> /// 指し手に投票します。 /// </summary> public void Vote(ShogiPlayer player, Move move, DateTime timestamp) { if (move == null || player == null) { throw new ArgumentNullException(); } using (LazyLock()) { // プレイヤーの棋力が変わっている場合があるので、 // プレイヤーも必ず設定し直します。 if (this.moveDatas.ContainsKey(player)) { this.moveDatas.Remove(player); } this.moveDatas[player] = new RegistereredMove() { Move = move, Timestamp = timestamp, }; this.RaisePropertyChanged("MoveList"); } }
/// <summary> /// 参加者を文字列化します。 /// </summary> public static string ToString(ShogiPlayer player) { if (player == null) { return null; } if (string.IsNullOrEmpty(player.Nickname)) { return ToString(player.SkillLevel); } else { var skillName = ToString(player.SkillLevel); return string.Format("{0}{1}", player.Nickname, (string.IsNullOrEmpty(skillName) ? "" : "(" + skillName + ")")); } }