public void RatingPreOrder() { List <BoardRating> ratingList = CreateBoardRatingList(); IBoardRatingComparer boardRatingWhiteComparer = BoardRatingComparerFactory.GetComparer(Color.White); var orderedListWhite = ratingList.Select(rating => rating).ToList(); orderedListWhite.Sort(boardRatingWhiteComparer); LinkedList <BoardRating> lw = new LinkedList <BoardRating>(orderedListWhite); var pairsWhite = lw.Select(e => new Tuple <BoardRating, BoardRating>(e, lw.Find(e)?.Next?.Value)).ToList(); Assert.IsTrue(pairsWhite.All(t => (t.Item2 == null) || boardRatingWhiteComparer.Compare(t.Item1, t.Item2) <= 0)); IBoardRatingComparer boardRatingBlackComparer = BoardRatingComparerFactory.GetComparer(Color.Black); var orderedListBlack = ratingList.Select(rating => rating).ToList(); orderedListBlack.Sort(boardRatingBlackComparer); LinkedList <BoardRating> lb = new LinkedList <BoardRating>(orderedListWhite); var pairsBlack = lb.Select(e => new Tuple <BoardRating, BoardRating>(e, lb.Find(e)?.Next?.Value)).ToList(); Assert.IsTrue(pairsBlack.All(t => (t.Item2 == null) || boardRatingWhiteComparer.Compare(t.Item1, t.Item2) <= 0)); }
public void MoveListPreOrder() { MoveList moveList = CreateMoveList(); var whiteBestMove = moveList.GetBestMove(Color.White); Assert.IsNotNull(whiteBestMove.Rating.Evaluation == Evaluation.BlackCheckMate); moveList.Sort(Color.White); var ratingList = moveList.Moves.Select(move => move.Rating).ToList(); IBoardRatingComparer boardRatingComparer = BoardRatingComparerFactory.GetComparer(Color.White); for (int i = 0; i < ratingList.Count - 1; i++) { Assert.IsTrue(boardRatingComparer.Compare(ratingList[i], ratingList[i + 1]) <= 0); } }
public MoveSorter(Color color) { _Comparer = BoardRatingComparerFactory.GetComparer(color); }