Advertisement

AI GAME (HELP) Please ANY suggestion

Started by February 26, 2009 05:20 PM
-1 comments, last by mashimathi 15 years, 8 months ago
Please check here for how my game look like http://www.freeimagehosting.net/uploads/17a07aa1a2.jpg Rules of the game. 1. The object of the game is to occupy (leave your Slime in) more of the GridSquares than all of your opponents when the game ends. 2. Players take turns to move. A player turn consists of moving a Snail horizontally or vertically to an adjacent empty square. 3. Moving into an empty GridSquare leaves your previously occupied GridSquare with a trail of your slime. SPLAT! 4. Not only can you move into empty squares, but you can move back onto your own Trail of Slime. This has a disadvantage, however; your Slime is slippy, and any move back onto your Slime will send you sliding to the furthest point on that Trail in the direction you moved.This may be useful for getting some missed GridSquares, or ones that were previously unavailable. 5. You can not, however, move onto your opponent's Trail of Slime. As the colours suggest your opponent's Trails are toxic, making them impassable. Your opponent, also cannot move into a GridSquare occupied by your Trail. 6. If you make 10 moves in a row without capturing a new empty GridSquare, (i.e. just keep sliding around on your slime for 10 moves) then your game ends, but your opponent can still move, until his/her 10 moves are up. 7. When both players have finished moving, or cannot capture any more GridSquares, the game is over and the player with the highest score (most GridSquares captured) is the winner. ______________________________________________________________________________ I use the AlphaBeta Pruning to find the best move.This is working great.

 double GetGameResultDepthLimitedAlphaBeta(int player, int depth, double alpha, double beta)
        {
            BoardsEvaluated++;
            score = -5000.00;
            List<Move> moves = TheBoard.GetMoves(player);

            // If we have reached the maximum search depth, return our best "guess" as to the game result.
            if (depth == MaxDepth)
                return TheBoard.GetEstimatedResult(player);

            foreach (Move m in moves)
            {
                if (alpha >= beta)
                {

                    return alpha; // cut off search here.
                   
                }

                // Get the result from the other player's point of view after making move m.
   
                TheBoard.DoMove(m);
                double gr = -GetGameResultDepthLimitedAlphaBeta(3 - player, depth + 1, -beta, -alpha);
                if (gr > alpha) // is this a new best move?
                {
                    alpha = gr; // yes - new best move so store the value
                    if (depth == 0)
                        BestMove = m.TheCommand;  // save the best move from the root position.
                }

                if (gr > score) score = gr;


                TheBoard.UndoMove(m); // take back move m
            }

            return alpha;
        }
The problem is I can even beat the program :( It is because of the weakness in following function,I think. Can you please suggest me to improve it.


            /// Returns ((player snails + player trails) - (opponent snails + opponent trails))
            /// </summary>
            public int GetAllPiecesNumericalAdvantage(int player)
            {
                int cna = 0;
                int opponent = 3 - player; // if player = 1, opponent = 2. If player = 2, opponent = 1.

                for (int x = 0; x < MyWorldState.GridWidthInSquares; x++)
                    for (int y = 0; y < MyWorldState.GridHeightInSquares; y++)
                    {
                        if (this[x, y] == player || this[x, y] == -player)
                            cna++;
                        else if (this[x, y] == opponent || this[x, y] == -opponent)
                            cna--;
                    }

                return cna;
            }
The estimated result of the board from the point of view of player. I think,I need to tune this function to make a good player. by defining board parameters which define features which are advantageous to a player or the opponent, and multiply the features by appropriate numerical weights.


public double GetEstimatedResult(int player)
            {
                double score = 0.0; // the score so far

                score += 1.0 * GetAllPiecesNumericalAdvantage(player);
                score += 0.25 * GetAdjacentEmptySquaresNumericalAdvantage(player);
                // you should add some more parameters in here

                // Ensure score is in the legal range from -1000 to +1000.
                if (score > 1000.0)
                    score = 1000.0;
                if (score < -1000.0)
                    score = -1000.0;

                return score;
            }

Please give me some suggestion! Thanks. [Edited by - mashimathi on February 27, 2009 2:25:45 AM]

This topic is closed to new replies.

Advertisement