예제 #1
0
        /// <summary>
        /// 指し手に投票します。
        /// </summary>
        public void Vote(ShogiPlayer player, LiteralMove 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");
            }
        }
예제 #2
0
        /// <summary>
        /// 与えられたプレイヤーが含まれているか調べます。
        /// </summary>
        public bool Contains(ShogiPlayer player)
        {
            if (player == null)
            {
                return(false);
            }

            return(Contains(player.PlayerId));
        }
예제 #3
0
        /// <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);
            }
        }
예제 #4
0
        /// <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 + ")")));
            }
        }
예제 #5
0
        /*/// <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,
                };
            }
        }