private InsertionSpace GetSuitableSpaces(DirectionalProcess dirProcess, int pos, string word) { var emptySpace = GetEmptyConsecSpace(dirProcess, word); var joinedSpace = GetJoinedSpace(dirProcess, word); if (emptySpace == null && joinedSpace != null) { return(joinedSpace); } if (emptySpace != null && joinedSpace == null) { return(emptySpace); } if (emptySpace != null && joinedSpace != null) { var num = Rand.GetRandomNumber(0, 2); if (num == 0) { return(emptySpace); } else { return(joinedSpace); } } return(new InsertionSpace(-1, 0, 0, Enums.InsertionSpaceType.Empty)); }
private ConsecEmptyInsertionSpace GetEmptyConsecSpace(DirectionalProcess dirProcess, string word) { var values = dirProcess.GetEmptyConsecSpace(word); if (values.Count == 0) { return(null); } return(values.OrderByDescending(csv => csv.EmptySpaces).First()); }
private JoinedInsertionSpace GetJoinedSpace(DirectionalProcess dirProcess, string word) { var validatedEntries = dirProcess.GetJoinedSpace(word); if (validatedEntries.Count == 0) { return(null); } return(validatedEntries[Rand.GetRandomNumber(0, validatedEntries.Count)]); }
private DirectionalProcess GetDirectionProcess(Enums.Direction dir) { DirectionalProcess dirProcess = null; switch ((Enums.Direction)dir) { case Enums.Direction.Row: dirProcess = new DirectionalProcessRow(_grid); break; case Enums.Direction.Column: dirProcess = new DirectionalProcessColumn(_grid); break; //case Enums.Direction.Diagonal: // dirProcess = new DirectionalProcessDiagonal(_grid); //break; } return(dirProcess); }
private SubmissionResponse SubmitTextInternal(DirectionalProcess dirProcess, int sizeValue, string text) { var finalResult = false; WordData wordData = null; var originalCol = dirProcess.StartRowCol; var iterateCol = originalCol; var exitLoop = false; InsertionSpace space = null; do { space = GetSuitableSpaces(dirProcess, iterateCol, text); var canInsert = space != null && text.Length <= space.EmptySpaces; // When it can't insert try the next row, moving back to the beginning when it hits the end of the rows. if (!canInsert) { iterateCol = iterateCol + 1 > sizeValue - 1 ? 0 : iterateCol + 1; } finalResult = canInsert; // Exit loop if it can insert, or if we've tried every row and gone back to the original row. exitLoop = canInsert || originalCol == iterateCol; } while (!exitLoop); // If validation passes, then insert it. if (finalResult) { wordData = PerformInsert(dirProcess, text, space); } return(new SubmissionResponse(finalResult, wordData)); }
private DirectionalProcess GetRandomDirectionalProcess() { var dir = Rand.GetRandomNumber(0, DirectionalProcess.GetDirectionalProcessLimit()); return(GetDirectionProcess((Enums.Direction)dir)); }
private WordData PerformInsert(DirectionalProcess dirProcess, string value, InsertionSpace space) { return(dirProcess.PerformInsert(space, value)); }