public List <FigureModel> GetFigure(string sessionKey, int gameId) { //hard code // return this.data.figureRepository.GetGameFigures(gameId); FigureRepository figureRepository = data.GetFigureRepository(); var figures = figureRepository.GetGameFigures(gameId); List <FigureModel> returnList = new List <FigureModel>(); foreach (var figure in figures) { var checkListForDuplicate = returnList.Find(x => x.PosCol == figure.PositionCol && x.PosRow == figure.PositionRow); if (figure.GameId == gameId && checkListForDuplicate == null) { returnList.Add(FigureModel.ConvertToModel(figure)); } } return(returnList); }
private bool ValidateMove(Figure figure, int toRow, int toCol) { PositionModel toPosition = new PositionModel() { Row = toRow, Col = toCol }; PositionModel fromPosition = new PositionModel() { Row = figure.PositionRow, Col = figure.PositionCol }; if (toRow > 8 || toCol > 8) { return(false); } if (toRow < 0 || toCol < 0) { return(false); } var currentFigure = FigureFactory.GetFigure(figure); List <PositionModel> possibleMoves = currentFigure.GetPossibleMoves(); List <PositionModel> possibleHits = currentFigure.GetPossibleHits(); var checkedPosMoves = possibleMoves.Find(x => x.Col == toPosition.Col && x.Row == toPosition.Row); var checkedPosHits = possibleHits.Find(x => x.Col == toPosition.Col && x.Row == toPosition.Row); if (checkedPosMoves == null && checkedPosHits == null) { return(false); } if (!currentFigure.CanJump()) { FigureRepository figureRepository = data.GetFigureRepository(); HashSet <PositionModel> movePath = GetMovePath(fromPosition, toPosition); IQueryable <Figure> allGameFigures = figureRepository.GetGameFigures(figure.GameId); HashSet <PositionModel> gameFiguresPositions = new HashSet <PositionModel>(); foreach (Figure gameFig in allGameFigures) { gameFiguresPositions.Add(new PositionModel() { Row = gameFig.PositionRow, Col = gameFig.PositionCol }); } var positionIntersection = movePath.Intersect <PositionModel>(gameFiguresPositions); if (positionIntersection.Count() > 0) { return(false); } } return(true); }