Ejemplo n.º 1
0
        //Test Me
        public int GetRatingForTile(GameCore gameCore, Tile tile, Object player)
        {
            int rating = 0;

            //First check if placing a tile here will force the opponent to block us, or give the
            //opponent a wining move. We shouldn't consider those tiles.
            var copy = gameCore.Copy();

            copy.DropTokenOnColumn(tile.ColumnNo);
            var otherPlayerDirectWinnable = AIHelper.FindDirectWinningPossibilities(copy.Board, gameCore.GetOtherPlayer(player));

            if (otherPlayerDirectWinnable.Count > 0)
            {
                //lower skilled players can miss an opponents winning move, especially if they are
                //focused on their own win
                if (_difficulty == AIDifficulty.VeryEasy)
                {
                    rating -= 2;
                }
                else if (_difficulty == AIDifficulty.Easy)
                {
                    rating -= 4;
                }
                else if (_difficulty == AIDifficulty.Medium)
                {
                    rating -= 6;
                }
                else
                {
                    //the other player can win if we play here, so don't play
                    return(-1000);
                }
            }

            var usDirectWinnable = AIHelper.FindDirectWinningPossibilities(copy.Board, player);

            if (usDirectWinnable.Count > 0)
            {
                //we can win next turn if we place here, forcing the other player to make a blocking move.
                //It may be worth making the move anyway if it gives us a good position, and there isn't
                //anything better, so don't completley discount it.
                if (CanCreateCompulsion(copy.Board))
                {
                    rating -= 3;
                }
                else
                {
                    //if the player can't create compulsions we shouldn't penalize them for
                    //trying to win

                    if (_difficulty < AIDifficulty.Medium)
                    {
                        //lower skilled players will chase a win
                        rating += 2;
                    }
                }
            }

            //We are trying to create general opportunities to head into the end game by creating
            //potential token connections. So we want to look at where we have potential connections
            //and try to build that area up to generate a compulsion.
            rating += (FindTilesInConnection(gameCore, tile, player).Count * 2);


            //Future ToDos
            //Now check the opponents tile connections. Add points based on how many they have, sine we're
            //blocking their position
            if (_tryToBlockOpponentsGoodConnections)
            {
                rating += FindTilesInConnection(gameCore, tile, gameCore.GetOtherPlayer(player)).Count;
            }

            //Check what will happen once we play our tile. Does it open up any good positions?

            //Do some planning stuff now:

            //If placing a tile here will start a compulsion for us, add points
            //If placing a tile here will block an opponents compulsion then add some points.
            //Check the tile connections for the tile above this one. If the opponent would have good
            //connections then subtract points. If we would have a good connections subtract points
            //(since it alows the opponent to block us.

            return(rating);
        }