Beispiel #1
0
        public Position PlayTurn(TurnContext context)
        {
            try
            {
                var center = context.Board.GetCenterPosition();
                if (context.IsPlayerFirst)
                {
                    if (context.OurPosition == center || context.Board.GetSquare(center) != 0)
                    {
                        _centerReached = true;
                    }
                    if (_centerReached)
                    {
                        return(_minimax.PlayTurn(context));
                    }
                    if (context.OurPosition != center)
                    {
                        return(_centerHunting.PlayTurn(context));
                    }
                }
                else
                {
                    if (context.OurPosition == center || context.Board.GetSquare(center) != 0)
                    {
                        _centerReached = true;
                    }
                    if (_centerReached)
                    {
                        if (!_randomPlayed)
                        {
                            _randomPlayed = true;
                            return(_random.PlayTurn(context));
                        }
                        return(_minimax.PlayTurn(context));
                    }
                    if (context.OurPosition != center)
                    {
                        return(_centerHunting.PlayTurn(context));
                    }
                }
#if DEBUG
                throw new InvalidOperationException("No moves");
#endif
                return(_random.PlayTurn(context));
            }
            catch
            {
                return(_random.PlayTurn(context));
            }
        }
        public Position PlayTurn(TurnContext context)
        {
            var newPosition = _strategy.PlayTurn(context);

#if DEBUG
            Console.WriteLine($"Player {_player} turn:");
#endif
            Console.WriteLine(newPosition.X);
            Console.WriteLine(newPosition.Y);
#if DEBUG
            Console.WriteLine("------");
#endif
            return(newPosition);
        }