Exemple #1
0
        internal static int WithAllCombinationsCalculateBlock(List <int> engineMoves, List <int> playerMoves)
        {
            List <int> blocks = new List <int>();

            foreach (var combination in EngineManager.GetAllRiskyCombinationsOfTwo(engineMoves, playerMoves))
            {
                if (!engineMoves.Contains(EngineManager.CalculateBlock(combination[0], combination[1])))
                {
                    blocks.Add(EngineManager.CalculateBlock(combination[0], combination[1]));
                }
            }
            var rand = new Random();

            return(blocks[rand.Next(0, blocks.Count)]);
        }
        private string Play()
        {
            switch (MyGame.MyPlayer.Moves.Count)
            {
            case 1:
                MyGame.MyEngine.Moves.Add(BlockingStrategy.FirstMove(MyGame.MyPlayer));
                return($" Computer First move is: {MyGame.MyEngine.Moves[0]} ");

            case 2:
                if (EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves).Count > 0)
                {
                    MyGame.MyEngine.Moves.Add(BlockingStrategy.WithAllCombinationsCalculateBlock(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves));
                    return($" Computer Second move is: {MyGame.MyEngine.Moves[1]} ");
                }
                MyGame.MyEngine.Moves.Add(WiningStrategy.CalculateWiningMove(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves));
                return($" Computer Second move is: {MyGame.MyEngine.Moves[1]} ");

            case 3:
                if (WinnerStateChecker.CheckState(MyGame.MyPlayer))
                {
                    return("YOU WIN!");
                }
                if (EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves).Count > 0 &&
                    EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyPlayer.Moves, MyGame.MyEngine.Moves).Count < 1)
                {
                    MyGame.MyEngine.Moves.Add(BlockingStrategy.WithAllCombinationsCalculateBlock(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves));
                    if (WinnerStateChecker.CheckState(MyGame.MyEngine))
                    {
                        return($" Computer Third move is: {MyGame.MyEngine.Moves[2]}, Haha, You loose");
                    }
                    return($" Computer Third move is: {MyGame.MyEngine.Moves[2]} ");
                }
                MyGame.MyEngine.Moves.Add(WiningStrategy.CalculateWiningMove(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves));
                if (WinnerStateChecker.CheckState(MyGame.MyEngine))
                {
                    return($" Computer Third move is: {MyGame.MyEngine.Moves[2]}, oh Haha, You loose");
                }
                return($" Computer Third move is: {MyGame.MyEngine.Moves[2]} ");

            case 4:
                if (WinnerStateChecker.CheckState(MyGame.MyPlayer))
                {
                    return("YOU WIN!");
                }

                if (EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves).Count > 0 &&
                    EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyPlayer.Moves, MyGame.MyEngine.Moves).Count < 1)
                {
                    MyGame.MyEngine.Moves.Add(BlockingStrategy.WithAllCombinationsCalculateBlock(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves));
                    if (WinnerStateChecker.CheckState(MyGame.MyEngine))
                    {
                        return($" Computer Fourth move is: {MyGame.MyEngine.Moves[3]}, Haha, You loose");
                    }
                    return($" Computer Fourth move is: {MyGame.MyEngine.Moves[3]} ");
                }
                MyGame.MyEngine.Moves.Add(WiningStrategy.CalculateWiningMove(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves));
                if (WinnerStateChecker.CheckState(MyGame.MyEngine))
                {
                    return($" Computer Fourth move is: {MyGame.MyEngine.Moves[3]}, Haha, You loose");
                }
                return($" Computer Fourth move is: {MyGame.MyEngine.Moves[3]} ");

            case 5:
                if (WinnerStateChecker.CheckState(MyGame.MyPlayer))
                {
                    return("YOU WIN!");
                }
                if (EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves).Count > 0 &&
                    EngineManager.GetAllRiskyCombinationsOfTwo(MyGame.MyPlayer.Moves, MyGame.MyEngine.Moves).Count < 1)
                {
                    MyGame.MyEngine.Moves.Add(BlockingStrategy.WithAllCombinationsCalculateBlock(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves));
                    if (WinnerStateChecker.CheckState(MyGame.MyEngine))
                    {
                        return($" Computer Fifth move is: {MyGame.MyEngine.Moves[4]}, Haha, You loose");
                    }
                    return($" Computer Fifth move is: {MyGame.MyEngine.Moves[4]} ");
                }
                MyGame.MyEngine.Moves.Add(WiningStrategy.CalculateWiningMove(MyGame.MyEngine.Moves, MyGame.MyPlayer.Moves));
                if (WinnerStateChecker.CheckState(MyGame.MyEngine))
                {
                    return($" Computer Fifth move is: {MyGame.MyEngine.Moves[4]}, Haha, You loose");
                }
                return($" Computer Fifth move is: {MyGame.MyEngine.Moves[4]} ");


            default:
                return("Inesperated Error");
            }
        }
Exemple #3
0
 internal static bool ThereIsANeedToBlock(List <int> engineMoves, List <int> playerMoves)
 {
     return(EngineManager.GetAllRiskyCombinationsOfTwo(engineMoves, playerMoves).Count > 0);
 }