I'm trying to write some AI for a game of checkers. I want to select the move with the highest board score.
Need something like this:
var bestMove = from m in validMoves
where BoardScore(opp, board.Clone().ApplyMove(m)) is max
select m
Except I can't figure out the "is max" part. Would prefer it returns a single item rather than an enumerable too.
Basically, the equivalent of this:
Move bestMove = null;
float highestScore = float.MinValue;
foreach (var move in validMoves)
{
float score = BoardScore(opp, board.Clone().ApplyMove(move));
if (score > highestScore)
{
highestScore = score;
bestMove = move;
}
}