private void DealwithStraight(kindsOfCombination combination, int CardPlayer) { for (int i = 0; i < Hand.Count; i++) { if (Chosen.Count == 0) { if (Hand[i].rank > (Rank)combination.index) { Chosen.Add(Hand[i]); } } else if (Hand[i].rank == Chosen.Last().rank + 1 && Hand[i].rank < (Rank)15) { Chosen.Add(Hand[i]); } else if (Hand[i].rank > Chosen.Last().rank + 1) { Chosen.Clear(); } if (Chosen.Count == combination.assist) { break; } } if (Chosen.Count != combination.assist) { Chosen.Clear(); } if (Chosen.Count == 0 && combination.assist >= 7) //use bomb { DealwithBomb(combination, CardPlayer); } }
/* * public void DiscardCard(Card card) * { * Hand.Remove(card); * if (HasWon && OnPlayerHasWon != null) * OnPlayerHasWon(this, new PlayerEventArgs { Player = this, State = PlayerState.Winner }); * if (OnCardDiscarded != null) * OnCardDiscarded(this, new CardEventArgs { Card = card }); * } */ public void play(kindsOfCombination k) { kindsOfCombination result = validCards(); if (result == null) { return; } if (!result.biggerThan(k)) { return; } for (int i = 0; i < Chosen.Count; i++) { Hand.Remove(Chosen[i]); } CardEventArgs args = new CardEventArgs(); args.Card = new Card((Suit)1, (Rank)3); args.Cards = (Cards)Chosen.Clone(); args.index = Index; args.CurrentCombination = result; OnCardPlayed(this, args); Chosen.Clear(); if (HasWon && OnPlayerHasWon != null) { OnPlayerHasWon(this, new PlayerEventArgs { Player = this, State = PlayerState.Winner }); } }
public bool biggerThan(kindsOfCombination koc) { if (koc == null) return true; if (koc.kind != Kind.Bomb && this.kind == Kind.Bomb) return true; return koc.kind == this.kind && koc.assist == this.assist&&this.index>koc.index ; }
private void DealwithSingle(kindsOfCombination combination, int CardPlayer) { foreach (Card c in Hand) { if (c.rank > (Rank)combination.index) { Chosen.Add(c); break; } } }
public void Perform(kindsOfCombination combination, int CardPlayer) { switch (Skill) { case ComputerSkillLevel.Easy: decision(combination,CardPlayer);//DrawCard(deck); break; default: pass(0);//DrawBestCard(deck, availableCard, (Skill == ComputerSkillLevel.Hard)); break; } }
private void DealwithPair(kindsOfCombination combination, int CardPlayer) { for (int i = 0; i < Hand.Count - 1; i++) { if (Hand[i].rank == Hand[i + 1].rank && Hand[i].rank > (Rank)combination.index) { Chosen.Add(Hand[i]); Chosen.Add(Hand[i + 1]); break; } } }
public bool biggerThan(kindsOfCombination koc) { if (koc == null) { return(true); } if (koc.kind != Kind.Bomb && this.kind == Kind.Bomb) { return(true); } return(koc.kind == this.kind && koc.assist == this.assist && this.index > koc.index); }
public void Perform(kindsOfCombination combination, int CardPlayer) { switch (Skill) { case ComputerSkillLevel.Easy: decision(combination, CardPlayer);//DrawCard(deck); break; default: pass(0);//DrawBestCard(deck, availableCard, (Skill == ComputerSkillLevel.Hard)); break; } }
private void DealwithThree(kindsOfCombination combination, int CardPlayer) { for (int i = 0; i < Hand.Count - 2; i++) { if (Hand[i].rank == Hand[i + 1].rank && Hand[i].rank == Hand[i + 2].rank && Hand[i].rank > (Rank)combination.index) { Chosen.Add(Hand[i]); Chosen.Add(Hand[i + 1]); Chosen.Add(Hand[i + 2]); break; } } if (combination.assist == 1) { for (int i = 0; i < Hand.Count; i++) { if (!Chosen.Contains(Hand[i])) { Chosen.Add(Hand[i]); break; } } if (Chosen.Count != 4) { Chosen.Clear(); } } else if (combination.assist == 2) { for (int i = 0; i < Hand.Count - 1; i++) { if (!Chosen.Contains(Hand[i]) && !Chosen.Contains(Hand[i + 1])) { Chosen.Add(Hand[i]); Chosen.Add(Hand[i + 1]); break; } } if (Chosen.Count != 5) { Chosen.Clear(); } } if (Chosen.Count == 0 && combination.index >= 10) //use bomb { DealwithBomb(combination, CardPlayer); } }
/* * public void PerformDiscard(Deck deck) * { * switch (Skill) * { * case ComputerSkillLevel.Easy: * int discardIndex = _random.Next(Hand.Count); * DiscardCard(Hand[discardIndex]); * break; * default: * DiscardWorstCard(); * break; * } * } */ private void decision(kindsOfCombination combination, int CardPlayer) { if (Index == CardPlayer) { combination = null; } if (combination == null) //free to play { Chosen.Add(Hand[0]); } else { if (combination.kind == Kind.Single) { DealwithSingle(combination, CardPlayer); } else if (combination.kind == Kind.Pair) { DealwithPair(combination, CardPlayer); } else if (combination.kind == Kind.Three) { DealwithThree(combination, CardPlayer); } else if (combination.kind == Kind.Bomb) { DealwithBomb(combination, CardPlayer); } else if (combination.kind == Kind.Straight) { DealwithStraight(combination, CardPlayer); } else if (combination.kind == Kind.StraightPair) { DealwithStraightPair(combination, CardPlayer); } } if (Chosen.Count > 0) { play(null); } else { pass(CardPlayer); } }
private void DealwithStraightPair(kindsOfCombination combination, int CardPlayer) { bool chooseFirst = true; for (int i = 0; i < Hand.Count - 3; i++) { if (Chosen.Count == 0) { if (Hand[i].rank > (Rank)combination.index) { Chosen.Add(Hand[i]); } } else if (chooseFirst && Hand[i].rank == Chosen.Last().rank&& Hand[i].rank < (Rank)15) { chooseFirst = false; Chosen.Add(Hand[i]); } else if (chooseFirst && Hand[i].rank > Chosen.Last().rank&& Hand[i].rank < (Rank)15) { Chosen.Clear(); } else if (!chooseFirst && Hand[i].rank == Chosen.Last().rank + 1 && Hand[i].rank < (Rank)15) { chooseFirst = true; Chosen.Add(Hand[i]); } else if (!chooseFirst && Hand[i].rank > Chosen.Last().rank + 1) { Chosen.Clear(); } if (Chosen.Count == combination.assist) { break; } } if (Chosen.Count != combination.assist * 2) { Chosen.Clear(); } if (Chosen.Count == 0 && combination.assist >= 4) //use bomb { DealwithBomb(combination, CardPlayer); } }
private void DealwithBomb(kindsOfCombination combination, int CardPlayer) { for (int i = 0; i < Hand.Count - 3; i++) { if (Hand[i].rank == Hand[i + 1].rank && Hand[i].rank == Hand[i + 2].rank && Hand[i].rank == Hand[i + 3].rank && Hand[i].rank > (Rank)combination.index) { Chosen.Add(Hand[i]); Chosen.Add(Hand[i + 1]); Chosen.Add(Hand[i + 2]); Chosen.Add(Hand[i + 3]); break; } } if (Chosen.Count != 4 && Hand.Count >= 2 && Hand[Hand.Count - 1].rank == Rank.Joker && Hand[Hand.Count - 2].rank == Rank.joker) { Chosen.Add(Hand[Hand.Count - 1]); Chosen.Add(Hand[Hand.Count - 2]); } }
private void DealwithBomb(kindsOfCombination combination, int CardPlayer) { for (int i = 0; i < Hand.Count - 3; i++) { if (Hand[i].rank == Hand[i + 1].rank && Hand[i].rank == Hand[i + 2].rank && Hand[i].rank == Hand[i + 3].rank && Hand[i].rank > (Rank)combination.index) { Chosen.Add(Hand[i]); Chosen.Add(Hand[i + 1]); Chosen.Add(Hand[i + 2]); Chosen.Add(Hand[i + 3]); break; } } if (Chosen.Count != 4 && Hand.Count >= 2 && Hand[Hand.Count - 1].rank == Rank.Joker && Hand[Hand.Count - 2].rank == Rank.joker) { Chosen.Add(Hand[Hand.Count - 1]); Chosen.Add(Hand[Hand.Count - 2]); } }
/* public void DiscardCard(Card card) { Hand.Remove(card); if (HasWon && OnPlayerHasWon != null) OnPlayerHasWon(this, new PlayerEventArgs { Player = this, State = PlayerState.Winner }); if (OnCardDiscarded != null) OnCardDiscarded(this, new CardEventArgs { Card = card }); } */ public void play(kindsOfCombination k) { kindsOfCombination result = validCards(); if (result == null) return; if (!result.biggerThan(k)) return; for (int i = 0; i < Chosen.Count;i++ ) Hand.Remove(Chosen[i]); CardEventArgs args = new CardEventArgs(); args.Card = new Card((Suit)1,(Rank)3); args.Cards = (Cards)Chosen.Clone(); args.index = Index; args.CurrentCombination = result; OnCardPlayed(this, args); Chosen.Clear(); if (HasWon && OnPlayerHasWon != null) OnPlayerHasWon(this, new PlayerEventArgs { Player = this, State = PlayerState.Winner }); }
private void DealwithSingle(kindsOfCombination combination, int CardPlayer) { foreach (Card c in Hand) { if (c.rank > (Rank)combination.index) { Chosen.Add(c); break; } } }
private void DealwithStraight(kindsOfCombination combination, int CardPlayer) { for (int i = 0; i < Hand.Count ; i++) { if (Chosen.Count == 0) { if (Hand[i].rank > (Rank)combination.index) Chosen.Add(Hand[i]); } else if (Hand[i].rank == Chosen.Last().rank + 1 && Hand[i].rank < (Rank)15) Chosen.Add(Hand[i]); else if (Hand[i].rank > Chosen.Last().rank + 1) Chosen.Clear(); if (Chosen.Count == combination.assist) break; } if (Chosen.Count != combination.assist) Chosen.Clear(); if (Chosen.Count == 0 && combination.assist >= 7) //use bomb DealwithBomb(combination, CardPlayer); }
private void DealwithStraightPair(kindsOfCombination combination, int CardPlayer) { bool chooseFirst = true; for (int i = 0; i < Hand.Count - 3; i++) { if (Chosen.Count == 0) { if (Hand[i].rank > (Rank)combination.index) Chosen.Add(Hand[i]); } else if (chooseFirst&&Hand[i].rank == Chosen.Last().rank && Hand[i].rank < (Rank)15) { chooseFirst = false; Chosen.Add(Hand[i]); } else if (chooseFirst && Hand[i].rank > Chosen.Last().rank && Hand[i].rank < (Rank)15) Chosen.Clear(); else if (!chooseFirst && Hand[i].rank == Chosen.Last().rank + 1 && Hand[i].rank < (Rank)15) { chooseFirst = true; Chosen.Add(Hand[i]); } else if (!chooseFirst&&Hand[i].rank > Chosen.Last().rank + 1) Chosen.Clear(); if (Chosen.Count == combination.assist) break; } if (Chosen.Count != combination.assist*2) Chosen.Clear(); if (Chosen.Count == 0 && combination.assist >= 4) //use bomb DealwithBomb(combination, CardPlayer); }
private void DealwithThree(kindsOfCombination combination, int CardPlayer) { for (int i = 0; i < Hand.Count - 2; i++) { if (Hand[i].rank == Hand[i + 1].rank && Hand[i].rank == Hand[i + 2].rank && Hand[i].rank > (Rank)combination.index) { Chosen.Add(Hand[i]); Chosen.Add(Hand[i + 1]); Chosen.Add(Hand[i + 2]); break; } } if (combination.assist == 1) { for (int i = 0; i < Hand.Count; i++) { if (!Chosen.Contains(Hand[i])) { Chosen.Add(Hand[i]); break; } } if (Chosen.Count != 4) Chosen.Clear(); } else if (combination.assist == 2) { for (int i = 0; i < Hand.Count - 1; i++) { if (!Chosen.Contains(Hand[i]) && !Chosen.Contains(Hand[i + 1])) { Chosen.Add(Hand[i]); Chosen.Add(Hand[i + 1]); break; } } if (Chosen.Count != 5) Chosen.Clear(); } if (Chosen.Count == 0 && combination.index >= 10) //use bomb DealwithBomb(combination, CardPlayer); }
private void DealwithPair(kindsOfCombination combination, int CardPlayer) { for (int i = 0; i < Hand.Count - 1; i++) { if (Hand[i].rank == Hand[i + 1].rank && Hand[i].rank > (Rank)combination.index) { Chosen.Add(Hand[i]); Chosen.Add(Hand[i + 1]); break; } } }
/* public void PerformDiscard(Deck deck) { switch (Skill) { case ComputerSkillLevel.Easy: int discardIndex = _random.Next(Hand.Count); DiscardCard(Hand[discardIndex]); break; default: DiscardWorstCard(); break; } } */ private void decision(kindsOfCombination combination, int CardPlayer) { if(Index == CardPlayer) combination=null; if (combination == null) //free to play Chosen.Add(Hand[0]); else { if (combination.kind == Kind.Single) DealwithSingle(combination, CardPlayer); else if (combination.kind == Kind.Pair) DealwithPair(combination, CardPlayer); else if (combination.kind == Kind.Three) DealwithThree(combination, CardPlayer); else if (combination.kind == Kind.Bomb) DealwithBomb(combination, CardPlayer); else if (combination.kind == Kind.Straight) DealwithStraight(combination, CardPlayer); else if (combination.kind == Kind.StraightPair) DealwithStraightPair(combination, CardPlayer); } if (Chosen.Count > 0) play(null); else pass(CardPlayer); }