Пример #1
0
        public override Func <TGame, int, int> GetEvaluator <TGame>(int evalId)
        {
            switch (evalId)
            {
            case 1:
                return((g, p) =>
                {
                    CthelloGame game = g as CthelloGame;
                    return game.CountStonesWeighted(p) - game.CountStonesWeighted(1 - p);
                });

            case 2:
                return((g, p) =>
                {
                    CthelloGame game = g as CthelloGame;
                    int myMoves = game.MovesFor(p).Count();
                    int yourMoves = game.MovesFor(1 - p).Count();
                    if (myMoves < 2 && yourMoves < 2)
                    {
                        return game.CountStonesFor(p) - game.CountStonesFor(1 - p);
                    }
                    else
                    {
                        return (game.CountStonesWeighted(p) + 10 * myMoves) - (game.CountStonesWeighted(1 - p) + 10 * yourMoves);
                    }
                });

            default:
                return((g, p) =>
                {
                    CthelloGame game = g as CthelloGame;
                    return game.CountStonesFor(p) - game.CountStonesFor(1 - p);
                });
            }
        }
Пример #2
0
        public override Func <TGame, int, int> GetEvaluator <TGame>(int evalId)
        {
            switch (evalId)
            {
            case 1:
                // Nur die gewichteten Steine zählen
                return((g, p) =>
                {
                    CthelloGame game = g as CthelloGame;
                    return game.CountStonesWeighted(p) - game.CountStonesWeighted(1 - p);
                });

            case 2:
                // Gewichtete Steine und Anzahl der möglichen Züge werten.
                return((g, p) =>
                {
                    CthelloGame game = g as CthelloGame;
                    var myMoves = game.MovesFor(p);
                    bool iPass = myMoves.First().Pass;
                    var yourMoves = game.MovesFor(1 - p);
                    bool youPass = yourMoves.First().Pass;
                    if (iPass && youPass)
                    {
                        // Wenn jeder nur noch einen Zug (nämlich "Passe") hat,
                        // ist das Spiel zu Ende und es zählen nur die Steine.
                        return game.CountStonesFor(p) - game.CountStonesFor(1 - p);
                    }
                    else
                    {
                        return (game.CountStonesWeighted(p) + MoveWeight * myMoves.Count()) - (game.CountStonesWeighted(1 - p) + MoveWeight * yourMoves.Count());
                    }
                });

            default:
                // Fallback: Steine zählen
                return((g, p) =>
                {
                    CthelloGame game = g as CthelloGame;
                    return game.CountStonesFor(p) - game.CountStonesFor(1 - p);
                });
            }
        }