Exemplo n.º 1
0
        public string NeutralMove(char[,] inBoardState, Player inCurrentPlayer)
        {
            // this is just the number where the token should go
            string _pickedPosition = null;

            //  simple - look for opposing player with 2 tokens in a line,
            char _otherPlayerToken = inCurrentPlayer.PlayerToken == 'X' ? 'O' : 'X';

            //TODO: logic goes here
            BotLogic _botLogic = new BotLogic();
            Random   _random   = new Random();

            //1-5 = 2, 6-10 = 4, 11-15 = 6, 16-20 = 8, 21-100 = center
            // if first by bot, then go on offense
            if (_botLogic.IsFirstMove(inBoardState))
            {
                int _somenumber = _random.Next(1, 101);
                if (_somenumber >= 1 && _somenumber <= 5)
                {
                    _pickedPosition = "2";
                }
                else if (_somenumber >= 6 && _somenumber <= 10)
                {
                    _pickedPosition = "4";
                }
                else if (_somenumber >= 11 && _somenumber <= 15)
                {
                    _pickedPosition = "6";
                }
                else if (_somenumber >= 16 && _somenumber <= 20)
                {
                    _pickedPosition = "8";
                }
                else
                {
                    _pickedPosition = "5"; // leghold trap
                }
            }
            else
            {
                // analyze board more - step 1
                int[,] _weightedBoard = this.WeightTheBoard(inBoardState, inCurrentPlayer);

                // score the board - step 2
                int[,] _scoredBoard = this.ScoreTheBoard(_weightedBoard, inCurrentPlayer);

                // step 3 pick a spot
                _pickedPosition = this.PickSpotBasedOnScoreBoard(_scoredBoard, inCurrentPlayer);
            }

            return(_pickedPosition);
        }
Exemplo n.º 2
0
        // methods
        public string BotMove(char[,] inBoardState)
        {
            BotLogic _botLogic = new BotLogic();
            //Random _random = new Random();
            string _position = "";

            ////1-5 = 2, 6-10 = 4, 11-15 = 6, 16-20 = 8, 21-100 = center
            //// if first by bot, then go on offense
            //if (_botLogic.IsFirstMove(inBoardState))
            //{
            //    int _somenumber = _random.Next(1, 101);
            //    if (_somenumber >= 1 && _somenumber <= 5)
            //    {
            //        _position = "2";
            //    }
            //    else if (_somenumber >= 6 && _somenumber <= 10)
            //    {
            //        _position = "4";
            //    }
            //    else if (_somenumber >= 11 && _somenumber <= 15)
            //    {
            //        _position = "6";
            //    }
            //    else if (_somenumber >= 16 && _somenumber <= 20)
            //    {
            //        _position = "8";
            //    }
            //    else
            //    {
            //        _position = "5";
            //    }
            //}
            //else
            //{
            //    // analyze board
            _position = _botLogic.Analyze(inBoardState, this);
            //}


            return(_position);
        }