public void NewGame(int roundsToWin, ComputerType gameType)
 {
     _playerScore    = 0;
     _computerScore  = 0;
     _roundsToWin    = roundsToWin;
     _computerPlayer = ComputerProvider.GetComputer(gameType);
 }
Esempio n. 2
0
        private void AcceptComputerPicker(IHand hand, IComputerPlayer picker)
        {
            var buriedCards = picker.DropCardsForPick(hand);

            hand.SetPicker(picker, buriedCards);
            if (hand.IGame.PlayerCount == 3 || picker.GoItAlone(hand))
            {
                return;
            }
            if (hand.IGame.PartnerMethodEnum == PartnerMethod.CalledAce)
            {
                var partnerCard = picker.ChooseCalledAce(hand);
                hand.SetPartnerCard(partnerCard);
            }
        }
Esempio n. 3
0
        public void PlayRound(IPlayer normalPlayer, IComputerPlayer computerPlayer)
        {
            GameMoveViewModel chosenMove = null;

            while (chosenMove == null)
            {
                _inputOutputWrapper.WriteLine("Please enter your choice:");
                var choice = _inputOutputWrapper.ReadLine();
                chosenMove = _gameMoveViewModelHelper.GameMoveViewModels.FirstOrDefault(x => x.InputValue == choice);
                if (chosenMove == null)
                {
                    _inputOutputWrapper.WriteLine("That was an invalid choice, please try again");
                }
            }

            var computerGameMove          = computerPlayer.GetComputerMove();
            var computerGameMoveViewModel = _gameMoveViewModelHelper.GameMoveViewModels.FirstOrDefault(x => x.GameMove == computerGameMove);

            if (computerGameMoveViewModel == null)
            {
                throw new ApplicationException("Error Generating computer choice");
            }

            var result = _roundCalculator.CalculateRoundResult(chosenMove.GameMove, computerGameMove);

            _inputOutputWrapper.WriteLine($"Computer chose: {computerGameMoveViewModel.FriendlyName}");

            string resultString = null;

            switch (result)
            {
            case Result.Draw:
                resultString = "Draw!";
                break;

            case Result.Player1Wins:
                resultString = "You win!";
                IncrementWins(normalPlayer);
                break;

            case Result.Player2Wins:
                resultString = "Computer wins!";
                IncrementWins(computerPlayer);
                break;
            }

            _inputOutputWrapper.WriteLine(resultString);
        }
Esempio n. 4
0
        /// <summary>
        /// The constructor for the game; instantializes all required variables
        /// </summary>
        /// <param name="numOfCards"> The deck size for the game </param>
        /// <param name="difficulty"> The difficulty of the ai player </param>
        public frmDurakGame(int numOfCards, char difficulty)
        {
            InitializeComponent();

            //Create a deck with the specified number of cards
            talon = new Deck(numOfCards);

            //Shuffle the deck
            talon = talon.Shuffle();

            //Create the human player
            humanPlayer = new Player(talon);

            //Set the attacker to be the human player
            attacker = humanPlayer;

            //Create an ai player based on the difficulty
            if (difficulty == 'e')
            {
                EasyPlayer easy = new EasyPlayer(talon);

                //Set the defender and cpuPlayer
                defender  = easy;
                cpuPlayer = easy;
            }
            else if (difficulty == 'h')
            {
                MediumPlayer med = new MediumPlayer(talon);

                //Set the defender and cpuPlayer
                defender  = med;
                cpuPlayer = med;
            }

            //Set the trump suit
            Card.trump = talon.getTrumpSuit();

            //Adds the deck images to the form
            SetDeck();

            //Draw everything to the form
            Redraw();
        }
Esempio n. 5
0
        public Game(Symbol seed, Difficulty level, bool singlePlayer,
            bool AIFirst, string p1Name = "Guest Player One",
            string p2Name = "Guest Player Two")
        {
            InitializeComponent();

            turnsRemaining = 36;

            this.currentSymbol = seed;
            this.p1Name = p1Name;
            this.p2Name = p2Name;
            this.singlePlayer = singlePlayer;

            SetUpCells();

            if (singlePlayer)
            {
                if (level == Difficulty.easy)
                {
                    AI = new EasyAI();
                    p2Name = "Easy Computer";
                }
                else if (level == Difficulty.medium)
                {
                    AI = new MediumAI();
                    p2Name = "Medium Computer";
                }
                else if (level == Difficulty.hard)
                {
                    AI = new HardAI();
                    p2Name = "Hard Computer";
                }
            }

            this.Visibility = Visibility.Visible;

            if (AIFirst)
            {
                AI.MakeMove(board, currentSymbol, turnsRemaining);
            }
        }
Esempio n. 6
0
        private void ChooseComputerPlayerType()
        {
            var computerPlayerTypeViewModels = _computerPlayerViewModelHelper.ComputerPlayerTypeViewModels;

            _inputOutputWrapper.WriteLine($"You can choose from {computerPlayerTypeViewModels.Count} types of computer player. Please enter:");

            foreach (var computerPlayerTypeViewModel in computerPlayerTypeViewModels)
            {
                _inputOutputWrapper.WriteLine($"{computerPlayerTypeViewModel.InputValue} for {computerPlayerTypeViewModel.FriendlyName}");
            }

            ComputerPlayerTypeViewModel computerTypeChoice = null;

            while (computerTypeChoice == null)
            {
                var choice = _inputOutputWrapper.ReadLine();
                computerTypeChoice = computerPlayerTypeViewModels.FirstOrDefault(x => x.InputValue == choice);
                if (computerTypeChoice == null)
                {
                    _inputOutputWrapper.WriteLine("That was an invalid choice, please try again");
                }
            }
            _computerPlayer = _computerPlayerFactory(computerTypeChoice.InputValue);
        }
Esempio n. 7
0
 public ComputerPlayerTest()
 {
     _gameService = new GameService(new GameManager(new Board()));
     _computer    = new ComputerPlayer(_gameService);
 }
Esempio n. 8
0
        static void Main(string[] args)
        {
            //Deck testDeck = new Deck();

            //foreach (Card card in testDeck)
            //{
            //    Console.WriteLine(card.ToString());
            //}

            Deck testDeck = new Deck(36);

            foreach (Card card in testDeck)
            {
                Console.WriteLine(card.ToString());
            }

            testDeck = testDeck.Shuffle();

            Card.trump = testDeck[testDeck.Count - 1].suit;

            Console.WriteLine("");

            foreach (Card card in testDeck)
            {
                Console.WriteLine(card.ToString());
            }

            EasyPlayer compPlayer = new EasyPlayer(testDeck);

            IComputerPlayer cpuPlayer = compPlayer;

            Player testPlayer = compPlayer;

            Cards playedCards = new Cards();

            //playedCards.Add(new Card(Suit.Spade, Rank.Eight));
            //playedCards.Add(new Card(Suit.Spade, Rank.Jack));

            Console.WriteLine("");

            foreach (Card card in playedCards)
            {
                Console.WriteLine(card.ToString());
            }

            Console.WriteLine("");

            foreach (Card card in testPlayer.GetHand())
            {
                if (card.isPlayable(playedCards))
                {
                    Console.WriteLine(card.ToString() + " is playable");
                }
                else
                {
                    Console.WriteLine(card.ToString() + " is not playable");
                }
            }

            Console.WriteLine("");

            try
            {
                Console.WriteLine(cpuPlayer.selectCard(playedCards).ToString() + " was played!");
            }
            catch (OperationCanceledException e)
            {
                Console.WriteLine(e.Message);
            }

            //Console.WriteLine("");

            //foreach (Card card in testHand)
            //{
            //    Console.WriteLine(card.ToString());
            //}

            //Console.WriteLine("");

            //foreach (Card card in testDeck)
            //{
            //    Console.WriteLine(card.ToString());
            //}

            //if (testDeck[0] > testDeck[1])
            //{
            //    Console.WriteLine("Greater");
            //}
            //else
            //{
            //    Console.WriteLine("Less or equal");
            //}

            //if (testDeck[0] >= testDeck[1])
            //{
            //    Console.WriteLine("Greater or equal");
            //}
            //else
            //{
            //    Console.WriteLine("Less");
            //}

            Console.ReadKey();
        }
Esempio n. 9
0
 public Game(IComputerPlayer computerPlayer)
 {
     _computerPlayer = computerPlayer;
 }
Esempio n. 10
0
 public Controller(IComputerPlayer computerPlayer, IHumanPlayer humanPlayer, IGameService gameService)
 {
     _computerPlayer = computerPlayer;
     _humanPlayer    = humanPlayer;
     _gameService    = gameService;
 }
Esempio n. 11
0
 public ComputerPlayerTest()
 {
     _gameService = new GameService(new GameManager(new Board()));
     _computer = new ComputerPlayer(_gameService);
 }
Esempio n. 12
0
 public Controller(IComputerPlayer computerPlayer, IHumanPlayer humanPlayer, IGameService gameService)
 {
     _computerPlayer = computerPlayer;
     _humanPlayer = humanPlayer;
     _gameService = gameService;
 }
Esempio n. 13
0
        }                                     // The player whose turn it currently is

        void Start()
        {
            // Cache major scripts to be initialized
            scenarioLoader   = GetComponent <ScenarioLoader>();
            uiHandler        = GetComponent <UIHandler>();
            selectionManager = GetComponent <SelectionManager>();
            unitFactory      = GetComponent <UnitFactory>();

            // Load map, then camera
            scenarioLoader.Initialize();
            uiHandler.Initialize();


            // Establish player types, network information
            GameObject matchControllerObject = GameObject.Find("MatchController");

            if (matchControllerObject != null)
            {
                matchController = matchControllerObject.GetComponent <Netcode.MatchController>();
            }
            if (matchController != null)
            {
                playerDirectory = new Dictionary <int, PlayerType>();
                foreach (int player in matchController.netRepPlayers.Keys)
                {
                    if (matchController.whoAmI == player)
                    {
                        playerDirectory.Add(player, PlayerType.Local);
                    }
                    else
                    {
                        playerDirectory.Add(player, PlayerType.Online);
                    }
                }
            }
            else if (Vaults.playerDirectory != null)
            {
                playerDirectory = Vaults.playerDirectory;
            }
            else
            {
                Debug.Log("Using default playerDirectory");
                playerDirectory = new Dictionary <int, PlayerType>();
                playerDirectory.Add(1, PlayerType.Local);
                playerDirectory.Add(2, PlayerType.AI); // FOR TESTING__, these defaults shouldn't be reached
            }

            Tutorial.TutorialManager tutorialManager = GetComponent <Tutorial.TutorialManager>();
            if (tutorialManager != null)
            {
                computerPlayer = new Tutorial.TutorialAI(tutorialManager, selectionManager, scenarioLoader);
            }
            else if (playerDirectory.Values.Contains(PlayerType.AI))
            {
                computerPlayer = new DefaultAI(selectionManager, scenarioLoader);
            }
            ActivePlayer = 1;

            // Build & load units onto the map
            if (Vaults.wsUnitList != null)
            {
                foreach (WeaponSelect.WSController.WSUnitDescriptor unit in Vaults.wsUnitList)
                {
                    unitFactory.Create(unit.player, unit.unitType, unit.weaponType, scenarioLoader.HexGrid[unit.position]);
                }
            }
            else   // FOR TESTING

            /*
             * unitFactory.Create(1, UnitBaseType.Simple, WeaponType.Longbow, GetComponent<ScenarioLoader>().HexGrid[new Vector2(-5, 5)]);
             * unitFactory.Create(1, UnitBaseType.Simple, WeaponType.Shield, GetComponent<ScenarioLoader>().HexGrid[new Vector2(-3, 5)]);
             * unitFactory.Create(2, UnitBaseType.Simple, WeaponType.Spear, GetComponent<ScenarioLoader>().HexGrid[new Vector2(0, -5)]);
             * unitFactory.Create(2, UnitBaseType.Simple, WeaponType.Flail, GetComponent<ScenarioLoader>().HexGrid[new Vector2(-3, -5)]);*/
            {
            }

            // Initialize the first turn
            selectionManager.Initialize();

            if (tutorialManager != null)
            {
                tutorialManager.Initialize();
            }
        }