コード例 #1
0
        private int indexOfMax(ChessDrawScore[] ratedDraws, int offset)
        {
            // return -1 if the list does not contain a single item
            if (ratedDraws?.Length <= 0)
            {
                return(-1);
            }

            // initialize max item cache with first item
            int            maxIndex = offset;
            ChessDrawScore temp     = ratedDraws[offset];

            // loop through all remaining items to compare
            for (int i = offset + 1; i < ratedDraws.Length; i++)
            {
                // compare score to temporary max score
                if (temp.Score < ratedDraws[i].Score)
                {
                    // update max score / index of max item if a greater score was found
                    temp     = ratedDraws[i];
                    maxIndex = i;
                }
            }

            // return the index of the max. item onto the array subset
            return(maxIndex);
        }
コード例 #2
0
        private ChessDraw[] getPreorderedDrawsByPossibleGain(IChessBoard board, IList <ChessDraw> draws, ChessColor drawingSide)
        {
            // initialize score array
            var drawsXScoreTuples = new ChessDrawScore[draws.Count()];

            // loop through all draws
            for (int i = 0; i < draws.Count(); i++)
            {
                // simulate the draw
                var simDraw  = draws[i];
                var simBoard = board.ApplyDraw(simDraw);

                // compute the score of the resulting position (= score of the draw)
                double score = _estimator.GetScore(simBoard, drawingSide);

                // add the (draw, score) tuple to the list
                drawsXScoreTuples[i] = new ChessDrawScore()
                {
                    Draw = simDraw, Score = score
                };
            }

            return(sortByScoreDesc(drawsXScoreTuples));
        }