예제 #1
0
        //Command Pattern: Recevier
        public override int[] makeMove(Player player)
        {
            IRule          rule   = new Connect4Rule();
            RuleCommand    gameOn = new ConcreteRuleCommand(rule);
            CommandInvoker ruleC  = new CommandInvoker(gameOn);

            int[]  move     = new int[2];
            Random random   = new Random();
            bool   moveMade = false;

            while (!moveMade)
            {
                int AI_Move = random.Next(1, 7);

                if (ruleC.getValidMove(AI_Move) != null)
                {
                    move     = ruleC.getValidMove(AI_Move);
                    moveMade = true;
                }
                else
                {
                    continue;
                }
            }

            return(move);
        }
예제 #2
0
        //Command Pattern: Recevier
        public override int[] makeMove(Player player)
        {
            IRule          rule   = new Connect4Rule();
            RuleCommand    gameOn = new ConcreteRuleCommand(rule);
            CommandInvoker ruleC  = new CommandInvoker(gameOn);

            Boolean moveMade = false;
            int     col_move;

            int[] move = new int[2];

            Console.Write("player {0} turn's ", Name);
            while (!moveMade)
            {
                Console.Write("Make a Move from 1 to {0} or read menu by  999:  ", Board.Instance.ColumnsCount);
                if (Int32.TryParse(Console.ReadLine(), out col_move))
                {
                    if (1 <= col_move && col_move <= Board.Instance.ColumnsCount)
                    {
                        move = ruleC.getValidMove(col_move);

                        if (move != null)
                        {
                            Console.Clear();
                            Board.Instance.DisplayBoard();
                            moveMade = true;
                        }
                        else
                        {
                            Console.WriteLine("\nThat column is full.");
                            continue;
                        }
                    }
                    else if (col_move == 999)
                    {
                        Menu.Instance.DisplayMenu();
                    }
                }
                else
                {
                    Console.Clear();
                    Board.Instance.DisplayBoard();
                    Console.WriteLine("\nPlease enter an valid integer.");
                    continue;
                }
            }

            return(move);
        }
예제 #3
0
        //Command Pattern: Recevier
        public override int[] makeMove(Player player)
        {
            //easy rule;
            IRule          rule   = new Connect4Rule();
            RuleCommand    gameOn = new ConcreteRuleCommand(rule);
            CommandInvoker ruleC  = new CommandInvoker(gameOn);

            int[]  move     = new int[2];
            Random random   = new Random();
            bool   moveMade = false;

            while (!moveMade)
            {
                int AI_Move = random.Next(1, 7);

                if (ruleC.getValidMove(AI_Move) != null)
                {
                    move     = ruleC.getValidMove(AI_Move);
                    moveMade = true;
                }
                else
                {
                    continue;
                }
            }

            return(move);

            //Hard Rule haven't been implement yet
            //IRule rule = new Connect4Rule();
            //RuleCommand gameOn = new ConcreteRuleCommand(rule);
            //CommandInvoker ruleC = new CommandInvoker(gameOn);

            //int[] move = new int[2];

            //bool moveMade = false;
            //while (!moveMade)
            //{
            //    for(int i = 0; i<Board.Instance.ColumnsCount; i++)
            //    {
            //        if (ruleC.getValidMove(i) != null)
            //        {
            //            move = ruleC.getValidMove(i);


            //            if (ruleC.getComputerHardMove(i,player) != null)
            //            {
            //                move = ruleC.getComputerHardMove(i, player);
            //                moveMade = true;
            //            }
            //            else
            //            {
            //                return move;
            //            }

            //        }
            //        else
            //        {
            //            continue;
            //        }
            //    }



            //}

            //return move;
        }