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); }); } }
protected void OnMoved(CthelloGame game) { if (Moved != null) { Moved(this, new GameEventArgs(game)); } }
// Einen Zug ausführen public void MakeMove(CthelloMove move) { CthelloGame newGame = (CthelloGame)_game.MakeMove(move); _game = newGame; OnMoved(newGame); }
public override Game <CthelloMove> MakeMove(CthelloMove move) { CthelloGame copy = new CthelloGame(this); copy.AddMove(move); if (!move.Pass) { copy.MoveAndFlip(move); } return(copy); }
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); }); } }
public CthelloGame(CthelloGame other) : base(other) { _board = other._board; }
public CthelloGame(CthelloGame other) : base(other) { _board = new UInt64[2]; other._board.CopyTo(_board, 0); }
public CthelloMatch(Brain <CthelloMove> player1, Brain <CthelloMove> player2) : base(player1, player2) { _game = new CthelloGame().Init(); _nextPlayer = player1; }
public GameEventArgs(CthelloGame game) { Game = game; }