private bool AssignPlayerActions(Round round, RoundPlayer throwerPlayer) { //TODO: Support multiple winner bool foundActionForUser = false; var roundTiles = round.RoundTiles; //there will be action except for the player that throw the tile var players = round.RoundPlayers.Where(rp => rp.GamePlayer.Player.UserName != throwerPlayer.GamePlayer.Player.UserName); var boardActiveTile = roundTiles.FirstOrDefault(rt => rt.Status == TileStatus.BoardActive); if (boardActiveTile == null) { throw new RestException(HttpStatusCode.NotFound, new { Round = "Could not find active board tile" }); } var nextPlayer = RoundHelper.GetNextPlayer(round.RoundPlayers, throwerPlayer.Wind); //there could be more than one possible action given user's turn and the tile's thrown foreach (var player in players) { var userTiles = roundTiles.Where(rt => rt.Owner == player.GamePlayer.Player.UserName); List <RoundPlayerAction> rpas = new List <RoundPlayerAction>(); if (RoundHelper.DetermineIfUserCanWin(round, player, _pointCalculator)) { rpas.Add(new RoundPlayerAction { ActionType = ActionType.Win, ActionStatus = ActionStatus.Inactive }); } if (DetermineIfUserCanKongFromBoard(userTiles, boardActiveTile)) { rpas.Add(new RoundPlayerAction { ActionType = ActionType.Kong, ActionStatus = ActionStatus.Inactive }); } if (DetermineIfUserCanPong(userTiles, boardActiveTile)) { rpas.Add(new RoundPlayerAction { ActionType = ActionType.Pong, ActionStatus = ActionStatus.Inactive }); } if (player.GamePlayer.Player.UserName == nextPlayer.GamePlayer.Player.UserName) { var nextPlayerTiles = round.RoundTiles.Where(rt => rt.Owner == nextPlayer.GamePlayer.Player.UserName); if (DetermineIfUserCanChow(nextPlayerTiles, boardActiveTile)) { rpas.Add(new RoundPlayerAction { ActionType = ActionType.Chow, ActionStatus = ActionStatus.Inactive }); } } if (rpas.Count() > 0) { foundActionForUser = true; foreach (var pa in rpas) { player.RoundPlayerActions.Add(pa); } } } return(foundActionForUser); }