Beispiel #1
0
        private IEnumerable <List <DraughtsAction> > GetAllHits(DraughtsPlayerType playerType, DraughtsState state, List <DraughtsAction> hits)
        {
            DraughtsState stateTmp = (DraughtsState)state.Clone();

            foreach (DraughtsActionHit hit in hits)
            {
                hit.Execute(stateTmp);
            }
            IEnumerable <DraughtsActionHit> nextLevelHit = GetHit(playerType, (DraughtsActionHit)hits.Last(), stateTmp);

            if (!nextLevelHit.Any())
            {
                yield return(hits);
            }
            else
            {
                foreach (DraughtsActionHit hit in nextLevelHit)
                {
                    List <DraughtsAction> newHits = new List <DraughtsAction>(hits);
                    newHits.Add(hit);
                    foreach (List <DraughtsAction> newHit in GetAllHits(playerType, state, newHits))
                    {
                        yield return(newHit);
                    }
                }
            }
        }
Beispiel #2
0
 private static IEnumerable <DraughtsActionHit> GetHit(DraughtsPlayerType playerType, DraughtsActionHit hit, DraughtsState state)
 {
     foreach (KeyValuePair <Point, Vector[]> placeAndNeighbors in state.Board.PlacesAndNeighbors)
     {
         if (hit == null || hit.PointTarget == placeAndNeighbors.Key)
         {
             foreach (Vector neighbor in placeAndNeighbors.Value)
             {
                 DraughtsActionHit hitNew = new DraughtsActionHit(playerType, placeAndNeighbors.Key, neighbor, state);
                 if (hitNew.IsAllowed)
                 {
                     yield return(hitNew);
                 }
             }
         }
     }
 }
Beispiel #3
0
        public DraughtsActionMove(DraughtsPlayerType playerType, Point point, Vector vector, DraughtsState state) : base(playerType, point, vector)
        {
            IsEnd       = true;
            PointTarget = new Point(point.X + vector.X, point.Y + vector.Y);
            Vector[] neighbors = state.Board.PlacesAndNeighbors[point];

            if (!neighbors.Contains(vector) ||
                playerType != state.Board[point] ||
                state.Board[PointTarget] != default ||
                PlayerType == DraughtsPlayerType.Black && vector.X == -1 ||
                PlayerType == DraughtsPlayerType.White && vector.X == 1)
            {
                IsAllowed = false;
            }
            else
            {
                IsAllowed = true;
            }
        }
Beispiel #4
0
        public DraughtsActionHit(DraughtsPlayerType playerType, Point point, Vector vector, DraughtsState state) : base(playerType, point, vector)
        {
            Vector[] neighbors = state.Board.PlacesAndNeighbors[point];
            PointTargetToHit = new Point(point.X + vector.X, point.Y + vector.Y);
            PointTarget      = new Point(point.X + vector.X * 2, point.Y + vector.Y * 2);
            DraughtsPlayerType enemy = PlayerType == DraughtsPlayerType.Black ? DraughtsPlayerType.White : DraughtsPlayerType.Black;

            if (!neighbors.Contains(vector) ||
                !state.Board.PlacesAndNeighbors[PointTargetToHit].Contains(vector) ||
                playerType != state.Board[point] ||
                state.Board[PointTargetToHit] != enemy ||
                state.Board[PointTarget] != default)
            {
                IsAllowed = false;
            }
            else
            {
                IsAllowed = true;
            }
        }
Beispiel #5
0
 protected DraughtsAction(DraughtsPlayerType playerType, Point point, Vector vector)
 {
     PlayerType = playerType;
     Vector     = vector;
     Point      = point;
 }