Пример #1
0
        public int GenerateMove(IGame game)
        {
            if (!game.NextPlayer.Type.Equals(PlayerType.Bot))
            {
                throw new GenerateMoveException(
                          StringResources.CannotGenerateMoveNextPlayerIsNotBot());
            }

            int    botId  = game.Players.SingleOrDefault(p => p.Type.Equals(PlayerType.Bot)).OnlineId;
            Random random = new Random();

            while (true)
            {
                int move = random.Next(0, game.Board.Width);
                return(move);
            }
        }
Пример #2
0
        public int GenerateMove(IGame game)
        {
            if (!game.NextPlayer.Type.Equals(PlayerType.Bot))
            {
                throw new GenerateMoveException(
                          StringResources.CannotGenerateMoveNextPlayerIsNotBot());
            }

            board   = game.Board;
            humanId = game.Players.SingleOrDefault(p => p.Type.Equals(PlayerType.Human)).OnlineId;
            botId   = game.Players.SingleOrDefault(p => p.Type.Equals(PlayerType.Bot)).OnlineId;

            List <int> moves = new List <int>();
            double     max   = -1;

            for (int i = 0; i < board.Width; i++)
            {
                if (board.IsColumnValid(i))
                {
                    double value = GetMoveValue(i);
                    Debug.WriteLine("Move {0}: {1}", i, value);

                    if (value > max)
                    {
                        max = value;
                        moves.Clear();
                        moves.Add(i);
                    }
                    else if (value == max)
                    {
                        moves.Add(i);
                    }
                }
            }

            Random random = new Random();
            int    move   = moves[random.Next(0, moves.Count)];

            return(move);
        }