private double GetHeuristicHandStrength(Player currentPlayer, Suits trump) { double predictionOfTricks = 0; foreach(Card card in currentPlayer.hand.Cards) { predictionOfTricks += (int)card.Number - 1;//2 is card rank 1, 3 is card rank 2, ..., king is card rank 12, ace is card rank 13 if(card.Suit == trump) { predictionOfTricks += 39;//trump is stronger than all other suits(13 * 3 = 39) } } //return predictionOfTricks / 52;//divide by total amount of cards(chance of card winning a trick) this works better for worse cards return predictionOfTricks / 598 * 13;//all trumpvalues added equals 598(max value of cards in hand) this works better for better cards //double heuristicHandStrength = 0; //for (int i = 0; i < 13; i++) //{ // heuristicHandStrength += (int)currentPlayer.hand.Cards[i].Number; // if (currentPlayer.hand.Cards[i].Suit == trump) // { // heuristicHandStrength += 13; // } //} //sum of all cardStrengths = (2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14) * 3 + (15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27) = 585 //your handStrength / sum of all cardStrengths * #tricks = statistical average number of tricks you will make in unlimited # games //return heuristicHandStrength / 273 * 13; 273 is sum of all trump values }
public override void ProcessOtherPlayerAction(Player otherPlayer, Action action) { if (Round.GameCase == Case.UNDECIDED) switch (action) { case Action.PASS: { memory[otherPlayer].minInitialHandStrength = 0; memory[otherPlayer].maxInitialHandStrength = 4; break; } case Action.ASK: { memory[otherPlayer].minInitialHandStrength = 5; memory[otherPlayer].maxInitialHandStrength = 9; break; } case Action.JOIN: { memory[otherPlayer].minInitialHandStrength = 3; memory[otherPlayer].maxInitialHandStrength = 9; break; } case Action.ABONDANCE: { memory[otherPlayer].minInitialHandStrength = 10; memory[otherPlayer].maxInitialHandStrength = 13; break; } } }
public GameController(Player[] players, IReferee referee) { this.players = players; this.PlayersLeft = players.ToList(); this.referee = referee; pile = new ObservableCollection<Card>(); }
private GameManager InitialiseTest() { var players = new Player[] { new Player("C1", 0), new Player("C2", 1), new Player("C3", 2), new Player("C4", 3) }; var gameManager = new GameManager(players, 13, new AIBidType[] { AIBidType.BASIC, AIBidType.BASIC, AIBidType.BASIC, AIBidType.BASIC }, new AIGameType[] { AIGameType.MEMORY, AIGameType.MEMORY, AIGameType.MEMORY, AIGameType.MEMORY, }); return gameManager; }
public override bool AfterDealCheck(Player[] players) { //What about Trump? Need some way to give Trump, or decide troel doesn't change Trump. foreach (Player player in players) if (player.hand.Cards.Where(c => c.Number == Numbers.ACE).Count() >= 3) return true; return false; }
public void DealCards(Player[] players) { DeckCollection cardCollection = new DeckCollection(); cardCollection.initialise(); cardCollection.shuffle(); int nCards = cardCollection.Count / players.Length; foreach (var player in players) player.hand.AddCards(cardCollection.Draw(nCards)); }
public Round(Player[] players) { Players = players; foreach (Player player in Players) player.clearTricks(); phase1 = new DealAndBidNormal(Players); RoundInProgress = true; //LetAIHandleFirstPhase(); }
private static int GetHandStrength(Player player, Suits trump) { int handStrength = 0; var cards = player.hand.Cards; var kingsAndAces = cards.Where(c => c.Number == Numbers.ACE || c.Number == Numbers.KING); handStrength += kingsAndAces.Count(); var trumps = cards.Where(c => c.Suit == trump); handStrength += trumps.Except(kingsAndAces).Count(); return handStrength; }
public GameManager(Player[] players, int roundsToPlay, AIBidType[] bidAITypes, AIGameType[] gameAITypes) { Players = players; aiPlayers = new Dictionary<Player, AI>(); for (int i = 0; i < 4; i++) { aiPlayers.Add(players[i], AIFactory.CreateAI(players[i], this, bidAITypes[i], gameAITypes[i])); } RoundsToPlay = roundsToPlay; RoundNumber = 1; IsGameInProgress = true; Round = new Round(players); }
public static IBidAI CreateBidAI(Player player, GameManager game, AIBidType type) { switch (type) { case AIBidType.BASIC: return new BaseBidAI(player, game); case AIBidType.CAUTIOUS: return new CautiousBidAI(player, game); case AIBidType.SIMGAME: return new SimulateGameBidAI(player, game); case AIBidType.OMNISCIENT: return new BidSearchAI(game); } throw new ApplicationException(); }
public override void ProcessOtherPlayerCard(Player otherPlayer, Card card) { if (otherPlayer != player) { if (Round.Pile.Count > 0) { var leadCard = Round.Pile[0]; if (leadCard.Suit != card.Suit) memory[otherPlayer].NoCardsOfSuitLeft(leadCard.Suit); } if (card.Suit == Round.Trump) trumpsPlayed++; } playedCards.Add(card); playedCardsByPlayer[otherPlayer].Add(card); }
public override Team[] Teams(Player[] players) { foreach (Player player in players) { int aces = player.hand.Cards.Where(c => c.Number == Numbers.ACE).Count(); if (aces >= 3) { selectedPlayers.Add(player); if (aces == 3) { foreach (Player playerTwo in players.Except(selectedPlayers)) { if (playerTwo.hand.Cards.Where(c => c.Number == Numbers.ACE).Count() > 0) { selectedPlayers.Add(playerTwo); break; } } } else if (aces == 4) { var playerOneHearts = player.hand.Cards.Where(c => c.Suit == Suits.HEARTS); Numbers highestHeart = Numbers.KING; while (playerOneHearts.Any(c => c.Number == highestHeart)) { highestHeart--; } foreach (Player p in players.Except(selectedPlayers)) { if (p.hand.Cards.Any(c => c.Suit == Suits.HEARTS && c.Number == highestHeart)) { selectedPlayers.Add(p); break; } } } break; } } return new Team[] { new Team(selectedPlayers.ToArray(), 8), new Team(players.Except(selectedPlayers).ToArray(), 6) }; }
public static IGameAI CreateGameAI(Player player, GameManager game, AIGameType type) { switch (type) { case AIGameType.BASIC: return new BaseGameAI(player, game); case AIGameType.MEMORY: return new MemoryAI(player, game); case AIGameType.PERFECTMEMORY: return new PerfectMemoryAI(player, game); case AIGameType.BRUTEFORCE: return new BruteForceAI(player, game); case AIGameType.OMNISCIENT: return new OmniscentSearchAI(game, new StandardReferee()); } throw new ApplicationException(); }
public static Action GetAction(Player player, IEnumerable<Action> possibleActions, Suits trump) { int handStrength = GetHandStrength(player, trump); if (!possibleActions.Contains(Action.PASS)) { switch (trump) { case Suits.HEARTS: return Action.HEARTS; case Suits.DIAMONDS: return Action.DIAMONDS; case Suits.SPADES: return Action.SPADES; case Suits.CLUBS: return Action.CLUBS; default: return 0; } } if (handStrength >= 9) { if (possibleActions.Contains(Action.ABONDANCE)) return Action.ABONDANCE; } if (handStrength >= 5) { if (possibleActions.Contains(Action.ASK)) return Action.ASK; if (possibleActions.Contains(Action.ALONE)) return Action.ALONE; } if (handStrength >= 3) { if (possibleActions.Contains(Action.JOIN)) return Action.JOIN; } return Action.PASS; }
private void init() { playerA = null; playerB = null; askForTrump = false; GameCase = Case.UNDECIDED; currentSpecial = 0; specialGameCases = SpecialGameCaseFactory.GetDictionary(); CurrentPlayer = players[0]; actionsDone = 0; passedPlayers = new Dictionary<Player, bool>(); foreach (var player in players) { passedPlayers.Add(player, false); player.hand.Cards.Clear(); } DealCards(); }
private void SetHandsToTestConfiguration(Player[] players) { players[0].hand.Cards.Clear(); players[1].hand.Cards.Clear(); players[2].hand.Cards.Clear(); players[3].hand.Cards.Clear(); players[0].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.KING)); players[0].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.JACK)); players[0].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.THREE)); players[0].hand.Cards.Add(new Card(Suits.SPADES, Numbers.THREE)); players[1].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.FOUR)); players[1].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.NINE)); players[1].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.SEVEN)); players[1].hand.Cards.Add(new Card(Suits.SPADES, Numbers.FOUR)); players[2].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.ACE)); players[2].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.FIVE)); players[2].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.QUEEN)); players[2].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.TWO)); players[3].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.TEN)); players[3].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.EIGHT)); players[3].hand.Cards.Add(new Card(Suits.HEARTS, Numbers.SIX)); players[3].hand.Cards.Add(new Card(Suits.SPADES, Numbers.FIVE)); }
public Team(Player[] players, int objective) { this.players = players; this.objective = objective; }
public WhistController(Player[] players, Player FirstPlayer, Suits trump, IReferee referee) : base(players, referee) { this.trump = trump; for (int i = 0; i < players.Length; i++) if (players[i] == FirstPlayer) { currentPlayer = i; break; } CardPlayedByPlayer = new Dictionary<Player, Card>(); foreach (Player player in players) CardPlayedByPlayer.Add(player, null); }
public ObservableCollection<Card> GetPlayerCards(Player player) { return player.hand.Cards; }
protected override int GetHandStrength(Suits trump) { Player[] CopyPlayers = new Player[] { new Player("copy0", 0), new Player("copy1", 1), new Player("copy2", 2), new Player("copy3", 3) }; Round simRound; do { simRound = new Round(CopyPlayers); } while (simRound.GameCase != Case.UNDECIDED); for (int i = 0; i < 4; i++) { CopyPlayers[i].hand.Cards.Clear(); foreach (var card in game.Players[i].hand.Cards) CopyPlayers[i].hand.AddCard(card); } while (simRound.InBiddingPhase) { if (simRound.CurrentPlayer == CopyPlayers.Where(cp => cp.Number == player.Number).Single()) { if (simRound.BiddingGetPossibleActions().Contains(Action.ABONDANCE)) simRound.BiddingDoAction(Action.ABONDANCE); else { switch (trump) { case Suits.HEARTS: { simRound.BiddingDoAction(Action.HEARTS); break; } case Suits.DIAMONDS: { simRound.BiddingDoAction(Action.DIAMONDS); break; } case Suits.SPADES: { simRound.BiddingDoAction(Action.SPADES); break; } case Suits.CLUBS: { simRound.BiddingDoAction(Action.CLUBS); break; } default: break; } } simRound.BiddingDoAction(Action.ASK); } else simRound.BiddingDoAction(Action.PASS); } simRound.EndBiddingRound(); while (simRound.InTrickPhase) { while (simRound.TrickInProgress) simRound.PlayCard(SimpleGameAI.GetMove(simRound)); simRound.EndTrick(); } return CopyPlayers.Where(cp => cp.Number == player.Number).Single().Tricks; }
/// <summary> /// When a player (including this one) plays a card, this function should be called so it is made aware of the other player's move. /// </summary> public void ProcessOtherPlayerCard(Player otherPlayer, Card card) { GameAI.ProcessOtherPlayerCard(otherPlayer, card); }
/// <summary> /// When a player (including this one) submits an action, this function should be called so it is made aware of the other player's action. /// </summary> public void ProcessOtherPlayerAction(Player otherPlayer, Action action) { GameAI.ProcessOtherPlayerAction(otherPlayer, action); }
/// <summary> /// Returns the AI corresponding to the given Player. /// </summary> public AI GetAI(Player player) { return aiPlayers[player]; }
public void ProcessOtherPlayerCard(Player otherPlayer, Card card) { }
public void ProcessOtherPlayerAction(Player otherPlayer, GameLogic.ControlEntities.Action action) { }
public CautiousBidAI(Player player, GameManager game) : base(player, game) { }
public SimulateGameBidAI(Player player, GameManager game) : base(player, game) { }
/// <summary> /// In the trick phase, returns which card was played by a certain player. /// </summary> public Card CardPlayedByPlayer(Player player) { return phase2?.CardPlayedByPlayer[player]; }
public BruteForceAI(Player player, GameManager game) { this.player = player; this.game = game; }
public AI(Player player, IBidAI bidAI, IGameAI gameAI) { this.player = player; BidAI = bidAI; GameAI = gameAI; }