コード例 #1
0
        public static ConnectFourPlayer GetWinner(this IEnumerable <ConnectFourPlayer> source)
        {
            ConnectFourPlayer winner = null;
            var iteratedFirstElement = false;

            foreach (var p in source)
            {
                if (!iteratedFirstElement)
                {
                    iteratedFirstElement = true;
                    winner = p;
                }
                if (p == null || p != winner)
                {
                    return(null);
                }
            }

            return(winner);
        }
コード例 #2
0
        public static bool CanWin(this IEnumerable <ConnectFourPlayer> source)
        {
            ConnectFourPlayer firstFoundPlayer = null;

            foreach (var p in source)
            {
                if (p != null)
                {
                    if (firstFoundPlayer == null)
                    {
                        firstFoundPlayer = p;
                    }
                    if (p != firstFoundPlayer)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }