Exemple #1
0
        //Test Me
        public Dictionary <int, List <Tile> > RatePosibilePlacements(Game.GameCore gameCore, Object player)
        {
            //Assumptions: If we could win, or the other player could win we
            //would have placed a tile already and not reached this step.

            //Get all the placeable tiles on the board, then go through each of them and rate how
            //good each placement would be.

            //After doing all this we need to make sure we're not placing a token where we would be giving the
            //opponent a winning position.
            var board          = gameCore.Board;
            var placeableTiles = gameCore.Board.GetAllPlaceableTiles();

            var ratings = new Dictionary <int, List <Tile> >();

            foreach (Tile pt in placeableTiles)
            {
                int rating = GetRatingForTile(gameCore, pt, player);
                if (!ratings.ContainsKey(rating))
                {
                    ratings.Add(rating, new List <Tile>());
                }
                ratings[rating].Add(pt);
            }

            return(ratings);
        }
Exemple #2
0
        static private bool CheckTwoTurnCompulsionWinForTile(Game.GameCore game, Object player, Game.Tile tile)
        {
            //Create a copy of the game to test with, ensuring that it is the player we are checking's turn
            var testGame = game.Copy(player);

            //Drop a token on the column
            testGame.DropTokenOnColumn(tile.Column.ColumnNo);

            //Check if the other player will compulsed to make a blocking move, which will be the case if
            //we have a winning move
            var winPossibilities = FindDirectWinningPossibilities(testGame.Board, player);

            //Check that we can make a winning move
            var won = false;

            winPossibilities.ForEach(winingTile => {
                var blockedGame = testGame.Copy();
                blockedGame.DropTokenOnColumn(winingTile.Column.ColumnNo); //simulate the opponent dropping a blocking tile
                var finishingMovePosibilities = FindDirectWinningPossibilities(blockedGame.Board, player);
                if (finishingMovePosibilities.Count > 0)
                {
                    //make sure that we don't give the game away though
                    var opponentWins = FindDirectWinningPossibilities(testGame.Board, game.GetOtherPlayer(player));
                    if (opponentWins.Count() == 0)
                    {
                        won = true; //c# question: how do we return out of the parent function here?
                    }
                }
            });

            return(won);
        }
        public AIBattleGameController(Player player1, Player player2)
        {
            _player1 = player1;
            _player2 = player2;

            _game = new Game.GameCore(_player1, _player2);
        }
        public AIBattleGameController(Player player1, Player player2)
        {
            _player1 = player1;
            _player2 = player2;

            _game = new Game.GameCore(_player1, _player2);
        }
        public GameController(MainForm mainForm, DropBoard dropBoard, Player player1, Player player2)
        {
            _mainForm = mainForm;
            _dropBoard = dropBoard;
            _player1 = player1;
            _player2 = player2;

            _game = new Game.GameCore(_player1, _player2);
            _game.GameStateChanged += new EventHandler(OnGameStateChanged);
        }
Exemple #6
0
        public GameController(MainForm mainForm, DropBoard dropBoard, Player player1, Player player2)
        {
            _mainForm  = mainForm;
            _dropBoard = dropBoard;
            _player1   = player1;
            _player2   = player2;

            _game = new Game.GameCore(_player1, _player2);
            _game.GameStateChanged += new EventHandler(OnGameStateChanged);
        }
Exemple #7
0
 public void SetFinishedState(Game.GameCore game)
 {
     if (game.IsStatemate)
     {
         lblStateDescription.Text = "The game is a stalemate";
     }
     else
     {
         lblStateDescription.Text      = string.Format("{0} has won the game", _gameController.GetWinningPlayer().PlayerName);
         lblStateDescription.BackColor = _gameController.GetWinningPlayer().HighlightColour;
     }
 }
Exemple #8
0
        static public List <Game.Tile> FindTwoTurnCompulsionWin(
            Game.GameCore game,
            Object player)
        {
            //Look through the playable tiles for each column.
            //Consider the case where if it was filled, the player would be forced to make
            //a follow-up move that would allow us to make a winning followup move.

            var twoTurnCompulsionWinTiles = new List <Game.Tile>();

            game.Board.Columns.ForEach(column => {
                if (!column.IsFull)
                {
                    if (CheckTwoTurnCompulsionWinForTile(game, player, column.GetFirstEmptyTile()))
                    {
                        twoTurnCompulsionWinTiles.Add(column.GetFirstEmptyTile());
                    }
                }
            });

            return(twoTurnCompulsionWinTiles);
        }