private void MapCards(FutureTricks data, Action<Suit, Rank, int> mapper) { for (int i = 0; i < data.FutureCards.Count; i++) { var card = data.FutureCards.Cards[i]; mapper(card.Suit, card.Rank, data.Scores[i]); } }
public FutureTricks SolveBoardPbn(BridgeGame game, int target, int solutions, int mode) { if (game.CurrentTrick.Deck.Count > 3) { throw new ArgumentException("Invalid current trick cards count", "CurrentTrick.Deck.Count"); } var deal = new DealPbn(); deal.trump = game.Contract.Trump.Order; deal.first = game.CurrentTrick.TrickDealer.Order; deal.currentTrickRank = new int[3]; deal.currentTrickSuit = new int[3]; for (int i = 0; i < game.CurrentTrick.Deck.Count; i++) { var card = game.CurrentTrick.Deck.Cards[i]; deal.currentTrickRank[i] = card.Rank.Score; deal.currentTrickSuit[i] = card.Suit.Order; } deal.remainCards = DdsHelper.PbnStringToChars(BridgeHelper.ToPbn(game)); var ddsResult = new Integration.FutureTricks(); //TODO: Support mutiple threads. var res = DdsImport.SolveBoardPBN(deal, target, solutions, mode, ref ddsResult, 0); if (res != 1) { throw new DdsSolveBoardException(res); } var result = new FutureTricks(); result.Cards = ddsResult.cards; result.Nodes = ddsResult.nodes; result.Scores = ddsResult.score.ToList(); for (int i = 0; i < 13; i++) { if (ddsResult.rank[i] != 0) { var rank = new Rank(ddsResult.rank[i]); var suit = new Suit(ddsResult.suit[i]); result.FutureCards.Cards.Add(new Card(rank, suit)); } else { break; } } return(result); }
public FutureTricks SolveBoardPbn(BridgeGame game, int target, int solutions, int mode) { if (game.CurrentTrick.Deck.Count > 3) throw new ArgumentException("Invalid current trick cards count", "CurrentTrick.Deck.Count"); var deal = new DealPbn(); deal.trump = game.Contract.Trump.Order; deal.first = game.CurrentTrick.TrickDealer.Order; deal.currentTrickRank = new int[3]; deal.currentTrickSuit = new int[3]; for (int i = 0; i < game.CurrentTrick.Deck.Count; i++) { var card = game.CurrentTrick.Deck.Cards[i]; deal.currentTrickRank[i] = card.Rank.Score; deal.currentTrickSuit[i] = card.Suit.Order; } deal.remainCards = DdsHelper.PbnStringToChars(BridgeHelper.ToPbn(game)); var ddsResult = new Integration.FutureTricks(); //TODO: Support mutiple threads. var res = DdsImport.SolveBoardPBN(deal, target, solutions, mode, ref ddsResult, 0); if (res != 1) throw new DdsSolveBoardException(res); var result = new FutureTricks(); result.Cards = ddsResult.cards; result.Nodes = ddsResult.nodes; result.Scores = ddsResult.score.ToList(); for (int i = 0; i < 13; i++) { if (ddsResult.rank[i] != 0) { var rank = new Rank(ddsResult.rank[i]); var suit = new Suit(ddsResult.suit[i]); result.FutureCards.Cards.Add(new Card(rank, suit)); } else { break; } } return result; }