public override void PerformMove(PawnMove pawnMove) { if (moveList.Contains(pawnMove) == false) { throw new ArgumentException("Invalid move"); } UpdateBoard(pawnMove); moveCount++; SwapPawnColor(); }
protected List <PawnMove> GetCaptureList(Dot pos, BoardState boardState, PawnMove pawnMove) { var result = new List <PawnMove>(); result.Add(pawnMove); result.AddRange(GetCaptureList(pos, boardState, new Dot(1, 1), pawnMove)); result.AddRange(GetCaptureList(pos, boardState, new Dot(-1, -1), pawnMove)); result.AddRange(GetCaptureList(pos, boardState, new Dot(-1, 1), pawnMove)); result.AddRange(GetCaptureList(pos, boardState, new Dot(1, -1), pawnMove)); return(result); }
protected void UpdateBoard(PawnMove pawnMove) { foreach (var pawn in pawnMove.GetCapturedList()) { pawnList.Remove(pawn); } pawnList.Remove(pawnMove.MovedPawn); var movedPos = pawnMove.GetPosList().Last(); if (pawnMove.TurnDame) { pawnList.Add(new DamePawn(movedPos, pawnMove.MovedPawn.GetPawnColor())); } else { pawnList.Add(pawnMove.MovedPawn.GetMovedToPos(movedPos)); } }
abstract public void PerformMove(PawnMove pawnMove);
protected abstract List <PawnMove> GetCaptureList(Dot pos, BoardState bState, Dot dir, PawnMove pMove);
protected override List <PawnMove> GetCaptureList(Dot pos, BoardState bState, Dot dir, PawnMove pMove) { var capPawn = GetCapturedPawn(pos, bState, dir); if (capPawn == null) { return(new List <PawnMove>()); } pos = capPawn.GetPosition(); if (pMove.GetCapturedList().Contains(capPawn)) { return(GetCaptureList(pos, bState, dir, pMove)); } pos = pos.GetMoved(dir); var result = new List <PawnMove>(); while (bState.IsOnBoard(pos) && bState.GetColor(pos) == PawnColor.NONE) { var destMove = pMove.CreateIncrMove(pos, capPawn, false); result.AddRange(GetCaptureList(pos, bState, destMove)); pos = pos.GetMoved(dir); } return(result); }
protected override List <PawnMove> GetCaptureList(Dot pos, BoardState bState, Dot dir, PawnMove pMove) { if (CanCapture(pos, bState, dir) == false) { return(new List <PawnMove>()); } var capPawn = bState.GetPawn(pos.GetMoved(dir)); if (pMove.GetCapturedList().Contains(capPawn)) { return(new List <PawnMove>()); } var destPos = pos.GetMoved(dir.X * 2, dir.Y * 2); bool isDamePos = IsDameLanePos(destPos, bState); var destMove = pMove.CreateIncrMove(destPos, capPawn, isDamePos); return(GetCaptureList(destPos, bState, destMove)); }