public bool SetPoints(ref int points, int x, int y, int boardHeight, int boardWidth, FieldStateEnum activePlayer, IReadOnlyList <IReadOnlyList <Field> > board) { if (x < 0 || y < 0 || y >= boardHeight || x >= boardWidth || board[y][x].State == FieldStateEnum.Empty) { points = 0; return(true); } if (board[y][x].State == activePlayer) { return(true); } points++; return(false); }
public int CalculateFieldPoints(Cordinate fieldCord, FieldStateEnum activePlayer, IReadOnlyList <IReadOnlyList <Field> > board, int boardHeight, int boardWidth) { var points = 0; var pointsTmp = 0; //UP var x = fieldCord.X; var y = fieldCord.Y; pointsTmp = 0; do { y--; } while (!SetPoints(ref pointsTmp, x, y, boardHeight, boardWidth, activePlayer, board)); //UP-RIGHT x = fieldCord.X; y = fieldCord.Y; points += pointsTmp; pointsTmp = 0; do { y--; x++; } while (!SetPoints(ref pointsTmp, x, y, boardHeight, boardWidth, activePlayer, board)); //RIGHT x = fieldCord.X; y = fieldCord.Y; points += pointsTmp; pointsTmp = 0; do { x++; } while (!SetPoints(ref pointsTmp, x, y, boardHeight, boardWidth, activePlayer, board)); //DOWN RIGHT x = fieldCord.X; y = fieldCord.Y; points += pointsTmp; pointsTmp = 0; do { y++; x++; } while (!SetPoints(ref pointsTmp, x, y, boardHeight, boardWidth, activePlayer, board)); //DOWN y++ x = fieldCord.X; y = fieldCord.Y; points += pointsTmp; pointsTmp = 0; do { y++; } while (!SetPoints(ref pointsTmp, x, y, boardHeight, boardWidth, activePlayer, board)); //DOWN LEFT x = fieldCord.X; y = fieldCord.Y; points += pointsTmp; pointsTmp = 0; do { y++; x--; } while (!SetPoints(ref pointsTmp, x, y, boardHeight, boardWidth, activePlayer, board)); //LEFT x-- x = fieldCord.X; y = fieldCord.Y; points += pointsTmp; pointsTmp = 0; do { x--; } while (!SetPoints(ref pointsTmp, x, y, boardHeight, boardWidth, activePlayer, board)); // UP-LEFT x = fieldCord.X; y = fieldCord.Y; points += pointsTmp; pointsTmp = 0; do { y--; x--; } while (!SetPoints(ref pointsTmp, x, y, boardHeight, boardWidth, activePlayer, board)); points += pointsTmp; return(points); }
private static SkillResponse SetTheFieldState(SkillResponse response, IntentRequest intentRequest, FieldStateEnum fieldState) { if (intentRequest.Intent.Slots.TryGetValue("site", out var siteSlot) && intentRequest.Intent.Slots.TryGetValue("field", out var fieldSlot)) { string message; if (!string.IsNullOrEmpty(siteSlot.Value) && !string.IsNullOrEmpty(fieldSlot.Value)) { var siteName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(siteSlot.Value.ToLower()); var fieldName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(fieldSlot.Value.ToLower()); var allFields = WebService.GetSites().FirstOrDefault(x => x.Name == siteName)?.Fields; var selectedfield = allFields.Where(x => x.Name == fieldName).Select(y => y.Id).FirstOrDefault(); var result = WebService.SetFieldState(selectedfield, fieldState); if (result.IsSuccessful) { message = $"Current Status of {fieldSlot.Value} is {fieldState.ToString()} state"; } else { message = result.Content; } response = ResponseBuilder.Tell(message); } } return(response); }