예제 #1
0
        public ITurn ChooseTurn(IPlayerState playerState, IPlayerState opponentState)
        {
            var canSwitchNeuromon = playerState.InactiveNeuromon.Any(n => !n.IsDead);

            var validTurnTypes = new List<int>
            {
                AttackTurnType
            };

            var sb = new StringBuilder();
            sb.AppendLine("1: Attack");

            if (canSwitchNeuromon)
            {
                sb.AppendLine("2: Change Neuromon");
                validTurnTypes.Add(ChangeNeuromonTurnType);
            }

            Console.WriteLine(sb.ToString());

            ITurn selectedTurn = null;
            var turnType = ReadInputUntilValid(input => validTurnTypes.Contains(input));

            if (turnType == AttackTurnType)
            {
                selectedTurn = ChooseAttack(playerState.ActiveNeuromon);
            }
            else if (turnType == ChangeNeuromonTurnType && canSwitchNeuromon)
            {
                selectedTurn = new SwitchActiveNeuromon(SelectActiveNeuromon(playerState, opponentState));
            }

            return selectedTurn;
        }
예제 #2
0
        private static bool TryParseValidTurn(NeatAiTurnChoice turnChoice, IPlayerState playerState, IEnumerable<TurnType> validTurnTypes, out ITurn turn)
        {
            turn = null;

            if (!validTurnTypes.Contains(turnChoice.TurnType))
            {
                return false;
            }

            if (turnChoice.TurnType == TurnType.Attack)
            {
                var chosenMove = playerState.ActiveNeuromon.MoveSet.Moves.ElementAtOrDefault(turnChoice.Index);

                if (chosenMove != default(Move))
                {
                    turn = new Attack(chosenMove);
                    return true;
                }
            }
            else if (turnChoice.TurnType == TurnType.SwitchActiveNeuromon)
            {
                var chosenActiveNeuromon = playerState.InactiveNeuromon.ElementAtOrDefault(turnChoice.Index);

                if (chosenActiveNeuromon != default(Neuromon) && !chosenActiveNeuromon.IsDead)
                {
                    turn = new SwitchActiveNeuromon(chosenActiveNeuromon);
                    return true;
                }
            }

            return false;
        }