Esempio n. 1
0
        internal MovesCalculator(GameBoardState state, CheckerColor color, int fromPosition, List <int> moves)
        {
            initialMoveState = new MoveState(state, color, fromPosition, moves, new List <Change>());


            //Initialises the set of reachable states given the starting GameBoardState, position and moves
            IEnumerable <MoveState> tmp1 = initialMoveState.GenerateMoveStatesForPosition();

            while (tmp1.Count() > 0)
            {
                reachableStates.AddRange(tmp1); //Adds all the states in tmp1 to the reachable states

                tmp1 = tmp1
                       //Maps every state 'a' in tmp1 to a list that contains the states that are reachable from 'a'
                       .Select(s => s.GenerateMoveStatesForPosition())
                       //Concatenates all the lists, yielding a new set of reachable states
                       .Aggregate((a, b) => a.Concat(b));
            }
        }