private bool playCheck(List <Card> board, int n, Bid bid) { try { cards.ElementAt(n); if (board.Count == 0) { return(true); } if (cards.ElementAt(n).getSuit() == board.ElementAt(0).getSuit()) { return(true); } if (board.ElementAt(0).doYouHaveSuit(cards)) { return(false); } if (cards.ElementAt(n).getSuit() == bid.getSuit()) { /*if (cards.elementAt(n).isItBiggest(board, true)) * return true; * else * return (!cards.elementAt(n).isItBiggest(cards, true));*/ return(true); } Card card = new Card(bid.getSuit(), Value.ACE); return(!card.doYouHaveSuit(cards)); } catch (Exception) { Network.SendPrivate(this, "Out of range!"); return(false); } }
private int whoWon(List <Card> board) { int winner = -1; for (int i = 0; i != board.Count; i += 1) { if (i == 0) { winner = i; } else { if (board.ElementAt(i).getSuit() == bid.getSuit()) { if (board.ElementAt(winner).getSuit() == bid.getSuit()) { if (Array.IndexOf(Card.withAsset, board.ElementAt(i).getValue()) > Array.IndexOf(Card.withAsset, board.ElementAt(winner).getValue())) { winner = i; } } else { winner = i; } } else if (board.ElementAt(winner).getSuit() != bid.getSuit() && Array.IndexOf(Card.withAsset, board.ElementAt(i).getValue()) > Array.IndexOf(Card.withoutAsset, board.ElementAt(winner).getValue())) { winner = i; } } } Network.SendAll(players, " -- Player " + winner + " won this trick! -- "); players.ElementAt(winner).addWonTrick(board); return(winner); }
public Bid auction(Bid bid) { int n; bool end = false; if (bid.getAmount() != 0) { Network.SendPrivate(this, "The actual bill is " + bid.getAmount() + " " + bid.getSuit() + " from " + bid.getTeam() + " team.\n"); } else { Network.SendPrivate(this, "You are the first one to bid!"); } Network.SendPrivate(this, "Player " + id + " turn to bid:"); while (!end) { string str = "What do you want to do? "; switch (bid.getStatus()) { case Status.AMOUNT: str += "1->bid "; goto case Status.CAPOT; case Status.CAPOT: str += "2->coinche "; goto case Status.COINCH; case Status.COINCH: if (bid.getStatus() == Status.COINCH) { str += "3->surcoinche "; } break; case Status.SURCOINCH: Network.SendPrivate(this, "You can't bid anymore."); passed = true; return(bid); } if (bid.getStatus() == Status.AMOUNT) { str += "4->capot "; } Network.SendPrivate(this, str + "5->pass"); n = WaitForMessage(); end = true; switch (n) { case 1: Network.SendPrivate(this, "What is the amount of your bid ? (>= " + (bid.getAmount() == 0 ? 80 : bid.getAmount() + 10) + ")"); if (!bid.setAmount(WaitForMessage()) || bid.getStatus() != Status.AMOUNT) { Network.SendPrivate(this, "Incorrect input"); end = false; break; } Network.SendPrivate(this, "What is the suit ? (0->CLUB | 1->DIAMOND | 2->HEART | 3->SPADE)"); n = WaitForMessage(); if (n < 0 || n > 3) { Network.SendPrivate(this, "Incorrect input"); end = false; break; } bid.setSuit(n); bid.setTeam(this.team); passed = false; break; case 2: if (bid.getStatus() != Status.AMOUNT && bid.getStatus() != Status.CAPOT) { Network.SendPrivate(this, "Incorrect input"); end = false; break; } bid.setStatus(Status.COINCH); passed = false; break; case 3: if (bid.getStatus() != Status.COINCH) { Network.SendPrivate(this, "Incorrect input"); end = false; break; } bid.setStatus(Status.SURCOINCH); passed = false; break; case 4: if (bid.getStatus() == Status.COINCH || bid.getStatus() == Status.SURCOINCH || bid.getStatus() == Status.CAPOT) { Network.SendPrivate(this, "Incorrect input"); end = false; break; } bid.setStatus(Status.CAPOT); bid.setTeam(team); passed = false; break; case 5: passed = true; break; default: Network.SendPrivate(this, "Incorrect input"); end = false; break; } } Network.SendPrivate(this, "Great!"); return(bid); }
public Card play(List <Card> board, Bid bid) { if (board.Count != 0) { Network.SendPrivate(this, "The current board is composed of :"); } foreach (Card i in board) { Network.SendPrivate(this, " - " + i.getValue() + " of " + i.getSuit()); } Network.SendPrivate(this, "Player " + this.id + "! Your turn! The asset's suit is " + bid.getSuit() + "."); Network.SendPrivate(this, "Your current cards:"); for (int j = 0; j != cards.Count; j += 1) { Network.SendPrivate(this, j + " -> " + cards.ElementAt(j).getValue() + " of " + cards.ElementAt(j).getSuit()); } Network.SendPrivate(this, "What is the number of the card you want to play?"); int n = 0; bool end = false; while (!end) { n = WaitForMessage(); if (!(end = playCheck(board, n, bid))) { Network.SendPrivate(this, "Wait... You can't play this card!"); } } Network.SendPrivate(this, "Great!"); Card res = cards.ElementAt(n); cards.Remove(cards.ElementAt(n)); return(res); }