public DraughtsSummary(DraughtsState draughtsState) { foreach (System.Drawing.Point place in draughtsState.Board.PlacesAndNeighbors.Keys) { if (draughtsState.Board[place] != null) { Results[draughtsState.Board[place].Value]++; } } byte max = Results.Values.Max(); if (!Results.All(a => a.Value == max)) { Winner = Results.First(a => a.Value == max).Key; } }
public override void Execute(DraughtsState state) { state.Board[Point] = default; state.Board[PointTargetToHit] = default; state.Board[PointTarget] = PlayerType; }
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; } }
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; } }
public abstract void Execute(DraughtsState state);
public override async Task <DraughtsMove> NextMove(DraughtsState state, List <DraughtsMove> allowedMoves) { return(allowedMoves[random.Next(allowedMoves.Count)]); }
private DraughtsState(DraughtsState state) { CurentPlayer = state.CurentPlayer; Players = state.Players; Board = (DraughtsBoard)state.Board.Clone(); }