Exemplo n.º 1
0
        private int ScoreWindow(TokenWindow tokenWindow, ConnectFourToken playerToken)
        {
            // Ignore blank windows
            if (tokenWindow.Tokens.All(t => t == ConnectFourToken.Blank))
            {
                return(0);
            }

            int score = 0;

            // This player has four in a row
            if (tokenWindow.Tokens.All(t => t == playerToken))
            {
                score += 100;
            }
            // This player has three placed with one blank in a window
            else if (tokenWindow.Tokens.Count(t => t == playerToken) == 3 &&
                     tokenWindow.Tokens.Count(t => t == ConnectFourToken.Blank) == 1)
            {
                score += 50;
            }
            // Player has two tokens and two blank spaces in a window
            else if (tokenWindow.Tokens.Count(t => t == playerToken) == 2 &&
                     tokenWindow.Tokens.Count(t => t == ConnectFourToken.Blank) == 2)
            {
                score += 20;
            }
            // Player has two tokens and two blank spaces in a window
            else if (tokenWindow.Tokens.Count(t => t == playerToken) == 1 &&
                     tokenWindow.Tokens.Count(t => t == ConnectFourToken.Blank) == 3)
            {
                score += 10;
            }
            // Other player player has four in a row
            else if (tokenWindow.Tokens.All(t => t != playerToken && t != ConnectFourToken.Blank))
            {
                score -= 100;
            }
            // Other player has three tokens and one blank space in a window
            else if (tokenWindow.Tokens.Count(t => t != playerToken && t != ConnectFourToken.Blank) == 3 &&
                     tokenWindow.Tokens.Count(t => t == ConnectFourToken.Blank) == 1)
            {
                score -= 50;
            }
            // Other player has two tokens and two blank spaces in a window
            else if (tokenWindow.Tokens.Count(t => t != playerToken && t != ConnectFourToken.Blank) == 2 &&
                     tokenWindow.Tokens.Count(t => t == ConnectFourToken.Blank) == 2)
            {
                score -= 20;
            }
            // Other player has two tokens and two blank spaces in a window
            else if (tokenWindow.Tokens.Count(t => t != playerToken && t != ConnectFourToken.Blank) == 1 &&
                     tokenWindow.Tokens.Count(t => t == ConnectFourToken.Blank) == 3)
            {
                score -= 10;
            }


            return(score);
        }
Exemplo n.º 2
0
 public bool IsWinningTokenWindow(TokenWindow tokenWindow)
 {
     return(tokenWindow.Tokens.Distinct().Count() == 1 &&
            tokenWindow.Tokens.All(t => t != ConnectFourToken.Blank));
 }