HumanStrategy4c.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Odbc;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MauMau.Game.Interfaces;
  8. using MauMau.Logic;
  9. namespace MauMau.Game.Players
  10. {
  11. public class HumanStrategy4c : BasicPlayStrategy
  12. {
  13. public override GameAction GetNextAction(GameState state)
  14. {
  15. var standartAction = base.GetNextAction(state);
  16. if (standartAction != null)
  17. return standartAction;
  18. var returnAction = new GameAction();
  19. var playableCards =
  20. state.PlayerHands[_id].Where(m => m.CanPlayOnCard(state.TopCard, state.LastWishedColor)).ToList();
  21. if (state.PlayerHands[(_id + 1)%state.PlayerHands.Length].Count <= 2 &&
  22. playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Sieben) != null)
  23. {
  24. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  25. returnAction.PlayedCard = playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Sieben);
  26. return returnAction;
  27. }
  28. if (state.PlayerHands[(_id + 1)%state.PlayerHands.Length].Count <= 2 &&
  29. playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Acht) != null)
  30. {
  31. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  32. returnAction.PlayedCard = playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Acht);
  33. return returnAction;
  34. }
  35. if (state.PlayerHands[(_id)].Count(m => m.Number == Card.CardNumber.Bube) >=
  36. 1 + state.PlayerHands[(_id)].Count)
  37. {
  38. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  39. returnAction.PlayedCard = playableCards.FirstOrDefault(m => m.Number == Card.CardNumber.Bube);
  40. var cardsWithMostColor = state.PlayerHands[_id].OrderByDescending(m => m.Color).ToList();
  41. returnAction.WishedColor = cardsWithMostColor[0].Color;
  42. return returnAction;
  43. }
  44. var playableCardsWithoutBube = playableCards.Where(m => m.Number != Card.CardNumber.Bube).ToList();
  45. var mostColor = state.PlayerHands[_id].OrderByDescending(m => m.Color).ToList()[0].Color;
  46. if (playableCardsWithoutBube.Count == 0)
  47. {
  48. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  49. returnAction.PlayedCard = playableCards[Global.Random.Next(0, playableCards.Count - 1)];
  50. returnAction.WishedColor = mostColor;
  51. return returnAction;
  52. }
  53. var mostColorPlayableCardsWithoutBube = playableCardsWithoutBube.OrderBy(m => m.Color).ToList();
  54. var playableCardsMostColor =
  55. mostColorPlayableCardsWithoutBube.Where(m => m.Color == mostColorPlayableCardsWithoutBube[0].Color)
  56. .ToList();
  57. returnAction.ActionType = GameAction.GameActionType.PlayCard;
  58. returnAction.PlayedCard = playableCardsMostColor[Global.Random.Next(0, playableCardsMostColor.Count - 1)];
  59. return returnAction;
  60. }
  61. }
  62. }