private bool CheckTake(Vector2Int takePos, Vector2Int posAfterTake, Checkboard checkboard, out Move move) { move = null; if (checkboard.Exists(takePos) && !checkboard.IsEmptyAndExists(takePos) && checkboard[takePos].Color != Color && checkboard.IsEmptyAndExists(posAfterTake)) { move = new Move { NewPos = posAfterTake, PawnPos = Position, TakePos = takePos }; return(true); } return(false); }
private bool CheckNormalMove(Vector2Int movePos, Checkboard checkboard, out Move move) { move = null; if (checkboard.IsEmptyAndExists(movePos)) { move = new Move { NewPos = movePos, PawnPos = Position }; return(true); } return(false); }
private IEnumerable <Move> CheckKingMoves(Vector2Int startPos, System.Func <Vector2Int, Vector2Int> moveFunc, Checkboard checkboard) { var checkPos = moveFunc(startPos); while (checkboard.IsEmptyAndExists(checkPos)) { yield return(new Move { NewPos = checkPos, PawnPos = startPos, }); checkPos = moveFunc(checkPos); } }
private IEnumerable <Move> CheckKingTakes(Vector2Int startPos, System.Func <Vector2Int, Vector2Int> moveFunc, Checkboard checkboard) { var checkPos = startPos; var prevPos = startPos; while (checkboard.Exists(checkPos)) { checkPos = moveFunc(checkPos); var posAfterTake = moveFunc(checkPos); if (!(checkboard.IsEmptyAndExists(prevPos) || checkboard[prevPos].Position == startPos)) { yield break; } if (CheckTake(checkPos, posAfterTake, checkboard, out var move)) { yield return(move); var endPos = moveFunc(move.NewPos); while (checkboard.IsEmptyAndExists(endPos)) { yield return(new Move { NewPos = endPos, PawnPos = move.PawnPos, TakePos = move.TakePos, }); endPos = moveFunc(endPos); } yield break; } prevPos = moveFunc(prevPos); } }